[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
This commit is contained in:
Robert Schumacher 2020-12-30 12:12:17 -08:00 committed by GitHub
parent f55a5d91d9
commit 6772fdd145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 4 deletions

View File

@ -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"

View File

@ -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,

View File

@ -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);
}

View File

@ -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

View File

@ -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));