[llvm] 16fef6d - Fix build failure when source is read only

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 07:35:22 PDT 2020


Author: Pushpinder Singh
Date: 2020-05-29T20:04:22+05:30
New Revision: 16fef6d0b46f0494c502f8fe416fe841f7b000f6

URL: https://github.com/llvm/llvm-project/commit/16fef6d0b46f0494c502f8fe416fe841f7b000f6
DIFF: https://github.com/llvm/llvm-project/commit/16fef6d0b46f0494c502f8fe416fe841f7b000f6.diff

LOG: 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

Added: 
    

Modified: 
    llvm/cmake/modules/AddLLVM.cmake
    llvm/include/llvm/Support/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 9f14561fe0a6..f16f63c32c95 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2118,7 +2118,13 @@ function(find_first_existing_vc_file path out_var)
         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" "")
+          execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+            WORKING_DIRECTORY "${git_dir}/logs"
+            RESULT_VARIABLE touch_head_result
+            ERROR_QUIET)
+          if (NOT touch_head_result EQUAL 0)
+            return()
+          endif()
         endif()
         set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
       endif()

diff  --git a/llvm/include/llvm/Support/CMakeLists.txt b/llvm/include/llvm/Support/CMakeLists.txt
index 680be8fdf391..da8a4da443ed 100644
--- a/llvm/include/llvm/Support/CMakeLists.txt
+++ b/llvm/include/llvm/Support/CMakeLists.txt
@@ -5,12 +5,19 @@ set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
 
 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})
+
+  # A fake version file and is not expected to exist. It is being used to
+  # force regeneration of VCSRevision.h for source directory with no write
+  # permission available.
+  if (NOT llvm_vc)
+    set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
+  endif()
 endif()
 
 # Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
+add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
   DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
                            "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@ set_source_files_properties("${version_inc}"
   PROPERTIES GENERATED TRUE
              HEADER_FILE_ONLY TRUE)
 
-add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
+add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" "${fake_version_inc}")
 set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")


        


More information about the llvm-commits mailing list