From d8a4e6369059aeeaa76fdd6d5e53d22fe60d8244 Mon Sep 17 00:00:00 2001 From: ras0219 <533828+ras0219@users.noreply.github.com> Date: Tue, 6 Oct 2020 14:34:59 -0700 Subject: [PATCH] [vcpkg] Avoid computing triplet ABIs for editable packages (#13446) * [vcpkg] Avoid computing triplet ABIs for editable packages * [vcpkg] Address PR comments * [vcpkg-end-to-end-tests] Add tests for --no-binarycaching, binarycaching by default, and --editable Co-authored-by: Robert Schumacher --- scripts/azure-pipelines/end-to-end-tests.ps1 | 29 +++++++++++- toolsrc/include/vcpkg/binarycaching.h | 5 --- toolsrc/include/vcpkg/build.h | 6 --- toolsrc/src/vcpkg/build.cpp | 47 ++++++++++++++++---- 4 files changed, 66 insertions(+), 21 deletions(-) diff --git a/scripts/azure-pipelines/end-to-end-tests.ps1 b/scripts/azure-pipelines/end-to-end-tests.ps1 index 43ec7aa73e..3a38a83826 100644 --- a/scripts/azure-pipelines/end-to-end-tests.ps1 +++ b/scripts/azure-pipelines/end-to-end-tests.ps1 @@ -124,7 +124,7 @@ Throw-IfFailed Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" # Test restoring from files archive -$args = $commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read") +$args = $commonArgs + @("install","rapidjson","--x-binarysource=clear;files,$ArchiveRoot,read") $CurrentTest = "./vcpkg $($args -join ' ')" Remove-Item -Recurse -Force $installRoot Remove-Item -Recurse -Force $buildtreesRoot @@ -134,6 +134,33 @@ Throw-IfFailed Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" Require-FileNotExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$buildtreesRoot/detect_compiler" + +# Test --no-binarycaching +$args = $commonArgs + @("install","rapidjson","--no-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read") +$CurrentTest = "./vcpkg $($args -join ' ')" +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Write-Host $CurrentTest +./vcpkg @args +Throw-IfFailed + +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$buildtreesRoot/detect_compiler" + +# Test --editable +$args = $commonArgs + @("install","rapidjson","--editable","--x-binarysource=clear;files,$ArchiveRoot,read") +$CurrentTest = "./vcpkg $($args -join ' ')" +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Write-Host $CurrentTest +./vcpkg @args +Throw-IfFailed + +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileExists "$buildtreesRoot/rapidjson/src" +Require-FileNotExists "$buildtreesRoot/detect_compiler" # Test restoring from nuget $args = $commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;nuget,$NuGetRoot") diff --git a/toolsrc/include/vcpkg/binarycaching.h b/toolsrc/include/vcpkg/binarycaching.h index be52d1e498..d76d603707 100644 --- a/toolsrc/include/vcpkg/binarycaching.h +++ b/toolsrc/include/vcpkg/binarycaching.h @@ -11,11 +11,6 @@ namespace vcpkg::Dependencies struct InstallPlanAction; struct ActionPlan; } -namespace vcpkg::Build -{ - struct AbiTagAndFile; - struct BuildPackageOptions; -} namespace vcpkg { diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 99effe4752..443bcd3a2d 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -299,12 +299,6 @@ namespace vcpkg::Build } }; - struct AbiTagAndFile - { - std::string tag; - fs::path tag_file; - }; - struct CompilerInfo { std::string id; diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index da2094cffd..92b657c9b5 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -850,8 +850,6 @@ namespace vcpkg::Build static void abi_entries_from_abi_info(const AbiInfo& abi_info, std::vector& abi_tag_entries) { - abi_tag_entries.emplace_back("triplet", abi_info.triplet_abi.value_or_exit(VCPKG_LINE_INFO)); - const auto& pre_build_info = *abi_info.pre_build_info; if (pre_build_info.public_abi_override) { @@ -869,6 +867,13 @@ namespace vcpkg::Build } } + struct AbiTagAndFile + { + const std::string* triplet_abi; + std::string tag; + fs::path tag_file; + }; + static Optional compute_abi_tag(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action, Span dependency_abis) @@ -876,9 +881,35 @@ namespace vcpkg::Build auto& fs = paths.get_filesystem(); Triplet triplet = action.spec.triplet(); + if (action.build_options.use_head_version == UseHeadVersion::YES) + { + Debug::print("Binary caching for package ", action.spec, " is disabled due to --head\n"); + return nullopt; + } + if (action.build_options.editable == Editable::YES) + { + Debug::print("Binary caching for package ", action.spec, " is disabled due to --editable\n"); + return nullopt; + } + for (auto&& dep_abi : dependency_abis) + { + if (dep_abi.value.empty()) + { + Debug::print("Binary caching for package ", + action.spec, + " is disabled due to missing abi info for ", + dep_abi.key, + '\n'); + return nullopt; + } + } + std::vector abi_tag_entries(dependency_abis.begin(), dependency_abis.end()); - abi_entries_from_abi_info(action.abi_info.value_or_exit(VCPKG_LINE_INFO), abi_tag_entries); + const auto& abi_info = action.abi_info.value_or_exit(VCPKG_LINE_INFO); + const auto& triplet_abi = paths.get_triplet_info(abi_info); + abi_tag_entries.emplace_back("triplet", triplet_abi); + abi_entries_from_abi_info(abi_info, abi_tag_entries); // If there is an unusually large number of files in the port then // something suspicious is going on. Rather than hash all of them @@ -926,9 +957,6 @@ namespace vcpkg::Build Util::sort(sorted_feature_list); abi_tag_entries.emplace_back("features", Strings::join(";", sorted_feature_list)); - if (action.build_options.use_head_version == UseHeadVersion::YES) abi_tag_entries.emplace_back("head", ""); - if (action.build_options.editable == Editable::YES) abi_tag_entries.emplace_back("editable", ""); - Util::sort(abi_tag_entries); const std::string full_abi_info = @@ -954,7 +982,8 @@ namespace vcpkg::Build const auto abi_file_path = current_build_tree / (triplet.canonical_name() + ".vcpkg_abi_info.txt"); fs.write_contents(abi_file_path, full_abi_info, VCPKG_LINE_INFO); - return AbiTagAndFile{Hash::get_file_hash(VCPKG_LINE_INFO, fs, abi_file_path, Hash::Algorithm::Sha1), + return AbiTagAndFile{&triplet_abi, + Hash::get_file_hash(VCPKG_LINE_INFO, fs, abi_file_path, Hash::Algorithm::Sha1), abi_file_path}; } @@ -1013,12 +1042,12 @@ namespace vcpkg::Build abi_info.pre_build_info = std::make_unique( paths, action.spec.triplet(), var_provider.get_tag_vars(action.spec).value_or_exit(VCPKG_LINE_INFO)); abi_info.toolset = paths.get_toolset(*abi_info.pre_build_info); - abi_info.compiler_info = paths.get_compiler_info(abi_info); - abi_info.triplet_abi = paths.get_triplet_info(abi_info); auto maybe_abi_tag_and_file = compute_abi_tag(paths, action, dependency_abis); if (auto p = maybe_abi_tag_and_file.get()) { + abi_info.compiler_info = paths.get_compiler_info(abi_info); + abi_info.triplet_abi = *p->triplet_abi; abi_info.package_abi = std::move(p->tag); abi_info.abi_tag_file = std::move(p->tag_file); }