aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_ci.cpp
diff options
context:
space:
mode:
authorThomas Fussell <thomas.fussell@gmail.com>2017-03-12 17:44:06 -0400
committerThomas Fussell <thomas.fussell@gmail.com>2017-03-12 17:44:06 -0400
commit2f42035ab43dd50cd863b51944aa099a99ae60f0 (patch)
tree4b6cfd43955e946721c58028fd8564c861d5c331 /toolsrc/src/commands_ci.cpp
parente02e85626f3206feda86a6f5757009005e0cfe3e (diff)
parent1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff)
downloadvcpkg-2f42035ab43dd50cd863b51944aa099a99ae60f0.tar.gz
vcpkg-2f42035ab43dd50cd863b51944aa099a99ae60f0.zip
Merge branch 'master' of git://github.com/Microsoft/vcpkg
Diffstat (limited to 'toolsrc/src/commands_ci.cpp')
-rw-r--r--toolsrc/src/commands_ci.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp
new file mode 100644
index 000000000..315308a62
--- /dev/null
+++ b/toolsrc/src/commands_ci.cpp
@@ -0,0 +1,120 @@
+#include "pch.h"
+#include "vcpkg_Commands.h"
+#include "vcpkglib.h"
+#include "vcpkg_Files.h"
+#include "vcpkg_System.h"
+#include "vcpkg_Dependencies.h"
+#include "vcpkg_Input.h"
+#include "vcpkg_Chrono.h"
+#include "Paragraphs.h"
+
+namespace vcpkg::Commands::CI
+{
+ using Dependencies::package_spec_with_install_plan;
+ using Dependencies::install_plan_type;
+ using Build::BuildResult;
+
+ static std::vector<package_spec> load_all_package_specs(const fs::path& ports_directory, const triplet& target_triplet)
+ {
+ std::vector<SourceParagraph> ports = Paragraphs::load_all_ports(ports_directory);
+ std::vector<package_spec> specs;
+ for (const SourceParagraph& p : ports)
+ {
+ specs.push_back(package_spec::from_name_and_triplet(p.name, target_triplet).get_or_throw());
+ }
+
+ return specs;
+ }
+
+ void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
+ {
+ static const std::string example = Commands::Help::create_example_string("ci x64-windows");
+ args.check_max_arg_count(1, example);
+ const triplet target_triplet = args.command_arguments.size() == 1 ? triplet::from_canonical_name(args.command_arguments.at(0)) : default_target_triplet;
+ Input::check_triplet(target_triplet, paths);
+ args.check_and_get_optional_command_arguments({});
+ const std::vector<package_spec> specs = load_all_package_specs(paths.ports, target_triplet);
+
+ StatusParagraphs status_db = database_load_check(paths);
+ const std::vector<package_spec_with_install_plan> install_plan = Dependencies::create_install_plan(paths, specs, status_db);
+ Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty");
+
+ std::vector<BuildResult> results;
+ std::vector<std::chrono::milliseconds::rep> timing;
+ const ElapsedTime timer = ElapsedTime::createStarted();
+ size_t counter = 0;
+ const size_t package_count = install_plan.size();
+ for (const package_spec_with_install_plan& action : install_plan)
+ {
+ const ElapsedTime build_timer = ElapsedTime::createStarted();
+ counter++;
+ System::println("Starting package %d/%d: %s", counter, package_count, action.spec.toString());
+
+ timing.push_back(-1);
+ results.push_back(BuildResult::NULLVALUE);
+
+ try
+ {
+ if (action.plan.plan_type == install_plan_type::ALREADY_INSTALLED)
+ {
+ results.back() = BuildResult::SUCCEEDED;
+ System::println(System::color::success, "Package %s is already installed", action.spec);
+ }
+ else if (action.plan.plan_type == install_plan_type::BUILD_AND_INSTALL)
+ {
+ const BuildResult result = Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec), status_db);
+ timing.back() = build_timer.elapsed<std::chrono::milliseconds>().count();
+ results.back() = result;
+ if (result != BuildResult::SUCCEEDED)
+ {
+ System::println(System::color::error, Build::create_error_message(result, action.spec));
+ continue;
+ }
+ const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw();
+ Install::install_package(paths, bpgh, &status_db);
+ System::println(System::color::success, "Package %s is installed", action.spec);
+ }
+ else if (action.plan.plan_type == install_plan_type::INSTALL)
+ {
+ results.back() = BuildResult::SUCCEEDED;
+ Install::install_package(paths, *action.plan.binary_pgh, &status_db);
+ System::println(System::color::success, "Package %s is installed from cache", action.spec);
+ }
+ else
+ Checks::unreachable();
+ }
+ catch (const std::exception& e)
+ {
+ System::println(System::color::error, "Error: Could not install package %s: %s", action.spec, e.what());
+ results.back() = BuildResult::NULLVALUE;
+ }
+ System::println("Elapsed time for package %s: %s", action.spec, build_timer.toString());
+ }
+
+ System::println("Total time taken: %s", timer.toString());
+
+ for (size_t i = 0; i < results.size(); i++)
+ {
+ System::println("%s: %s: %dms", install_plan[i].spec.toString(), Build::to_string(results[i]), timing[i]);
+ }
+
+ std::map<BuildResult, int> summary;
+ for (const BuildResult& v : Build::BuildResult_values)
+ {
+ summary[v] = 0;
+ }
+
+ for (const BuildResult& r : results)
+ {
+ summary[r]++;
+ }
+
+ System::println("\n\nSUMMARY");
+ for (const std::pair<const BuildResult, int>& entry : summary)
+ {
+ System::println(" %s: %d", Build::to_string(entry.first), entry.second);
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+}