mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 12:26:08 +08:00
[vcpkg build] fix build command (#12072)
This commit is contained in:
parent
f10c49281a
commit
22c8e3a23a
@ -37,12 +37,18 @@ namespace vcpkg::Build
|
|||||||
{
|
{
|
||||||
namespace Command
|
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,
|
void perform_and_exit_ex(const FullPackageSpec& full_spec,
|
||||||
const SourceControlFileLocation& scfl,
|
const SourceControlFileLocation& scfl,
|
||||||
const PortFileProvider::PathsPortFileProvider& provider,
|
const PortFileProvider::PathsPortFileProvider& provider,
|
||||||
IBinaryProvider& binaryprovider,
|
IBinaryProvider& binaryprovider,
|
||||||
const VcpkgPaths& paths);
|
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);
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +228,7 @@ namespace vcpkg::Build
|
|||||||
struct BuildPolicies
|
struct BuildPolicies
|
||||||
{
|
{
|
||||||
BuildPolicies() = default;
|
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
|
bool is_enabled(BuildPolicy policy) const
|
||||||
{
|
{
|
||||||
@ -261,7 +267,7 @@ namespace vcpkg::Build
|
|||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
AbiEntry() = default;
|
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
|
bool operator<(const AbiEntry& other) const
|
||||||
{
|
{
|
||||||
@ -290,7 +296,7 @@ namespace vcpkg::Build
|
|||||||
|
|
||||||
struct EnvCache
|
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 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);
|
const std::string& get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <vcpkg/base/system.h>
|
#include <vcpkg/base/system.h>
|
||||||
#include <vcpkg/base/optional.h>
|
#include <vcpkg/base/optional.h>
|
||||||
|
|
||||||
|
#include <vcpkg/vcpkgcmdarguments.h>
|
||||||
|
|
||||||
namespace vcpkg
|
namespace vcpkg
|
||||||
{
|
{
|
||||||
struct TripletInstance;
|
struct TripletInstance;
|
||||||
@ -11,7 +13,7 @@ namespace vcpkg
|
|||||||
struct Triplet
|
struct Triplet
|
||||||
{
|
{
|
||||||
public:
|
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);
|
static Triplet from_canonical_name(std::string&& triplet_as_string);
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ namespace vcpkg
|
|||||||
static const Triplet X64_UWP;
|
static const Triplet X64_UWP;
|
||||||
static const Triplet ARM_UWP;
|
static const Triplet ARM_UWP;
|
||||||
static const Triplet ARM64_UWP;
|
static const Triplet ARM64_UWP;
|
||||||
|
|
||||||
static const Triplet ARM_ANDROID;
|
static const Triplet ARM_ANDROID;
|
||||||
static const Triplet ARM64_ANDROID;
|
static const Triplet ARM64_ANDROID;
|
||||||
static const Triplet X86_ANDROID;
|
static const Triplet X86_ANDROID;
|
||||||
@ -41,12 +43,14 @@ namespace vcpkg
|
|||||||
private:
|
private:
|
||||||
static const TripletInstance DEFAULT_INSTANCE;
|
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;
|
const TripletInstance* m_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator!=(Triplet left, Triplet right) { return !(left == right); }
|
inline bool operator!=(Triplet left, Triplet right) { return !(left == right); }
|
||||||
|
|
||||||
|
Triplet default_triplet(const VcpkgCmdArguments& args);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
|
22
toolsrc/src/vcpkg-test/commands.build.cpp
Normal file
22
toolsrc/src/vcpkg-test/commands.build.cpp
Normal file
@ -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")));
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
#include <vcpkg/vcpkgcmdarguments.h>
|
#include <vcpkg/vcpkgcmdarguments.h>
|
||||||
#include <vcpkg/vcpkgpaths.h>
|
#include <vcpkg/vcpkgpaths.h>
|
||||||
|
|
||||||
TEST_CASE ("smoke test", "[create]")
|
TEST_CASE ("create smoke test", "[commands-create]")
|
||||||
{
|
{
|
||||||
using namespace vcpkg;
|
using namespace vcpkg;
|
||||||
static const std::string argsRaw[] = {"create", "zlib2", "http://zlib.net/zlib-1.2.11.tar.gz", "zlib-1.2.11.zip"};
|
static const std::string argsRaw[] = {"create", "zlib2", "http://zlib.net/zlib-1.2.11.tar.gz", "zlib-1.2.11.zip"};
|
||||||
|
@ -105,34 +105,7 @@ static void inner(vcpkg::Files::Filesystem& fs, const VcpkgCmdArguments& args)
|
|||||||
return command_function->function(args, paths);
|
return command_function->function(args, paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
Triplet default_triplet;
|
Triplet default_triplet = vcpkg::default_triplet(args);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Input::check_triplet(default_triplet, paths);
|
Input::check_triplet(default_triplet, paths);
|
||||||
|
|
||||||
if (const auto command_function = find_command(Commands::get_available_commands_type_a()))
|
if (const auto command_function = find_command(Commands::get_available_commands_type_a()))
|
||||||
|
@ -42,6 +42,28 @@ namespace vcpkg::Build
|
|||||||
const PathsPortFileProvider& provider,
|
const PathsPortFileProvider& provider,
|
||||||
IBinaryProvider& binaryprovider,
|
IBinaryProvider& binaryprovider,
|
||||||
const VcpkgPaths& paths)
|
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_storage = CMakeVars::make_triplet_cmake_var_provider(paths);
|
||||||
auto& var_provider = *var_provider_storage;
|
auto& var_provider = *var_provider_storage;
|
||||||
@ -62,6 +84,8 @@ namespace vcpkg::Build
|
|||||||
scf.core_paragraph->name,
|
scf.core_paragraph->name,
|
||||||
spec.name());
|
spec.name());
|
||||||
|
|
||||||
|
compute_all_abis(paths, action_plan, var_provider, status_db);
|
||||||
|
|
||||||
const Build::BuildPackageOptions build_package_options{
|
const Build::BuildPackageOptions build_package_options{
|
||||||
Build::UseHeadVersion::NO,
|
Build::UseHeadVersion::NO,
|
||||||
Build::AllowDownloads::YES,
|
Build::AllowDownloads::YES,
|
||||||
@ -122,15 +146,7 @@ namespace vcpkg::Build
|
|||||||
Checks::exit_success(VCPKG_LINE_INFO);
|
Checks::exit_success(VCPKG_LINE_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommandStructure COMMAND_STRUCTURE = {
|
int Command::perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet)
|
||||||
create_example_string("build zlib:x64-windows"),
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
{{}, {}},
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
void Command::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet)
|
|
||||||
{
|
{
|
||||||
// Build only takes a single package and all dependencies must already be installed
|
// Build only takes a single package and all dependencies must already be installed
|
||||||
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
|
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);
|
Checks::check_exit(VCPKG_LINE_INFO, scfl != nullptr, "Error: Couldn't find port '%s'", port_name);
|
||||||
ASSUME(scfl != nullptr);
|
ASSUME(scfl != nullptr);
|
||||||
|
|
||||||
perform_and_exit_ex(
|
return perform_ex(
|
||||||
spec, *scfl, provider, args.binary_caching_enabled() ? *binaryprovider : null_binary_provider(), paths);
|
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<BinaryControlFile>&& bcf)
|
ExtendedBuildResult::ExtendedBuildResult(BuildResult code, std::unique_ptr<BinaryControlFile>&& bcf)
|
||||||
: code(code), binary_control_file(std::move(bcf))
|
: code(code), binary_control_file(std::move(bcf))
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ namespace vcpkg
|
|||||||
{
|
{
|
||||||
struct TripletInstance
|
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 std::string value;
|
||||||
const size_t hash = 0;
|
const size_t hash = 0;
|
||||||
@ -65,7 +65,7 @@ namespace vcpkg
|
|||||||
{
|
{
|
||||||
return CPUArchitecture::X86;
|
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;
|
return CPUArchitecture::X64;
|
||||||
}
|
}
|
||||||
@ -80,4 +80,34 @@ namespace vcpkg
|
|||||||
|
|
||||||
return nullopt;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user