Skip to content

Commit

Permalink
[vcpkg] Reduce dependencies and contents of vcpkgpaths.h (microsoft#1…
Browse files Browse the repository at this point in the history
…2876)

* [vcpkg] Remove globally-constructed pre-defined Triplets from vcpkg.exe

The tool should be as triplet-agnostic as possible, which leaves little room for special, pre-defined names like this. However, tests do have use of them: moved into test assets.

* [vcpkg] Move predefined tools strings vcpkgpaths.h -> tools.h

* [vcpkg] Add forward declarations to vcpkgpaths.h to reduce header deps

* Merge from origin/master

Co-authored-by: Robert Schumacher <[email protected]>
  • Loading branch information
2 people authored and remz1337 committed Aug 23, 2020
1 parent f430749 commit e4217fb
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 176 deletions.
8 changes: 7 additions & 1 deletion toolsrc/include/vcpkg-test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ namespace vcpkg::Test
const char* depends = "",
const char* triplet = "x86-windows");

extern const Triplet X86_WINDOWS;
extern const Triplet X64_WINDOWS;
extern const Triplet X86_UWP;
extern const Triplet ARM_UWP;
extern const Triplet X64_ANDROID;

/// <summary>
/// Map of source control files by their package name.
/// </summary>
struct PackageSpecMap
{
std::unordered_map<std::string, SourceControlFileLocation> map;
Triplet triplet;
PackageSpecMap(Triplet t = Triplet::X86_WINDOWS) noexcept : triplet(t) { }
PackageSpecMap(Triplet t = X86_WINDOWS) noexcept : triplet(t) { }

PackageSpec emplace(const char* name,
const char* depends = "",
Expand Down
15 changes: 15 additions & 0 deletions toolsrc/include/vcpkg/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ namespace vcpkg
{
struct VcpkgPaths;

namespace Tools
{
static const std::string SEVEN_ZIP = "7zip";
static const std::string SEVEN_ZIP_ALT = "7z";
static const std::string MAVEN = "mvn";
static const std::string CMAKE = "cmake";
static const std::string GIT = "git";
static const std::string MONO = "mono";
static const std::string NINJA = "ninja";
static const std::string NUGET = "nuget";
static const std::string IFW_INSTALLER_BASE = "ifw_installerbase";
static const std::string IFW_BINARYCREATOR = "ifw_binarycreator";
static const std::string IFW_REPOGEN = "ifw_repogen";
}

struct ToolCache
{
virtual ~ToolCache() { }
Expand Down
17 changes: 1 addition & 16 deletions toolsrc/include/vcpkg/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
#include <vcpkg/base/optional.h>
#include <vcpkg/base/system.h>

#include <vcpkg/vcpkgcmdarguments.h>

#include <string>

namespace vcpkg
{
struct TripletInstance;
struct VcpkgCmdArguments;

struct Triplet
{
Expand All @@ -18,20 +17,6 @@ namespace vcpkg

static Triplet from_canonical_name(std::string&& triplet_as_string);

static const Triplet X86_WINDOWS;
static const Triplet X64_WINDOWS;
static const Triplet ARM_WINDOWS;
static const Triplet ARM64_WINDOWS;
static const Triplet X86_UWP;
static const Triplet X64_UWP;
static const Triplet ARM_UWP;
static const Triplet ARM64_UWP;

static const Triplet ARM_ANDROID;
static const Triplet ARM64_ANDROID;
static const Triplet X86_ANDROID;
static const Triplet X64_ANDROID;

const std::string& canonical_name() const;
const std::string& to_string() const;
void to_string(std::string& out) const;
Expand Down
26 changes: 6 additions & 20 deletions toolsrc/include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,11 @@
#include <vcpkg/base/files.h>
#include <vcpkg/base/lazy.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/util.h>

#include <vcpkg/binaryparagraph.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/tools.h>
#include <vcpkg/vcpkgcmdarguments.h>

namespace vcpkg
{
namespace Tools
{
static const std::string SEVEN_ZIP = "7zip";
static const std::string SEVEN_ZIP_ALT = "7z";
static const std::string MAVEN = "mvn";
static const std::string CMAKE = "cmake";
static const std::string GIT = "git";
static const std::string MONO = "mono";
static const std::string NINJA = "ninja";
static const std::string NUGET = "nuget";
static const std::string IFW_INSTALLER_BASE = "ifw_installerbase";
static const std::string IFW_BINARYCREATOR = "ifw_binarycreator";
static const std::string IFW_REPOGEN = "ifw_repogen";
}

struct ToolsetArchOption
{
CStringView name;
Expand Down Expand Up @@ -61,6 +42,11 @@ namespace vcpkg
struct VcpkgPathsImpl;
}

struct BinaryParagraph;
struct VcpkgCmdArguments;
struct PackageSpec;
struct Triplet;

struct VcpkgPaths : Util::MoveOnlyBase
{
struct TripletFile
Expand Down
8 changes: 5 additions & 3 deletions toolsrc/src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include <string>

#include <vcpkg-test/util.h>

using namespace vcpkg;

TEST_CASE ("reformat_version semver-ish", "[reformat_version]")
Expand Down Expand Up @@ -65,7 +67,7 @@ Build-Depends: bzip
REQUIRE(maybe_scf.has_value());
SourceControlFileLocation scfl{std::move(*maybe_scf.get()), fs::path()};

Dependencies::InstallPlanAction ipa(PackageSpec{"zlib2", Triplet::X64_WINDOWS},
Dependencies::InstallPlanAction ipa(PackageSpec{"zlib2", Test::X64_WINDOWS},
scfl,
Dependencies::RequestType::USER_REQUESTED,
{{"a", {}}, {"b", {}}});
Expand Down Expand Up @@ -177,7 +179,7 @@ Description: a spiffy compression library wrapper
REQUIRE(maybe_scf.has_value());
SourceControlFileLocation scfl{std::move(*maybe_scf.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
plan.install_actions[0].spec = PackageSpec("zlib", Triplet::X64_ANDROID);
plan.install_actions[0].spec = PackageSpec("zlib", Test::X64_ANDROID);
plan.install_actions[0].source_control_file_location = scfl;
plan.install_actions[0].abi_info = Build::AbiInfo{};
plan.install_actions[0].abi_info.get()->package_abi = "packageabi";
Expand All @@ -200,7 +202,7 @@ Description: a spiffy compression library wrapper
REQUIRE(maybe_scf2.has_value());
SourceControlFileLocation scfl2{std::move(*maybe_scf2.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
plan.install_actions[1].spec = PackageSpec("zlib2", Triplet::X64_ANDROID);
plan.install_actions[1].spec = PackageSpec("zlib2", Test::X64_ANDROID);
plan.install_actions[1].source_control_file_location = scfl2;
plan.install_actions[1].abi_info = Build::AbiInfo{};
plan.install_actions[1].abi_info.get()->package_abi = "packageabi2";
Expand Down
16 changes: 8 additions & 8 deletions toolsrc/src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ TEST_CASE ("filter depends", "[dependencies]")
auto deps_ = parse_dependencies_list("liba (!uwp), libb, libc (uwp)");
REQUIRE(deps_);
auto& deps = *deps_.get();
auto v = filter_dependencies(deps, Triplet::X64_WINDOWS, x64_win_cmake_vars);
auto v = filter_dependencies(deps, Test::X64_WINDOWS, x64_win_cmake_vars);
REQUIRE(v.size() == 2);
REQUIRE(v.at(0).package_spec.name() == "liba");
REQUIRE(v.at(1).package_spec.name() == "libb");

auto v2 = filter_dependencies(deps, Triplet::ARM_UWP, arm_uwp_cmake_vars);
auto v2 = filter_dependencies(deps, Test::ARM_UWP, arm_uwp_cmake_vars);
REQUIRE(v.size() == 2);
REQUIRE(v2.at(0).package_spec.name() == "libb");
REQUIRE(v2.at(1).package_spec.name() == "libc");
Expand Down Expand Up @@ -101,7 +101,7 @@ TEST_CASE ("resolve_deps_as_top_level", "[dependencies]")
var_provider.dep_info_vars[{"a", t_linux}].emplace("VCPKG_CMAKE_SYSTEM_NAME", "Linux");
{
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("a").source_control_file, Triplet::X86_WINDOWS, {}, var_provider);
*spec_map.map.at("a").source_control_file, Test::X86_WINDOWS, {}, var_provider);
REQUIRE(deps.size() == 1);
REQUIRE(deps.at(0) == spec_b);
}
Expand All @@ -114,37 +114,37 @@ TEST_CASE ("resolve_deps_as_top_level", "[dependencies]")
{
// without defaults
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("c").source_control_file, Triplet::X86_WINDOWS, {}, var_provider);
*spec_map.map.at("c").source_control_file, Test::X86_WINDOWS, {}, var_provider);
REQUIRE(deps.size() == 1);
REQUIRE(deps.at(0) == spec_b);
}
FullPackageSpec spec_b_with_b1{spec_b.package_spec, {"b1"}};
{
// with defaults of c (c1)
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("c").source_control_file, Triplet::X86_WINDOWS, {"default"}, var_provider);
*spec_map.map.at("c").source_control_file, Test::X86_WINDOWS, {"default"}, var_provider);
REQUIRE(deps.size() == 1);
REQUIRE(deps.at(0) == spec_b_with_b1);
}
{
// with c1
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("c").source_control_file, Triplet::X86_WINDOWS, {"c1"}, var_provider);
*spec_map.map.at("c").source_control_file, Test::X86_WINDOWS, {"c1"}, var_provider);
REQUIRE(deps.size() == 1);
REQUIRE(deps.at(0) == spec_b_with_b1);
}
{
// with c2 implying c1
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("c").source_control_file, Triplet::X86_WINDOWS, {"c2"}, var_provider);
*spec_map.map.at("c").source_control_file, Test::X86_WINDOWS, {"c2"}, var_provider);
REQUIRE(deps.size() == 2);
REQUIRE(deps.at(0) == spec_a);
REQUIRE(deps.at(1) == spec_b_with_b1);
}
{
// d -> c[core]
auto deps = vcpkg::Dependencies::resolve_deps_as_top_level(
*spec_map.map.at("d").source_control_file, Triplet::X86_WINDOWS, {}, var_provider);
*spec_map.map.at("d").source_control_file, Test::X86_WINDOWS, {}, var_provider);
REQUIRE(deps.size() == 1);
REQUIRE(deps.at(0) == spec_c);
}
Expand Down
1 change: 1 addition & 0 deletions toolsrc/src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <vcpkg/paragraphs.h>
#include <vcpkg/sourceparagraph.h>
#include <vcpkg/vcpkgcmdarguments.h>

#include <vcpkg-test/util.h>

Expand Down
Loading

0 comments on commit e4217fb

Please sign in to comment.