Skip to content

Commit

Permalink
Restore old CMakeVarProvider interface changed in microsoft#1109
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort committed Jun 28, 2023
1 parent 021d1c9 commit 2428299
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
8 changes: 5 additions & 3 deletions include/vcpkg-test/mockcmakevarprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ namespace vcpkg::Test
dep_info_vars.emplace(spec, SMap{});
}

void load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const override
void load_tag_vars(Span<const FullPackageSpec> specs,
Span<Path> /*port_locations*/,
Triplet host_triplet) const override
{
for (auto&& install_action : action_plan.install_actions)
tag_vars.emplace(install_action.spec, SMap{});
for (auto&& spec : specs)
tag_vars.emplace(spec.package_spec, SMap{});
(void)(host_triplet);
}

Expand Down
8 changes: 7 additions & 1 deletion include/vcpkg/cmakevars.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vcpkg/base/fwd/files.h>

#include <vcpkg/fwd/dependencies.h>
#include <vcpkg/fwd/portfileprovider.h>
#include <vcpkg/fwd/vcpkgpaths.h>
Expand Down Expand Up @@ -32,7 +34,11 @@ namespace vcpkg::CMakeVars

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

virtual void load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const = 0;
virtual void load_tag_vars(Span<const FullPackageSpec> specs,
Span<Path> port_locations,
Triplet host_triplet) const = 0;

void load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const;
};

std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(const VcpkgPaths& paths);
Expand Down
38 changes: 29 additions & 9 deletions src/vcpkg/cmakevars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
using namespace vcpkg;
namespace vcpkg::CMakeVars
{

void CMakeVarProvider::load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const
{
std::vector<FullPackageSpec> install_package_specs;
std::vector<Path> port_locations;
install_package_specs.reserve(action_plan.install_actions.size());
port_locations.reserve(action_plan.install_actions.size());
for (auto&& action : action_plan.install_actions)
{
install_package_specs.emplace_back(action.spec, action.feature_list);
port_locations.emplace_back(
action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO).source_location);
}

load_tag_vars(install_package_specs, port_locations, host_triplet);
}

const std::unordered_map<std::string, std::string>& CMakeVarProvider::get_or_load_dep_info_vars(
const PackageSpec& spec, Triplet host_triplet) const
{
Expand All @@ -39,7 +56,9 @@ namespace vcpkg::CMakeVars

void load_dep_info_vars(View<PackageSpec> specs, Triplet host_triplet) const override;

void load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const override;
void load_tag_vars(Span<const FullPackageSpec> specs,
Span<Path> port_locations,
Triplet host_triplet) const override;

Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars(
Triplet triplet) const override;
Expand Down Expand Up @@ -358,18 +377,19 @@ endfunction()
}
}

void TripletCMakeVarProvider::load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const
void TripletCMakeVarProvider::load_tag_vars(Span<const FullPackageSpec> specs,
Span<Path> port_locations,
Triplet host_triplet) const
{
if (action_plan.install_actions.empty()) return;
if (specs.empty()) return;
std::vector<std::pair<FullPackageSpec, std::string>> spec_abi_settings;
spec_abi_settings.reserve(action_plan.install_actions.size());
spec_abi_settings.reserve(specs.size());
Checks::check_exit(VCPKG_LINE_INFO, specs.size() == port_locations.size());

for (const auto& install_action : action_plan.install_actions)
for (size_t i = 0; i < specs.size(); ++i)
{
auto& scfl = install_action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);
const auto override_path = scfl.source_location / "vcpkg-abi-settings.cmake";
spec_abi_settings.emplace_back(FullPackageSpec{install_action.spec, install_action.feature_list},
override_path.generic_u8string());
const auto override_path = port_locations[i] / "vcpkg-abi-settings.cmake";
spec_abi_settings.emplace_back(specs[i], override_path.generic_u8string());
}

std::vector<std::vector<std::pair<std::string, std::string>>> vars(spec_abi_settings.size());
Expand Down
5 changes: 4 additions & 1 deletion src/vcpkg/commands.test-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ namespace vcpkg::Commands::TestFeatures
msg::println(msgComputeInstallPlans, msg::count = specs_to_test.size());

std::vector<FullPackageSpec> specs;
std::vector<Path> port_locations;
std::vector<const InstallPlanAction*> actions_to_check;
CreateInstallPlanOptions install_plan_options{host_triplet, paths.packages(), UnsupportedPortAction::Warn};
auto install_plans = Util::fmap(specs_to_test, [&](auto& spec) {
Expand All @@ -293,13 +294,15 @@ namespace vcpkg::Commands::TestFeatures
for (auto& actions : install_plan.install_actions)
{
specs.emplace_back(actions.spec, actions.feature_list);
port_locations.emplace_back(
actions.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO).source_location);
}
actions_to_check.push_back(&install_plan.install_actions.back());
}
return std::make_pair(spec, std::move(install_plan));
});
msg::println(msgComputeAllAbis);
var_provider.load_tag_vars(specs, provider, host_triplet);
var_provider.load_tag_vars(specs, port_locations, host_triplet);
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
PortAbiCache cache;
for (auto& [spec, install_plan] : install_plans)
Expand Down

0 comments on commit 2428299

Please sign in to comment.