From 471f4efa30dd211ebbb3e2ac6c435f9989204966 Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Fri, 8 Nov 2024 11:39:16 -0800 Subject: [PATCH] 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. --- azure-pipelines/end-to-end-tests-dir/manifests.ps1 | 14 ++++++++++++++ include/vcpkg/base/contractual-constants.h | 1 + include/vcpkg/base/message-data.inc.h | 1 + include/vcpkg/vcpkgcmdarguments.h | 1 + locales/messages.json | 1 + src/vcpkg/vcpkgcmdarguments.cpp | 2 ++ src/vcpkg/vcpkgpaths.cpp | 11 +++++++---- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/azure-pipelines/end-to-end-tests-dir/manifests.ps1 b/azure-pipelines/end-to-end-tests-dir/manifests.ps1 index 8848ae223..2d900cfb7 100644 --- a/azure-pipelines/end-to-end-tests-dir/manifests.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/manifests.ps1 @@ -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 diff --git a/include/vcpkg/base/contractual-constants.h b/include/vcpkg/base/contractual-constants.h index 53f6954bf..1dd7d6fbc 100644 --- a/include/vcpkg/base/contractual-constants.h +++ b/include/vcpkg/base/contractual-constants.h @@ -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"; diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index 74b40b73b..82d4e5c8a 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -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, (), diff --git a/include/vcpkg/vcpkgcmdarguments.h b/include/vcpkg/vcpkgcmdarguments.h index bb1967c50..37109d305 100644 --- a/include/vcpkg/vcpkgcmdarguments.h +++ b/include/vcpkg/vcpkgcmdarguments.h @@ -212,6 +212,7 @@ namespace vcpkg Optional vcpkg_root_dir_arg; Optional vcpkg_root_dir_env; + Optional force_classic_mode; Optional manifest_root_dir; Optional buildtrees_root_dir; diff --git a/locales/messages.json b/locales/messages.json index 1bb9ac7d9..d26ca78f6 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -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 `", + "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.", diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 8cdcd6231..446466079 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -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, diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 4742e76c9..fe7748d6c 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -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