mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-28 11:21:12 +08:00
[vcpkg] Restore embedded git hash behind an option. (#15472)
This commit is contained in:
parent
9ddc9173d7
commit
d1ef42c0fd
@ -369,7 +369,7 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
$arguments = (
|
$arguments = (
|
||||||
"`"/p:VCPKG_VERSION=-nohash`"",
|
"`"/p:VCPKG_VERSION=-unknownhash`"",
|
||||||
"`"/p:DISABLE_METRICS=$disableMetricsValue`"",
|
"`"/p:DISABLE_METRICS=$disableMetricsValue`"",
|
||||||
"/p:Configuration=Release",
|
"/p:Configuration=Release",
|
||||||
"/p:Platform=$platform",
|
"/p:Platform=$platform",
|
||||||
|
@ -15,6 +15,7 @@ option(VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang, even versions t
|
|||||||
option(VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings" ON)
|
option(VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings" ON)
|
||||||
option(VCPKG_WARNINGS_AS_ERRORS "Set warnings to be errors" ${VCPKG_DEVELOPMENT_WARNINGS})
|
option(VCPKG_WARNINGS_AS_ERRORS "Set warnings to be errors" ${VCPKG_DEVELOPMENT_WARNINGS})
|
||||||
option(VCPKG_BUILD_FUZZING "Option for enabling vcpkg-fuzz support" OFF)
|
option(VCPKG_BUILD_FUZZING "Option for enabling vcpkg-fuzz support" OFF)
|
||||||
|
option(VCPKG_EMBED_GIT_SHA "Option for to fill in the Git SHA version; off by default to avoid privacy concerns out of official builds" OFF)
|
||||||
|
|
||||||
CMAKE_DEPENDENT_OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF
|
CMAKE_DEPENDENT_OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF
|
||||||
"BUILD_TESTING" OFF)
|
"BUILD_TESTING" OFF)
|
||||||
@ -51,6 +52,31 @@ vcpkg_detect_compiler()
|
|||||||
vcpkg_detect_standard_library()
|
vcpkg_detect_standard_library()
|
||||||
vcpkg_detect_std_filesystem()
|
vcpkg_detect_std_filesystem()
|
||||||
|
|
||||||
|
if (VCPKG_EMBED_GIT_SHA)
|
||||||
|
find_package(Git REQUIRED)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" status --porcelain=v1
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
OUTPUT_VARIABLE VCPKG_GIT_STATUS
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
if (VCPKG_GIT_STATUS STREQUAL "")
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
OUTPUT_VARIABLE VCPKG_VERSION
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(WARNING "Skipping embedding SHA due to local changes.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (VCPKG_VERSION STREQUAL "")
|
||||||
|
set(VCPKG_VERSION "nohash")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
@ -84,7 +110,8 @@ target_include_directories(vcpkglib PUBLIC include)
|
|||||||
|
|
||||||
vcpkg_target_add_warning_options(vcpkglib)
|
vcpkg_target_add_warning_options(vcpkglib)
|
||||||
target_compile_definitions(vcpkglib PUBLIC
|
target_compile_definitions(vcpkglib PUBLIC
|
||||||
VCPKG_USE_STD_FILESYSTEM=$<BOOL:${VCPKG_USE_STD_FILESYSTEM}>)
|
VCPKG_USE_STD_FILESYSTEM=$<BOOL:${VCPKG_USE_STD_FILESYSTEM}>
|
||||||
|
VCPKG_VERSION=${VCPKG_VERSION})
|
||||||
|
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
namespace vcpkg::Commands::Version
|
namespace vcpkg::Commands::Version
|
||||||
{
|
{
|
||||||
const char* base_version();
|
const char* base_version();
|
||||||
const std::string& version();
|
const char* version();
|
||||||
void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths);
|
void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths);
|
||||||
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs);
|
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs);
|
||||||
|
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
#define STRINGIFY(...) #__VA_ARGS__
|
#define STRINGIFY(...) #__VA_ARGS__
|
||||||
#define MACRO_TO_STRING(X) STRINGIFY(X)
|
#define MACRO_TO_STRING(X) STRINGIFY(X)
|
||||||
|
|
||||||
#if defined(VCPKG_VERSION)
|
#if !defined(VCPKG_VERSION)
|
||||||
#define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)
|
#error VCPKG_VERSION must be defined
|
||||||
#else
|
|
||||||
#define VCPKG_VERSION_AS_STRING "-unknownhash"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)
|
||||||
|
|
||||||
namespace vcpkg::Commands::Version
|
namespace vcpkg::Commands::Version
|
||||||
{
|
{
|
||||||
const char* base_version()
|
const char* base_version()
|
||||||
@ -24,17 +24,15 @@ namespace vcpkg::Commands::Version
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& version()
|
const char* version()
|
||||||
{
|
{
|
||||||
static const std::string S_VERSION =
|
return
|
||||||
#include "../VERSION.txt"
|
#include "../VERSION.txt"
|
||||||
|
"-" VCPKG_VERSION_AS_STRING
|
||||||
+std::string(VCPKG_VERSION_AS_STRING)
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
+ std::string("-debug")
|
"-debug"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
return S_VERSION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scan3(const char* input, const char* pattern, int* a, int* b, int* c)
|
static int scan3(const char* input, const char* pattern, int* a, int* b, int* c)
|
||||||
@ -55,7 +53,7 @@ namespace vcpkg::Commands::Version
|
|||||||
const auto num1 = scan3(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1);
|
const auto num1 = scan3(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1);
|
||||||
|
|
||||||
int maj2, min2, rev2;
|
int maj2, min2, rev2;
|
||||||
const auto num2 = scan3(Version::version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2);
|
const auto num2 = scan3(Version::version(), "%d.%d.%d-", &maj2, &min2, &rev2);
|
||||||
|
|
||||||
if (num1 == 3 && num2 == 3)
|
if (num1 == 3 && num2 == 3)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user