Skip to content

Commit

Permalink
don't use triplet file hash. Hash variables instead
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort committed Jun 19, 2022
1 parent 9268e36 commit 64f065f
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 50 deletions.
8 changes: 4 additions & 4 deletions azure-pipelines/end-to-end-tests-dir/compilertracking.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ $args = $commonArgs + @("--overlay-triplets=$PSScriptRoot/../e2e_ports/compilert
# Test simple installation
Run-Vcpkg -TestArgs ($args + @("install", "vcpkg-hello-world-1"))
Throw-IfFailed
if (-Not (select-string "^triplet_abi [0-9a-f]+-[0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-1/vcpkg_abi_info.txt")) {
if (-Not (select-string "^toolchain_abi [0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-1/vcpkg_abi_info.txt")) {
throw "Expected vcpkg-hello-world-1 to perform compiler detection"
}
Remove-Item -Recurse -Force $installRoot

Run-Vcpkg -TestArgs ($args + @("install", "vcpkg-hello-world-2"))
Throw-IfFailed
if (-Not (select-string "^triplet_abi [0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-2/vcpkg_abi_info.txt")) {
if (-Not (select-string "^toolchain_abi [0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-2/vcpkg_abi_info.txt")) {
throw "Expected vcpkg-hello-world-2 to not perform compiler detection"
}
Remove-Item -Recurse -Force $installRoot

Run-Vcpkg -TestArgs ($args + @("install", "vcpkg-hello-world-2", "vcpkg-hello-world-1"))
Throw-IfFailed
if (-Not (select-string "^triplet_abi [0-9a-f]+-[0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-1/vcpkg_abi_info.txt")) {
if (-Not (select-string "^toolchain_abi [0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-1/vcpkg_abi_info.txt")) {
throw "Expected vcpkg-hello-world-1 to perform compiler detection"
}
if (-Not (select-string "^triplet_abi [0-9a-f]+-[0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-2/vcpkg_abi_info.txt")) {
if (-Not (select-string "^toolchain_abi [0-9a-f]+$" "$installRoot/x64-linux/share/vcpkg-hello-world-2/vcpkg_abi_info.txt")) {
throw "Expected vcpkg-hello-world-2 to not perform compiler detection"
}
15 changes: 12 additions & 3 deletions include/vcpkg-test/mockcmakevarprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ namespace vcpkg::Test
dep_info_vars.emplace(spec, SMap{});
}

void load_tag_vars(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const override
void load_tag_vars_and_triplet_hash(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const override
{
for (auto&& spec : specs)
{
tag_vars.emplace(spec.package_spec, SMap{});
triplet_hashs.emplace(
spec.package_spec,
Strings::concat("fake hash for ", spec.package_spec.triplet(), " host:", host_triplet));
}

(void)(port_provider);
(void)(host_triplet);
}
Expand All @@ -37,8 +43,11 @@ namespace vcpkg::Test
Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars(
const PackageSpec& spec) const override;

Optional<std::string> get_triplet_hash(const PackageSpec& spec) const override;

mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> dep_info_vars;
mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> tag_vars;
mutable std::unordered_map<PackageSpec, std::string> triplet_hashs;
mutable std::unordered_map<Triplet, std::unordered_map<std::string, std::string>> generic_triplet_vars;
};
}
7 changes: 3 additions & 4 deletions include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace vcpkg::Build
{
std::unique_ptr<PreBuildInfo> pre_build_info;
Optional<const Toolset&> toolset;
Optional<const std::string&> triplet_abi;
Optional<std::string> triplet_abi;
std::string package_abi;
Optional<Path> abi_tag_file;
Optional<const CompilerInfo&> compiler_info;
Expand All @@ -386,21 +386,20 @@ namespace vcpkg::Build
explicit EnvCache(bool compiler_tracking) : m_compiler_tracking(compiler_tracking) { }

const 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_toolchain_abi(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> triplet_infos;
Cache<std::string, std::string> triplet_infos_without_compiler;
Cache<std::string, CompilerInfo> compiler_info;
};
Cache<Path, TripletMapEntry> m_triplet_cache;
Cache<Path, std::string> m_toolchain_cache;

const TripletMapEntry& get_triplet_cache(const Filesystem& fs, const Path& p);
const TripletMapEntry& get_triplet_cache(const Path& p);

#if defined(_WIN32)
struct EnvMapEntry
Expand Down
8 changes: 5 additions & 3 deletions include/vcpkg/cmakevars.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ namespace vcpkg::CMakeVars
virtual Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars(
const PackageSpec& spec) const = 0;

virtual Optional<std::string> get_triplet_hash(const PackageSpec& spec) const = 0;

virtual void load_generic_triplet_vars(Triplet triplet) const = 0;

virtual void load_dep_info_vars(Span<const PackageSpec> specs, Triplet host_triplet) const = 0;

virtual void load_tag_vars(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const = 0;
virtual void load_tag_vars_and_triplet_hash(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const = 0;

void load_tag_vars(const vcpkg::Dependencies::ActionPlan& action_plan,
const PortFileProvider::PortFileProvider& port_provider,
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace vcpkg
Filesystem& get_filesystem() const;

const 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_toolchain_abi(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(); }

Expand Down
7 changes: 7 additions & 0 deletions src/vcpkg-test/mockcmakevarsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ namespace vcpkg::Test
if (it == tag_vars.end()) return nullopt;
return it->second;
}

Optional<std::string> MockCMakeVarProvider::get_triplet_hash(const PackageSpec& spec) const
{
auto it = triplet_hashs.find(spec);
if (it == triplet_hashs.end()) return nullopt;
return it->second;
}
}
1 change: 0 additions & 1 deletion src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ using namespace vcpkg;

namespace
{

DECLARE_AND_REGISTER_MESSAGE(InvalidFormatString,
(msg::actual),
"{actual} is the provided format string",
Expand Down
33 changes: 16 additions & 17 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,9 @@ namespace vcpkg::Build
});
}

const EnvCache::TripletMapEntry& EnvCache::get_triplet_cache(const Filesystem& fs, const Path& p)
const EnvCache::TripletMapEntry& EnvCache::get_triplet_cache(const Path& p)
{
return m_triplet_cache.get_lazy(p, [&]() -> TripletMapEntry {
return TripletMapEntry{Hash::get_file_hash(fs, p, Hash::Algorithm::Sha256).value_or_exit(VCPKG_LINE_INFO)};
});
return m_triplet_cache.get_lazy(p, [&]() -> TripletMapEntry { return TripletMapEntry{}; });
}

const CompilerInfo& EnvCache::get_compiler_info(const VcpkgPaths& paths, const AbiInfo& abi_info)
Expand All @@ -691,7 +689,7 @@ namespace vcpkg::Build

auto&& toolchain_hash = get_toolchain_cache(m_toolchain_cache, abi_info.pre_build_info->toolchain_file(), fs);

auto&& triplet_entry = get_triplet_cache(fs, triplet_file_path);
auto&& triplet_entry = get_triplet_cache(triplet_file_path);

return triplet_entry.compiler_info.get_lazy(toolchain_hash, [&]() -> CompilerInfo {
if (m_compiler_tracking)
Expand All @@ -705,28 +703,27 @@ namespace vcpkg::Build
});
}

const std::string& EnvCache::get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info)
const std::string& EnvCache::get_toolchain_abi(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 auto triplet_file_path = paths.get_triplet_file_path(abi_info.pre_build_info->triplet);

auto&& toolchain_hash = get_toolchain_cache(m_toolchain_cache, abi_info.pre_build_info->toolchain_file(), fs);

auto&& triplet_entry = get_triplet_cache(fs, triplet_file_path);
auto&& triplet_entry = get_triplet_cache(triplet_file_path);

if (m_compiler_tracking && !abi_info.pre_build_info->disable_compiler_tracking)
{
return triplet_entry.triplet_infos.get_lazy(toolchain_hash, [&]() -> std::string {
auto& compiler_info = get_compiler_info(paths, abi_info);
return Strings::concat(triplet_entry.hash, '-', toolchain_hash, '-', compiler_info.hash);
return Strings::concat(toolchain_hash, '-', compiler_info.hash);
});
}
else
{
return triplet_entry.triplet_infos_without_compiler.get_lazy(toolchain_hash, [&]() -> std::string {
return Strings::concat(triplet_entry.hash, '-', toolchain_hash);
});
return triplet_entry.triplet_infos_without_compiler.get_lazy(
toolchain_hash, [&]() -> std::string { return Strings::concat(toolchain_hash); });
}
}

Expand Down Expand Up @@ -1221,7 +1218,7 @@ namespace vcpkg::Build

struct AbiTagAndFiles
{
const std::string* triplet_abi;
std::string triplet_abi;
std::string tag;
Path tag_file;

Expand All @@ -1232,6 +1229,7 @@ namespace vcpkg::Build

static Optional<AbiTagAndFiles> compute_abi_tag(const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action,
const CMakeVars::CMakeVarProvider& var_provider,
Span<const AbiEntry> dependency_abis)
{
auto& fs = paths.get_filesystem();
Expand Down Expand Up @@ -1263,9 +1261,10 @@ namespace vcpkg::Build
std::vector<AbiEntry> abi_tag_entries(dependency_abis.begin(), dependency_abis.end());

const auto& abi_info = action.abi_info.value_or_exit(VCPKG_LINE_INFO);
const auto& triplet_abi = paths.get_triplet_info(abi_info);
abi_tag_entries.emplace_back("triplet", triplet.canonical_name());
const auto& toolchain_abi = paths.get_toolchain_abi(abi_info);
std::string triplet_abi = var_provider.get_triplet_hash(action.spec).value_or_exit(VCPKG_LINE_INFO);
abi_tag_entries.emplace_back("triplet_abi", triplet_abi);
abi_tag_entries.emplace_back("toolchain_abi", toolchain_abi);
abi_entries_from_abi_info(abi_info, abi_tag_entries);

// If there is an unusually large number of files in the port then
Expand Down Expand Up @@ -1368,7 +1367,7 @@ namespace vcpkg::Build
fs.write_contents(abi_file_path, full_abi_info, VCPKG_LINE_INFO);

return AbiTagAndFiles{
&triplet_abi,
triplet_abi,
Hash::get_file_hash(fs, abi_file_path, Hash::Algorithm::Sha256).value_or_exit(VCPKG_LINE_INFO),
abi_file_path,
std::move(files),
Expand Down Expand Up @@ -1430,11 +1429,11 @@ namespace vcpkg::Build
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);

auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis);
auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, var_provider, dependency_abis);
if (auto p = maybe_abi_tag_and_file.get())
{
abi_info.compiler_info = paths.get_compiler_info(abi_info);
abi_info.triplet_abi = *p->triplet_abi;
abi_info.triplet_abi = std::move(p->triplet_abi);
abi_info.package_abi = std::move(p->tag);
abi_info.abi_tag_file = std::move(p->tag_file);
abi_info.relative_port_files = std::move(p->files);
Expand Down
Loading

0 comments on commit 64f065f

Please sign in to comment.