Skip to content

Commit ae18190

Browse files
starseekercshorler
authored andcommitted
Make copy more robust for parallel builds
This is a classic problem - the file copy will begin, the file will be "present" in some sense on the file system, and build steps that need it will begin - but they won't find what they actually need because the copy isn't fully executed. The standard approach for this is to add a second file which is only created after the first is done, and then make the target depend on the second file rather than the first.
1 parent 8c9b347 commit ae18190

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cmake/FindLEMON.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,24 @@ if (LEMON_EXECUTABLE)
126126
get_filename_component(_in_y_path ${LemonInput} ABSOLUTE)
127127
get_filename_component(_in_y_file ${LemonInput} NAME)
128128

129-
# TODO: is this really necessary?
129+
# Stage the source file in the binary directory for lemon. We need to make
130+
# sure it's fully copied, so use a sentinel guard
130131
add_custom_command(
131132
OUTPUT ${_in_y_file}
132133
COMMAND ${CMAKE_COMMAND} -E copy ${_in_y_path} ${CMAKE_CURRENT_BINARY_DIR}
133134
)
135+
add_custom_command(
136+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_in_y_file}.sentinel
137+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${_in_y_file}.sentinel
138+
DEPENDS ${_in_y_file}
139+
)
140+
add_custom_target(${Name}_input_cpy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_in_y_file}.sentinel)
134141

135142
# execute lemon
136143
add_custom_command(
137144
OUTPUT ${_out_src_file}
138145
COMMAND ${LEMON_EXECUTABLE} -T${LEMON_TEMPLATE} ${LEMON_EXECUTABLE_opts} ${_in_y_file}
139-
DEPENDS ${_in_y_file}
146+
DEPENDS ${Name}_input_cpy
140147
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
141148
COMMENT "[LEMON][${Name}] Building parser with ${LEMON_EXECUTABLE}"
142149
)

0 commit comments

Comments
 (0)