2017-02-14 06:01:56 +08:00
|
|
|
#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"
|
2017-02-17 08:32:14 +08:00
|
|
|
#include "vcpkg_Chrono.h"
|
2017-02-28 07:52:57 +08:00
|
|
|
#include "Paragraphs.h"
|
2017-02-14 06:01:56 +08:00
|
|
|
|
|
|
|
namespace vcpkg::Commands::CI
|
|
|
|
{
|
2017-04-04 07:23:23 +08:00
|
|
|
using Dependencies::PackageSpecWithInstallPlan;
|
2017-04-04 07:22:32 +08:00
|
|
|
using Dependencies::InstallPlanType;
|
2017-02-16 06:34:39 +08:00
|
|
|
using Build::BuildResult;
|
2017-02-14 06:01:56 +08:00
|
|
|
|
2017-04-11 04:11:36 +08:00
|
|
|
static std::vector<PackageSpec> load_all_package_specs(const fs::path& ports_directory, const Triplet& triplet)
|
2017-02-14 06:01:56 +08:00
|
|
|
{
|
2017-02-28 08:58:53 +08:00
|
|
|
std::vector<SourceParagraph> ports = Paragraphs::load_all_ports(ports_directory);
|
2017-04-04 05:45:00 +08:00
|
|
|
std::vector<PackageSpec> specs;
|
2017-02-28 08:58:53 +08:00
|
|
|
for (const SourceParagraph& p : ports)
|
2017-02-14 06:01:56 +08:00
|
|
|
{
|
2017-04-11 04:11:36 +08:00
|
|
|
specs.push_back(PackageSpec::from_name_and_triplet(p.name, triplet).value_or_exit(VCPKG_LINE_INFO));
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
|
|
|
|
2017-02-18 07:29:32 +08:00
|
|
|
return specs;
|
|
|
|
}
|
|
|
|
|
2017-04-11 04:00:33 +08:00
|
|
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
|
2017-02-18 07:29:32 +08:00
|
|
|
{
|
|
|
|
static const std::string example = Commands::Help::create_example_string("ci x64-windows");
|
|
|
|
args.check_max_arg_count(1, example);
|
2017-04-11 04:11:36 +08:00
|
|
|
const Triplet triplet = args.command_arguments.size() == 1 ? Triplet::from_canonical_name(args.command_arguments.at(0)) : default_triplet;
|
|
|
|
Input::check_triplet(triplet, paths);
|
2017-02-18 07:29:32 +08:00
|
|
|
args.check_and_get_optional_command_arguments({});
|
2017-04-11 04:11:36 +08:00
|
|
|
const std::vector<PackageSpec> specs = load_all_package_specs(paths.ports, triplet);
|
2017-02-18 07:29:32 +08:00
|
|
|
|
|
|
|
StatusParagraphs status_db = database_load_check(paths);
|
2017-04-04 07:23:23 +08:00
|
|
|
const std::vector<PackageSpecWithInstallPlan> install_plan = Dependencies::create_install_plan(paths, specs, status_db);
|
2017-03-14 08:38:04 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
|
2017-02-14 06:01:56 +08:00
|
|
|
|
2017-02-16 06:34:39 +08:00
|
|
|
std::vector<BuildResult> results;
|
2017-03-04 22:48:59 +08:00
|
|
|
std::vector<std::chrono::milliseconds::rep> timing;
|
2017-04-04 06:44:46 +08:00
|
|
|
const ElapsedTime timer = ElapsedTime::create_started();
|
2017-02-16 07:22:40 +08:00
|
|
|
size_t counter = 0;
|
|
|
|
const size_t package_count = install_plan.size();
|
2017-04-04 07:23:23 +08:00
|
|
|
for (const PackageSpecWithInstallPlan& action : install_plan)
|
2017-02-14 06:01:56 +08:00
|
|
|
{
|
2017-04-04 06:44:46 +08:00
|
|
|
const ElapsedTime build_timer = ElapsedTime::create_started();
|
2017-02-16 07:22:40 +08:00
|
|
|
counter++;
|
2017-04-08 07:17:54 +08:00
|
|
|
const std::string display_name = action.spec.to_string();
|
2017-04-08 07:01:09 +08:00
|
|
|
System::println("Starting package %d/%d: %s", counter, package_count, display_name);
|
2017-03-04 22:48:59 +08:00
|
|
|
|
|
|
|
timing.push_back(-1);
|
|
|
|
results.push_back(BuildResult::NULLVALUE);
|
|
|
|
|
2017-02-14 06:01:56 +08:00
|
|
|
try
|
|
|
|
{
|
2017-04-08 07:08:23 +08:00
|
|
|
switch (action.plan.plan_type)
|
2017-02-14 06:01:56 +08:00
|
|
|
{
|
2017-04-08 07:08:23 +08:00
|
|
|
case InstallPlanType::ALREADY_INSTALLED:
|
|
|
|
results.back() = BuildResult::SUCCEEDED;
|
|
|
|
System::println(System::Color::success, "Package %s is already installed", display_name);
|
|
|
|
break;
|
|
|
|
case InstallPlanType::BUILD_AND_INSTALL:
|
|
|
|
{
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println("Building package %s... ", display_name);
|
2017-04-08 07:08:23 +08:00
|
|
|
const BuildResult result = Commands::Build::build_package(action.plan.source_pgh.value_or_exit(VCPKG_LINE_INFO),
|
|
|
|
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;
|
|
|
|
}
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println(System::Color::success, "Building package %s... done", display_name);
|
|
|
|
|
2017-04-08 07:08:23 +08:00
|
|
|
const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println("Installing package %s... ", display_name);
|
2017-04-08 07:08:23 +08:00
|
|
|
Install::install_package(paths, bpgh, &status_db);
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println(System::Color::success, "Installing package %s... done", display_name);
|
2017-04-08 07:08:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InstallPlanType::INSTALL:
|
|
|
|
results.back() = BuildResult::SUCCEEDED;
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println("Installing package %s... ", display_name);
|
2017-04-08 07:08:23 +08:00
|
|
|
Install::install_package(paths, action.plan.binary_pgh.value_or_exit(VCPKG_LINE_INFO), &status_db);
|
2017-04-08 07:11:08 +08:00
|
|
|
System::println(System::Color::success, "Installing package %s... done", display_name);
|
2017-04-08 07:08:23 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Checks::unreachable(VCPKG_LINE_INFO);
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
2017-04-08 07:17:54 +08:00
|
|
|
System::println(System::Color::error, "Error: Could not install package %s: %s", action.spec, e.what());
|
2017-03-04 22:48:59 +08:00
|
|
|
results.back() = BuildResult::NULLVALUE;
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
2017-04-08 07:17:54 +08:00
|
|
|
System::println("Elapsed time for package %s: %s", action.spec, build_timer.to_string());
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 06:44:46 +08:00
|
|
|
System::println("Total time taken: %s", timer.to_string());
|
2017-02-16 06:34:39 +08:00
|
|
|
|
2017-02-16 12:18:39 +08:00
|
|
|
for (size_t i = 0; i < results.size(); i++)
|
2017-02-14 06:01:56 +08:00
|
|
|
{
|
2017-04-08 08:39:47 +08:00
|
|
|
System::println("%s: %s: %dms", install_plan[i].spec, Build::to_string(results[i]), timing[i]);
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 06:34:39 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-23 08:45:39 +08:00
|
|
|
Checks::exit_success(VCPKG_LINE_INFO);
|
2017-02-14 06:01:56 +08:00
|
|
|
}
|
|
|
|
}
|