aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois Rivard <30326057+RoguePointer80@users.noreply.github.com>2020-09-27 21:18:27 -0400
committerGitHub <noreply@github.com>2020-09-27 18:18:27 -0700
commit741c8cbecde77f771f8c05f00f59a436a2b4213b (patch)
tree2c77fb7d283deb47a0ad612764d6dcc243f380b9
parent64a281b865f31cf846c1e36d635361c2eaa985f4 (diff)
downloadvcpkg-741c8cbecde77f771f8c05f00f59a436a2b4213b.tar.gz
vcpkg-741c8cbecde77f771f8c05f00f59a436a2b4213b.zip
[vcpkg] Add compiler info to nuspec description (#13571)
* Add compiler info to nuspec description * Run clang-format on some files * Fix the unit tests * [vcpkg] Clarify NuGet description to note 'CXX compiler' * [vcpkg] Fix tests Co-authored-by: frivard <frivard@coveo.com> Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
-rw-r--r--scripts/detect_compiler/CMakeLists.txt3
-rw-r--r--toolsrc/include/vcpkg/build.h10
-rw-r--r--toolsrc/include/vcpkg/vcpkgpaths.h2
-rw-r--r--toolsrc/src/vcpkg-test/binarycaching.cpp14
-rw-r--r--toolsrc/src/vcpkg/binarycaching.cpp10
-rw-r--r--toolsrc/src/vcpkg/build.cpp70
-rw-r--r--toolsrc/src/vcpkg/vcpkgpaths.cpp5
7 files changed, 100 insertions, 14 deletions
diff --git a/scripts/detect_compiler/CMakeLists.txt b/scripts/detect_compiler/CMakeLists.txt
index ea27db2b9..80961c40b 100644
--- a/scripts/detect_compiler/CMakeLists.txt
+++ b/scripts/detect_compiler/CMakeLists.txt
@@ -6,7 +6,6 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_COMPILER_FORCED 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
- set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_COMPILER_FORCED 1)
endif()
@@ -18,3 +17,5 @@ file(SHA1 "${CMAKE_C_COMPILER}" C_HASH)
string(SHA1 COMPILER_HASH "${C_HASH}${CXX_HASH}")
message("#COMPILER_HASH#${COMPILER_HASH}")
+message("#COMPILER_CXX_VERSION#${CMAKE_CXX_COMPILER_VERSION}")
+message("#COMPILER_CXX_ID#${CMAKE_CXX_COMPILER_ID}")
diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h
index 83d797fd1..99effe475 100644
--- a/toolsrc/include/vcpkg/build.h
+++ b/toolsrc/include/vcpkg/build.h
@@ -305,6 +305,13 @@ namespace vcpkg::Build
fs::path tag_file;
};
+ struct CompilerInfo
+ {
+ std::string id;
+ std::string version;
+ std::string hash;
+ };
+
struct AbiInfo
{
std::unique_ptr<PreBuildInfo> pre_build_info;
@@ -312,6 +319,7 @@ namespace vcpkg::Build
Optional<const std::string&> triplet_abi;
std::string package_abi;
Optional<fs::path> abi_tag_file;
+ Optional<const CompilerInfo&> compiler_info;
};
void compute_all_abis(const VcpkgPaths& paths,
@@ -325,12 +333,14 @@ namespace vcpkg::Build
const System::Environment& get_action_env(const VcpkgPaths& paths, const AbiInfo& abi_info);
const std::string& get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info);
+ const CompilerInfo& get_compiler_info(const VcpkgPaths& paths, const AbiInfo& abi_info);
private:
struct TripletMapEntry
{
std::string hash;
Cache<std::string, std::string> compiler_hashes;
+ Cache<std::string, CompilerInfo> compiler_info;
};
Cache<fs::path, TripletMapEntry> m_triplet_cache;
Cache<fs::path, std::string> m_toolchain_cache;
diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h
index 8abc84129..da0e2ec14 100644
--- a/toolsrc/include/vcpkg/vcpkgpaths.h
+++ b/toolsrc/include/vcpkg/vcpkgpaths.h
@@ -37,6 +37,7 @@ namespace vcpkg
{
struct PreBuildInfo;
struct AbiInfo;
+ struct CompilerInfo;
}
namespace System
@@ -121,6 +122,7 @@ namespace vcpkg
const System::Environment& get_action_env(const Build::AbiInfo& abi_info) const;
const std::string& get_triplet_info(const Build::AbiInfo& abi_info) const;
+ const Build::CompilerInfo& get_compiler_info(const Build::AbiInfo& abi_info) const;
bool manifest_mode_enabled() const { return get_manifest().has_value(); }
void track_feature_flag_metrics() const;
diff --git a/toolsrc/src/vcpkg-test/binarycaching.cpp b/toolsrc/src/vcpkg-test/binarycaching.cpp
index 0b529f959..33f63e2ea 100644
--- a/toolsrc/src/vcpkg-test/binarycaching.cpp
+++ b/toolsrc/src/vcpkg-test/binarycaching.cpp
@@ -88,6 +88,11 @@ Build-Depends: bzip
ipa.abi_info.get()->package_abi = "packageabi";
std::string tripletabi("tripletabi");
ipa.abi_info.get()->triplet_abi = tripletabi;
+ Build::CompilerInfo compiler_info;
+ compiler_info.hash = "compilerhash";
+ compiler_info.id = "compilerid";
+ compiler_info.version = "compilerversion";
+ ipa.abi_info.get()->compiler_info = compiler_info;
NugetReference ref(ipa);
@@ -110,6 +115,9 @@ Build-Depends: bzip
a spiffy compression library wrapper
Version: 1.5
+Triplet: x64-windows
+CXX Compiler id: compilerid
+CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi
Features: a, b
Dependencies:
@@ -139,6 +147,9 @@ Dependencies:
a spiffy compression library wrapper
Version: 1.5
+Triplet: x64-windows
+CXX Compiler id: compilerid
+CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi
Features: a, b
Dependencies:
@@ -168,6 +179,9 @@ Dependencies:
a spiffy compression library wrapper
Version: 1.5
+Triplet: x64-windows
+CXX Compiler id: compilerid
+CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi
Features: a, b
Dependencies:
diff --git a/toolsrc/src/vcpkg/binarycaching.cpp b/toolsrc/src/vcpkg/binarycaching.cpp
index 130eab3ba..4563f575e 100644
--- a/toolsrc/src/vcpkg/binarycaching.cpp
+++ b/toolsrc/src/vcpkg/binarycaching.cpp
@@ -1016,13 +1016,21 @@ std::string vcpkg::generate_nuspec(const VcpkgPaths& paths,
auto& spec = action.spec;
auto& scf = *action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO).source_control_file;
auto& version = scf.core_paragraph->version;
+ const auto& abi_info = action.abi_info.value_or_exit(VCPKG_LINE_INFO);
+ const auto& compiler_info = abi_info.compiler_info.value_or_exit(VCPKG_LINE_INFO);
std::string description =
Strings::concat("NOT FOR DIRECT USE. Automatically generated cache package.\n\n",
Strings::join("\n ", scf.core_paragraph->description),
"\n\nVersion: ",
version,
+ "\nTriplet: ",
+ spec.triplet().to_string(),
+ "\nCXX Compiler id: ",
+ compiler_info.id,
+ "\nCXX Compiler version: ",
+ compiler_info.version,
"\nTriplet/Compiler hash: ",
- action.abi_info.value_or_exit(VCPKG_LINE_INFO).triplet_abi.value_or_exit(VCPKG_LINE_INFO),
+ abi_info.triplet_abi.value_or_exit(VCPKG_LINE_INFO),
"\nFeatures:",
Strings::join(",", action.feature_list, [](const std::string& s) { return " " + s; }),
"\nDependencies:\n");
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index a0ff09327..6952b5c3b 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -347,7 +347,33 @@ namespace vcpkg::Build
}
#endif
- static std::string load_compiler_hash(const VcpkgPaths& paths, const AbiInfo& abi_info);
+ static CompilerInfo load_compiler_info(const VcpkgPaths& paths, const AbiInfo& abi_info);
+
+ const CompilerInfo& EnvCache::get_compiler_info(const VcpkgPaths& paths, const AbiInfo& abi_info)
+ {
+ const auto& fs = paths.get_filesystem();
+ Checks::check_exit(VCPKG_LINE_INFO, abi_info.pre_build_info != nullptr);
+ const fs::path triplet_file_path = paths.get_triplet_file_path(abi_info.pre_build_info->triplet);
+
+ auto tcfile = abi_info.pre_build_info->toolchain_file();
+ auto&& toolchain_hash = m_toolchain_cache.get_lazy(
+ tcfile, [&]() { return Hash::get_file_hash(VCPKG_LINE_INFO, fs, tcfile, Hash::Algorithm::Sha1); });
+
+ auto&& triplet_entry = m_triplet_cache.get_lazy(triplet_file_path, [&]() -> TripletMapEntry {
+ return TripletMapEntry{Hash::get_file_hash(VCPKG_LINE_INFO, fs, triplet_file_path, Hash::Algorithm::Sha1)};
+ });
+
+ return triplet_entry.compiler_info.get_lazy(toolchain_hash, [&]() -> CompilerInfo {
+ if (m_compiler_tracking)
+ {
+ return load_compiler_info(paths, abi_info);
+ }
+ else
+ {
+ return CompilerInfo{};
+ }
+ });
+ }
const std::string& EnvCache::get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info)
{
@@ -366,8 +392,17 @@ namespace vcpkg::Build
return triplet_entry.compiler_hashes.get_lazy(toolchain_hash, [&]() -> std::string {
if (m_compiler_tracking)
{
- auto compiler_hash = load_compiler_hash(paths, abi_info);
- return Strings::concat(triplet_entry.hash, '-', toolchain_hash, '-', compiler_hash);
+ auto& compiler_info = triplet_entry.compiler_info.get_lazy(toolchain_hash, [&]() -> CompilerInfo {
+ if (m_compiler_tracking)
+ {
+ return load_compiler_info(paths, abi_info);
+ }
+ else
+ {
+ return CompilerInfo{};
+ }
+ });
+ return Strings::concat(triplet_entry.hash, '-', toolchain_hash, '-', compiler_info.hash);
}
else
{
@@ -464,7 +499,7 @@ namespace vcpkg::Build
}
}
- static std::string load_compiler_hash(const VcpkgPaths& paths, const AbiInfo& abi_info)
+ static CompilerInfo load_compiler_info(const VcpkgPaths& paths, const AbiInfo& abi_info)
{
auto triplet = abi_info.pre_build_info->triplet;
System::print2("Detecting compiler hash for triplet ", triplet, "...\n");
@@ -499,14 +534,24 @@ namespace vcpkg::Build
auto stdoutlog = buildpath / ("stdout-" + triplet.canonical_name() + ".log");
std::ofstream out_file(stdoutlog.native().c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
Checks::check_exit(VCPKG_LINE_INFO, out_file, "Failed to open '%s' for writing", fs::u8string(stdoutlog));
- std::string compiler_hash;
+ CompilerInfo compiler_info;
System::cmd_execute_and_stream_lines(
command,
[&](const std::string& s) {
- static const StringLiteral s_marker = "#COMPILER_HASH#";
- if (Strings::starts_with(s, s_marker))
+ static const StringLiteral s_hash_marker = "#COMPILER_HASH#";
+ if (Strings::starts_with(s, s_hash_marker))
+ {
+ compiler_info.hash = s.data() + s_hash_marker.size();
+ }
+ static const StringLiteral s_version_marker = "#COMPILER_CXX_VERSION#";
+ if (Strings::starts_with(s, s_version_marker))
+ {
+ compiler_info.version = s.data() + s_version_marker.size();
+ }
+ static const StringLiteral s_id_marker = "#COMPILER_CXX_ID#";
+ if (Strings::starts_with(s, s_id_marker))
{
- compiler_hash = s.data() + s_marker.size();
+ compiler_info.id = s.data() + s_id_marker.size();
}
Debug::print(s, '\n');
out_file.write(s.data(), s.size()).put('\n');
@@ -516,7 +561,7 @@ namespace vcpkg::Build
env);
out_file.close();
- if (compiler_hash.empty())
+ if (compiler_info.hash.empty())
{
Debug::print("Compiler information tracking can be disabled by passing --",
VcpkgCmdArguments::FEATURE_FLAGS_ARG,
@@ -525,11 +570,11 @@ namespace vcpkg::Build
"\n");
}
Checks::check_exit(VCPKG_LINE_INFO,
- !compiler_hash.empty(),
+ !compiler_info.hash.empty(),
"Error occurred while detecting compiler information. Pass `--debug` for more information.");
- Debug::print("Detecting compiler hash for triplet ", triplet, ": ", compiler_hash, "\n");
- return compiler_hash;
+ Debug::print("Detecting compiler hash for triplet ", triplet, ": ", compiler_info.hash, "\n");
+ return compiler_info;
}
static std::vector<System::CMakeVariable> get_cmake_build_args(const VcpkgPaths& paths,
@@ -957,6 +1002,7 @@ namespace vcpkg::Build
abi_info.pre_build_info = std::make_unique<PreBuildInfo>(
paths, action.spec.triplet(), var_provider.get_tag_vars(action.spec).value_or_exit(VCPKG_LINE_INFO));
abi_info.toolset = paths.get_toolset(*abi_info.pre_build_info);
+ abi_info.compiler_info = paths.get_compiler_info(abi_info);
abi_info.triplet_abi = paths.get_triplet_info(abi_info);
auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis);
diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp
index 60403edbd..b76ed19d9 100644
--- a/toolsrc/src/vcpkg/vcpkgpaths.cpp
+++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp
@@ -555,6 +555,11 @@ If you wish to silence this error and use classic mode, you can:
return m_pimpl->m_env_cache.get_triplet_info(*this, abi_info);
}
+ const Build::CompilerInfo& VcpkgPaths::get_compiler_info(const Build::AbiInfo& abi_info) const
+ {
+ return m_pimpl->m_env_cache.get_compiler_info(*this, abi_info);
+ }
+
Files::Filesystem& VcpkgPaths::get_filesystem() const { return *m_pimpl->fs_ptr; }
void VcpkgPaths::track_feature_flag_metrics() const