From 75a0685514fd6f2e10adf7e2225ba0805dfe3238 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 30 Mar 2021 13:54:34 -0700 Subject: [PATCH] [vcpkg] Introduce experimental workaround X_VCPKG_NUGET_ID_PREFIX --- include/vcpkg/binarycaching.private.h | 29 ++++++++++++++++----------- src/vcpkg-test/binarycaching.cpp | 6 +++++- src/vcpkg/binarycaching.cpp | 22 ++++++++++++++++---- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/include/vcpkg/binarycaching.private.h b/include/vcpkg/binarycaching.private.h index 2ac4467929..3106e14e9d 100644 --- a/include/vcpkg/binarycaching.private.h +++ b/include/vcpkg/binarycaching.private.h @@ -13,18 +13,7 @@ namespace vcpkg struct NugetReference { - explicit NugetReference(const Dependencies::InstallPlanAction& action) - : NugetReference(action.spec, - action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO) - .source_control_file->core_paragraph->version, - action.abi_info.value_or_exit(VCPKG_LINE_INFO).package_abi) - { - } - - NugetReference(const PackageSpec& spec, const std::string& raw_version, const std::string& abi_tag) - : id(spec.dir()), version(reformat_version(raw_version, abi_tag)) - { - } + NugetReference(std::string id, std::string version) : id(std::move(id)), version(std::move(version)) { } std::string id; std::string version; @@ -32,6 +21,22 @@ namespace vcpkg std::string nupkg_filename() const { return Strings::concat(id, '.', version, ".nupkg"); } }; + inline NugetReference make_nugetref(const PackageSpec& spec, + const std::string& raw_version, + const std::string& abi_tag, + const std::string& prefix) + { + return {Strings::concat(prefix, spec.dir()), reformat_version(raw_version, abi_tag)}; + } + inline NugetReference make_nugetref(const Dependencies::InstallPlanAction& action, const std::string& prefix) + { + return make_nugetref(action.spec, + action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO) + .source_control_file->core_paragraph->version, + action.abi_info.value_or_exit(VCPKG_LINE_INFO).package_abi, + prefix); + } + namespace details { struct NuGetRepoInfo diff --git a/src/vcpkg-test/binarycaching.cpp b/src/vcpkg-test/binarycaching.cpp index d4352d07e9..d4635831d7 100644 --- a/src/vcpkg-test/binarycaching.cpp +++ b/src/vcpkg-test/binarycaching.cpp @@ -100,7 +100,11 @@ Build-Depends: bzip compiler_info.version = "compilerversion"; ipa.abi_info.get()->compiler_info = compiler_info; - NugetReference ref(ipa); + NugetReference ref2 = make_nugetref(ipa, "prefix_"); + + REQUIRE(ref2.nupkg_filename() == "prefix_zlib2_x64-windows.1.5.0-vcpkgpackageabi.nupkg"); + + NugetReference ref = make_nugetref(ipa, ""); REQUIRE(ref.nupkg_filename() == "zlib2_x64-windows.1.5.0-vcpkgpackageabi.nupkg"); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 4ce25ac4be..6cfd365d1a 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -19,6 +19,19 @@ using namespace vcpkg; namespace { + static const std::string& get_nuget_prefix() + { + static std::string nuget_prefix = []() { + auto x = System::get_environment_variable("X_VCPKG_NUGET_ID_PREFIX").value_or(""); + if (!x.empty()) + { + x.push_back('_'); + } + return x; + }(); + return nuget_prefix; + } + struct NullBinaryProvider : IBinaryProvider { void prefetch(const VcpkgPaths&, std::vector&) { } @@ -488,7 +501,7 @@ namespace auto& spec = action->spec; fs.remove_all(paths.package_dir(spec), VCPKG_LINE_INFO); - nuget_refs.emplace_back(spec, NugetReference(*action)); + nuget_refs.emplace_back(spec, make_nugetref(*action, get_nuget_prefix())); } if (nuget_refs.empty()) @@ -643,7 +656,7 @@ namespace auto& spec = action.spec; - NugetReference nuget_ref(action); + NugetReference nuget_ref = make_nugetref(action, get_nuget_prefix()); auto nuspec_path = paths.buildtrees / spec.name() / (spec.triplet().to_string() + ".nuspec"); paths.get_filesystem().write_contents( nuspec_path, generate_nuspec(paths, action, nuget_ref), VCPKG_LINE_INFO); @@ -1644,8 +1657,9 @@ void vcpkg::help_topic_binary_caching(const VcpkgPaths&) std::string vcpkg::generate_nuget_packages_config(const Dependencies::ActionPlan& action) { - auto refs = Util::fmap(action.install_actions, - [&](const Dependencies::InstallPlanAction& ipa) { return NugetReference(ipa); }); + auto refs = Util::fmap(action.install_actions, [&](const Dependencies::InstallPlanAction& ipa) { + return make_nugetref(ipa, get_nuget_prefix()); + }); XmlSerializer xml; xml.emit_declaration().line_break(); xml.open_tag("packages").line_break();