[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only
Pushpinder Singh via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 5 02:06:41 PDT 2020
pdhaliwal created this revision.
pdhaliwal added reviewers: chandlerc, beanz, pcc.
Herald added subscribers: llvm-commits, cfe-commits, mgorny.
Herald added projects: clang, LLVM.
The AddLLVM.cmake file exposes a function find_first_existing_vc_file which in case of git repository looks for .git/logs/HEAD. This file can be missing when repository is checked out using repo tool. So, the function tries to create an empty file in the same directory. This can fail if the source directory is read only. E.g. if the llvm source directory is mounted inside docker as ro (read-only).
E.g. error reported,
CMake Error at /src/external/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1940 (file):
file failed to open for writing (Read-only file system):
/src/external/llvm-project/.git/logs/HEAD
Call Stack (most recent call first):
/src/external/llvm-project/clang/lib/Basic/CMakeLists.txt:7 (find_first_existing_vc_file)
I have made the changes to not create .git/logs/HEAD.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79400
Files:
clang/lib/Basic/CMakeLists.txt
lld/Common/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/include/llvm/Support/CMakeLists.txt
Index: llvm/include/llvm/Support/CMakeLists.txt
===================================================================
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -5,7 +5,7 @@
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
endif()
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2110,7 +2110,7 @@
get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
# Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
if (NOT EXISTS "${git_dir}/logs/HEAD")
- file(WRITE "${git_dir}/logs/HEAD" "")
+ return()
endif()
set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
endif()
Index: lld/Common/CMakeLists.txt
===================================================================
--- lld/Common/CMakeLists.txt
+++ lld/Common/CMakeLists.txt
@@ -2,13 +2,12 @@
set(tablegen_deps intrinsics_gen)
endif()
-find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
find_first_existing_vc_file("${LLD_SOURCE_DIR}" lld_vc)
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
-if(lld_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
set(lld_source_dir ${LLD_SOURCE_DIR})
endif()
Index: clang/lib/Basic/CMakeLists.txt
===================================================================
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -12,10 +12,10 @@
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
endif()
-if(clang_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
set(clang_source_dir ${CLANG_SOURCE_DIR})
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79400.262024.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200505/288d0a1e/attachment.bin>
More information about the cfe-commits
mailing list