Skip to content

Commit 16fef6d

Browse files
pdhaliwal-amdssahasra
authored andcommitted
Fix build failure when source is read only
cmake configure fails when it tries to setup target for llvm_vcsrevision_h This happens only when source is checked out using repo in a read only filesystem, because cmake tries to create `.git/logs/HEAD` file. This patch: 1. Recovers from failure gracefully. 2. Ensures that VCSRevision.h is successfully created and updated in above scenarios. Differential Revision: https://reviews.llvm.org/D79400
1 parent 0609704 commit 16fef6d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,13 @@ function(find_first_existing_vc_file path out_var)
21182118
get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
21192119
# Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
21202120
if (NOT EXISTS "${git_dir}/logs/HEAD")
2121-
file(WRITE "${git_dir}/logs/HEAD" "")
2121+
execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
2122+
WORKING_DIRECTORY "${git_dir}/logs"
2123+
RESULT_VARIABLE touch_head_result
2124+
ERROR_QUIET)
2125+
if (NOT touch_head_result EQUAL 0)
2126+
return()
2127+
endif()
21222128
endif()
21232129
set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
21242130
endif()

llvm/include/llvm/Support/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
55

66
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
77

8-
if(llvm_vc AND LLVM_APPEND_VC_REV)
8+
if(LLVM_APPEND_VC_REV)
99
set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
10+
11+
# A fake version file and is not expected to exist. It is being used to
12+
# force regeneration of VCSRevision.h for source directory with no write
13+
# permission available.
14+
if (NOT llvm_vc)
15+
set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
16+
endif()
1017
endif()
1118

1219
# Create custom target to generate the VC revision include.
13-
add_custom_command(OUTPUT "${version_inc}"
20+
add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
1421
DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
1522
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
1623
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@ set_source_files_properties("${version_inc}"
2229
PROPERTIES GENERATED TRUE
2330
HEADER_FILE_ONLY TRUE)
2431

25-
add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
32+
add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" "${fake_version_inc}")
2633
set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")

0 commit comments

Comments
 (0)