Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[supports] Add native identifier expression and x-check-support command #29

Merged
merged 6 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/vcpkg-test/mockcmakevarprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ namespace vcpkg::Test
}

void load_tag_vars(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider) const override
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const override
{
for (auto&& spec : specs)
tag_vars.emplace(spec.package_spec, SMap{});
(void)(port_provider);
(void)(host_triplet);
}

Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars(
Expand Down
6 changes: 4 additions & 2 deletions include/vcpkg/cmakevars.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ namespace vcpkg::CMakeVars
virtual void load_dep_info_vars(Span<const PackageSpec> specs) const = 0;

virtual void load_tag_vars(Span<const FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider) const = 0;
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) const;
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const;
ras0219-msft marked this conversation as resolved.
Show resolved Hide resolved
};

std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(const vcpkg::VcpkgPaths& paths);
Expand Down
19 changes: 19 additions & 0 deletions include/vcpkg/commands.check-support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands::CheckSupport
{
void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet,
Triplet host_triplet);

struct CheckSupportCommand : TripletCommand
{
void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet,
Triplet host_triplet) const override;
};
}
3 changes: 2 additions & 1 deletion include/vcpkg/commands.setinstalled.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace vcpkg::Commands::SetInstalled
const CMakeVars::CMakeVarProvider& cmake_vars,
Dependencies::ActionPlan action_plan,
DryRun dry_run,
const Optional<fs::path>& pkgsconfig_path);
const Optional<fs::path>& pkgsconfig_path,
Triplet host_triplet);
void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet,
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace vcpkg::Dependencies
/// <param name="status_db">Status of installed packages in the current environment.</param>
ActionPlan create_feature_install_plan(const PortFileProvider::PortFileProvider& provider,
const CMakeVars::CMakeVarProvider& var_provider,
const std::vector<FullPackageSpec>& specs,
View<FullPackageSpec> specs,
const StatusParagraphs& status_db,
const CreateInstallPlanOptions& options = {Triplet{}});

Expand Down
1 change: 1 addition & 0 deletions src/vcpkg-test/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TEST_CASE ("get_available_commands_type_a works", "[commands]")
"build-external",
"export",
"depend-info",
"x-check-support"
});
}
// clang-format on
120 changes: 66 additions & 54 deletions src/vcpkg-test/plan.cpp

Large diffs are not rendered by default.

37 changes: 30 additions & 7 deletions src/vcpkg-test/platform-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,37 @@ static vcpkg::ExpectedS<Expr> parse_expr(StringView s)

TEST_CASE ("platform-expression-identifier", "[platform-expression]")
{
auto m_expr = parse_expr("windows");
REQUIRE(m_expr);
auto& expr = *m_expr.get();
auto m_windows = parse_expr("windows");
REQUIRE(m_windows);
auto m_native = parse_expr("native");
REQUIRE(m_native);
auto m_staticlink = parse_expr("static");
REQUIRE(m_staticlink);
auto m_staticcrt = parse_expr("staticcrt");
REQUIRE(m_staticcrt);

auto& windows = *m_windows.get();
auto& native = *m_native.get();
auto& staticlink = *m_staticlink.get();
auto& staticcrt = *m_staticcrt.get();

CHECK(windows.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", ""}}));
CHECK(windows.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "WindowsStore"}}));
CHECK_FALSE(windows.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "Linux"}}));
CHECK_FALSE(windows.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "Darwin"}}));

CHECK(native.evaluate({{"Z_VCPKG_IS_NATIVE", "1"}}));
CHECK_FALSE(native.evaluate({{"Z_VCPKG_IS_NATIVE", "0"}}));

CHECK(staticlink.evaluate({{"VCPKG_LIBRARY_LINKAGE", "static"}, {"VCPKG_CRT_LINKAGE", "static"}}));
CHECK(staticlink.evaluate({{"VCPKG_LIBRARY_LINKAGE", "static"}, {"VCPKG_CRT_LINKAGE", "dynamic"}}));
CHECK_FALSE(staticlink.evaluate({{"VCPKG_LIBRARY_LINKAGE", "dynamic"}, {"VCPKG_CRT_LINKAGE", "static"}}));
CHECK_FALSE(staticlink.evaluate({{"VCPKG_LIBRARY_LINKAGE", "dynnamic"}, {"VCPKG_CRT_LINKAGE", "dynamic"}}));

CHECK(expr.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", ""}}));
CHECK(expr.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "WindowsStore"}}));
CHECK_FALSE(expr.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "Linux"}}));
CHECK_FALSE(expr.evaluate({{"VCPKG_CMAKE_SYSTEM_NAME", "Darwin"}}));
CHECK(staticcrt.evaluate({{"VCPKG_CRT_LINKAGE", "static"}, {"VCPKG_LIBRARY_LINKAGE", "static"}}));
CHECK(staticcrt.evaluate({{"VCPKG_CRT_LINKAGE", "static"}, {"VCPKG_LIBRARY_LINKAGE", "dynamic"}}));
CHECK_FALSE(staticcrt.evaluate({{"VCPKG_CRT_LINKAGE", "dynamic"}, {"VCPKG_LIBRARY_LINKAGE", "static"}}));
CHECK_FALSE(staticcrt.evaluate({{"VCPKG_CRT_LINKAGE", "dynamic"}, {"VCPKG_LIBRARY_LINKAGE", "dynamic"}}));
}

TEST_CASE ("platform-expression-not", "[platform-expression]")
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg-test/versionplan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ TEST_CASE ("qualified dependency", "[dependencies]")
PortFileProvider::MapPortFileProvider map_port{spec_map.map};
MockCMakeVarProvider var_provider;

auto plan = vcpkg::Dependencies::create_feature_install_plan(map_port, var_provider, {spec_a}, {});
auto plan = vcpkg::Dependencies::create_feature_install_plan(map_port, var_provider, {&spec_a, 1}, {});
REQUIRE(plan.install_actions.size() == 2);
REQUIRE(plan.install_actions.at(0).feature_list == std::vector<std::string>{"core"});

FullPackageSpec linspec_a{{"a", Triplet::from_canonical_name("x64-linux")}, {}};
var_provider.dep_info_vars[linspec_a.package_spec].emplace("VCPKG_CMAKE_SYSTEM_NAME", "Linux");
auto plan2 = vcpkg::Dependencies::create_feature_install_plan(map_port, var_provider, {linspec_a}, {});
auto plan2 = vcpkg::Dependencies::create_feature_install_plan(map_port, var_provider, {&linspec_a, 1}, {});
REQUIRE(plan2.install_actions.size() == 2);
REQUIRE(plan2.install_actions.at(0).feature_list == std::vector<std::string>{"b1", "core"});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace vcpkg::Build
auto action_plan = Dependencies::create_feature_install_plan(
provider, var_provider, std::vector<FullPackageSpec>{full_spec}, status_db, {host_triplet});

var_provider.load_tag_vars(action_plan, provider);
var_provider.load_tag_vars(action_plan, provider, host_triplet);

const PackageSpec& spec = full_spec.package_spec;
const SourceControlFile& scf = *scfl.source_control_file;
Expand Down
22 changes: 13 additions & 9 deletions src/vcpkg/cmakevars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ using vcpkg::Optional;
namespace vcpkg::CMakeVars
{
void CMakeVarProvider::load_tag_vars(const vcpkg::Dependencies::ActionPlan& action_plan,
const PortFileProvider::PortFileProvider& port_provider) const
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const
{
std::vector<FullPackageSpec> install_package_specs;
for (auto&& action : action_plan.install_actions)
{
install_package_specs.emplace_back(FullPackageSpec{action.spec, action.feature_list});
}

load_tag_vars(install_package_specs, port_provider);
load_tag_vars(install_package_specs, port_provider, host_triplet);
}

namespace
Expand All @@ -37,7 +38,8 @@ namespace vcpkg::CMakeVars
void load_dep_info_vars(View<PackageSpec> specs) const override;

void load_tag_vars(View<FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider) const override;
const PortFileProvider::PortFileProvider& port_provider,
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 @@ -254,7 +256,8 @@ endmacro()
}

void TripletCMakeVarProvider::load_tag_vars(View<FullPackageSpec> specs,
const PortFileProvider::PortFileProvider& port_provider) const
const PortFileProvider::PortFileProvider& port_provider,
Triplet host_triplet) const
{
if (specs.size() == 0) return;
std::vector<std::pair<const FullPackageSpec*, std::string>> spec_abi_settings;
Expand All @@ -276,12 +279,13 @@ endmacro()
for (const auto& spec_abi_setting : spec_abi_settings)
{
const FullPackageSpec& spec = *spec_abi_setting.first;

tag_vars.emplace(std::piecewise_construct,
std::forward_as_tuple(spec.package_spec),
std::forward_as_tuple(std::make_move_iterator(var_list_itr->begin()),
std::make_move_iterator(var_list_itr->end())));
PlatformExpression::Context ctxt{std::make_move_iterator(var_list_itr->begin()),
std::make_move_iterator(var_list_itr->end())};
++var_list_itr;

ctxt.emplace("Z_VCPKG_IS_NATIVE", host_triplet == spec.package_spec.triplet() ? "1" : "0");

tag_vars.emplace(spec.package_spec, std::move(ctxt));
}
}

Expand Down
Loading