From 6772fdd145f2b69da18cdf14a5f93bc935aaf7e9 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 30 Dec 2020 12:12:17 -0800 Subject: [PATCH] [vcpkg] Teach `vcpkg install` `--no-build-missing` (#15139) * [vcpkg] Teach `vcpkg install` `--no-build-missing` This switch causes failure to restore from cache to abort the build instead of performing a just-in-time build. This is useful in complex CI systems where the build was expected to have been performed previously, such as via another pipeline. * [vcpkg] Rename flag to require binary caching --- .../end-to-end-tests-dir/build-missing.ps1 | 18 ++++++++++++++++++ toolsrc/include/vcpkg/build.h | 10 ++++++++++ toolsrc/src/vcpkg/build.cpp | 6 ++++++ toolsrc/src/vcpkg/dependencies.cpp | 2 +- toolsrc/src/vcpkg/install.cpp | 11 ++++++++--- 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/build-missing.ps1 diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/build-missing.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/build-missing.ps1 new file mode 100644 index 0000000000..5f318e6af9 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/build-missing.ps1 @@ -0,0 +1,18 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +$CurrentTest = "Build Missing tests" + +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--only-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) +Throw-IfNotFailed +Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" + +# Create the rapidjson archive +Remove-Item -Recurse -Force $installRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson","--x-binarysource=clear;files,$ArchiveRoot,write")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" + +Remove-Item -Recurse -Force $installRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--only-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 88a12e5c16..bd5188b9fb 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -42,6 +42,7 @@ namespace vcpkg::Build FILE_CONFLICTS, CASCADED_DUE_TO_MISSING_DEPENDENCIES, EXCLUDED, + CACHE_MISSING, DOWNLOADED }; @@ -141,8 +142,15 @@ namespace vcpkg::Build PROHIBIT }; + enum class BuildMissing + { + NO = 0, + YES + }; + struct BuildPackageOptions { + BuildMissing build_missing; UseHeadVersion use_head_version; AllowDownloads allow_downloads; OnlyDownloads only_downloads; @@ -156,6 +164,7 @@ namespace vcpkg::Build }; static constexpr BuildPackageOptions default_build_package_options{ + Build::BuildMissing::YES, Build::UseHeadVersion::NO, Build::AllowDownloads::YES, Build::OnlyDownloads::NO, @@ -169,6 +178,7 @@ namespace vcpkg::Build }; static constexpr BuildPackageOptions backcompat_prohibiting_package_options{ + Build::BuildMissing::YES, Build::UseHeadVersion::NO, Build::AllowDownloads::YES, Build::OnlyDownloads::NO, diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index b01162b4f3..eb2a338b26 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -1164,6 +1164,10 @@ namespace vcpkg::Build // missing package, proceed to build. } } + if (action.build_options.build_missing == BuildMissing::NO) + { + return BuildResult::CACHE_MISSING; + } ExtendedBuildResult result = do_build_package_and_clean_buildtrees(args, paths, action); @@ -1190,6 +1194,7 @@ namespace vcpkg::Build static const std::string POST_BUILD_CHECKS_FAILED_STRING = "POST_BUILD_CHECKS_FAILED"; static const std::string CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING = "CASCADED_DUE_TO_MISSING_DEPENDENCIES"; static const std::string EXCLUDED_STRING = "EXCLUDED"; + static const std::string CACHE_MISSING_STRING = "CACHE_MISSING"; static const std::string DOWNLOADED_STRING = "DOWNLOADED"; switch (build_result) @@ -1201,6 +1206,7 @@ namespace vcpkg::Build case BuildResult::FILE_CONFLICTS: return FILE_CONFLICTS_STRING; case BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES: return CASCADED_DUE_TO_MISSING_DEPENDENCIES_STRING; case BuildResult::EXCLUDED: return EXCLUDED_STRING; + case BuildResult::CACHE_MISSING: return CACHE_MISSING_STRING; case BuildResult::DOWNLOADED: return DOWNLOADED_STRING; default: Checks::unreachable(VCPKG_LINE_INFO); } diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp index e7768f2bfd..e811efd2fc 100644 --- a/toolsrc/src/vcpkg/dependencies.cpp +++ b/toolsrc/src/vcpkg/dependencies.cpp @@ -356,7 +356,7 @@ namespace vcpkg::Dependencies std::string to_output_string(RequestType request_type, const CStringView s) { - return to_output_string(request_type, s, {Build::UseHeadVersion::NO}, {}, {}, {}); + return to_output_string(request_type, s, {}, {}, {}, {}); } InstallPlanAction::InstallPlanAction() noexcept diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 50f07c7326..cac0e0e694 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -511,6 +511,7 @@ namespace vcpkg::Install static constexpr StringLiteral OPTION_DRY_RUN = "dry-run"; static constexpr StringLiteral OPTION_USE_HEAD_VERSION = "head"; static constexpr StringLiteral OPTION_NO_DOWNLOADS = "no-downloads"; + static constexpr StringLiteral OPTION_ONLY_BINARYCACHING = "only-binarycaching"; static constexpr StringLiteral OPTION_ONLY_DOWNLOADS = "only-downloads"; static constexpr StringLiteral OPTION_RECURSE = "recurse"; static constexpr StringLiteral OPTION_KEEP_GOING = "keep-going"; @@ -523,11 +524,12 @@ namespace vcpkg::Install static constexpr StringLiteral OPTION_MANIFEST_FEATURE = "x-feature"; static constexpr StringLiteral OPTION_PROHIBIT_BACKCOMPAT_FEATURES = "x-prohibit-backcompat-features"; - static constexpr std::array INSTALL_SWITCHES = {{ + static constexpr std::array INSTALL_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually build or install"}, {OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"}, {OPTION_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_ONLY_DOWNLOADS, "Download sources but don't build packages"}, + {OPTION_ONLY_BINARYCACHING, "Fail if cached binaries are not available"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, {OPTION_EDITABLE, "Disable source re-extraction and binary caching for libraries on the command line"}, @@ -537,12 +539,12 @@ namespace vcpkg::Install {OPTION_PROHIBIT_BACKCOMPAT_FEATURES, "(experimental) Fail install if a package attempts to use a deprecated feature"}, }}; - - static constexpr std::array MANIFEST_INSTALL_SWITCHES = {{ + static constexpr std::array MANIFEST_INSTALL_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually build or install"}, {OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"}, {OPTION_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_ONLY_DOWNLOADS, "Download sources but don't build packages"}, + {OPTION_ONLY_BINARYCACHING, "Fail if cached binaries are not available"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, {OPTION_EDITABLE, "Disable source re-extraction and binary caching for libraries on the command line"}, @@ -765,6 +767,7 @@ namespace vcpkg::Install const bool use_head_version = Util::Sets::contains(options.switches, (OPTION_USE_HEAD_VERSION)); const bool no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS)); const bool only_downloads = Util::Sets::contains(options.switches, (OPTION_ONLY_DOWNLOADS)); + const bool no_build_missing = Util::Sets::contains(options.switches, OPTION_ONLY_BINARYCACHING); const bool is_recursive = Util::Sets::contains(options.switches, (OPTION_RECURSE)); const bool is_editable = Util::Sets::contains(options.switches, (OPTION_EDITABLE)) || !args.cmake_args.empty(); const bool use_aria2 = Util::Sets::contains(options.switches, (OPTION_USE_ARIA2)); @@ -780,6 +783,7 @@ namespace vcpkg::Install if (use_aria2) download_tool = Build::DownloadTool::ARIA2; const Build::BuildPackageOptions install_plan_options = { + Util::Enum::to_enum(!no_build_missing), Util::Enum::to_enum(use_head_version), Util::Enum::to_enum(!no_downloads), Util::Enum::to_enum(only_downloads), @@ -1070,6 +1074,7 @@ namespace vcpkg::Install case BuildResult::POST_BUILD_CHECKS_FAILED: case BuildResult::FILE_CONFLICTS: case BuildResult::BUILD_FAILED: + case BuildResult::CACHE_MISSING: result_string = "Fail"; message_block = Strings::format("", to_string(code));