Skip to content

Commit

Permalink
[vcpkg build] fix build command (microsoft#12072)
Browse files Browse the repository at this point in the history
  • Loading branch information
strega-nil authored Jun 26, 2020
1 parent f4daf01 commit 53521d2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 48 deletions.
12 changes: 9 additions & 3 deletions include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ namespace vcpkg::Build
{
namespace Command
{
int perform_ex(const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const VcpkgPaths& paths);
void perform_and_exit_ex(const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const VcpkgPaths& paths);

int perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
}

Expand Down Expand Up @@ -222,7 +228,7 @@ namespace vcpkg::Build
struct BuildPolicies
{
BuildPolicies() = default;
BuildPolicies(std::map<BuildPolicy, bool>&& map) : m_policies(std::move(map)) {}
BuildPolicies(std::map<BuildPolicy, bool>&& map) : m_policies(std::move(map)) { }

bool is_enabled(BuildPolicy policy) const
{
Expand Down Expand Up @@ -261,7 +267,7 @@ namespace vcpkg::Build
std::string value;

AbiEntry() = default;
AbiEntry(const std::string& key, const std::string& value) : key(key), value(value) {}
AbiEntry(const std::string& key, const std::string& value) : key(key), value(value) { }

bool operator<(const AbiEntry& other) const
{
Expand Down Expand Up @@ -290,7 +296,7 @@ namespace vcpkg::Build

struct EnvCache
{
explicit EnvCache(bool compiler_tracking) : m_compiler_tracking(compiler_tracking) {}
explicit EnvCache(bool compiler_tracking) : m_compiler_tracking(compiler_tracking) { }

const System::Environment& get_action_env(const VcpkgPaths& paths, const AbiInfo& abi_info);
const std::string& get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info);
Expand Down
10 changes: 7 additions & 3 deletions include/vcpkg/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <vcpkg/base/system.h>
#include <vcpkg/base/optional.h>

#include <vcpkg/vcpkgcmdarguments.h>

namespace vcpkg
{
struct TripletInstance;

struct Triplet
{
public:
constexpr Triplet() noexcept : m_instance(&DEFAULT_INSTANCE) {}
constexpr Triplet() noexcept : m_instance(&DEFAULT_INSTANCE) { }

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

Expand All @@ -23,7 +25,7 @@ namespace vcpkg
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;
Expand All @@ -41,12 +43,14 @@ namespace vcpkg
private:
static const TripletInstance DEFAULT_INSTANCE;

constexpr Triplet(const TripletInstance* ptr) : m_instance(ptr) {}
constexpr Triplet(const TripletInstance* ptr) : m_instance(ptr) { }

const TripletInstance* m_instance;
};

inline bool operator!=(Triplet left, Triplet right) { return !(left == right); }

Triplet default_triplet(const VcpkgCmdArguments& args);
}

namespace std
Expand Down
22 changes: 22 additions & 0 deletions src/vcpkg-test/commands.build.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <catch2/catch.hpp>

#include <string>
#include <iterator>
#include <vcpkg/base/files.h>
#include <vcpkg/commands.h>
#include <vcpkg/vcpkgcmdarguments.h>
#include <vcpkg/vcpkgpaths.h>

TEST_CASE ("build smoke test", "[commands-build]")
{
using namespace vcpkg;
static const std::string args_raw[] = {"build", "zlib"};

auto& fs_wrapper = Files::get_real_filesystem();
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_arg_sequence(std::begin(args_raw), std::end(args_raw));
VcpkgPaths paths(fs_wrapper, args);
auto triplet = default_triplet(args);
const auto exit_code = Build::Command::perform(args, paths, triplet);
REQUIRE(exit_code == 0);
REQUIRE(paths.get_filesystem().is_directory(paths.buildtrees / fs::u8path("zlib")));
}
2 changes: 1 addition & 1 deletion src/vcpkg-test/commands.create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vcpkg/vcpkgcmdarguments.h>
#include <vcpkg/vcpkgpaths.h>

TEST_CASE ("smoke test", "[create]")
TEST_CASE ("create smoke test", "[commands-create]")
{
using namespace vcpkg;
static const std::string argsRaw[] = {"create", "zlib2", "http://zlib.net/zlib-1.2.11.tar.gz", "zlib-1.2.11.zip"};
Expand Down
29 changes: 1 addition & 28 deletions src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,7 @@ static void inner(vcpkg::Files::Filesystem& fs, const VcpkgCmdArguments& args)
return command_function->function(args, paths);
}

Triplet default_triplet;
if (args.triplet != nullptr)
{
default_triplet = Triplet::from_canonical_name(std::string(*args.triplet));
}
else
{
auto vcpkg_default_triplet_env = System::get_environment_variable("VCPKG_DEFAULT_TRIPLET");
if (auto v = vcpkg_default_triplet_env.get())
{
default_triplet = Triplet::from_canonical_name(std::move(*v));
}
else
{
#if defined(_WIN32)
default_triplet = Triplet::X86_WINDOWS;
#elif defined(__APPLE__)
default_triplet = Triplet::from_canonical_name("x64-osx");
#elif defined(__FreeBSD__)
default_triplet = Triplet::from_canonical_name("x64-freebsd");
#elif defined(__GLIBC__)
default_triplet = Triplet::from_canonical_name("x64-linux");
#else
default_triplet = Triplet::from_canonical_name("x64-linux-musl");
#endif
}
}

Triplet default_triplet = vcpkg::default_triplet(args);
Input::check_triplet(default_triplet, paths);

if (const auto command_function = find_command(Commands::get_available_commands_type_a()))
Expand Down
38 changes: 27 additions & 11 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ namespace vcpkg::Build
const PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const VcpkgPaths& paths)
{
Checks::exit_with_code(VCPKG_LINE_INFO, perform_ex(full_spec, scfl, provider, binaryprovider, paths));
}

const CommandStructure COMMAND_STRUCTURE = {
create_example_string("build zlib:x64-windows"),
1,
1,
{{}, {}},
nullptr,
};

void Command::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet)
{
Checks::exit_with_code(VCPKG_LINE_INFO, perform(args, paths, default_triplet));
}

int Command::perform_ex(const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const VcpkgPaths& paths)
{
auto var_provider_storage = CMakeVars::make_triplet_cmake_var_provider(paths);
auto& var_provider = *var_provider_storage;
Expand All @@ -62,6 +84,8 @@ namespace vcpkg::Build
scf.core_paragraph->name,
spec.name());

compute_all_abis(paths, action_plan, var_provider, status_db);

const Build::BuildPackageOptions build_package_options{
Build::UseHeadVersion::NO,
Build::AllowDownloads::YES,
Expand Down Expand Up @@ -122,15 +146,7 @@ namespace vcpkg::Build
Checks::exit_success(VCPKG_LINE_INFO);
}

const CommandStructure COMMAND_STRUCTURE = {
create_example_string("build zlib:x64-windows"),
1,
1,
{{}, {}},
nullptr,
};

void Command::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet)
int Command::perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet)
{
// Build only takes a single package and all dependencies must already be installed
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
Expand All @@ -151,7 +167,7 @@ namespace vcpkg::Build
Checks::check_exit(VCPKG_LINE_INFO, scfl != nullptr, "Error: Couldn't find port '%s'", port_name);
ASSUME(scfl != nullptr);

perform_and_exit_ex(
return perform_ex(
spec, *scfl, provider, args.binary_caching_enabled() ? *binaryprovider : null_binary_provider(), paths);
}
}
Expand Down Expand Up @@ -1186,7 +1202,7 @@ namespace vcpkg::Build
}
}

ExtendedBuildResult::ExtendedBuildResult(BuildResult code) : code(code) {}
ExtendedBuildResult::ExtendedBuildResult(BuildResult code) : code(code) { }
ExtendedBuildResult::ExtendedBuildResult(BuildResult code, std::unique_ptr<BinaryControlFile>&& bcf)
: code(code), binary_control_file(std::move(bcf))
{
Expand Down
34 changes: 32 additions & 2 deletions src/vcpkg/triplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace vcpkg
{
struct TripletInstance
{
TripletInstance(std::string&& s) : value(std::move(s)), hash(std::hash<std::string>()(value)) {}
TripletInstance(std::string&& s) : value(std::move(s)), hash(std::hash<std::string>()(value)) { }

const std::string value;
const size_t hash = 0;
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace vcpkg
{
return CPUArchitecture::X86;
}
else if (*this == X64_WINDOWS || *this == X64_UWP || *this ==X64_ANDROID)
else if (*this == X64_WINDOWS || *this == X64_UWP || *this == X64_ANDROID)
{
return CPUArchitecture::X64;
}
Expand All @@ -80,4 +80,34 @@ namespace vcpkg

return nullopt;
}

Triplet default_triplet(const VcpkgCmdArguments& args)
{
if (args.triplet != nullptr)
{
return Triplet::from_canonical_name(std::string(*args.triplet));
}
else
{
auto vcpkg_default_triplet_env = System::get_environment_variable("VCPKG_DEFAULT_TRIPLET");
if (auto v = vcpkg_default_triplet_env.get())
{
return Triplet::from_canonical_name(std::move(*v));
}
else
{
#if defined(_WIN32)
return Triplet::X86_WINDOWS;
#elif defined(__APPLE__)
return Triplet::from_canonical_name("x64-osx");
#elif defined(__FreeBSD__)
return Triplet::from_canonical_name("x64-freebsd");
#elif defined(__GLIBC__)
return Triplet::from_canonical_name("x64-linux");
#else
return Triplet::from_canonical_name("x64-linux-musl");
#endif
}
}
}
}

0 comments on commit 53521d2

Please sign in to comment.