[PATCH] D148262: [clang][cmake] Add options to pass in vcs repo and revision info
Han Zhu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 13 11:32:24 PDT 2023
zhuhan0 created this revision.
Herald added subscribers: ekilmer, hoy, wenlei.
Herald added a project: All.
zhuhan0 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148262
Files:
clang/lib/Basic/CMakeLists.txt
llvm/cmake/modules/GenerateVersionFromVCS.cmake
Index: llvm/cmake/modules/GenerateVersionFromVCS.cmake
===================================================================
--- llvm/cmake/modules/GenerateVersionFromVCS.cmake
+++ llvm/cmake/modules/GenerateVersionFromVCS.cmake
@@ -18,9 +18,11 @@
# Handle strange terminals
set(ENV{TERM} "dumb")
-function(append_info name path)
- if(path)
- get_source_info("${path}" revision repository)
+function(append_info name path repository revision)
+ if (NOT repository AND NOT revision)
+ if(path)
+ get_source_info("${path}" revision repository)
+ endif()
endif()
if(revision)
file(APPEND "${HEADER_FILE}.tmp"
@@ -39,10 +41,14 @@
endfunction()
foreach(name IN LISTS NAMES)
- if(NOT DEFINED ${name}_SOURCE_DIR)
- message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
+ if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
+ append_info(${name} "" "${${name}_VC_REPOSITORY}" "${${name}_VC_REVISION}")
+ else()
+ if(NOT DEFINED ${name}_SOURCE_DIR)
+ message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
+ endif()
+ append_info(${name} "${${name}_SOURCE_DIR}" "" "")
endif()
- append_info(${name} "${${name}_SOURCE_DIR}")
endforeach()
# Copy the file only if it has changed.
Index: clang/lib/Basic/CMakeLists.txt
===================================================================
--- clang/lib/Basic/CMakeLists.txt
+++ clang/lib/Basic/CMakeLists.txt
@@ -17,6 +17,11 @@
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,6 +29,8 @@
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}"
-P "${generate_vcs_version_script}")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148262.513320.patch
Type: text/x-patch
Size: 2307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230413/1786d801/attachment.bin>
More information about the cfe-commits
mailing list