[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
Thu May 28 03:13:03 PDT 2020
pdhaliwal updated this revision to Diff 266794.
pdhaliwal marked an inline comment as done.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79400/new/
https://reviews.llvm.org/D79400
Files:
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,12 +5,16 @@
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})
+
+ 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 +26,5 @@
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")
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1913,34 +1913,27 @@
if(NOT EXISTS "${path}")
return()
endif()
- if(EXISTS "${path}/.svn")
- set(svn_files
- "${path}/.svn/wc.db" # SVN 1.7
- "${path}/.svn/entries" # SVN 1.6
- )
- foreach(file IN LISTS svn_files)
- if(EXISTS "${file}")
- set(${out_var} "${file}" PARENT_SCOPE)
- return()
- endif()
- endforeach()
- else()
- find_package(Git)
- if(GIT_FOUND)
- execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
- WORKING_DIRECTORY ${path}
- RESULT_VARIABLE git_result
- OUTPUT_VARIABLE git_output
- ERROR_QUIET)
- if(git_result EQUAL 0)
- string(STRIP "${git_output}" git_output)
- 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" "")
+ find_package(Git)
+ if(GIT_FOUND)
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
+ WORKING_DIRECTORY ${path}
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output
+ ERROR_QUIET)
+ if(git_result EQUAL 0)
+ string(STRIP "${git_output}" git_output)
+ 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")
+ 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()
- set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
endif()
+ set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
endif()
endif()
endfunction()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79400.266794.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200528/ab68b327/attachment-0001.bin>
More information about the cfe-commits
mailing list