Skip to content

Commit c49698c

Browse files
committed
fix(cmake): configure again when coretrace-compiler's checkout changes
The revision was read only when CMake configured. After a source of the checkout was changed, a build that did not configure again kept a revision those sources no longer had: the rebuilt analyzer still recorded b4ad336 with a changed args.cpp. Every file git tracks in the checkout, and its HEAD, are now configure dependencies: changing one makes the next build configure again and read the revision anew. If git cannot list them, the revision is left empty and the cache unused. Refs #223
1 parent 8b39722 commit c49698c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎cmake/compiler/coretrace-compiler.cmake‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ FetchContent_MakeAvailable(cc)
2121
# entry (InputPipeline.cpp). It is read from the sources FetchContent selected, not
2222
# taken from GIT_TAG above: a parent project's declaration of cc wins over this one.
2323
# It is known only for a clean git checkout that FetchContent made itself, read at
24-
# configure time. Sources FetchContent did not fetch (FETCHCONTENT_SOURCE_DIR_CC, a
25-
# SOURCE_DIR, an archive, a package) can change without CMake knowing: the revision
26-
# is then left empty, and the analyzer does not use the cache.
24+
# configure time and again whenever that checkout changes. Sources FetchContent did
25+
# not fetch (FETCHCONTENT_SOURCE_DIR_CC, a SOURCE_DIR, an archive, a package) can
26+
# change without CMake knowing: the revision is then left empty, and the analyzer
27+
# does not use the cache.
2728
set(CORETRACE_COMPILER_REVISION "")
2829
FetchContent_GetProperties(cc)
2930
find_package(Git QUIET)
@@ -38,6 +39,20 @@ if(GIT_FOUND AND NOT FETCHCONTENT_SOURCE_DIR_CC
3839
if(NOT cc_head_failed AND NOT cc_status_failed AND cc_changes STREQUAL "")
3940
set(CORETRACE_COMPILER_REVISION "${cc_head}")
4041
endif()
42+
# The revision holds only while the checkout stays as it is: changing any of its files, or
43+
# its HEAD, makes the next build configure again and read the revision anew.
44+
execute_process(
45+
COMMAND "${GIT_EXECUTABLE}" -C "${cc_SOURCE_DIR}" -c core.quotePath=false ls-files
46+
RESULT_VARIABLE cc_files_failed OUTPUT_VARIABLE cc_files
47+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
48+
if(cc_files_failed)
49+
set(CORETRACE_COMPILER_REVISION "")
50+
else()
51+
string(REPLACE "\n" ";" cc_files "${cc_files}")
52+
list(TRANSFORM cc_files PREPEND "${cc_SOURCE_DIR}/")
53+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
54+
${cc_files} "${cc_SOURCE_DIR}/.git/HEAD")
55+
endif()
4156
endif()
4257
if(CORETRACE_COMPILER_REVISION)
4358
message(STATUS "coretrace-compiler ${CORETRACE_COMPILER_REVISION}: compile IR cache enabled")

0 commit comments

Comments
 (0)