Add switch to force classic mode. (#1535)

A customer wanted to run vcpkg in a place where they could not control that a `vcpkg.json` was in a directory above, and requested a way to force classic mode. One used to be able to do this with the `--no-manifest` feature flag, but that was removed some years ago.

This adds a new switch, `--classic`, which effectively skips looking for a manifest.
This commit is contained in:
Billy O'Neal 2024-11-08 11:39:16 -08:00 коммит произвёл GitHub
Родитель a823584ec7
Коммит 471f4efa30
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 27 добавлений и 4 удалений

Просмотреть файл

@ -185,3 +185,17 @@ Throw-IfFailed
Write-Trace "test manifest features: self-reference, features = [a], with overlay"
Run-Vcpkg install @manifestDirArgs --x-feature=a "--overlay-ports=$manifestDir/manifest-test"
Throw-IfFailed
Write-Trace "test manifest install with specific package names fails"
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs vcpkg-empty-port
Throw-IfNotFailed
Throw-IfNonContains -Expected 'error: In manifest mode, `vcpkg install` does not support individual package arguments.' -Actual $output
Write-Trace "test manifest install with specific package names forced to classic mode succeeds"
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs --classic vcpkg-empty-port
Throw-IfFailed
$expected = @"
The following packages will be built and installed:
vcpkg-empty-port:
"@
Throw-IfNonContains -Expected $expected -Actual $output

Просмотреть файл

@ -187,6 +187,7 @@ namespace vcpkg
inline constexpr StringLiteral SwitchBuiltinPortsRoot = "builtin-ports-root";
inline constexpr StringLiteral SwitchBuiltinRegistryVersionsDir = "builtin-registry-versions-dir";
inline constexpr StringLiteral SwitchCIBaseline = "ci-baseline";
inline constexpr StringLiteral SwitchClassic = "classic";
inline constexpr StringLiteral SwitchCleanAfterBuild = "clean-after-build";
inline constexpr StringLiteral SwitchCleanBuildtreesAfterBuild = "clean-buildtrees-after-build";
inline constexpr StringLiteral SwitchCleanDownloadsAfterBuild = "clean-downloads-after-build";

Просмотреть файл

@ -1358,6 +1358,7 @@ DECLARE_MESSAGE(
(),
"",
"Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.")
DECLARE_MESSAGE(ForceClassicMode, (), "", "Force classic mode, even if a manifest could be found.")
DECLARE_MESSAGE(FormattedParseMessageExpressionPrefix, (), "", "on expression:")
DECLARE_MESSAGE(ForMoreHelp,
(),

Просмотреть файл

@ -212,6 +212,7 @@ namespace vcpkg
Optional<std::string> vcpkg_root_dir_arg;
Optional<std::string> vcpkg_root_dir_env;
Optional<bool> force_classic_mode;
Optional<std::string> manifest_root_dir;
Optional<std::string> buildtrees_root_dir;

Просмотреть файл

@ -807,6 +807,7 @@
"FollowingPackagesUpgraded": "The following packages are up-to-date:",
"ForMoreHelp": "For More Help",
"_ForMoreHelp.comment": "Printed before a suggestion for the user to run `vcpkg help <topic>`",
"ForceClassicMode": "Force classic mode, even if a manifest could be found.",
"ForceSystemBinariesOnWeirdPlatforms": "Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.",
"FormattedParseMessageExpressionPrefix": "on expression:",
"GHAParametersMissing": "The GHA binary source requires the ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL environment variables to be set. See {url} for details.",

Просмотреть файл

@ -336,6 +336,8 @@ namespace vcpkg
args.host_triplet,
msg::format(msgSpecifyHostArch,
msg::env_var = format_environment_variable(EnvironmentVariableVcpkgDefaultHostTriplet)));
args.parser.parse_switch(
SwitchClassic, StabilityTag::Standard, args.force_classic_mode, msg::format(msgForceClassicMode));
args.parser.parse_option(SwitchManifestRoot, StabilityTag::Experimental, args.manifest_root_dir);
args.parser.parse_option(SwitchBuildtreesRoot,
StabilityTag::Experimental,

Просмотреть файл

@ -259,14 +259,17 @@ namespace
Path compute_manifest_dir(const ReadOnlyFilesystem& fs, const VcpkgCmdArguments& args, const Path& original_cwd)
{
if (args.force_classic_mode.value_or(false))
{
return Path{};
}
if (auto manifest_root_dir = args.manifest_root_dir.get())
{
return fs.almost_canonical(*manifest_root_dir, VCPKG_LINE_INFO);
}
else
{
return fs.find_file_recursively_up(original_cwd, "vcpkg.json", VCPKG_LINE_INFO);
}
return fs.find_file_recursively_up(original_cwd, FileVcpkgDotJson, VCPKG_LINE_INFO);
}
// This structure holds members for VcpkgPathsImpl that don't require explicit initialization/destruction