diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2020-12-30 12:12:17 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 12:12:17 -0800 |
| commit | 6772fdd145f2b69da18cdf14a5f93bc935aaf7e9 (patch) | |
| tree | cccc445d310b1da351fbd9e2c398d1b223e8675d | |
| parent | f55a5d91d965ec3aa7c5ce63872fcd5d90cc635e (diff) | |
| download | vcpkg-6772fdd145f2b69da18cdf14a5f93bc935aaf7e9.tar.gz vcpkg-6772fdd145f2b69da18cdf14a5f93bc935aaf7e9.zip | |
[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
| -rw-r--r-- | scripts/azure-pipelines/end-to-end-tests-dir/build-missing.ps1 | 18 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/build.h | 10 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 6 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/dependencies.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/install.cpp | 11 |
5 files changed, 43 insertions, 4 deletions
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 000000000..5f318e6af --- /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 88a12e5c1..bd5188b9f 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 b01162b4f..eb2a338b2 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 e7768f2bf..e811efd2f 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 50f07c732..cac0e0e69 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<CommandSwitch, 10> INSTALL_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 11> 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<CommandSwitch, 10> MANIFEST_INSTALL_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 11> 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<Build::BuildMissing>(!no_build_missing), Util::Enum::to_enum<Build::UseHeadVersion>(use_head_version), Util::Enum::to_enum<Build::AllowDownloads>(!no_downloads), Util::Enum::to_enum<Build::OnlyDownloads>(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("<failure><message><![CDATA[%s]]></message></failure>", to_string(code)); |
