Skip to content

Commit 3e6199b

Browse files
authored
Add a switch to not include git commit hash in the built artifacts (#32998)
This PR adds a SWIFT_APPEND_VC_REV Cmake option (in symmetry with LLVM's LLVM_APPEND_VC_REV). When enabled, lib/Basic/SwiftRevision.inc header contains git commit hash and repository information, e.g. #define SWIFT_REVISION "ed4cef9b839d4a87618758d8b8705ab66b61917f" #define SWIFT_REPOSITORY "https://github.com/scentini/swift.git" This is useful for keeping track of the VCS state that produced a binary. But for local development builds, this information is often ignored and since this file is invalidated by every git commit or git checkout command and it leads to long rebuilds, it's useful to have a switch to disable this behavior. When SWIFT_APPEND_VC_REV is disabled, lib/Basic/SwiftRevision.inc contains: #undef SWIFT_REVISION #undef SWIFT_REPOSITORY
1 parent 9fd6df6 commit 3e6199b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ include(CheckSymbolExists)
5454
# This is primarily to support building smaller or faster project files.
5555
#
5656

57+
option(SWIFT_APPEND_VC_REV
58+
"Embed the version control system revision in Swift"
59+
TRUE)
60+
5761
option(SWIFT_INCLUDE_TOOLS
5862
"Generate build targets for swift tools"
5963
TRUE)

lib/Basic/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ else()
1212
endif()
1313

1414
function(generate_revision_inc revision_inc_var name dir)
15-
find_first_existing_vc_file("${dir}" ${name}_vc)
15+
if(SWIFT_APPEND_VC_REV)
16+
# generate_vcs_version_script generates header with only `undef`s
17+
# inside when source directory doesn't exist.
18+
find_first_existing_vc_file("${dir}" ${name}_vc)
19+
set(dir_when_append_enabled ${dir})
20+
endif()
1621

1722
# Create custom target to generate the VC revision include.
1823
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/${name}Revision.inc")
@@ -22,7 +27,7 @@ function(generate_revision_inc revision_inc_var name dir)
2227
add_custom_command(OUTPUT "${version_inc}"
2328
DEPENDS "${${name}_vc}" "${generate_vcs_version_script}"
2429
COMMAND ${CMAKE_COMMAND} "-DNAMES=$<UPPER_CASE:${name}>"
25-
"-D$<UPPER_CASE:${name}>_SOURCE_DIR=${dir}"
30+
"-D$<UPPER_CASE:${name}>_SOURCE_DIR=${dir_when_append_enabled}"
2631
"-DHEADER_FILE=${version_inc}"
2732
-P "${generate_vcs_version_script}")
2833

0 commit comments

Comments
 (0)