Skip to content

Commit 471f4ef

Browse files
authored
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.
1 parent a823584 commit 471f4ef

File tree

7 files changed

+27
-4
lines changed

7 files changed

+27
-4
lines changed

azure-pipelines/end-to-end-tests-dir/manifests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,17 @@ Throw-IfFailed
185185
Write-Trace "test manifest features: self-reference, features = [a], with overlay"
186186
Run-Vcpkg install @manifestDirArgs --x-feature=a "--overlay-ports=$manifestDir/manifest-test"
187187
Throw-IfFailed
188+
189+
Write-Trace "test manifest install with specific package names fails"
190+
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs vcpkg-empty-port
191+
Throw-IfNotFailed
192+
Throw-IfNonContains -Expected 'error: In manifest mode, `vcpkg install` does not support individual package arguments.' -Actual $output
193+
194+
Write-Trace "test manifest install with specific package names forced to classic mode succeeds"
195+
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs --classic vcpkg-empty-port
196+
Throw-IfFailed
197+
$expected = @"
198+
The following packages will be built and installed:
199+
vcpkg-empty-port:
200+
"@
201+
Throw-IfNonContains -Expected $expected -Actual $output

include/vcpkg/base/contractual-constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ namespace vcpkg
187187
inline constexpr StringLiteral SwitchBuiltinPortsRoot = "builtin-ports-root";
188188
inline constexpr StringLiteral SwitchBuiltinRegistryVersionsDir = "builtin-registry-versions-dir";
189189
inline constexpr StringLiteral SwitchCIBaseline = "ci-baseline";
190+
inline constexpr StringLiteral SwitchClassic = "classic";
190191
inline constexpr StringLiteral SwitchCleanAfterBuild = "clean-after-build";
191192
inline constexpr StringLiteral SwitchCleanBuildtreesAfterBuild = "clean-buildtrees-after-build";
192193
inline constexpr StringLiteral SwitchCleanDownloadsAfterBuild = "clean-downloads-after-build";

include/vcpkg/base/message-data.inc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ DECLARE_MESSAGE(
13581358
(),
13591359
"",
13601360
"Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.")
1361+
DECLARE_MESSAGE(ForceClassicMode, (), "", "Force classic mode, even if a manifest could be found.")
13611362
DECLARE_MESSAGE(FormattedParseMessageExpressionPrefix, (), "", "on expression:")
13621363
DECLARE_MESSAGE(ForMoreHelp,
13631364
(),

include/vcpkg/vcpkgcmdarguments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ namespace vcpkg
212212

213213
Optional<std::string> vcpkg_root_dir_arg;
214214
Optional<std::string> vcpkg_root_dir_env;
215+
Optional<bool> force_classic_mode;
215216
Optional<std::string> manifest_root_dir;
216217

217218
Optional<std::string> buildtrees_root_dir;

locales/messages.json

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

src/vcpkg/vcpkgcmdarguments.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ namespace vcpkg
336336
args.host_triplet,
337337
msg::format(msgSpecifyHostArch,
338338
msg::env_var = format_environment_variable(EnvironmentVariableVcpkgDefaultHostTriplet)));
339+
args.parser.parse_switch(
340+
SwitchClassic, StabilityTag::Standard, args.force_classic_mode, msg::format(msgForceClassicMode));
339341
args.parser.parse_option(SwitchManifestRoot, StabilityTag::Experimental, args.manifest_root_dir);
340342
args.parser.parse_option(SwitchBuildtreesRoot,
341343
StabilityTag::Experimental,

src/vcpkg/vcpkgpaths.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,17 @@ namespace
259259

260260
Path compute_manifest_dir(const ReadOnlyFilesystem& fs, const VcpkgCmdArguments& args, const Path& original_cwd)
261261
{
262-
if (auto manifest_root_dir = args.manifest_root_dir.get())
262+
if (args.force_classic_mode.value_or(false))
263263
{
264-
return fs.almost_canonical(*manifest_root_dir, VCPKG_LINE_INFO);
264+
return Path{};
265265
}
266-
else
266+
267+
if (auto manifest_root_dir = args.manifest_root_dir.get())
267268
{
268-
return fs.find_file_recursively_up(original_cwd, "vcpkg.json", VCPKG_LINE_INFO);
269+
return fs.almost_canonical(*manifest_root_dir, VCPKG_LINE_INFO);
269270
}
271+
272+
return fs.find_file_recursively_up(original_cwd, FileVcpkgDotJson, VCPKG_LINE_INFO);
270273
}
271274

272275
// This structure holds members for VcpkgPathsImpl that don't require explicit initialization/destruction

0 commit comments

Comments
 (0)