[vcpkg build] fix build command
MODIFY
include/vcpkg/build.h
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);
}

MODIFY
include/vcpkg/triplet.h
include/vcpkg/triplet.h
#include <vcpkg/base/system.h>
#include <vcpkg/base/optional.h>
+#include <vcpkg/vcpkgcmdarguments.h>
+
namespace vcpkg
{
struct TripletInstance;
@@ -47,6 +49,8 @@ namespace vcpkg
};
inline bool operator!=(Triplet left, Triplet right) { return !(left == right); }
+
+ Triplet default_triplet(const VcpkgCmdArguments& args);
}
namespace std

ADD
src/vcpkg-test/commands.build.cpp
+#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")));
+}

MODIFY
src/vcpkg-test/commands.create.cpp
src/vcpkg-test/commands.create.cpp
#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"};

MODIFY
src/vcpkg.cpp
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()))

MODIFY
src/vcpkg/build.cpp
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);
}
}

MODIFY
src/vcpkg/triplet.cpp
src/vcpkg/triplet.cpp
@@ -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
+ }
+ }
+ }
}

[vcpkg build] fix build command (#12072)