Skip to content

Commit

Permalink
[vcpkg] Introduce experimental workaround X_VCPKG_NUGET_ID_PREFIX (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft authored Apr 1, 2021
1 parent ce90b08 commit e70d42b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
29 changes: 17 additions & 12 deletions include/vcpkg/binarycaching.private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ 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;

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
Expand Down
6 changes: 5 additions & 1 deletion src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
22 changes: 18 additions & 4 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*>&) { }
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e70d42b

Please sign in to comment.