[clang] ee68f61 - Second try: [clang][cmake] Add options to pass in vcs repo and revision info

Han Zhu via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 10:54:39 PDT 2023


Author: Han Zhu
Date: 2023-04-17T10:54:28-07:00
New Revision: ee68f612ba682ddb911c5621e63df56039ec5824

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

LOG: Second try: [clang][cmake] Add options to pass in vcs repo and revision info

V2: Fix cmake error when -DLLVM_APPEND_VC_REV=OFF

Clang may be built in an environment where Git is not available. In our case,
Clang is part of a larger monorepo which is not Git-based, and
GenerateVersionFromVCS was not able to get source info.

Provide options to pass in repo and revision info from cmake.
```
cmake \
  -DCLANG_VC_REPOSITORY=abc://repo.url.com \
  -DCLANG_VC_REVISION=abcd1234 \
  ...
```
This would allow us to prepare the source info beforehand and pass it to the
clang binary.

Differential Revision: https://reviews.llvm.org/D148262

Added: 
    

Modified: 
    clang/lib/Basic/CMakeLists.txt
    llvm/cmake/modules/GenerateVersionFromVCS.cmake

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 8c828e4c73225..c05036a216c74 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -14,9 +14,19 @@ set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake"
 if(llvm_vc AND LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
 endif()
+if (LLVM_VC_REPOSITORY AND LLVM_VC_REVISION)
+  set(llvm_source_dir ${LLVM_SOURCE_DIR})
+  set(llvm_vc_repository ${LLVM_VC_REPOSITORY})
+  set(llvm_vc_revision ${LLVM_VC_REVISION})
+endif()
 if(clang_vc AND LLVM_APPEND_VC_REV)
   set(clang_source_dir ${CLANG_SOURCE_DIR})
 endif()
+if (CLANG_VC_REPOSITORY AND CLANG_VC_REVISION)
+  set(clang_source_dir ${CLANG_SOURCE_DIR})
+  set(clang_vc_repository ${CLANG_VC_REPOSITORY})
+  set(clang_vc_revision ${CLANG_VC_REVISION})
+endif()
 
 # Create custom target to generate the VC revision include.
 add_custom_command(OUTPUT "${version_inc}"
@@ -24,7 +34,11 @@ add_custom_command(OUTPUT "${version_inc}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;CLANG\""
                            "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
                            "-DCLANG_SOURCE_DIR=${clang_source_dir}"
+                           "-DCLANG_VC_REPOSITORY=${clang_vc_repository}"
+                           "-DCLANG_VC_REVISION=${clang_vc_revision}"
                            "-DHEADER_FILE=${version_inc}"
+                           "-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
+                           "-DLLVM_VC_REVISION=${llvm_vc_revision}"
                            -P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.

diff  --git a/llvm/cmake/modules/GenerateVersionFromVCS.cmake b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
index d8ec54df41ebd..9cd780e5aa162 100644
--- a/llvm/cmake/modules/GenerateVersionFromVCS.cmake
+++ b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
@@ -18,10 +18,7 @@ include(VersionFromVCS)
 # Handle strange terminals
 set(ENV{TERM} "dumb")
 
-function(append_info name path)
-  if(path)
-    get_source_info("${path}" revision repository)
-  endif()
+function(append_info name revision repository)
   if(revision)
     file(APPEND "${HEADER_FILE}.tmp"
       "#define ${name}_REVISION \"${revision}\"\n")
@@ -39,10 +36,17 @@ function(append_info name path)
 endfunction()
 
 foreach(name IN LISTS NAMES)
-  if(NOT DEFINED ${name}_SOURCE_DIR)
+  if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
+    set(revision ${${name}_VC_REVISION})
+    set(repository ${${name}_VC_REPOSITORY})
+  elseif(DEFINED ${name}_SOURCE_DIR)
+    if (${name}_SOURCE_DIR)
+      get_source_info("${${name}_SOURCE_DIR}" revision repository)
+    endif()
+  else()
     message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
   endif()
-  append_info(${name} "${${name}_SOURCE_DIR}")
+  append_info(${name} "${revision}" "${repository}")
 endforeach()
 
 # Copy the file only if it has changed.


        


More information about the cfe-commits mailing list