[vcpkg] Introduce experimental workaround X_VCPKG_NUGET_ID_PREFIX
MODIFY
include/vcpkg/binarycaching.private.h
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

MODIFY
src/vcpkg-test/binarycaching.cpp
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");

MODIFY
src/vcpkg/binarycaching.cpp
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<const Dependencies::InstallPlanAction*>&) { }
@@ -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();

[vcpkg] Introduce experimental workaround X_VCPKG_NUGET_ID_PREFIX (#40)