CMake 3.28: Bug in OUTPUT_FILE with execute_process
Started a global build (~40k builds) using the release candidate and got a <1% incomplete rate. The report produced 7 builds that errored (none of them leaf builds). Each build failed to find some file produced by code generation. All but one failed for the same codegen so I tested that out and found the replication below. The other failure was the same issue but it was using Protobuf.
Replication
cmake_minimum_required(VERSION 3.27)
project(test C CXX)
set(OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/codegen")
set(TEST_COMMAND pwd -P)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
execute_process(COMMAND ${TEST_COMMAND} WORKING_DIRECTORY ${OUTPUT_DIR} OUTPUT_FILE "test.out")
Results
# CMake 3.27.6
$ tree -I CMakeFiles
.
├── build27
│ ├── CMakeCache.txt
│ ├── cmake_install.cmake
│ ├── codegen
│ │ └── test.out
│ └── Makefile
└── CMakeLists.txt
2 directories, 5 files
$ cat build27/codegen/test.out
/demo/build27/codegen
# CMake 3.28.0-rc1
$ tree -I CMakeFiles
.
├── build
│ ├── CMakeCache.txt
│ ├── cmake_install.cmake
│ ├── codegen
│ └── Makefile
├── CMakeLists.txt
└── test.out
2 directories, 5 files
$ cat test.out
/demo/build28/codegen
Possible Cause
Think it comes down to 5420639a
The old code sets the current working directory before opening the file, the new one just opens the file.