[clang] [cmake] Add LLVM_FORCE_VC_REVISION option (PR #67125)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 22 05:40:06 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

This patch adds a LLVM_FORCE_VC_REVISION option to force a custom
VC revision to be included instead of trying to fetch one from a
git command. This is helpful in environments where git is not
available or is non-functional but the vc revision is available
through some other means.


---
Full diff: https://github.com/llvm/llvm-project/pull/67125.diff


7 Files Affected:

- (modified) clang/lib/Basic/CMakeLists.txt (+2) 
- (modified) flang/lib/Common/CMakeLists.txt (+3-1) 
- (modified) lld/Common/CMakeLists.txt (+2) 
- (modified) lldb/source/Version/CMakeLists.txt (+2) 
- (modified) llvm/CMakeLists.txt (+6) 
- (modified) llvm/cmake/modules/GenerateVersionFromVCS.cmake (+8-1) 
- (modified) llvm/include/llvm/Support/CMakeLists.txt (+4) 


``````````diff
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index db59d7dd96da0a4..36ccf7d0809453e 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -39,6 +39,8 @@ add_custom_command(OUTPUT "${version_inc}"
                            "-DHEADER_FILE=${version_inc}"
                            "-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
                            "-DLLVM_VC_REVISION=${llvm_vc_revision}"
+                           "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                           "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
                            -P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index 81cee82e04b88ae..c6f818ad27cd19a 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -12,7 +12,7 @@ endif()
 if(flang_vc AND LLVM_APPEND_VC_REV)
   set(flang_source_dir ${FLANG_SOURCE_DIR})
 endif()
-
+ 
 # Create custom target to generate the VC revision include.
 add_custom_command(OUTPUT "${version_inc}"
   DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
@@ -20,6 +20,8 @@ add_custom_command(OUTPUT "${version_inc}"
                            "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
                            "-DFLANG_SOURCE_DIR=${flang_source_dir}"
                            "-DHEADER_FILE=${version_inc}"
+                           "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                           "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
                            -P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.
diff --git a/lld/Common/CMakeLists.txt b/lld/Common/CMakeLists.txt
index c975da2a49b6bda..4f503d04f7844f7 100644
--- a/lld/Common/CMakeLists.txt
+++ b/lld/Common/CMakeLists.txt
@@ -13,6 +13,8 @@ add_custom_command(OUTPUT "${version_inc}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
   "-DLLD_SOURCE_DIR=${lld_source_dir}"
   "-DHEADER_FILE=${version_inc}"
+  "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+  "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
   -P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.
diff --git a/lldb/source/Version/CMakeLists.txt b/lldb/source/Version/CMakeLists.txt
index c1393b5dd6e6b62..90fe53d52cc5d05 100644
--- a/lldb/source/Version/CMakeLists.txt
+++ b/lldb/source/Version/CMakeLists.txt
@@ -17,6 +17,8 @@ add_custom_command(OUTPUT "${vcs_version_inc}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
                            "-DLLDB_SOURCE_DIR=${lldb_source_dir}"
                            "-DHEADER_FILE=${vcs_version_inc}"
+                           "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                           "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
                            -P "${generate_vcs_version_script}")
 
 set_source_files_properties("${vcs_version_inc}"
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index fa39c7554de1f61..5985256498dcbb2 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -325,6 +325,12 @@ include(VersionFromVCS)
 option(LLVM_APPEND_VC_REV
   "Embed the version control system revision in LLVM" ON)
 
+set(LLVM_FORCE_VC_REVISION
+  "" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")
+
+set(LLVM_FORCE_VC_REPOSITORY
+  "" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")
+
 option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)
 
 set(PACKAGE_NAME LLVM)
diff --git a/llvm/cmake/modules/GenerateVersionFromVCS.cmake b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
index 9cd780e5aa162c0..1b3b2946e62b25c 100644
--- a/llvm/cmake/modules/GenerateVersionFromVCS.cmake
+++ b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
@@ -36,7 +36,14 @@ function(append_info name revision repository)
 endfunction()
 
 foreach(name IN LISTS NAMES)
-  if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
+  if(LLVM_FORCE_VC_REVISION AND LLVM_FORCE_VC_REPOSITORY)
+    set(revision ${LLVM_FORCE_VC_REVISION})
+    set(repository ${LLVM_FORCE_VC_REPOSITORY})
+  elseif(LLVM_FORCE_VC_REVISION)
+    set(revision ${LLVM_FORCE_VC_REVISION})
+  elseif(LLVM_FORCE_VC_REPOSITORY)
+    set(repository ${LLVM_FORCE_VC_REPOSITORY})
+  elseif(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
     set(revision ${${name}_VC_REVISION})
     set(repository ${${name}_VC_REPOSITORY})
   elseif(DEFINED ${name}_SOURCE_DIR)
diff --git a/llvm/include/llvm/Support/CMakeLists.txt b/llvm/include/llvm/Support/CMakeLists.txt
index b6be96525c744a3..76c382bfc644f2e 100644
--- a/llvm/include/llvm/Support/CMakeLists.txt
+++ b/llvm/include/llvm/Support/CMakeLists.txt
@@ -28,6 +28,8 @@ if (fake_version_inc)
     COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
                              "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
                              "-DHEADER_FILE=${version_inc}"
+                             "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                             "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
                              -P "${generate_vcs_version_script}")
 else()
   add_custom_command(OUTPUT "${version_inc}"
@@ -35,6 +37,8 @@ else()
     COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
                              "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
                              "-DHEADER_FILE=${version_inc}"
+                             "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                             "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
                              -P "${generate_vcs_version_script}")
 endif()
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/67125


More information about the cfe-commits mailing list