[vcpkg] Add option cmake-args (#12877)

* [vcpkg] Add option cmake-args to pass additional args to the script execution

* apply clang format to install.cpp

* rename command to x-cmake-args

* imply editable if x-cmake-args are not empty.

* don't use bitwise or

* add a definition for CMAKE_SCRIPT_ARG

Co-authored-by: wangli28 <wangli28@beyondsoft.com>
This commit is contained in:
Alexander Neumann 2020-11-30 19:07:51 +01:00 committed by GitHub
parent 24c67cb379
commit 3fd77452e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 29 deletions

View File

@ -15,6 +15,7 @@ namespace vcpkg::System
CMakeVariable(const StringView varname, const char* varvalue);
CMakeVariable(const StringView varname, const std::string& varvalue);
CMakeVariable(const StringView varname, const fs::path& path);
CMakeVariable(std::string var);
std::string s;
};

View File

@ -56,13 +56,15 @@ namespace vcpkg::Build
namespace Command
{
int perform_ex(const FullPackageSpec& full_spec,
int perform_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const IBuildLogsRecorder& build_logs_recorder,
const VcpkgPaths& paths);
void perform_and_exit_ex(const FullPackageSpec& full_spec,
void perform_and_exit_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
@ -232,7 +234,8 @@ namespace vcpkg::Build
std::unique_ptr<BinaryControlFile> binary_control_file;
};
ExtendedBuildResult build_package(const VcpkgPaths& paths,
ExtendedBuildResult build_package(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& config,
IBinaryProvider& binaries_provider,
const IBuildLogsRecorder& build_logs_recorder,

View File

@ -59,7 +59,8 @@ namespace vcpkg::Install
const fs::path& listfile() const;
};
Build::ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths,
Build::ExtendedBuildResult perform_install_plan_action(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Dependencies::InstallPlanAction& action,
StatusParagraphs& status_db,
const CMakeVars::CMakeVarProvider& var_provider);
@ -83,7 +84,8 @@ namespace vcpkg::Install
const BinaryControlFile& binary_paragraph,
StatusParagraphs* status_db);
InstallSummary perform(Dependencies::ActionPlan& action_plan,
InstallSummary perform(const VcpkgCmdArguments& args,
Dependencies::ActionPlan& action_plan,
const KeepGoing keep_going,
const VcpkgPaths& paths,
StatusParagraphs& status_db,

View File

@ -149,6 +149,9 @@ namespace vcpkg
constexpr static StringLiteral BINARY_SOURCES_ARG = "binarysource";
std::vector<std::string> binary_sources;
constexpr static StringLiteral CMAKE_SCRIPT_ARG = "x-cmake-args";
std::vector<std::string> cmake_args;
constexpr static StringLiteral DEBUG_SWITCH = "debug";
Optional<bool> debug = nullopt;
constexpr static StringLiteral SEND_METRICS_SWITCH = "sendmetrics";

View File

@ -182,6 +182,7 @@ namespace vcpkg
: CMakeVariable(varname, fs::generic_u8string(path))
{
}
System::CMakeVariable::CMakeVariable(std::string var) : s(std::move(var)) { }
std::string System::make_basic_cmake_cmd(const fs::path& cmake_tool_path,
const fs::path& cmake_script,

View File

@ -57,7 +57,8 @@ namespace vcpkg::Build
using Dependencies::InstallPlanAction;
using Dependencies::InstallPlanType;
void Command::perform_and_exit_ex(const FullPackageSpec& full_spec,
void Command::perform_and_exit_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
@ -65,7 +66,7 @@ namespace vcpkg::Build
const VcpkgPaths& paths)
{
Checks::exit_with_code(VCPKG_LINE_INFO,
perform_ex(full_spec, scfl, provider, binaryprovider, build_logs_recorder, paths));
perform_ex(args, full_spec, scfl, provider, binaryprovider, build_logs_recorder, paths));
}
const CommandStructure COMMAND_STRUCTURE = {
@ -81,7 +82,8 @@ namespace vcpkg::Build
Checks::exit_with_code(VCPKG_LINE_INFO, perform(args, paths, default_triplet));
}
int Command::perform_ex(const FullPackageSpec& full_spec,
int Command::perform_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
@ -134,7 +136,7 @@ namespace vcpkg::Build
action->build_options.clean_packages = CleanPackages::NO;
const auto build_timer = Chrono::ElapsedTimer::create_started();
const auto result = Build::build_package(paths, *action, binaryprovider, build_logs_recorder, status_db);
const auto result = Build::build_package(args, paths, *action, binaryprovider, build_logs_recorder, status_db);
System::print2("Elapsed time for package ", spec, ": ", build_timer, '\n');
if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES)
@ -182,7 +184,8 @@ namespace vcpkg::Build
Checks::check_exit(VCPKG_LINE_INFO, scfl != nullptr, "Error: Couldn't find port '%s'", port_name);
ASSUME(scfl != nullptr);
return perform_ex(spec,
return perform_ex(args,
spec,
*scfl,
provider,
args.binary_caching_enabled() ? *binaryprovider : null_binary_provider(),
@ -602,7 +605,8 @@ namespace vcpkg::Build
return compiler_info;
}
static std::vector<System::CMakeVariable> get_cmake_build_args(const VcpkgPaths& paths,
static std::vector<System::CMakeVariable> get_cmake_build_args(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action,
Triplet triplet)
{
@ -631,6 +635,11 @@ namespace vcpkg::Build
{"ALL_FEATURES", all_features},
};
for (auto cmake_arg : args.cmake_args)
{
variables.push_back(System::CMakeVariable{cmake_arg});
}
if (action.build_options.backcompat_features == BackcompatFeatures::PROHIBIT)
{
variables.emplace_back("_VCPKG_PROHIBIT_BACKCOMPAT_FEATURES", "1");
@ -723,7 +732,9 @@ namespace vcpkg::Build
}
}
static ExtendedBuildResult do_build_package(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action)
static ExtendedBuildResult do_build_package(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action)
{
const auto& pre_build_info = action.pre_build_info(VCPKG_LINE_INFO);
@ -753,7 +764,8 @@ namespace vcpkg::Build
const auto timer = Chrono::ElapsedTimer::create_started();
auto command = vcpkg::make_cmake_cmd(paths, paths.ports_cmake, get_cmake_build_args(paths, action, triplet));
auto command =
vcpkg::make_cmake_cmd(paths, paths.ports_cmake, get_cmake_build_args(args, paths, action, triplet));
const auto& env = paths.get_action_env(action.abi_info.value_or_exit(VCPKG_LINE_INFO));
@ -849,10 +861,11 @@ namespace vcpkg::Build
return {BuildResult::SUCCEEDED, std::move(bcf)};
}
static ExtendedBuildResult do_build_package_and_clean_buildtrees(const VcpkgPaths& paths,
static ExtendedBuildResult do_build_package_and_clean_buildtrees(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action)
{
auto result = do_build_package(paths, action);
auto result = do_build_package(args, paths, action);
if (action.build_options.clean_buildtrees == CleanBuildtrees::YES)
{
@ -1078,7 +1091,8 @@ namespace vcpkg::Build
}
}
ExtendedBuildResult build_package(const VcpkgPaths& paths,
ExtendedBuildResult build_package(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action,
IBinaryProvider& binaries_provider,
const IBuildLogsRecorder& build_logs_recorder,
@ -1122,7 +1136,7 @@ namespace vcpkg::Build
auto& abi_info = action.abi_info.value_or_exit(VCPKG_LINE_INFO);
if (!abi_info.abi_tag_file)
{
return do_build_package_and_clean_buildtrees(paths, action);
return do_build_package_and_clean_buildtrees(args, paths, action);
}
auto& abi_file = *abi_info.abi_tag_file.get();
@ -1149,7 +1163,7 @@ namespace vcpkg::Build
}
}
ExtendedBuildResult result = do_build_package_and_clean_buildtrees(paths, action);
ExtendedBuildResult result = do_build_package_and_clean_buildtrees(args, paths, action);
fs.create_directories(abi_package_dir, ec);
fs.copy_file(abi_file, abi_file_in_package, fs::copy_options::none, ec);

View File

@ -36,7 +36,8 @@ namespace vcpkg::Commands::BuildExternal
Checks::check_exit(
VCPKG_LINE_INFO, maybe_scfl.has_value(), "could not load control file for %s", spec.package_spec.name());
Build::Command::perform_and_exit_ex(spec,
Build::Command::perform_and_exit_ex(args,
spec,
maybe_scfl.value_or_exit(VCPKG_LINE_INFO),
provider,
args.binary_caching_enabled() ? *binaryprovider : null_binary_provider(),

View File

@ -525,7 +525,8 @@ namespace vcpkg::Commands::CI
else
{
auto collection_timer = Chrono::ElapsedTimer::create_started();
auto summary = Install::perform(action_plan,
auto summary = Install::perform(args,
action_plan,
Install::KeepGoing::YES,
paths,
status_db,

View File

@ -103,7 +103,8 @@ namespace vcpkg::Commands::SetInstalled
Checks::exit_success(VCPKG_LINE_INFO);
}
const auto summary = Install::perform(action_plan,
const auto summary = Install::perform(args,
action_plan,
Install::KeepGoing::NO,
paths,
status_db,

View File

@ -182,7 +182,8 @@ namespace vcpkg::Commands::Upgrade
var_provider.load_tag_vars(action_plan, provider);
const Install::InstallSummary summary =
Install::perform(action_plan,
Install::perform(args,
action_plan,
keep_going,
paths,
status_db,

View File

@ -305,7 +305,8 @@ namespace vcpkg::Install
using Build::BuildResult;
using Build::ExtendedBuildResult;
static ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths,
static ExtendedBuildResult perform_install_plan_action(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
InstallPlanAction& action,
StatusParagraphs& status_db,
IBinaryProvider& binaries_provider,
@ -336,7 +337,7 @@ namespace vcpkg::Install
else
System::printf("Building package %s...\n", display_name_with_features);
auto result = Build::build_package(paths, action, binaries_provider, build_logs_recorder, status_db);
auto result = Build::build_package(args, paths, action, binaries_provider, build_logs_recorder, status_db);
if (BuildResult::DOWNLOADED == result.code)
{
@ -454,7 +455,8 @@ namespace vcpkg::Install
TrackedPackageInstallGuard& operator=(const TrackedPackageInstallGuard&) = delete;
};
InstallSummary perform(ActionPlan& action_plan,
InstallSummary perform(const VcpkgCmdArguments& args,
ActionPlan& action_plan,
const KeepGoing keep_going,
const VcpkgPaths& paths,
StatusParagraphs& status_db,
@ -476,7 +478,7 @@ namespace vcpkg::Install
{
results.emplace_back(action.spec, &action);
results.back().build_result =
perform_install_plan_action(paths, action, status_db, binaryprovider, build_logs_recorder);
perform_install_plan_action(args, paths, action, status_db, binaryprovider, build_logs_recorder);
}
Build::compute_all_abis(paths, action_plan, var_provider, status_db);
@ -487,7 +489,8 @@ namespace vcpkg::Install
for (auto&& action : action_plan.install_actions)
{
TrackedPackageInstallGuard this_install(package_count, results, action.spec);
auto result = perform_install_plan_action(paths, action, status_db, binaryprovider, build_logs_recorder);
auto result =
perform_install_plan_action(args, paths, action, status_db, binaryprovider, build_logs_recorder);
if (result.code != BuildResult::SUCCEEDED && keep_going == KeepGoing::NO)
{
System::print2(Build::create_user_troubleshooting_message(action.spec), '\n');
@ -759,7 +762,7 @@ namespace vcpkg::Install
const bool no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS));
const bool only_downloads = Util::Sets::contains(options.switches, (OPTION_ONLY_DOWNLOADS));
const bool is_recursive = Util::Sets::contains(options.switches, (OPTION_RECURSE));
const bool is_editable = Util::Sets::contains(options.switches, (OPTION_EDITABLE));
const bool is_editable = Util::Sets::contains(options.switches, (OPTION_EDITABLE)) || !args.cmake_args.empty();
const bool use_aria2 = Util::Sets::contains(options.switches, (OPTION_USE_ARIA2));
const bool clean_after_build = Util::Sets::contains(options.switches, (OPTION_CLEAN_AFTER_BUILD));
const KeepGoing keep_going =
@ -954,7 +957,8 @@ namespace vcpkg::Install
}
const InstallSummary summary =
perform(action_plan,
perform(args,
action_plan,
keep_going,
paths,
status_db,

View File

@ -283,6 +283,7 @@ namespace vcpkg
{OVERLAY_PORTS_ARG, &VcpkgCmdArguments::overlay_ports},
{OVERLAY_TRIPLETS_ARG, &VcpkgCmdArguments::overlay_triplets},
{BINARY_SOURCES_ARG, &VcpkgCmdArguments::binary_sources},
{CMAKE_SCRIPT_ARG, &VcpkgCmdArguments::cmake_args},
};
constexpr static std::pair<StringView, Optional<bool> VcpkgCmdArguments::*> switches[] = {
@ -948,4 +949,6 @@ namespace vcpkg
constexpr StringLiteral VcpkgCmdArguments::REGISTRIES_FEATURE;
constexpr StringLiteral VcpkgCmdArguments::RECURSIVE_DATA_ENV;
constexpr StringLiteral VcpkgCmdArguments::VERSIONS_FEATURE;
constexpr StringLiteral VcpkgCmdArguments::CMAKE_SCRIPT_ARG;
}