From 3d841c9b6a67edf2126c68698a9f05b5d1b5fbcd Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 11 Feb 2020 23:52:56 -0800 Subject: [vcpkg] Compute all ABIs upfront instead of during build_package() --- toolsrc/src/vcpkg/binarycaching.cpp | 76 ++++++++++++++---------- toolsrc/src/vcpkg/build.cpp | 111 +++++++++++++++++++++++++----------- toolsrc/src/vcpkg/commands.ci.cpp | 77 ++++++------------------- toolsrc/src/vcpkg/dependencies.cpp | 9 +++ toolsrc/src/vcpkg/install.cpp | 12 ++-- 5 files changed, 157 insertions(+), 128 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/binarycaching.cpp b/toolsrc/src/vcpkg/binarycaching.cpp index bbf565c9c..dd8770330 100644 --- a/toolsrc/src/vcpkg/binarycaching.cpp +++ b/toolsrc/src/vcpkg/binarycaching.cpp @@ -56,29 +56,21 @@ namespace #endif } - static void compress_archive(const VcpkgPaths& paths, const PackageSpec& spec, const fs::path& destination) - { - compress_directory(paths, paths.package_dir(spec), destination); - } - struct ArchivesBinaryProvider : IBinaryProvider { ~ArchivesBinaryProvider() = default; void prefetch() override {} - RestoreResult try_restore(const VcpkgPaths& paths, - const PackageSpec& spec, - const Build::AbiTagAndFile& abi_tag_and_file, - const Build::BuildPackageOptions& build_options) override + RestoreResult try_restore(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) override { + const auto& abi_tag = action.package_abi.value_or_exit(VCPKG_LINE_INFO); + auto& spec = action.spec; auto& fs = paths.get_filesystem(); std::error_code ec; const fs::path archives_root_dir = paths.root / "archives"; - const std::string archive_name = abi_tag_and_file.tag + ".zip"; - const fs::path archive_subpath = fs::u8path(abi_tag_and_file.tag.substr(0, 2)) / archive_name; + const std::string archive_name = abi_tag + ".zip"; + const fs::path archive_subpath = fs::u8path(abi_tag.substr(0, 2)) / archive_name; const fs::path archive_path = archives_root_dir / archive_subpath; const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath; - const fs::path abi_package_dir = paths.package_dir(spec) / "share" / spec.name(); - const fs::path abi_file_in_package = paths.package_dir(spec) / "share" / spec.name() / "vcpkg_abi_info.txt"; if (fs.exists(archive_path)) { System::print2("Using cached binary package: ", archive_path.u8string(), "\n"); @@ -88,7 +80,7 @@ namespace if (archive_result != 0) { System::print2("Failed to decompress archive package\n"); - if (build_options.purge_decompress_failure == Build::PurgeDecompressFailure::NO) + if (action.build_options.purge_decompress_failure == Build::PurgeDecompressFailure::NO) { return RestoreResult::BUILD_FAILED; } @@ -106,7 +98,7 @@ namespace if (fs.exists(archive_tombstone_path)) { - if (build_options.fail_on_tombstone == Build::FailOnTombstone::YES) + if (action.build_options.fail_on_tombstone == Build::FailOnTombstone::YES) { System::print2("Found failure tombstone: ", archive_tombstone_path.u8string(), "\n"); return RestoreResult::BUILD_FAILED; @@ -124,24 +116,20 @@ namespace return RestoreResult::MISSING; } - void push_success(const VcpkgPaths& paths, - const Build::AbiTagAndFile& abi_tag_and_file, - const Dependencies::InstallPlanAction& action) override + void push_success(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) override { + const auto& abi_tag = action.package_abi.value_or_exit(VCPKG_LINE_INFO); auto& spec = action.spec; auto& fs = paths.get_filesystem(); std::error_code ec; const fs::path archives_root_dir = paths.root / "archives"; - const std::string archive_name = abi_tag_and_file.tag + ".zip"; - const fs::path archive_subpath = fs::u8path(abi_tag_and_file.tag.substr(0, 2)) / archive_name; + const std::string archive_name = abi_tag + ".zip"; + const fs::path archive_subpath = fs::u8path(abi_tag.substr(0, 2)) / archive_name; const fs::path archive_path = archives_root_dir / archive_subpath; - const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath; - const fs::path abi_package_dir = paths.package_dir(spec) / "share" / spec.name(); - const fs::path abi_file_in_package = paths.package_dir(spec) / "share" / spec.name() / "vcpkg_abi_info.txt"; const auto tmp_archive_path = paths.buildtrees / spec.name() / (spec.triplet().to_string() + ".zip"); - compress_archive(paths, spec, tmp_archive_path); + compress_directory(paths, paths.package_dir(spec), tmp_archive_path); fs.create_directories(archive_path.parent_path(), ec); fs.rename_or_copy(tmp_archive_path, archive_path, ".tmp", ec); @@ -155,15 +143,13 @@ namespace else System::printf("Stored binary cache: %s\n", archive_path.u8string()); } - void push_failure(const VcpkgPaths& paths, - const Build::AbiTagAndFile& abi_tag_and_file, - const PackageSpec& spec) override + void push_failure(const VcpkgPaths& paths, const std::string& abi_tag, const PackageSpec& spec) override { auto& fs = paths.get_filesystem(); std::error_code ec; const fs::path archives_root_dir = paths.root / "archives"; - const std::string archive_name = abi_tag_and_file.tag + ".zip"; - const fs::path archive_subpath = fs::u8path(abi_tag_and_file.tag.substr(0, 2)) / archive_name; + const std::string archive_name = abi_tag + ".zip"; + const fs::path archive_subpath = fs::u8path(abi_tag.substr(0, 2)) / archive_name; const fs::path archive_path = archives_root_dir / archive_subpath; const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath; const fs::path abi_package_dir = paths.package_dir(spec) / "share" / spec.name(); @@ -197,6 +183,38 @@ namespace fs.remove_all(tmp_log_path, VCPKG_LINE_INFO); } } + RestoreResult precheck(const VcpkgPaths& paths, + const Dependencies::InstallPlanAction& action, + bool purge_tombstones) override + { + const auto& abi_tag = action.package_abi.value_or_exit(VCPKG_LINE_INFO); + auto& fs = paths.get_filesystem(); + std::error_code ec; + const fs::path archives_root_dir = paths.root / "archives"; + const std::string archive_name = abi_tag + ".zip"; + const fs::path archive_subpath = fs::u8path(abi_tag.substr(0, 2)) / archive_name; + const fs::path archive_path = archives_root_dir / archive_subpath; + const fs::path archive_tombstone_path = archives_root_dir / "fail" / archive_subpath; + + if (fs.exists(archive_path)) + { + return RestoreResult::SUCCESS; + } + + if (purge_tombstones) + { + fs.remove(archive_tombstone_path, ec); // Ignore error + } + else if (fs.exists(archive_tombstone_path)) + { + if (action.build_options.fail_on_tombstone == Build::FailOnTombstone::YES) + { + return RestoreResult::BUILD_FAILED; + } + } + + return RestoreResult::MISSING; + } }; } diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 7ec6ff60e..c6b358819 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -92,8 +92,7 @@ namespace vcpkg::Build::Command action->build_options = build_package_options; const auto build_timer = Chrono::ElapsedTimer::create_started(); - const auto result = - Build::build_package(paths, *action, var_provider, create_archives_provider().get(), status_db); + const auto result = Build::build_package(paths, *action, create_archives_provider().get(), status_db); System::print2("Elapsed time for package ", spec, ": ", build_timer, '\n'); if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES) @@ -462,11 +461,10 @@ namespace vcpkg::Build return hash; } - static ExtendedBuildResult do_build_package(const VcpkgPaths& paths, - const PreBuildInfo& pre_build_info, - const std::string& abi_tag, - const Dependencies::InstallPlanAction& action) + static ExtendedBuildResult do_build_package(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) { + const auto& pre_build_info = *action.pre_build_info.value_or_exit(VCPKG_LINE_INFO).get(); + auto& fs = paths.get_filesystem(); auto&& scfl = action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO); @@ -563,8 +561,11 @@ namespace vcpkg::Build auto find_itr = action.feature_dependencies.find("core"); Checks::check_exit(VCPKG_LINE_INFO, find_itr != action.feature_dependencies.end()); - std::unique_ptr bcf = create_binary_control_file( - *scfl.source_control_file->core_paragraph, triplet, build_info, abi_tag, std::move(find_itr->second)); + std::unique_ptr bcf = create_binary_control_file(*scfl.source_control_file->core_paragraph, + triplet, + build_info, + action.public_abi(), + std::move(find_itr->second)); if (error_count != 0) { @@ -590,11 +591,9 @@ namespace vcpkg::Build } static ExtendedBuildResult do_build_package_and_clean_buildtrees(const VcpkgPaths& paths, - const PreBuildInfo& pre_build_info, - const std::string& abi_tag, const Dependencies::InstallPlanAction& action) { - auto result = do_build_package(paths, pre_build_info, abi_tag, action); + auto result = do_build_package(paths, action); if (action.build_options.clean_buildtrees == CleanBuildtrees::YES) { @@ -617,12 +616,12 @@ namespace vcpkg::Build Optional compute_abi_tag(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action, - const PreBuildInfo& pre_build_info, Span dependency_abis) { auto& fs = paths.get_filesystem(); Triplet triplet = action.spec.triplet(); const std::string& name = action.spec.name(); + const auto& pre_build_info = *action.pre_build_info.value_or_exit(VCPKG_LINE_INFO); std::vector abi_tag_entries(dependency_abis.begin(), dependency_abis.end()); @@ -736,9 +735,62 @@ namespace vcpkg::Build return nullopt; } + void compute_all_abis(const VcpkgPaths& paths, + Dependencies::ActionPlan& action_plan, + const CMakeVars::CMakeVarProvider& var_provider, + const StatusParagraphs& status_db) + { + using Dependencies::InstallPlanAction; + for (auto it = action_plan.install_actions.begin(); it != action_plan.install_actions.end(); ++it) + { + auto& action = *it; + std::vector dependency_abis; + if (!Util::Enum::to_bool(action.build_options.only_downloads)) + { + for (auto&& pspec : action.package_dependencies) + { + if (pspec == action.spec) continue; + + auto pred = [&](const InstallPlanAction& ipa) { return ipa.spec == pspec; }; + auto it2 = std::find_if(action_plan.install_actions.begin(), it, pred); + if (it2 == it) + { + // Finally, look in current installed + auto status_it = status_db.find(pspec); + if (status_it == status_db.end()) + { + Checks::exit_with_message( + VCPKG_LINE_INFO, "Failed to find dependency abi for %s -> %s", action.spec, pspec); + } + else + { + dependency_abis.emplace_back(AbiEntry{pspec.name(), status_it->get()->package.abi}); + } + } + else + { + dependency_abis.emplace_back(AbiEntry{pspec.name(), it2->public_abi()}); + } + } + } + + action.pre_build_info = std::make_unique( + paths, action.spec.triplet(), var_provider.get_tag_vars(action.spec).value_or_exit(VCPKG_LINE_INFO)); + auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis); + if (auto p = maybe_abi_tag_and_file.get()) + { + action.abi_tag_file = std::move(p->tag_file); + action.package_abi = std::move(p->tag); + } + else + { + action.package_abi = ""; + } + } + } + ExtendedBuildResult build_package(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action, - const CMakeVars::CMakeVarProvider& var_provider, IBinaryProvider* binaries_provider, const StatusParagraphs& status_db) { @@ -746,17 +798,18 @@ namespace vcpkg::Build auto& fs = paths.get_filesystem(); Triplet triplet = action.spec.triplet(); + auto& spec = action.spec; const std::string& name = action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO) .source_control_file->core_paragraph->name; std::vector missing_fspecs; for (const auto& kv : action.feature_dependencies) { - for (const FeatureSpec& spec : kv.second) + for (const FeatureSpec& fspec : kv.second) { - if (!(status_db.is_installed(spec) || spec.name() == name)) + if (!(status_db.is_installed(fspec) || spec.name() == name)) { - missing_fspecs.emplace_back(spec); + missing_fspecs.emplace_back(fspec); } } } @@ -766,8 +819,6 @@ namespace vcpkg::Build return {BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES, std::move(missing_fspecs)}; } - const PackageSpec spec(name, triplet); - std::vector dependency_abis; for (auto&& pspec : action.package_dependencies) { @@ -781,24 +832,19 @@ namespace vcpkg::Build AbiEntry{status_it->get()->package.spec.name(), status_it->get()->package.abi}); } - const std::unordered_map& cmake_vars = - var_provider.get_tag_vars(spec).value_or_exit(VCPKG_LINE_INFO); - const PreBuildInfo pre_build_info(paths, triplet, cmake_vars); - - auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, pre_build_info, dependency_abis); - if (!maybe_abi_tag_and_file) + if (!action.abi_tag_file) { - return do_build_package_and_clean_buildtrees( - paths, pre_build_info, pre_build_info.public_abi_override.value_or(AbiTagAndFile{}.tag), action); + return do_build_package_and_clean_buildtrees(paths, action); } + auto& abi_file = *action.abi_tag_file.get(); + std::error_code ec; - const auto abi_tag_and_file = maybe_abi_tag_and_file.get(); const fs::path abi_package_dir = paths.package_dir(spec) / "share" / spec.name(); const fs::path abi_file_in_package = paths.package_dir(spec) / "share" / spec.name() / "vcpkg_abi_info.txt"; if (binary_caching_enabled) { - auto restore = binaries_provider->try_restore(paths, spec, *abi_tag_and_file, action.build_options); + auto restore = binaries_provider->try_restore(paths, action); if (restore == RestoreResult::BUILD_FAILED) return BuildResult::BUILD_FAILED; else if (restore == RestoreResult::SUCCESS) @@ -813,21 +859,20 @@ namespace vcpkg::Build } } - ExtendedBuildResult result = do_build_package_and_clean_buildtrees( - paths, pre_build_info, pre_build_info.public_abi_override.value_or(abi_tag_and_file->tag), action); + ExtendedBuildResult result = do_build_package_and_clean_buildtrees(paths, action); fs.create_directories(abi_package_dir, ec); - fs.copy_file(abi_tag_and_file->tag_file, abi_file_in_package, fs::stdfs::copy_options::none, ec); + fs.copy_file(abi_file, abi_file_in_package, fs::stdfs::copy_options::none, ec); Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not copy into file: %s", abi_file_in_package.u8string()); if (binary_caching_enabled && result.code == BuildResult::SUCCEEDED) { - binaries_provider->push_success(paths, *abi_tag_and_file, action); + binaries_provider->push_success(paths, action); } else if (binary_caching_enabled && (result.code == BuildResult::BUILD_FAILED || result.code == BuildResult::POST_BUILD_CHECKS_FAILED)) { - binaries_provider->push_failure(paths, *abi_tag_and_file, spec); + binaries_provider->push_failure(paths, action.package_abi.value_or_exit(VCPKG_LINE_INFO), spec); } return result; diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp index 00e25e223..842bb9b0a 100644 --- a/toolsrc/src/vcpkg/commands.ci.cpp +++ b/toolsrc/src/vcpkg/commands.ci.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -220,7 +221,6 @@ namespace vcpkg::Commands::CI std::map known; std::map> features; std::unordered_map default_feature_provider; - std::map abi_tag_map; }; static bool supported_for_triplet(const CMakeVars::TripletCMakeVarProvider& var_provider, @@ -259,8 +259,6 @@ namespace vcpkg::Commands::CI { auto ret = std::make_unique(); - auto& fs = paths.get_filesystem(); - std::set will_fail; const Build::BuildPackageOptions build_options = { @@ -306,59 +304,24 @@ namespace vcpkg::Commands::CI Checks::check_exit(VCPKG_LINE_INFO, action_plan.already_installed.empty(), "Cannot use CI command with packages already installed."); + + Build::compute_all_abis(paths, action_plan, var_provider, {}); + + auto binaryprovider = create_archives_provider(); + std::string stdout_buffer; for (auto&& action : action_plan.install_actions) { auto p = &action; - // determine abi tag - std::string abi; if (auto scfl = p->source_control_file_location.get()) { auto emp = ret->default_feature_provider.emplace(p->spec.name(), *scfl); emp.first->second.source_control_file->core_paragraph->default_features = p->feature_list; - auto triplet = p->spec.triplet(); - p->build_options = build_options; - - auto dependency_abis = - Util::fmap(p->package_dependencies, [&](const PackageSpec& spec) -> Build::AbiEntry { - auto it = ret->abi_tag_map.find(spec); - - if (it == ret->abi_tag_map.end()) - return {spec.name(), ""}; - else - return {spec.name(), it->second}; - }); - - const auto pre_build_info = Build::PreBuildInfo( - paths, triplet, var_provider.get_tag_vars(p->spec).value_or_exit(VCPKG_LINE_INFO)); - - auto maybe_tag_and_file = Build::compute_abi_tag(paths, *p, pre_build_info, dependency_abis); - if (auto tag_and_file = maybe_tag_and_file.get()) - { - abi = tag_and_file->tag; - ret->abi_tag_map.emplace(p->spec, abi); - } - } - else if (auto ipv = p->installed_package.get()) - { - abi = ipv->core->package.abi; - if (!abi.empty()) ret->abi_tag_map.emplace(p->spec, abi); - } - - auto archives_root_dir = paths.root / "archives"; - auto archive_name = abi + ".zip"; - auto archive_subpath = fs::u8path(abi.substr(0, 2)) / archive_name; - auto archive_path = archives_root_dir / archive_subpath; - auto archive_tombstone_path = archives_root_dir / "fail" / archive_subpath; - - if (purge_tombstones) - { - std::error_code ec; - fs.remove(archive_tombstone_path, ec); // Ignore error } + auto precheck_result = binaryprovider->precheck(paths, action, purge_tombstones); bool b_will_build = false; std::string state; @@ -385,12 +348,12 @@ namespace vcpkg::Commands::CI ret->known.emplace(p->spec, BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES); will_fail.emplace(p->spec); } - else if (fs.exists(archive_path)) + else if (precheck_result == RestoreResult::SUCCESS) { state = "pass"; ret->known.emplace(p->spec, BuildResult::SUCCEEDED); } - else if (fs.exists(archive_tombstone_path)) + else if (precheck_result == RestoreResult::BUILD_FAILED) { state = "fail"; ret->known.emplace(p->spec, BuildResult::BUILD_FAILED); @@ -402,8 +365,10 @@ namespace vcpkg::Commands::CI b_will_build = true; } - Strings::append(stdout_buffer, - Strings::format("%40s: %1s %8s: %s\n", p->spec, (b_will_build ? "*" : " "), state, abi)); + Strings::append( + stdout_buffer, + Strings::format( + "%40s: %1s %8s: %s\n", p->spec, (b_will_build ? "*" : " "), state, action.public_abi())); if (stdout_buffer.size() > 2048) { System::print2(stdout_buffer); @@ -465,7 +430,6 @@ namespace vcpkg::Commands::CI }; std::vector> all_known_results; - std::map abi_tag_map; XunitTestResults xunitTestResults; @@ -543,26 +507,19 @@ namespace vcpkg::Commands::CI { auto& port_features = split_specs->features[result.spec]; split_specs->known.erase(result.spec); - xunitTestResults.add_test_results(result.spec.to_string(), - result.build_result.code, - result.timing, - split_specs->abi_tag_map.at(result.spec), - port_features); + xunitTestResults.add_test_results( + result.spec.to_string(), result.build_result.code, result.timing, "", port_features); } // Adding results for ports that were not built because they have known states for (auto&& port : split_specs->known) { auto& port_features = split_specs->features[port.first]; - xunitTestResults.add_test_results(port.first.to_string(), - port.second, - Chrono::ElapsedTime{}, - split_specs->abi_tag_map.at(port.first), - port_features); + xunitTestResults.add_test_results( + port.first.to_string(), port.second, Chrono::ElapsedTime{}, "", port_features); } all_known_results.emplace_back(std::move(split_specs->known)); - abi_tag_map.insert(split_specs->abi_tag_map.begin(), split_specs->abi_tag_map.end()); results.push_back({triplet, std::move(summary)}); diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp index beb92f4b0..07aad4d22 100644 --- a/toolsrc/src/vcpkg/dependencies.cpp +++ b/toolsrc/src/vcpkg/dependencies.cpp @@ -403,6 +403,15 @@ namespace vcpkg::Dependencies const std::string features = Strings::join(",", feature_list); return Strings::format("%s[%s]:%s", this->spec.name(), features, this->spec.triplet()); } + const std::string& InstallPlanAction::public_abi() const + { + if (auto p = pre_build_info.get()) + { + if (auto q = p->get()->public_abi_override.get()) return *q; + } + if (auto p = installed_package.get()) return p->core->package.abi; + return package_abi.value_or_exit(VCPKG_LINE_INFO); + } bool InstallPlanAction::compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right) { diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 1cd29284c..fc398bd45 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -300,8 +300,7 @@ namespace vcpkg::Install ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths, InstallPlanAction& action, StatusParagraphs& status_db, - IBinaryProvider* binaries_provider, - const CMakeVars::CMakeVarProvider& var_provider) + IBinaryProvider* binaries_provider) { const InstallPlanType& plan_type = action.plan_type; const std::string display_name = action.spec.to_string(); @@ -341,7 +340,7 @@ namespace vcpkg::Install else System::printf("Building package %s...\n", display_name_with_features); - auto result = Build::build_package(paths, action, var_provider, binaries_provider, status_db); + auto result = Build::build_package(paths, action, binaries_provider, status_db); if (BuildResult::DOWNLOADED == result.code) { @@ -458,15 +457,16 @@ namespace vcpkg::Install for (auto&& action : action_plan.already_installed) { results.emplace_back(action.spec, &action); - results.back().build_result = perform_install_plan_action(paths, action, status_db, nullptr, var_provider); + results.back().build_result = perform_install_plan_action(paths, action, status_db, nullptr); } + Build::compute_all_abis(paths, action_plan, var_provider, status_db); + auto binary_provider = create_archives_provider(); for (auto&& action : action_plan.install_actions) { with_tracking(action.spec, [&]() { - auto result = - perform_install_plan_action(paths, action, status_db, binary_provider.get(), var_provider); + auto result = perform_install_plan_action(paths, action, status_db, binary_provider.get()); if (result.code != BuildResult::SUCCEEDED && keep_going == KeepGoing::NO) { -- cgit v1.2.3