Skip to content

Commit 12062e0

Browse files
committed
Revert "[CMake] Unify scripts for generating VCS headers"
This reverts commits r352729 and r352731: this broke Sanitizer Windows bots llvm-svn: 352733
1 parent 046cac6 commit 12062e0

File tree

11 files changed

+390
-223
lines changed

11 files changed

+390
-223
lines changed

clang/lib/Basic/CMakeLists.txt

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,45 @@ set(LLVM_LINK_COMPONENTS
44
Support
55
)
66

7-
find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
8-
find_first_existing_vc_file("${CLANG_SOURCE_DIR}" clang_vc)
7+
find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
8+
find_first_existing_vc_file(clang_vc "${CLANG_SOURCE_DIR}")
99

1010
# The VC revision include that we want to generate.
11-
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
11+
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
1212

13-
set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
13+
set(get_svn_script "${LLVM_CMAKE_PATH}/GetSVN.cmake")
1414

15-
if(llvm_vc)
16-
set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
17-
endif()
18-
if(clang_vc)
19-
set(clang_source_dir ${CLANG_SOURCE_DIR})
20-
endif()
15+
if(DEFINED llvm_vc AND DEFINED clang_vc)
16+
# Create custom target to generate the VC revision include.
17+
add_custom_command(OUTPUT "${version_inc}"
18+
DEPENDS "${llvm_vc}" "${clang_vc}" "${get_svn_script}"
19+
COMMAND
20+
${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLVM_MAIN_SRC_DIR}"
21+
"-DFIRST_NAME=LLVM"
22+
"-DSECOND_SOURCE_DIR=${CLANG_SOURCE_DIR}"
23+
"-DSECOND_NAME=SVN"
24+
"-DHEADER_FILE=${version_inc}"
25+
-P "${get_svn_script}")
2126

22-
# Create custom target to generate the VC revision include.
23-
add_custom_command(OUTPUT "${version_inc}"
24-
DEPENDS "${llvm_vc}" "${clang_vc}" "${get_svn_script}"
25-
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM\;CLANG"
26-
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
27-
"-DCLANG_SOURCE_DIR=${clang_source_dir}"
28-
"-DHEADER_FILE=${version_inc}"
29-
-P "${get_svn_script}")
27+
# Mark the generated header as being generated.
28+
set_source_files_properties("${version_inc}"
29+
PROPERTIES GENERATED TRUE
30+
HEADER_FILE_ONLY TRUE)
3031

31-
# Mark the generated header as being generated.
32-
set_source_files_properties("${version_inc}"
33-
PROPERTIES GENERATED TRUE
34-
HEADER_FILE_ONLY TRUE)
32+
# Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC.
33+
set_source_files_properties(Version.cpp
34+
PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
35+
else()
36+
# Not producing a VC revision include.
37+
set(version_inc)
38+
39+
# Being able to force-set the SVN revision in cases where it isn't available
40+
# is useful for performance tracking, and matches compatibility from autoconf.
41+
if(SVN_REVISION)
42+
set_source_files_properties(Version.cpp
43+
PROPERTIES COMPILE_DEFINITIONS "SVN_REVISION=\"${SVN_REVISION}\"")
44+
endif()
45+
endif()
3546

3647
add_clang_library(clangBasic
3748
Attributes.cpp

clang/lib/Basic/Version.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "VCSRevision.h"
1413
#include "clang/Basic/Version.h"
1514
#include "clang/Basic/LLVM.h"
1615
#include "clang/Config/config.h"
1716
#include "llvm/Support/raw_ostream.h"
1817
#include <cstdlib>
1918
#include <cstring>
2019

20+
#ifdef HAVE_SVN_VERSION_INC
21+
# include "SVNVersion.inc"
22+
#endif
23+
2124
namespace clang {
2225

2326
std::string getClangRepositoryPath() {
2427
#if defined(CLANG_REPOSITORY_STRING)
2528
return CLANG_REPOSITORY_STRING;
2629
#else
27-
#ifdef CLANG_REPOSITORY
28-
StringRef URL(CLANG_REPOSITORY);
30+
#ifdef SVN_REPOSITORY
31+
StringRef URL(SVN_REPOSITORY);
2932
#else
3033
StringRef URL("");
3134
#endif
3235

33-
// If the CLANG_REPOSITORY is empty, try to use the SVN keyword. This helps us
36+
// If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
3437
// pick up a tag in an SVN export, for example.
3538
StringRef SVNRepository("$URL$");
3639
if (URL.empty()) {
@@ -68,8 +71,8 @@ std::string getLLVMRepositoryPath() {
6871
}
6972

7073
std::string getClangRevision() {
71-
#ifdef CLANG_REVISION
72-
return CLANG_REVISION;
74+
#ifdef SVN_REVISION
75+
return SVN_REVISION;
7376
#else
7477
return "";
7578
#endif

lldb/source/CMakeLists.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,29 @@ foreach(file
1515
endif()
1616
endforeach()
1717

18-
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h")
19-
set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
18+
if(DEFINED lldb_vc)
19+
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
20+
set(get_svn_script "${LLVM_CMAKE_PATH}/GetSVN.cmake")
2021

21-
if(lldb_vc)
22-
set(lldb_source_dir ${LLDB_SOURCE_DIR})
23-
endif()
24-
25-
add_custom_command(OUTPUT "${version_inc}"
26-
DEPENDS "${lldb_vc}" "${get_svn_script}"
27-
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
28-
"-DLLDB_SOURCE_DIR=${LLDB_SOURCE_DIR}"
29-
"-DHEADER_FILE=${version_inc}"
30-
-P "${get_svn_script}")
22+
# Create custom target to generate the VC revision include.
23+
add_custom_command(OUTPUT "${version_inc}"
24+
DEPENDS "${lldb_vc}" "${get_svn_script}"
25+
COMMAND
26+
${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLDB_SOURCE_DIR}"
27+
"-DFIRST_NAME=LLDB"
28+
"-DHEADER_FILE=${version_inc}"
29+
-P "${get_svn_script}")
3130

32-
# Mark the generated header as being generated.
33-
set_source_files_properties("${version_inc}"
34-
PROPERTIES GENERATED TRUE
35-
HEADER_FILE_ONLY TRUE)
31+
# Mark the generated header as being generated.
32+
set_source_files_properties("${version_inc}"
33+
PROPERTIES GENERATED TRUE
34+
HEADER_FILE_ONLY TRUE)
3635

37-
list(APPEND lldbBase_SOURCES ${version_inc})
36+
# Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC.
37+
set_property(SOURCE lldb.cpp APPEND PROPERTY
38+
COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
39+
list(APPEND lldbBase_SOURCES ${version_inc})
40+
endif()
3841

3942
if(APPLE)
4043
set(apple_version_inc "${CMAKE_CURRENT_BINARY_DIR}/AppleVersion.inc")

lldb/source/lldb.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
using namespace lldb;
1212
using namespace lldb_private;
1313

14-
#include "VCSRevision.h"
1514
#include "clang/Basic/Version.h"
1615

16+
#ifdef HAVE_SVN_VERSION_INC
17+
#include "SVNVersion.inc"
18+
#endif
19+
1720
#ifdef HAVE_APPLE_VERSION_INC
1821
#include "AppleVersion.inc"
1922
#endif

llvm/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ endif()
200200
include(VersionFromVCS)
201201

202202
option(LLVM_APPEND_VC_REV
203-
"Embed the version control system revision in LLVM" ON)
203+
"Embed the version control system revision id in LLVM" ON)
204204

205205
set(PACKAGE_NAME LLVM)
206206
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
@@ -752,12 +752,13 @@ set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in
752752
set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec)
753753
set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm")
754754

755-
get_source_info(${CMAKE_CURRENT_SOURCE_DIR} revision repository)
756-
string(LENGTH "${revision}" revision_length)
757-
if(revision MATCHES "^[0-9]+$" AND revision_length LESS 40)
758-
set(LLVM_RPM_SPEC_REVISION "r${revision}")
759-
else()
760-
set(LLVM_RPM_SPEC_REVISION "${revision}")
755+
# SVN_REVISION and GIT_COMMIT get set by the call to add_version_info_from_vcs.
756+
# DUMMY_VAR contains a version string which we don't care about.
757+
add_version_info_from_vcs(DUMMY_VAR)
758+
if ( SVN_REVISION )
759+
set(LLVM_RPM_SPEC_REVISION "r${SVN_REVISION}")
760+
elseif ( GIT_COMMIT )
761+
set (LLVM_RPM_SPEC_REVISION "g${GIT_COMMIT}")
761762
endif()
762763

763764
configure_file(

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,35 +1707,35 @@ function(setup_dependency_debugging name)
17071707
set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command})
17081708
endfunction()
17091709

1710-
function(find_first_existing_vc_file path out_var)
1711-
if(EXISTS "${path}/.svn")
1712-
set(svn_files
1713-
"${path}/.svn/wc.db" # SVN 1.7
1714-
"${path}/.svn/entries" # SVN 1.6
1715-
)
1716-
foreach(file IN LISTS svn_files)
1717-
if(EXISTS "${file}")
1718-
set(${out_var} "${file}" PARENT_SCOPE)
1719-
return()
1720-
endif()
1721-
endforeach()
1722-
else()
1723-
find_package(Git)
1724-
if(GIT_FOUND)
1725-
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
1726-
WORKING_DIRECTORY ${path}
1727-
RESULT_VARIABLE git_result
1728-
OUTPUT_VARIABLE git_output
1729-
ERROR_QUIET)
1730-
if(git_result EQUAL 0)
1731-
string(STRIP "${git_output}" git_output)
1732-
get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
1733-
# Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
1734-
if (NOT EXISTS "${git_dir}/logs/HEAD")
1735-
file(WRITE "${git_dir}/logs/HEAD" "")
1736-
endif()
1737-
set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
1738-
endif()
1710+
# Figure out if we can track VC revisions.
1711+
function(find_first_existing_file out_var)
1712+
foreach(file ${ARGN})
1713+
if(EXISTS "${file}")
1714+
set(${out_var} "${file}" PARENT_SCOPE)
1715+
return()
17391716
endif()
1740-
endif()
1717+
endforeach()
17411718
endfunction()
1719+
1720+
macro(find_first_existing_vc_file out_var path)
1721+
find_program(git_executable NAMES git git.exe git.cmd)
1722+
# Run from a subdirectory to force git to print an absolute path.
1723+
execute_process(COMMAND ${git_executable} rev-parse --git-dir
1724+
WORKING_DIRECTORY ${path}/cmake
1725+
RESULT_VARIABLE git_result
1726+
OUTPUT_VARIABLE git_dir
1727+
ERROR_QUIET)
1728+
if(git_result EQUAL 0)
1729+
string(STRIP "${git_dir}" git_dir)
1730+
set(${out_var} "${git_dir}/logs/HEAD")
1731+
# some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
1732+
if (NOT EXISTS "${git_dir}/logs/HEAD")
1733+
file(WRITE "${git_dir}/logs/HEAD" "")
1734+
endif()
1735+
else()
1736+
find_first_existing_file(${out_var}
1737+
"${path}/.svn/wc.db" # SVN 1.7
1738+
"${path}/.svn/entries" # SVN 1.6
1739+
)
1740+
endif()
1741+
endmacro()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# CMake project that writes Subversion revision information to a header.
2+
#
3+
# Input variables:
4+
# SRC - Source directory
5+
# HEADER_FILE - The header file to write
6+
#
7+
# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION,
8+
# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and
9+
# "SECOND" are substituted with the names specified in the input variables.
10+
11+
12+
13+
# Chop off cmake/modules/GetSVN.cmake
14+
get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
15+
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
16+
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
17+
18+
set(CMAKE_MODULE_PATH
19+
${CMAKE_MODULE_PATH}
20+
"${LLVM_DIR}/cmake/modules")
21+
include(VersionFromVCS)
22+
23+
# Handle strange terminals
24+
set(ENV{TERM} "dumb")
25+
26+
function(append_info name path)
27+
add_version_info_from_vcs(REVISION ${path})
28+
string(STRIP "${REVISION}" REVISION)
29+
file(APPEND "${HEADER_FILE}.txt"
30+
"#define ${name} \"${REVISION}\"\n")
31+
endfunction()
32+
33+
append_info(${NAME} "${SOURCE_DIR}")
34+
35+
# Copy the file only if it has changed.
36+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
37+
"${HEADER_FILE}.txt" "${HEADER_FILE}")
38+
file(REMOVE "${HEADER_FILE}.txt")
39+

llvm/cmake/modules/GenerateVersionFromVCS.cmake

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)