llvm-project/llvm/cmake/modules/FileLock.cmake
arthurqiu 6655c53ff0
[cmake] Serialize native builds for Make generator (#121021)
The build system is fragile by allowing multiple invocation of
subprocess builds in the native folder for Make generator.

For example, during sub-invocation of the native llvm-config,
llvm-min-tblgen is also built. If there is another sub-invocation of the
native llvm-min-tblgen build running in parallel, they may overwrite
each other's build results, and may lead to errors like "Text file
busy".

This patch adds a cmake script that uses file lock to serialize all
native builds for Make generator.
2025-01-15 11:42:21 -08:00

10 lines
389 B
CMake

# CMake script that synchronizes process execution on a given file lock.
#
# Input variables:
# LOCK_FILE_PATH - The file to be locked for the scope of the process of this cmake script.
# COMMAND - The command to be executed.
file(LOCK ${LOCK_FILE_PATH})
string(REPLACE "@" ";" command_args ${COMMAND})
execute_process(COMMAND ${command_args} COMMAND_ERROR_IS_FATAL ANY)