mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-29 03:19:01 +08:00
[vcpkg ci] Introduce --exclude option
This commit is contained in:
parent
8a952743a3
commit
2c9536ce4f
@ -65,15 +65,17 @@ namespace vcpkg::Build
|
||||
BUILD_FAILED,
|
||||
POST_BUILD_CHECKS_FAILED,
|
||||
FILE_CONFLICTS,
|
||||
CASCADED_DUE_TO_MISSING_DEPENDENCIES
|
||||
CASCADED_DUE_TO_MISSING_DEPENDENCIES,
|
||||
EXCLUDED,
|
||||
};
|
||||
|
||||
static constexpr std::array<BuildResult, 5> BUILD_RESULT_VALUES = {
|
||||
static constexpr std::array<BuildResult, 6> BUILD_RESULT_VALUES = {
|
||||
BuildResult::SUCCEEDED,
|
||||
BuildResult::BUILD_FAILED,
|
||||
BuildResult::POST_BUILD_CHECKS_FAILED,
|
||||
BuildResult::FILE_CONFLICTS,
|
||||
BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES};
|
||||
BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES,
|
||||
BuildResult::EXCLUDED};
|
||||
|
||||
const std::string& to_string(const BuildResult build_result);
|
||||
std::string create_error_message(const BuildResult build_result, const PackageSpec& spec);
|
||||
|
@ -38,7 +38,8 @@ namespace vcpkg::Dependencies
|
||||
UNKNOWN,
|
||||
BUILD_AND_INSTALL,
|
||||
INSTALL,
|
||||
ALREADY_INSTALLED
|
||||
ALREADY_INSTALLED,
|
||||
EXCLUDED
|
||||
};
|
||||
|
||||
struct InstallPlanAction : Util::MoveOnlyBase
|
||||
|
@ -62,6 +62,8 @@ namespace vcpkg::Install
|
||||
SUCCESS,
|
||||
};
|
||||
|
||||
std::vector<std::string> get_all_port_names(const VcpkgPaths& paths);
|
||||
|
||||
void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& dirs);
|
||||
InstallResult install_package(const VcpkgPaths& paths,
|
||||
const BinaryControlFile& binary_paragraph,
|
||||
|
@ -20,6 +20,8 @@ namespace vcpkg
|
||||
static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name,
|
||||
const Triplet& triplet);
|
||||
|
||||
static std::vector<PackageSpec> to_package_specs(const std::vector<std::string>& ports, const Triplet& triplet);
|
||||
|
||||
const std::string& name() const;
|
||||
|
||||
const Triplet& triplet() const;
|
||||
|
@ -17,8 +17,9 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
case Dependencies::InstallPlanType::ALREADY_INSTALLED: return L"ALREADY_INSTALLED";
|
||||
case Dependencies::InstallPlanType::BUILD_AND_INSTALL: return L"BUILD_AND_INSTALL";
|
||||
case Dependencies::InstallPlanType::INSTALL: return L"INSTALL";
|
||||
case Dependencies::InstallPlanType::EXCLUDED: return L"EXCLUDED";
|
||||
case Dependencies::InstallPlanType::UNKNOWN: return L"UNKNOWN";
|
||||
default: return ToString((int)t);
|
||||
default: return ToString(static_cast<int>(t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +31,7 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
case Dependencies::RequestType::AUTO_SELECTED: return L"AUTO_SELECTED";
|
||||
case Dependencies::RequestType::USER_REQUESTED: return L"USER_REQUESTED";
|
||||
case Dependencies::RequestType::UNKNOWN: return L"UNKNOWN";
|
||||
default: return ToString((int)t);
|
||||
default: return ToString(static_cast<int>(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -484,4 +485,4 @@ namespace UnitTest1
|
||||
features_check(&install_plan[7], "c", {"core"});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,8 @@ namespace vcpkg::Build::Command
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
Checks::check_exit(VCPKG_LINE_INFO, result.code != BuildResult::EXCLUDED);
|
||||
|
||||
if (result.code != BuildResult::SUCCEEDED)
|
||||
{
|
||||
System::println(System::Color::error, Build::create_error_message(result.code, spec));
|
||||
@ -365,6 +367,7 @@ namespace vcpkg::Build
|
||||
static const std::string FILE_CONFLICTS_STRING = "FILE_CONFLICTS";
|
||||
static const std::string POST_BUILD_CHECKS_FAILED_STRING = "POST_BUILD_CHECKS_FAILED";
|
||||
static const std::string CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING = "CASCADED_DUE_TO_MISSING_DEPENDENCIES";
|
||||
static const std::string EXCLUDED_STRING = "EXCLUDED";
|
||||
|
||||
switch (build_result)
|
||||
{
|
||||
@ -372,8 +375,9 @@ namespace vcpkg::Build
|
||||
case BuildResult::SUCCEEDED: return SUCCEEDED_STRING;
|
||||
case BuildResult::BUILD_FAILED: return BUILD_FAILED_STRING;
|
||||
case BuildResult::POST_BUILD_CHECKS_FAILED: return POST_BUILD_CHECKS_FAILED_STRING;
|
||||
case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: return CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING;
|
||||
case BuildResult::FILE_CONFLICTS: return FILE_CONFLICTS_STRING;
|
||||
case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: return CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING;
|
||||
case BuildResult::EXCLUDED: return EXCLUDED_STRING;
|
||||
default: Checks::unreachable(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <vcpkg/base/chrono.h>
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/base/system.h>
|
||||
#include <vcpkg/base/util.h>
|
||||
@ -10,7 +9,6 @@
|
||||
#include <vcpkg/help.h>
|
||||
#include <vcpkg/input.h>
|
||||
#include <vcpkg/install.h>
|
||||
#include <vcpkg/paragraphs.h>
|
||||
#include <vcpkg/vcpkglib.h>
|
||||
|
||||
namespace vcpkg::Commands::CI
|
||||
@ -19,27 +17,28 @@ namespace vcpkg::Commands::CI
|
||||
using Dependencies::InstallPlanAction;
|
||||
using Dependencies::InstallPlanType;
|
||||
|
||||
static std::vector<PackageSpec> load_all_package_specs(Files::Filesystem& fs,
|
||||
const fs::path& ports_directory,
|
||||
const Triplet& triplet)
|
||||
{
|
||||
auto ports = Paragraphs::load_all_ports(fs, ports_directory);
|
||||
return Util::fmap(ports, [&](auto&& control_file) -> PackageSpec {
|
||||
return PackageSpec::from_name_and_triplet(control_file->core_paragraph->name, triplet)
|
||||
.value_or_exit(VCPKG_LINE_INFO);
|
||||
});
|
||||
}
|
||||
|
||||
static Install::InstallSummary run_ci_on_triplet(const Triplet& triplet, const VcpkgPaths& paths)
|
||||
static Install::InstallSummary run_ci_on_triplet(const Triplet& triplet,
|
||||
const VcpkgPaths& paths,
|
||||
const std::vector<std::string>& ports,
|
||||
const std::set<std::string>& exclusions_set)
|
||||
{
|
||||
Input::check_triplet(triplet, paths);
|
||||
|
||||
const std::vector<PackageSpec> specs = load_all_package_specs(paths.get_filesystem(), paths.ports, triplet);
|
||||
const std::vector<PackageSpec> specs = PackageSpec::to_package_specs(ports, triplet);
|
||||
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
const auto& paths_port_file = Dependencies::PathsPortFile(paths);
|
||||
std::vector<InstallPlanAction> install_plan =
|
||||
Dependencies::create_install_plan(paths_port_file, specs, status_db);
|
||||
|
||||
for (InstallPlanAction& plan : install_plan)
|
||||
{
|
||||
if (Util::Sets::contains(exclusions_set, plan.spec.name()))
|
||||
{
|
||||
plan.plan_type = InstallPlanType::EXCLUDED;
|
||||
}
|
||||
}
|
||||
|
||||
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
|
||||
|
||||
const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
|
||||
@ -60,8 +59,13 @@ namespace vcpkg::Commands::CI
|
||||
|
||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
|
||||
{
|
||||
static const std::string OPTION_EXCLUDE = "--exclude";
|
||||
|
||||
static const std::string EXAMPLE = Help::create_example_string("ci x64-windows");
|
||||
args.check_and_get_optional_command_arguments({});
|
||||
|
||||
const ParsedArguments options = args.check_and_get_optional_command_arguments({}, {OPTION_EXCLUDE});
|
||||
const std::vector<std::string> exclusions = Strings::split(options.settings.at(OPTION_EXCLUDE), ",");
|
||||
const std::set<std::string> exclusions_set(exclusions.cbegin(), exclusions.cend());
|
||||
|
||||
std::vector<Triplet> triplets;
|
||||
for (const std::string& triplet : args.command_arguments)
|
||||
@ -74,10 +78,11 @@ namespace vcpkg::Commands::CI
|
||||
triplets.push_back(default_triplet);
|
||||
}
|
||||
|
||||
const std::vector<std::string> ports = Install::get_all_port_names(paths);
|
||||
std::vector<TripletAndSummary> results;
|
||||
for (const Triplet& triplet : triplets)
|
||||
{
|
||||
Install::InstallSummary summary = run_ci_on_triplet(triplet, paths);
|
||||
Install::InstallSummary summary = run_ci_on_triplet(triplet, paths, ports, exclusions_set);
|
||||
results.push_back({triplet, std::move(summary)});
|
||||
}
|
||||
|
||||
|
@ -112,27 +112,21 @@ namespace vcpkg::Dependencies
|
||||
|
||||
std::vector<PackageSpec> AnyParagraph::dependencies(const Triplet& triplet) const
|
||||
{
|
||||
auto to_package_specs = [&](const std::vector<std::string>& dependencies_as_string) {
|
||||
return Util::fmap(dependencies_as_string, [&](const std::string s) {
|
||||
return PackageSpec::from_name_and_triplet(s, triplet).value_or_exit(VCPKG_LINE_INFO);
|
||||
});
|
||||
};
|
||||
|
||||
if (auto p = this->status_paragraph.get())
|
||||
if (const auto p = this->status_paragraph.get())
|
||||
{
|
||||
return to_package_specs(p->package.depends);
|
||||
return PackageSpec::to_package_specs(p->package.depends, triplet);
|
||||
}
|
||||
|
||||
if (auto p = this->binary_control_file.get())
|
||||
if (const auto p = this->binary_control_file.get())
|
||||
{
|
||||
auto deps = Util::fmap_flatten(p->features, [](const BinaryParagraph& pgh) { return pgh.depends; });
|
||||
deps.insert(deps.end(), p->core_paragraph.depends.begin(), p->core_paragraph.depends.end());
|
||||
return to_package_specs(deps);
|
||||
deps.insert(deps.end(), p->core_paragraph.depends.cbegin(), p->core_paragraph.depends.cend());
|
||||
return PackageSpec::to_package_specs(deps, triplet);
|
||||
}
|
||||
|
||||
if (auto p = this->source_paragraph.get())
|
||||
if (const auto p = this->source_paragraph.get())
|
||||
{
|
||||
return to_package_specs(filter_dependencies(p->depends, triplet));
|
||||
return PackageSpec::to_package_specs(filter_dependencies(p->depends, triplet), triplet);
|
||||
}
|
||||
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO,
|
||||
@ -163,7 +157,7 @@ namespace vcpkg::Dependencies
|
||||
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type)
|
||||
: spec(spec), plan_type(InstallPlanType::ALREADY_INSTALLED), request_type(request_type), feature_list(features)
|
||||
: spec(spec), plan_type(InstallPlanType::UNKNOWN), request_type(request_type), feature_list(features)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -342,6 +342,12 @@ namespace vcpkg::Install
|
||||
}
|
||||
}
|
||||
|
||||
if (plan_type == InstallPlanType::EXCLUDED)
|
||||
{
|
||||
System::println(System::Color::warning, "Package %s is excluded", display_name);
|
||||
return BuildResult::EXCLUDED;
|
||||
}
|
||||
|
||||
Checks::unreachable(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
@ -352,6 +358,7 @@ namespace vcpkg::Install
|
||||
std::vector<const InstallPlanAction*> only_install_plans;
|
||||
std::vector<const InstallPlanAction*> new_plans;
|
||||
std::vector<const InstallPlanAction*> already_installed_plans;
|
||||
std::vector<const InstallPlanAction*> excluded;
|
||||
|
||||
const bool has_non_user_requested_packages = Util::find_if(action_plan, [](const AnyAction& package) -> bool {
|
||||
if (auto iplan = package.install_plan.get())
|
||||
@ -382,6 +389,7 @@ namespace vcpkg::Install
|
||||
already_installed_plans.emplace_back(install_action);
|
||||
break;
|
||||
case InstallPlanType::BUILD_AND_INSTALL: new_plans.emplace_back(install_action); break;
|
||||
case InstallPlanType::EXCLUDED: excluded.emplace_back(install_action); break;
|
||||
default: Checks::unreachable(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
@ -397,6 +405,15 @@ namespace vcpkg::Install
|
||||
std::sort(only_install_plans.begin(), only_install_plans.end(), &InstallPlanAction::compare_by_name);
|
||||
std::sort(new_plans.begin(), new_plans.end(), &InstallPlanAction::compare_by_name);
|
||||
std::sort(already_installed_plans.begin(), already_installed_plans.end(), &InstallPlanAction::compare_by_name);
|
||||
std::sort(excluded.begin(), excluded.end(), &InstallPlanAction::compare_by_name);
|
||||
|
||||
if (excluded.size() > 0)
|
||||
{
|
||||
const std::string excluded_string = Strings::join("\n", excluded, [](const InstallPlanAction* p) {
|
||||
return to_output_string(p->request_type, p->displayname());
|
||||
});
|
||||
System::println("The following packages are excluded:\n%s", excluded_string);
|
||||
}
|
||||
|
||||
if (already_installed_plans.size() > 0)
|
||||
{
|
||||
@ -538,7 +555,7 @@ namespace vcpkg::Install
|
||||
};
|
||||
static const std::array<std::string, 0> INSTALL_SETTINGS;
|
||||
|
||||
static std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
|
||||
std::vector<std::string> get_all_port_names(const VcpkgPaths& paths)
|
||||
{
|
||||
auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
|
||||
|
||||
@ -552,7 +569,7 @@ namespace vcpkg::Install
|
||||
SIZE_MAX,
|
||||
INSTALL_SWITCHES,
|
||||
INSTALL_SETTINGS,
|
||||
&valid_arguments,
|
||||
&get_all_port_names,
|
||||
};
|
||||
|
||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
|
||||
|
@ -92,6 +92,14 @@ namespace vcpkg
|
||||
return p;
|
||||
}
|
||||
|
||||
std::vector<PackageSpec> PackageSpec::to_package_specs(const std::vector<std::string>& ports,
|
||||
const Triplet& triplet)
|
||||
{
|
||||
return Util::fmap(ports, [&](const std::string s) {
|
||||
return PackageSpec::from_name_and_triplet(s, triplet).value_or_exit(VCPKG_LINE_INFO);
|
||||
});
|
||||
}
|
||||
|
||||
const std::string& PackageSpec::name() const { return this->m_name; }
|
||||
|
||||
const Triplet& PackageSpec::triplet() const { return this->m_triplet; }
|
||||
|
Loading…
Reference in New Issue
Block a user