cmWorkingDirectory: Failure to set working dir gives no error
A variety of places in the CMake code use the cmWorkingDirectory
class to set the current working directory in a RAII fashion. Unfortunately, that class does not provide any feedback if it fails to set the working directory (e.g. the directory doesn't exist) and the places where it is used do not appear to be doing any sort of checks on whether setting the working directory was successful.
An example of the effect of this is with test cases where if the specified WORKING_DIRECTORY
doesn't exist, the test simply runs in CMAKE_BINARY_DIR
instead with no warning. This is particularly problematic when the test is expecting to find files in certain locations relative to the working directory. The cmWorkingDirectory
class seems to be used fairly widely, so this problem will have fairly broad effects.
It isn't clear what the best way to address this is, whether to get the cmWorkingDirectory
constructor to throw an exception if it fails or to provide a success flag that clients of the class must check. I'd personally favour the use of exceptions here to force failures to be dealt with. Either way, all of the places where the class is used will need to be updated to handle failures.