From 2c9536ce4fe0ac755e188617ce61076b26646100 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 26 Oct 2017 19:00:30 -0700 Subject: [PATCH] [vcpkg ci] Introduce --exclude option --- toolsrc/include/vcpkg/build.h | 8 +++--- toolsrc/include/vcpkg/dependencies.h | 3 ++- toolsrc/include/vcpkg/install.h | 2 ++ toolsrc/include/vcpkg/packagespec.h | 2 ++ toolsrc/src/tests.installplan.cpp | 7 ++--- toolsrc/src/vcpkg/build.cpp | 6 ++++- toolsrc/src/vcpkg/commands.ci.cpp | 39 ++++++++++++++++------------ toolsrc/src/vcpkg/dependencies.cpp | 22 ++++++---------- toolsrc/src/vcpkg/install.cpp | 21 +++++++++++++-- toolsrc/src/vcpkg/packagespec.cpp | 8 ++++++ 10 files changed, 77 insertions(+), 41 deletions(-) diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 774e25922e..bf52e54b28 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -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 BUILD_RESULT_VALUES = { + static constexpr std::array 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); diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h index 585338ae2f..60c83fcca6 100644 --- a/toolsrc/include/vcpkg/dependencies.h +++ b/toolsrc/include/vcpkg/dependencies.h @@ -38,7 +38,8 @@ namespace vcpkg::Dependencies UNKNOWN, BUILD_AND_INSTALL, INSTALL, - ALREADY_INSTALLED + ALREADY_INSTALLED, + EXCLUDED }; struct InstallPlanAction : Util::MoveOnlyBase diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index 809befb16c..895028865d 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -62,6 +62,8 @@ namespace vcpkg::Install SUCCESS, }; + std::vector 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, diff --git a/toolsrc/include/vcpkg/packagespec.h b/toolsrc/include/vcpkg/packagespec.h index 60c99782ee..99aaaf0d7d 100644 --- a/toolsrc/include/vcpkg/packagespec.h +++ b/toolsrc/include/vcpkg/packagespec.h @@ -20,6 +20,8 @@ namespace vcpkg static ExpectedT from_name_and_triplet(const std::string& name, const Triplet& triplet); + static std::vector to_package_specs(const std::vector& ports, const Triplet& triplet); + const std::string& name() const; const Triplet& triplet() const; diff --git a/toolsrc/src/tests.installplan.cpp b/toolsrc/src/tests.installplan.cpp index 120009db5d..347612abdf 100644 --- a/toolsrc/src/tests.installplan.cpp +++ b/toolsrc/src/tests.installplan.cpp @@ -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(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(t)); } } } @@ -484,4 +485,4 @@ namespace UnitTest1 features_check(&install_plan[7], "c", {"core"}); } }; -} \ No newline at end of file +} diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index cf16c8f9ce..c26dcc5918 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -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); } } diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp index ffeaad7907..559dc45412 100644 --- a/toolsrc/src/vcpkg/commands.ci.cpp +++ b/toolsrc/src/vcpkg/commands.ci.cpp @@ -1,6 +1,5 @@ #include "pch.h" -#include #include #include #include @@ -10,7 +9,6 @@ #include #include #include -#include #include namespace vcpkg::Commands::CI @@ -19,27 +17,28 @@ namespace vcpkg::Commands::CI using Dependencies::InstallPlanAction; using Dependencies::InstallPlanType; - static std::vector 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& ports, + const std::set& exclusions_set) { Input::check_triplet(triplet, paths); - const std::vector specs = load_all_package_specs(paths.get_filesystem(), paths.ports, triplet); + const std::vector specs = PackageSpec::to_package_specs(ports, triplet); StatusParagraphs status_db = database_load_check(paths); const auto& paths_port_file = Dependencies::PathsPortFile(paths); std::vector 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 exclusions = Strings::split(options.settings.at(OPTION_EXCLUDE), ","); + const std::set exclusions_set(exclusions.cbegin(), exclusions.cend()); std::vector 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 ports = Install::get_all_port_names(paths); std::vector 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)}); } diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp index 02b2ec7854..9d264baa24 100644 --- a/toolsrc/src/vcpkg/dependencies.cpp +++ b/toolsrc/src/vcpkg/dependencies.cpp @@ -112,27 +112,21 @@ namespace vcpkg::Dependencies std::vector AnyParagraph::dependencies(const Triplet& triplet) const { - auto to_package_specs = [&](const std::vector& 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& 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) { } diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index bd924fcba2..76e943e8c2 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -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 only_install_plans; std::vector new_plans; std::vector already_installed_plans; + std::vector 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 INSTALL_SETTINGS; - static std::vector valid_arguments(const VcpkgPaths& paths) + std::vector 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) diff --git a/toolsrc/src/vcpkg/packagespec.cpp b/toolsrc/src/vcpkg/packagespec.cpp index 6e40d70f5a..eeb9981afd 100644 --- a/toolsrc/src/vcpkg/packagespec.cpp +++ b/toolsrc/src/vcpkg/packagespec.cpp @@ -92,6 +92,14 @@ namespace vcpkg return p; } + std::vector PackageSpec::to_package_specs(const std::vector& 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; }