mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-19 06:53:58 +08:00
[vcpkg] Reduce arguments to build_package() by bundling
This commit is contained in:
parent
8c1b8b5ed7
commit
f10861fa7a
@ -8,7 +8,7 @@ namespace vcpkg
|
||||
struct PackageSpec
|
||||
{
|
||||
static Expected<PackageSpec> from_string(const std::string& spec_as_string, const Triplet& default_triplet);
|
||||
|
||||
static std::string to_string(const std::string& name, const Triplet& triplet);
|
||||
static Expected<PackageSpec> from_name_and_triplet(const std::string& name, const Triplet& triplet);
|
||||
|
||||
const std::string& name() const;
|
||||
|
@ -40,10 +40,20 @@ namespace vcpkg::Build
|
||||
std::vector<PackageSpec> unmet_dependencies;
|
||||
};
|
||||
|
||||
ExtendedBuildResult build_package(const SourceParagraph& source_paragraph,
|
||||
const PackageSpec& spec,
|
||||
const VcpkgPaths& paths,
|
||||
const fs::path& port_dir,
|
||||
struct BuildPackageConfig
|
||||
{
|
||||
BuildPackageConfig(const SourceParagraph& src, const Triplet& triplet, fs::path&& port_dir)
|
||||
: src(src), triplet(triplet), port_dir(std::move(port_dir)), use_head_version(false), no_downloads(false)
|
||||
{
|
||||
}
|
||||
|
||||
const SourceParagraph& src;
|
||||
const Triplet& triplet;
|
||||
fs::path port_dir;
|
||||
};
|
||||
|
||||
ExtendedBuildResult build_package(const VcpkgPaths& paths,
|
||||
const BuildPackageConfig& config,
|
||||
const StatusParagraphs& status_db);
|
||||
|
||||
struct BuildInfo
|
||||
|
@ -45,7 +45,11 @@ namespace vcpkg
|
||||
|
||||
std::string PackageSpec::dir() const { return Strings::format("%s_%s", this->m_name, this->m_triplet); }
|
||||
|
||||
std::string PackageSpec::to_string() const { return Strings::format("%s:%s", this->name(), this->triplet()); }
|
||||
std::string PackageSpec::to_string(const std::string& name, const Triplet& triplet)
|
||||
{
|
||||
return Strings::format("%s:%s", name, triplet);
|
||||
}
|
||||
std::string PackageSpec::to_string() const { return to_string(this->name(), this->triplet()); }
|
||||
|
||||
bool operator==(const PackageSpec& left, const PackageSpec& right)
|
||||
{
|
||||
|
@ -42,9 +42,17 @@ namespace vcpkg::Commands::BuildCommand
|
||||
spec,
|
||||
maybe_spgh.error_code().message());
|
||||
const SourceParagraph& spgh = *maybe_spgh.get();
|
||||
Checks::check_exit(VCPKG_LINE_INFO,
|
||||
spec.name() == spgh.name,
|
||||
"The Name: field inside the CONTROL does not match the port directory: '%s' != '%s'",
|
||||
spgh.name,
|
||||
spec.name());
|
||||
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
const auto result = Build::build_package(spgh, spec, paths, paths.port_dir(spec), status_db);
|
||||
const Build::BuildPackageConfig build_config{
|
||||
spgh, spec.triplet(), paths.port_dir(spec),
|
||||
};
|
||||
const auto result = Build::build_package(paths, build_config, status_db);
|
||||
if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES)
|
||||
{
|
||||
System::println(System::Color::error,
|
||||
|
@ -72,8 +72,10 @@ namespace vcpkg::Commands::CI
|
||||
{
|
||||
System::println("Building package %s... ", display_name);
|
||||
auto&& source_paragraph = action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO);
|
||||
const auto result_ex = Build::build_package(
|
||||
source_paragraph, action.spec, paths, paths.port_dir(action.spec), status_db);
|
||||
const Build::BuildPackageConfig build_config{
|
||||
source_paragraph, action.spec.triplet(), paths.port_dir(action.spec),
|
||||
};
|
||||
const auto result_ex = Build::build_package(paths, build_config, status_db);
|
||||
const auto result = result_ex.code;
|
||||
|
||||
timing.back() = build_timer.to_string();
|
||||
|
@ -301,8 +301,7 @@ namespace vcpkg::Commands::Install
|
||||
|
||||
if (has_non_user_requested_packages)
|
||||
{
|
||||
System::println(System::Color::warning,
|
||||
"Additional packages (*) need to be installed to complete this operation.");
|
||||
System::println("Additional packages (*) will be installed to complete this operation.");
|
||||
}
|
||||
|
||||
if (dryRun)
|
||||
@ -325,12 +324,13 @@ namespace vcpkg::Commands::Install
|
||||
case InstallPlanType::BUILD_AND_INSTALL:
|
||||
{
|
||||
System::println("Building package %s... ", display_name);
|
||||
const auto result =
|
||||
Build::build_package(action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
|
||||
action.spec,
|
||||
paths,
|
||||
paths.port_dir(action.spec),
|
||||
status_db);
|
||||
Build::BuildPackageConfig build_config{
|
||||
action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
|
||||
action.spec.triplet(),
|
||||
paths.port_dir(action.spec),
|
||||
};
|
||||
|
||||
const auto result = Build::build_package(paths, build_config, status_db);
|
||||
if (result.code != Build::BuildResult::SUCCEEDED)
|
||||
{
|
||||
System::println(System::Color::error,
|
||||
@ -338,7 +338,7 @@ namespace vcpkg::Commands::Install
|
||||
System::println(Build::create_user_troubleshooting_message(action.spec));
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
System::println(System::Color::success, "Building package %s... done", display_name);
|
||||
System::println("Building package %s... done", display_name);
|
||||
|
||||
const BinaryParagraph bpgh =
|
||||
Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
|
||||
|
@ -40,26 +40,25 @@ namespace vcpkg::Build
|
||||
|
||||
static void create_binary_control_file(const VcpkgPaths& paths,
|
||||
const SourceParagraph& source_paragraph,
|
||||
const Triplet& triplet)
|
||||
const Triplet& triplet,
|
||||
const BuildInfo& build_info)
|
||||
{
|
||||
const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, triplet);
|
||||
const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL";
|
||||
paths.get_filesystem().write_contents(binary_control_file, Strings::serialize(bpgh));
|
||||
}
|
||||
|
||||
ExtendedBuildResult build_package(const SourceParagraph& source_paragraph,
|
||||
const PackageSpec& spec,
|
||||
const VcpkgPaths& paths,
|
||||
const fs::path& port_dir,
|
||||
ExtendedBuildResult build_package(const VcpkgPaths& paths,
|
||||
const BuildPackageConfig& config,
|
||||
const StatusParagraphs& status_db)
|
||||
{
|
||||
Checks::check_exit(
|
||||
VCPKG_LINE_INFO, spec.name() == source_paragraph.name, "inconsistent arguments to build_package()");
|
||||
const PackageSpec spec =
|
||||
PackageSpec::from_name_and_triplet(config.src.name, config.triplet).value_or_exit(VCPKG_LINE_INFO);
|
||||
|
||||
const Triplet& triplet = spec.triplet();
|
||||
const Triplet& triplet = config.triplet;
|
||||
{
|
||||
std::vector<PackageSpec> missing_specs;
|
||||
for (auto&& dep : filter_dependencies(source_paragraph.depends, triplet))
|
||||
for (auto&& dep : filter_dependencies(config.src.depends, triplet))
|
||||
{
|
||||
if (status_db.find_installed(dep, triplet) == status_db.end())
|
||||
{
|
||||
@ -81,14 +80,15 @@ namespace vcpkg::Build
|
||||
const Toolset& toolset = paths.get_toolset();
|
||||
const auto cmd_set_environment = make_build_env_cmd(triplet, toolset);
|
||||
|
||||
const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path,
|
||||
ports_cmake_script_path,
|
||||
{{L"CMD", L"BUILD"},
|
||||
{L"PORT", source_paragraph.name},
|
||||
{L"CURRENT_PORT_DIR", port_dir / "/."},
|
||||
{L"TARGET_TRIPLET", triplet.canonical_name()},
|
||||
{L"VCPKG_PLATFORM_TOOLSET", toolset.version},
|
||||
{L"GIT", git_exe_path}});
|
||||
const std::wstring cmd_launch_cmake =
|
||||
make_cmake_cmd(cmake_exe_path,
|
||||
ports_cmake_script_path,
|
||||
{{L"CMD", L"BUILD"},
|
||||
{L"PORT", config.src.name},
|
||||
{L"CURRENT_PORT_DIR", config.port_dir / "/."},
|
||||
{L"TARGET_TRIPLET", triplet.canonical_name()},
|
||||
{L"VCPKG_PLATFORM_TOOLSET", toolset.version},
|
||||
{L"GIT", git_exe_path}});
|
||||
|
||||
const std::wstring command = Strings::wformat(LR"(%s && %s)", cmd_set_environment, cmd_launch_cmake);
|
||||
|
||||
@ -96,12 +96,13 @@ namespace vcpkg::Build
|
||||
|
||||
int return_code = System::cmd_execute_clean(command);
|
||||
auto buildtimeus = timer.microseconds();
|
||||
Metrics::track_metric("buildtimeus-" + spec.to_string(), buildtimeus);
|
||||
const auto spec_string = spec.to_string();
|
||||
Metrics::track_metric("buildtimeus-" + spec_string, buildtimeus);
|
||||
|
||||
if (return_code != 0)
|
||||
{
|
||||
Metrics::track_property("error", "build failed");
|
||||
Metrics::track_property("build_error", spec.to_string());
|
||||
Metrics::track_property("build_error", spec_string);
|
||||
return {BuildResult::BUILD_FAILED, {}};
|
||||
}
|
||||
|
||||
@ -113,7 +114,7 @@ namespace vcpkg::Build
|
||||
return {BuildResult::POST_BUILD_CHECKS_FAILED, {}};
|
||||
}
|
||||
|
||||
create_binary_control_file(paths, source_paragraph, triplet);
|
||||
create_binary_control_file(paths, config.src, triplet, build_info);
|
||||
|
||||
// const fs::path port_buildtrees_dir = paths.buildtrees / spec.name;
|
||||
// delete_directory(port_buildtrees_dir);
|
||||
|
Loading…
Reference in New Issue
Block a user