[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>
This commit is contained in:
Francois Rivard 2020-09-27 21:18:27 -04:00 коммит произвёл GitHub
Родитель 64a281b865
Коммит 741c8cbecd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 100 добавлений и 14 удалений

Просмотреть файл

@ -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_ID_RUN 1)
set(CMAKE_C_COMPILER_FORCED 1) set(CMAKE_C_COMPILER_FORCED 1)
set(CMAKE_CXX_COMPILER_WORKS 1) set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_COMPILER_FORCED 1) set(CMAKE_CXX_COMPILER_FORCED 1)
endif() endif()
@ -18,3 +17,5 @@ file(SHA1 "${CMAKE_C_COMPILER}" C_HASH)
string(SHA1 COMPILER_HASH "${C_HASH}${CXX_HASH}") string(SHA1 COMPILER_HASH "${C_HASH}${CXX_HASH}")
message("#COMPILER_HASH#${COMPILER_HASH}") message("#COMPILER_HASH#${COMPILER_HASH}")
message("#COMPILER_CXX_VERSION#${CMAKE_CXX_COMPILER_VERSION}")
message("#COMPILER_CXX_ID#${CMAKE_CXX_COMPILER_ID}")

Просмотреть файл

@ -305,6 +305,13 @@ namespace vcpkg::Build
fs::path tag_file; fs::path tag_file;
}; };
struct CompilerInfo
{
std::string id;
std::string version;
std::string hash;
};
struct AbiInfo struct AbiInfo
{ {
std::unique_ptr<PreBuildInfo> pre_build_info; std::unique_ptr<PreBuildInfo> pre_build_info;
@ -312,6 +319,7 @@ namespace vcpkg::Build
Optional<const std::string&> triplet_abi; Optional<const std::string&> triplet_abi;
std::string package_abi; std::string package_abi;
Optional<fs::path> abi_tag_file; Optional<fs::path> abi_tag_file;
Optional<const CompilerInfo&> compiler_info;
}; };
void compute_all_abis(const VcpkgPaths& paths, 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 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 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: private:
struct TripletMapEntry struct TripletMapEntry
{ {
std::string hash; std::string hash;
Cache<std::string, std::string> compiler_hashes; Cache<std::string, std::string> compiler_hashes;
Cache<std::string, CompilerInfo> compiler_info;
}; };
Cache<fs::path, TripletMapEntry> m_triplet_cache; Cache<fs::path, TripletMapEntry> m_triplet_cache;
Cache<fs::path, std::string> m_toolchain_cache; Cache<fs::path, std::string> m_toolchain_cache;

Просмотреть файл

@ -37,6 +37,7 @@ namespace vcpkg
{ {
struct PreBuildInfo; struct PreBuildInfo;
struct AbiInfo; struct AbiInfo;
struct CompilerInfo;
} }
namespace System namespace System
@ -121,6 +122,7 @@ namespace vcpkg
const System::Environment& get_action_env(const Build::AbiInfo& abi_info) const; 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 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(); } bool manifest_mode_enabled() const { return get_manifest().has_value(); }
void track_feature_flag_metrics() const; void track_feature_flag_metrics() const;

Просмотреть файл

@ -88,6 +88,11 @@ Build-Depends: bzip
ipa.abi_info.get()->package_abi = "packageabi"; ipa.abi_info.get()->package_abi = "packageabi";
std::string tripletabi("tripletabi"); std::string tripletabi("tripletabi");
ipa.abi_info.get()->triplet_abi = 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); NugetReference ref(ipa);
@ -110,6 +115,9 @@ Build-Depends: bzip
a spiffy compression library wrapper a spiffy compression library wrapper
Version: 1.5 Version: 1.5
Triplet: x64-windows
CXX Compiler id: compilerid
CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi Triplet/Compiler hash: tripletabi
Features: a, b Features: a, b
Dependencies: Dependencies:
@ -139,6 +147,9 @@ Dependencies:
a spiffy compression library wrapper a spiffy compression library wrapper
Version: 1.5 Version: 1.5
Triplet: x64-windows
CXX Compiler id: compilerid
CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi Triplet/Compiler hash: tripletabi
Features: a, b Features: a, b
Dependencies: Dependencies:
@ -168,6 +179,9 @@ Dependencies:
a spiffy compression library wrapper a spiffy compression library wrapper
Version: 1.5 Version: 1.5
Triplet: x64-windows
CXX Compiler id: compilerid
CXX Compiler version: compilerversion
Triplet/Compiler hash: tripletabi Triplet/Compiler hash: tripletabi
Features: a, b Features: a, b
Dependencies: Dependencies:

Просмотреть файл

@ -1016,13 +1016,21 @@ std::string vcpkg::generate_nuspec(const VcpkgPaths& paths,
auto& spec = action.spec; auto& spec = action.spec;
auto& scf = *action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO).source_control_file; auto& scf = *action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO).source_control_file;
auto& version = scf.core_paragraph->version; 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 = std::string description =
Strings::concat("NOT FOR DIRECT USE. Automatically generated cache package.\n\n", Strings::concat("NOT FOR DIRECT USE. Automatically generated cache package.\n\n",
Strings::join("\n ", scf.core_paragraph->description), Strings::join("\n ", scf.core_paragraph->description),
"\n\nVersion: ", "\n\nVersion: ",
version, version,
"\nTriplet: ",
spec.triplet().to_string(),
"\nCXX Compiler id: ",
compiler_info.id,
"\nCXX Compiler version: ",
compiler_info.version,
"\nTriplet/Compiler hash: ", "\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:", "\nFeatures:",
Strings::join(",", action.feature_list, [](const std::string& s) { return " " + s; }), Strings::join(",", action.feature_list, [](const std::string& s) { return " " + s; }),
"\nDependencies:\n"); "\nDependencies:\n");

Просмотреть файл

@ -347,7 +347,33 @@ namespace vcpkg::Build
} }
#endif #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) 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 { return triplet_entry.compiler_hashes.get_lazy(toolchain_hash, [&]() -> std::string {
if (m_compiler_tracking) if (m_compiler_tracking)
{ {
auto compiler_hash = load_compiler_hash(paths, abi_info); auto& compiler_info = triplet_entry.compiler_info.get_lazy(toolchain_hash, [&]() -> CompilerInfo {
return Strings::concat(triplet_entry.hash, '-', toolchain_hash, '-', compiler_hash); 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 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; auto triplet = abi_info.pre_build_info->triplet;
System::print2("Detecting compiler hash for triplet ", triplet, "...\n"); System::print2("Detecting compiler hash for triplet ", triplet, "...\n");
@ -499,14 +534,24 @@ namespace vcpkg::Build
auto stdoutlog = buildpath / ("stdout-" + triplet.canonical_name() + ".log"); 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); 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)); 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( System::cmd_execute_and_stream_lines(
command, command,
[&](const std::string& s) { [&](const std::string& s) {
static const StringLiteral s_marker = "#COMPILER_HASH#"; static const StringLiteral s_hash_marker = "#COMPILER_HASH#";
if (Strings::starts_with(s, s_marker)) if (Strings::starts_with(s, s_hash_marker))
{ {
compiler_hash = s.data() + s_marker.size(); 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_info.id = s.data() + s_id_marker.size();
} }
Debug::print(s, '\n'); Debug::print(s, '\n');
out_file.write(s.data(), s.size()).put('\n'); out_file.write(s.data(), s.size()).put('\n');
@ -516,7 +561,7 @@ namespace vcpkg::Build
env); env);
out_file.close(); out_file.close();
if (compiler_hash.empty()) if (compiler_info.hash.empty())
{ {
Debug::print("Compiler information tracking can be disabled by passing --", Debug::print("Compiler information tracking can be disabled by passing --",
VcpkgCmdArguments::FEATURE_FLAGS_ARG, VcpkgCmdArguments::FEATURE_FLAGS_ARG,
@ -525,11 +570,11 @@ namespace vcpkg::Build
"\n"); "\n");
} }
Checks::check_exit(VCPKG_LINE_INFO, Checks::check_exit(VCPKG_LINE_INFO,
!compiler_hash.empty(), !compiler_info.hash.empty(),
"Error occurred while detecting compiler information. Pass `--debug` for more information."); "Error occurred while detecting compiler information. Pass `--debug` for more information.");
Debug::print("Detecting compiler hash for triplet ", triplet, ": ", compiler_hash, "\n"); Debug::print("Detecting compiler hash for triplet ", triplet, ": ", compiler_info.hash, "\n");
return compiler_hash; return compiler_info;
} }
static std::vector<System::CMakeVariable> get_cmake_build_args(const VcpkgPaths& paths, 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>( 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)); 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.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); abi_info.triplet_abi = paths.get_triplet_info(abi_info);
auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis); auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis);

Просмотреть файл

@ -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); 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; } Files::Filesystem& VcpkgPaths::get_filesystem() const { return *m_pimpl->fs_ptr; }
void VcpkgPaths::track_feature_flag_metrics() const void VcpkgPaths::track_feature_flag_metrics() const