From 22c8e3a23afc6be45020cd3f8c92bcea783ce8fa Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Thu, 25 Jun 2020 18:23:30 -0700 Subject: [PATCH] [vcpkg build] fix build command (#12072) --- toolsrc/include/vcpkg/build.h | 12 +++++-- toolsrc/include/vcpkg/triplet.h | 10 ++++-- toolsrc/src/vcpkg-test/commands.build.cpp | 22 +++++++++++++ toolsrc/src/vcpkg-test/commands.create.cpp | 2 +- toolsrc/src/vcpkg.cpp | 29 +---------------- toolsrc/src/vcpkg/build.cpp | 38 +++++++++++++++------- toolsrc/src/vcpkg/triplet.cpp | 34 +++++++++++++++++-- 7 files changed, 99 insertions(+), 48 deletions(-) create mode 100644 toolsrc/src/vcpkg-test/commands.build.cpp diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 68cfd7d238cfba..e2e28b08ae7c53 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -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); } @@ -222,7 +228,7 @@ namespace vcpkg::Build struct BuildPolicies { BuildPolicies() = default; - BuildPolicies(std::map&& map) : m_policies(std::move(map)) {} + BuildPolicies(std::map&& map) : m_policies(std::move(map)) { } bool is_enabled(BuildPolicy policy) const { @@ -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 { @@ -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); diff --git a/toolsrc/include/vcpkg/triplet.h b/toolsrc/include/vcpkg/triplet.h index 92ea10175c5f69..4a88f5708b612e 100644 --- a/toolsrc/include/vcpkg/triplet.h +++ b/toolsrc/include/vcpkg/triplet.h @@ -4,6 +4,8 @@ #include #include +#include + namespace vcpkg { struct TripletInstance; @@ -11,7 +13,7 @@ namespace vcpkg 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); @@ -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; @@ -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 diff --git a/toolsrc/src/vcpkg-test/commands.build.cpp b/toolsrc/src/vcpkg-test/commands.build.cpp new file mode 100644 index 00000000000000..b1953f55ebe2d6 --- /dev/null +++ b/toolsrc/src/vcpkg-test/commands.build.cpp @@ -0,0 +1,22 @@ +#include + +#include +#include +#include +#include +#include +#include + +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"))); +} diff --git a/toolsrc/src/vcpkg-test/commands.create.cpp b/toolsrc/src/vcpkg-test/commands.create.cpp index 993be142b40ced..4a89d07995558d 100644 --- a/toolsrc/src/vcpkg-test/commands.create.cpp +++ b/toolsrc/src/vcpkg-test/commands.create.cpp @@ -7,7 +7,7 @@ #include #include -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"}; diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 1cc264e91f30ea..859fe99c51547d 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -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())) diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index c61c6b77bca7b6..575fc664c9f1e0 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -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; @@ -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, @@ -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); @@ -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); } } @@ -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&& bcf) : code(code), binary_control_file(std::move(bcf)) { diff --git a/toolsrc/src/vcpkg/triplet.cpp b/toolsrc/src/vcpkg/triplet.cpp index 47b82498964e71..75ca312dfb4603 100644 --- a/toolsrc/src/vcpkg/triplet.cpp +++ b/toolsrc/src/vcpkg/triplet.cpp @@ -7,7 +7,7 @@ namespace vcpkg { struct TripletInstance { - TripletInstance(std::string&& s) : value(std::move(s)), hash(std::hash()(value)) {} + TripletInstance(std::string&& s) : value(std::move(s)), hash(std::hash()(value)) { } const std::string value; const size_t hash = 0; @@ -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; } @@ -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 + } + } + } }