From 6c7b2b18becd07c5e04c9842b61794d11464c60c Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Wed, 23 Aug 2023 22:34:49 -0700 Subject: [PATCH 1/7] Make artifacts use common console handling. This resolves the missing `vcpkg help` entries noted in https://github.com/microsoft/vcpkg-tool/pull/1164 This must not be merged until it passes design review. --- include/vcpkg/base/message-data.inc.h | 49 +++++++ include/vcpkg/commands.acquire-project.h | 1 + include/vcpkg/commands.acquire.h | 1 + include/vcpkg/commands.activate.h | 1 + .../vcpkg/commands.generate-msbuild-props.h | 1 + include/vcpkg/commands.use.h | 1 + include/vcpkg/configure-environment.h | 23 +++- locales/messages.json | 76 +++++------ src/vcpkg/commands.acquire-project.cpp | 88 ++++++++++++- src/vcpkg/commands.acquire.cpp | 104 ++++++++++++++- src/vcpkg/commands.activate.cpp | 95 +++++++++++++- src/vcpkg/commands.add.cpp | 30 ++++- src/vcpkg/commands.deactivate.cpp | 3 +- src/vcpkg/commands.find.cpp | 25 +++- src/vcpkg/commands.generate-msbuild-props.cpp | 99 ++++++++++++++- src/vcpkg/commands.help.cpp | 8 ++ src/vcpkg/commands.use.cpp | 120 +++++++++++++++++- src/vcpkg/configure-environment.cpp | 9 -- vcpkg-artifacts/cli/argument.ts | 4 +- vcpkg-artifacts/cli/command-line.ts | 12 +- vcpkg-artifacts/cli/command.ts | 44 +------ .../cli/commands/acquire-project.ts | 3 - vcpkg-artifacts/cli/commands/acquire.ts | 5 +- vcpkg-artifacts/cli/commands/activate.ts | 3 - vcpkg-artifacts/cli/commands/add.ts | 3 - vcpkg-artifacts/cli/commands/cache.ts | 3 - vcpkg-artifacts/cli/commands/clean.ts | 18 --- vcpkg-artifacts/cli/commands/deactivate.ts | 3 - vcpkg-artifacts/cli/commands/delete.ts | 3 - vcpkg-artifacts/cli/commands/find.ts | 4 +- .../cli/commands/generate-msbuild-props.ts | 8 +- vcpkg-artifacts/cli/commands/help.ts | 77 ----------- vcpkg-artifacts/cli/commands/list.ts | 3 - .../cli/commands/regenerate-index.ts | 3 - vcpkg-artifacts/cli/commands/remove.ts | 3 - vcpkg-artifacts/cli/commands/update.ts | 4 +- vcpkg-artifacts/cli/commands/use.ts | 5 +- vcpkg-artifacts/cli/switch.ts | 8 +- vcpkg-artifacts/cli/switches/all.ts | 6 - vcpkg-artifacts/cli/switches/clear.ts | 6 - vcpkg-artifacts/cli/switches/debug.ts | 7 - vcpkg-artifacts/cli/switches/force.ts | 6 - vcpkg-artifacts/cli/switches/installed.ts | 6 - vcpkg-artifacts/cli/switches/json.ts | 7 - vcpkg-artifacts/cli/switches/msbuild-props.ts | 8 -- vcpkg-artifacts/cli/switches/normalize.ts | 7 - vcpkg-artifacts/cli/switches/project.ts | 5 - vcpkg-artifacts/cli/switches/verbose.ts | 14 -- vcpkg-artifacts/cli/switches/version.ts | 8 +- vcpkg-artifacts/locales/messages.json | 45 +------ vcpkg-artifacts/main.ts | 20 +-- vcpkg-artifacts/util/channels.ts | 1 - 52 files changed, 676 insertions(+), 420 deletions(-) delete mode 100644 vcpkg-artifacts/cli/commands/help.ts delete mode 100644 vcpkg-artifacts/cli/switches/verbose.ts diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index ee27f33066..b5585291a4 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -42,6 +42,10 @@ DECLARE_MESSAGE(AddTripletExpressionNotAllowed, "", "triplet expressions are not allowed here. You may want to change " "`{package_name}:{triplet}` to `{package_name}` instead.") +DECLARE_MESSAGE(AddVersionArtifactsOnly, + (), + "'--version', and 'vcpkg add port' are command lines that must not be localized", + "--version is artifacts only and can't be used with vcpkg add port") DECLARE_MESSAGE(AddVersionAddedVersionToFile, (msg::version, msg::path), "", "added version {version} to {path}") DECLARE_MESSAGE(AddVersionCommitChangesReminder, (), "", "Did you remember to commit your changes?") DECLARE_MESSAGE(AddVersionCommitResultReminder, (), "", "Don't forget to commit the result!") @@ -177,6 +181,47 @@ DECLARE_MESSAGE(ArtifactsNotInstalledReadonlyRoot, "readonly. Reinstalling vcpkg using the 'one liner' may fix this problem.") DECLARE_MESSAGE(ArtifactsNotOfficialWarning, (), "", "Using vcpkg-artifacts with an unofficial ") DECLARE_MESSAGE(ArtifactsOptionIncompatibility, (msg::option), "", "--{option} has no effect on find artifact.") +DECLARE_MESSAGE(ArtifactsOptionJson, + (), + "", + "Full path to JSON file where environment variables and other properties are recorded") +DECLARE_MESSAGE(ArtifactsOptionMSBuildProps, + (), + "", + "Full path to the file in which MSBuild properties will be written") +DECLARE_MESSAGE(ArtifactsOptionVersion, (), "", "A version or version range to match; only valid for artifacts") +DECLARE_MESSAGE(ArtifactsOptionVersionMismatch, + (), + "--version is a command line switch and must not be localized", + "The number of --version switches must match the number of named artifacts") +DECLARE_MESSAGE(ArtifactsSwitchAll, (), "", "Update all known artifact registries") +DECLARE_MESSAGE(ArtifactsSwitchAllLanguages, (), "", "Acquire all language files when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchARM, (), "", "Force host detection to ARM when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchARM64, (), "", "Force host detection to ARM64 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchForce, (), "", "Force reacquire if an artifact is already acquired") +DECLARE_MESSAGE(ArtifactsSwitchFreebsd, (), "", "Force host detection to FreeBSD when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchLinux, (), "", "Force host detection to Linux when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchNormalize, (), "", "Apply any deprecation fixups") +DECLARE_MESSAGE(ArtifactsSwitchTargetARM, (), "", "Set target detection to ARM when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchTargetARM64, (), "", "Set target detection to ARM64 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchTargetX64, (), "", "Set target detection to x64 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchTargetX86, (), "", "Set target to x86 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchOnlyOneOperatingSystem, + (), + "The words after -- are command line switches and must not be localized.", + "Only one operating system (--windows, --osx, --linux, --freebsd) may be set.") +DECLARE_MESSAGE(ArtifactsSwitchOnlyOneHostPlatform, + (), + "The words after -- are command line switches and must not be localized.", + "Only one host platform (--x64, --x86, --arm, --arm64) may be set.") +DECLARE_MESSAGE(ArtifactsSwitchOnlyOneTargetPlatform, + (), + "The words after -- are command line switches and must not be localized.", + "Only one target platform (--target:x64, --target:x86, --target:arm, --target:arm64) may be set.") +DECLARE_MESSAGE(ArtifactsSwitchOsx, (), "", "Force host detection to MacOS when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchX64, (), "", "Force host detection to x64 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchX86, (), "", "Force host detection to x86 when acquiring artifacts") +DECLARE_MESSAGE(ArtifactsSwitchWindows, (), "", "Force host detection to Windows when acquiring artifacts") DECLARE_MESSAGE(AssetCacheProviderAcceptsNoArguments, (msg::value), "{value} is a asset caching provider name such as azurl, clear, or x-block-origin", @@ -1058,6 +1103,10 @@ DECLARE_MESSAGE(FindHelp, "'artifact' and 'port' are what the user must literally type.", "Searches for the indicated artifact or port. With no parameter after 'artifact' or 'port', " "displays everything.") +DECLARE_MESSAGE(FindVersionArtifactsOnly, + (), + "'--version', 'vcpkg search', and 'vcpkg find port' are command lines that must not be localized", + "--version can't be used with vcpkg search or vcpkg find port") DECLARE_MESSAGE(FieldKindDidNotHaveExpectedValue, (msg::expected, msg::actual), "{expected} is a list of literal kinds the user must type, separated by commas, {actual} is what " diff --git a/include/vcpkg/commands.acquire-project.h b/include/vcpkg/commands.acquire-project.h index 731343664a..f048c2868e 100644 --- a/include/vcpkg/commands.acquire-project.h +++ b/include/vcpkg/commands.acquire-project.h @@ -5,5 +5,6 @@ namespace vcpkg { + extern const CommandMetadata CommandAcquireProjectMetadata; void command_acquire_project_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/include/vcpkg/commands.acquire.h b/include/vcpkg/commands.acquire.h index eb5f5d1dc2..7ff7f9907d 100644 --- a/include/vcpkg/commands.acquire.h +++ b/include/vcpkg/commands.acquire.h @@ -5,5 +5,6 @@ namespace vcpkg { + extern const CommandMetadata CommandAcquireMetadata; void command_acquire_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/include/vcpkg/commands.activate.h b/include/vcpkg/commands.activate.h index 3e76f0dd89..b6c0d41260 100644 --- a/include/vcpkg/commands.activate.h +++ b/include/vcpkg/commands.activate.h @@ -5,5 +5,6 @@ namespace vcpkg { + extern const CommandMetadata CommandActivateMetadata; void command_activate_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/include/vcpkg/commands.generate-msbuild-props.h b/include/vcpkg/commands.generate-msbuild-props.h index 256418b5a4..9ddcad38b3 100644 --- a/include/vcpkg/commands.generate-msbuild-props.h +++ b/include/vcpkg/commands.generate-msbuild-props.h @@ -5,5 +5,6 @@ namespace vcpkg { + extern const CommandMetadata CommandGenerateMsbuildPropsMetadata; void command_generate_msbuild_props_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/include/vcpkg/commands.use.h b/include/vcpkg/commands.use.h index 7ec79c127a..f3ee828bbe 100644 --- a/include/vcpkg/commands.use.h +++ b/include/vcpkg/commands.use.h @@ -5,5 +5,6 @@ namespace vcpkg { + extern const CommandMetadata CommandUseMetadata; void command_use_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/include/vcpkg/configure-environment.h b/include/vcpkg/configure-environment.h index 9e8beb5a6b..dbbf248c64 100644 --- a/include/vcpkg/configure-environment.h +++ b/include/vcpkg/configure-environment.h @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -18,5 +19,25 @@ namespace vcpkg const Path& download_root); int run_configure_environment_command(const VcpkgPaths& paths, View args); - int run_configure_environment_command(const VcpkgPaths& paths, StringView arg0, View args); + + template + bool more_than_one_mapped(const StringLiteral* const (&candidates)[N], + const std::set>& switches) + { + bool seen = false; + for (auto&& candidate : candidates) + { + if (Util::Sets::contains(switches, *candidate)) + { + if (seen) + { + return true; + } + + seen = true; + } + } + + return false; + } } diff --git a/locales/messages.json b/locales/messages.json index f5411caedd..fec03a842b 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -57,6 +57,8 @@ "_AddTripletExpressionNotAllowed.comment": "An example of {package_name} is zlib. An example of {triplet} is x64-windows.", "AddVersionAddedVersionToFile": "added version {version} to {path}", "_AddVersionAddedVersionToFile.comment": "An example of {version} is 1.3.8. An example of {path} is /foo/bar.", + "AddVersionArtifactsOnly": "--version is artifacts only and can't be used with vcpkg add port", + "_AddVersionArtifactsOnly.comment": "'--version', and 'vcpkg add port' are command lines that must not be localized", "AddVersionCommitChangesReminder": "Did you remember to commit your changes?", "AddVersionCommitResultReminder": "Don't forget to commit the result!", "AddVersionDetectLocalChangesError": "skipping detection of local changes due to unexpected format in git status output", @@ -143,6 +145,33 @@ "ArtifactsNotOfficialWarning": "Using vcpkg-artifacts with an unofficial ", "ArtifactsOptionIncompatibility": "--{option} has no effect on find artifact.", "_ArtifactsOptionIncompatibility.comment": "An example of {option} is editable.", + "ArtifactsOptionJson": "Full path to JSON file where environment variables and other properties are recorded", + "ArtifactsOptionMSBuildProps": "Full path to the file in which MSBuild properties will be written", + "ArtifactsOptionVersion": "A version or version range to match; only valid for artifacts", + "ArtifactsOptionVersionMismatch": "The number of --version switches must match the number of named artifacts", + "_ArtifactsOptionVersionMismatch.comment": "--version is a command line switch and must not be localized", + "ArtifactsSwitchARM": "Force host detection to ARM when acquiring artifacts", + "ArtifactsSwitchARM64": "Force host detection to ARM64 when acquiring artifacts", + "ArtifactsSwitchAll": "Update all known artifact registries", + "ArtifactsSwitchAllLanguages": "Acquire all language files when acquiring artifacts", + "ArtifactsSwitchForce": "Force reacquire if an artifact is already acquired", + "ArtifactsSwitchFreebsd": "Force host detection to FreeBSD when acquiring artifacts", + "ArtifactsSwitchLinux": "Force host detection to Linux when acquiring artifacts", + "ArtifactsSwitchNormalize": "Apply any deprecation fixups", + "ArtifactsSwitchOnlyOneHostPlatform": "Only one host platform (--x64, --x86, --arm, --arm64) may be set.", + "_ArtifactsSwitchOnlyOneHostPlatform.comment": "The words after -- are command line switches and must not be localized.", + "ArtifactsSwitchOnlyOneOperatingSystem": "Only one operating system (--windows, --osx, --linux, --freebsd) may be set.", + "_ArtifactsSwitchOnlyOneOperatingSystem.comment": "The words after -- are command line switches and must not be localized.", + "ArtifactsSwitchOnlyOneTargetPlatform": "Only one target platform (--target:x64, --target:x86, --target:arm, --target:arm64) may be set.", + "_ArtifactsSwitchOnlyOneTargetPlatform.comment": "The words after -- are command line switches and must not be localized.", + "ArtifactsSwitchOsx": "Force host detection to MacOS when acquiring artifacts", + "ArtifactsSwitchTargetARM": "Set target detection to ARM when acquiring artifacts", + "ArtifactsSwitchTargetARM64": "Set target detection to ARM64 when acquiring artifacts", + "ArtifactsSwitchTargetX64": "Set target detection to x64 when acquiring artifacts", + "ArtifactsSwitchTargetX86": "Set target to x86 when acquiring artifacts", + "ArtifactsSwitchWindows": "Force host detection to Windows when acquiring artifacts", + "ArtifactsSwitchX64": "Force host detection to x64 when acquiring artifacts", + "ArtifactsSwitchX86": "Force host detection to x86 when acquiring artifacts", "AssetCacheProviderAcceptsNoArguments": "unexpected arguments: '{value}' does not accept arguments", "_AssetCacheProviderAcceptsNoArguments.comment": "{value} is a asset caching provider name such as azurl, clear, or x-block-origin", "AssetSourcesArg": "Add sources for asset caching. See 'vcpkg help assetcaching'.", @@ -673,6 +702,8 @@ "_FilesExported.comment": "An example of {path} is /foo/bar.", "FindHelp": "Searches for the indicated artifact or port. With no parameter after 'artifact' or 'port', displays everything.", "_FindHelp.comment": "'artifact' and 'port' are what the user must literally type.", + "FindVersionArtifactsOnly": "--version can't be used with vcpkg search or vcpkg find port", + "_FindVersionArtifactsOnly.comment": "'--version', 'vcpkg search', and 'vcpkg find port' are command lines that must not be localized", "FishCompletion": "vcpkg fish completion is already added at \"{path}\".", "_FishCompletion.comment": "An example of {path} is /foo/bar.", "FloatingPointConstTooBig": "Floating point constant too big: {count}", @@ -1585,10 +1616,6 @@ "WindowsOnlyCommand": "This command only supports Windows.", "WroteNuGetPkgConfInfo": "Wrote NuGet package config information to {path}", "_WroteNuGetPkgConfInfo.comment": "An example of {path} is /foo/bar.", - "UnrecognizedCommand$": "Unrecognized command '${p0}'", - "_UnrecognizedCommand$.comment": "\n'${p0}' (aka 'commandline.inputs[0]') is a parameter of type 'string'\n", - "Use$ToGetHelp": "Use ${p0} to get help", - "_Use$ToGetHelp.comment": "\n'${p0}' is a parameter of type 'string'\n", "FatalTheRootFolder$CannotBeCreated": "Fatal: The root folder '${p0}' cannot be created", "_FatalTheRootFolder$CannotBeCreated.comment": "\n'${p0}' (aka 'this.homeFolder.fsPath') is a parameter of type 'string'\n", "FatalTheGlobalConfigurationFile$CannotBeCreated": "Fatal: The global configuration file '${p0}' cannot be created", @@ -1684,14 +1711,10 @@ "_Unpacking$.comment": "\n'${p0}' (aka 'archiveUri.fsPath') is a parameter of type 'string'\n", "ErrorInstalling$$": "Error installing ${p0} - ${p1}", "_ErrorInstalling$$.comment": "\n'${p0}' is a parameter of type 'string'\n\n'${p1}' is a parameter of type 'any'\n", - "ExpectedASingleValueFor$FoundMultiple": "Expected a single value for ${p0} - found multiple", - "_ExpectedASingleValueFor$FoundMultiple.comment": "\n'${p0}' is a parameter of type 'string'\n", - "Synopsis": "Synopsis", - "Description": "Description", - "Switches": "Switches", - "SeeAlso": "See Also", "error": "error:", "warning": "warning:", + "ExpectedASingleValueFor$FoundMultiple": "Expected a single value for ${p0} - found multiple", + "_ExpectedASingleValueFor$FoundMultiple.comment": "\n'${p0}' is a parameter of type 'string'\n", "ExpectedASingleValueFor$": "Expected a single value for '--${p0}'.", "_ExpectedASingleValueFor$.comment": "\n'${p0}' (aka 'this.switch') is a parameter of type 'string'\n", "Assuming$IsCorrectSupplyAHashInTheArtifactMetadataToSuppressThisMessage": "Assuming '${p0}' is correct; supply a hash in the artifact metadata to suppress this message.", @@ -1782,8 +1805,6 @@ "AcquireArtifactsInTheRegistry": "Acquire artifacts in the registry", "ThisAllowsTheConsumerToAcquiredownloadAndUnpackArtifactsArtifactsMustBeActivatedToBeUsed": "This allows the consumer to acquire (download and unpack) artifacts. Artifacts must be activated to be used", "NoArtifactsSpecified": "No artifacts specified", - "MultiplePackagesSpecifiedButNotAnEqualNumberOf$Switches": "Multiple packages specified, but not an equal number of ${p0} switches", - "_MultiplePackagesSpecifiedButNotAnEqualNumberOf$Switches.comment": "\n'${p0}' is a parameter of type 'string'\n", "NoArtifactsAreAcquired": "No artifacts are acquired", "AllArtifactsAreAlreadyInstalled": "All artifacts are already installed", "$ArtifactsInstalledSuccessfully": "${p0} artifacts installed successfully", @@ -1803,9 +1824,6 @@ "ManagesTheDownloadCache": "Manages the download cache", "DownloadsFolderCleared$": "Downloads folder cleared (${p0}) ", "_DownloadsFolderCleared$.comment": "\n'${p0}' (aka 'session.downloads.fsPath') is a parameter of type 'string'\n", - "cleansOutEverythingcacheInstalledArtifacts": "cleans out everything (cache, installed artifacts)", - "cleansOutTheDownloadsCache": "cleans out the downloads cache", - "removesAllTheArtifactsThatAreInstalled": "removes all the artifacts that are installed", "cleansUp": "cleans up", "AllowsTheUserToCleanOutTheCacheInstalledArtifactsEtc": "Allows the user to clean out the cache, installed artifacts, etc.", "InstalledArtifactFolderCleared$": "Installed Artifact folder cleared (${p0}) ", @@ -1823,21 +1841,7 @@ "NoArtifactsFoundMatchingCriteria$": "No artifacts found matching criteria: ${p0}", "_NoArtifactsFoundMatchingCriteria$.comment": "\n'${p0}' is a parameter of type 'string'\n", "GeneratesMSBuildPropertiesForAnActivationWithoutDownloadingAnythingForAProject": "Generates MSBuild properties for an activation without downloading anything for a project", - "generatemsbuildpropsRequiresmsbuildprops": "generate-msbuild-props requires --msbuild-props", "UnableToActivateProject": "Unable to activate project", - "theNameOfTheCommandForWhichYouWantHelp": "the name of the command for which you want help", - "getHelpOn$OrOneOfTheCommands": "get help on ${p0} or one of the commands", - "_getHelpOn$OrOneOfTheCommands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "GetsDetailedHelpOn$OrOneOfTheCommands": "Gets detailed help on ${p0}, or one of the commands", - "_GetsDetailedHelpOn$OrOneOfTheCommands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "Arguments": "Arguments:", - "Use$ToGetTheListOfAvailableCommands": "Use ${p0} to get the list of available commands", - "_Use$ToGetTheListOfAvailableCommands.comment": "\n'${p0}' is a parameter of type 'string'\n", - "Usage": "Usage", - "$COMMANDargumentsswitches": "${p0} COMMAND [--switches]", - "_$COMMANDargumentsswitches.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "Available$Commands": "Available ${p0} commands:", - "_Available$Commands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", "ListsTheArtifacts": "Lists the artifacts", "ThisAllowsTheConsumerToListArtifacts": "This allows the consumer to list artifacts.", "regenerateTheIndexForARegistry": "regenerate the index for a registry", @@ -1872,18 +1876,6 @@ "InstantlyActivatesAnArtifactOutsideOfTheProject": "Instantly activates an artifact outside of the project", "ThisWillInstantlyActivateAnArtifact": "This will instantly activate an artifact .", "NoArtifactsAreBeingAcquired": "No artifacts are being acquired", - "UpdateAllKnownArtifactRegistries": "Update all known artifact registries", - "removesAllFilesInTheLocalCache": "removes all files in the local cache", - "enablesDebugModeDisplaysInternalMesssagesAboutHow$Works": "enables debug mode, displays internal messsages about how ${p0} works", - "_enablesDebugModeDisplaysInternalMesssagesAboutHow$Works.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "proceedsWithThepotentiallyDangerousActionWithoutConfirmation": "proceeds with the (potentially dangerous) action without confirmation", - "showsTheinstalledArtifacts": "shows the _installed_ artifacts", - "DumpEnvironmentVariablesAndOtherPropertiesToAJsonFileWithThePathProvidedByTheUser": "Dump environment variables and other properties to a json file with the path provided by the user.", - "FullPathToTheFileInWhichMSBuildPropertiesWillBeWritten": "Full path to the file in which MSBuild properties will be written.", - "ApplyAnyDeprecationFixups": "Apply any deprecation fixups.", - "overrideThePathToTheProjectFolder": "override the path to the project folder", "UnableToFindProjectEnvironment$": "Unable to find project environment ${p0}", - "_UnableToFindProjectEnvironment$.comment": "\n'${p0}' is a parameter of type 'string'\n", - "enablesVerboseModeDisplaysVerboseMesssagesAboutTheProcess": "enables verbose mode, displays verbose messsages about the process", - "aVersionOrVersionRangeToMatch": "a version or version range to match" + "_UnableToFindProjectEnvironment$.comment": "\n'${p0}' is a parameter of type 'string'\n" } diff --git a/src/vcpkg/commands.acquire-project.cpp b/src/vcpkg/commands.acquire-project.cpp index 09e3c594b9..cb496d81d6 100644 --- a/src/vcpkg/commands.acquire-project.cpp +++ b/src/vcpkg/commands.acquire-project.cpp @@ -1,15 +1,95 @@ #include +#include #include #include #include +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch AcquireProjectSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* target_platforms[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; +} // unnamed namespace + namespace vcpkg { + constexpr CommandMetadata CommandAcquireProjectMetadata{ + [] { return create_example_string("acquire-project"); }, + 0, + 0, + {{AcquireProjectSwitches}, {}, {}}, + nullptr, + }; + void command_acquire_project_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - Checks::exit_with_code( - VCPKG_LINE_INFO, - run_configure_environment_command(paths, "acquire-project", args.get_forwardable_arguments())); + auto parsed = args.parse_arguments(CommandAcquireProjectMetadata); + std::vector ecmascript_args; + ecmascript_args.emplace_back("acquire-project"); + + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(operating_systems, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(host_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(target_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + for (auto&& parsed_option : parsed.settings) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); + ecmascript_args.push_back(parsed_option.second); + } + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } -} +} // namespace vcpkg diff --git a/src/vcpkg/commands.acquire.cpp b/src/vcpkg/commands.acquire.cpp index bf84926275..569da8d0d4 100644 --- a/src/vcpkg/commands.acquire.cpp +++ b/src/vcpkg/commands.acquire.cpp @@ -1,14 +1,114 @@ #include +#include #include #include #include +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch AcquireSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* target_platforms[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; + + constexpr StringLiteral OPTION_VERSION = "version"; + + constexpr CommandMultiSetting AcquireMultiOptions[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; +} // unnamed namespace + namespace vcpkg { + constexpr CommandMetadata CommandAcquireMetadata = { + [] { return create_example_string("acquire cmake"); }, + 1, + SIZE_MAX, + {{AcquireSwitches}, {}, {AcquireMultiOptions}}, + nullptr, + }; + void command_acquire_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - Checks::exit_with_code(VCPKG_LINE_INFO, - run_configure_environment_command(paths, "acquire", args.get_forwardable_arguments())); + auto parsed = args.parse_arguments(CommandAcquireMetadata); + std::vector ecmascript_args; + ecmascript_args.emplace_back("acquire"); + + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(operating_systems, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(host_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(target_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + auto maybe_versions = Util::lookup_value(parsed.multisettings, OPTION_VERSION); + if (auto versions = maybe_versions.get()) + { + if (versions->size() != parsed.command_arguments.size()) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsOptionVersionMismatch); + } + + for (auto&& version : *versions) + { + ecmascript_args.push_back("--version"); + ecmascript_args.push_back(version); + } + } + + ecmascript_args.insert(ecmascript_args.end(), + std::make_move_iterator(parsed.command_arguments.begin()), + std::make_move_iterator(parsed.command_arguments.end())); + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } } diff --git a/src/vcpkg/commands.activate.cpp b/src/vcpkg/commands.activate.cpp index 338c89eba7..b0f1c99129 100644 --- a/src/vcpkg/commands.activate.cpp +++ b/src/vcpkg/commands.activate.cpp @@ -1,14 +1,103 @@ #include +#include #include #include #include +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch ActivateSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* target_platforms[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; + + constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; + constexpr StringLiteral OPTION_JSON = "json"; + + constexpr CommandSetting ActivateOptions[] = { + {OPTION_MSBUILD_PROPS, [] { return msg::format(msgArtifactsOptionMSBuildProps); }}, + {OPTION_JSON, [] { return msg::format(msgArtifactsOptionJson); }}, + }; +} // unnamed namespace + namespace vcpkg { + constexpr CommandMetadata CommandActivateMetadata{ + [] { return create_example_string("activate"); }, + 0, + 0, + {{ActivateSwitches}, {ActivateOptions}, {}}, + nullptr, + }; + void command_activate_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - Checks::exit_with_code(VCPKG_LINE_INFO, - run_configure_environment_command(paths, "activate", args.get_forwardable_arguments())); + auto parsed = args.parse_arguments(CommandActivateMetadata); + std::vector ecmascript_args; + ecmascript_args.emplace_back("activate"); + + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(operating_systems, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(host_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(target_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + for (auto&& parsed_option : parsed.settings) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); + ecmascript_args.push_back(parsed_option.second); + } + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } -} +} // namespace vcpkg diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index bdeb6b6ca2..51a78b4bc9 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -15,6 +15,16 @@ #include #include +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral OPTION_VERSION = "version"; + constexpr CommandSetting AddOptions[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; +} + namespace vcpkg { constexpr CommandMetadata CommandAddMetadata = { @@ -27,7 +37,7 @@ namespace vcpkg }, 2, SIZE_MAX, - {{}, {}}, + {{}, {AddOptions}}, nullptr, }; @@ -50,8 +60,17 @@ namespace vcpkg metrics.track_string(StringMetric::CommandArgs, artifact_hash); get_global_metrics_collector().track_submission(std::move(metrics)); - std::string ce_args[] = {"add", artifact_name}; - Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args)); + std::vector ecmascript_args; + ecmascript_args.emplace_back("add"); + ecmascript_args.emplace_back(artifact_name); + auto maybe_version = Util::lookup_value(parsed.settings, OPTION_VERSION); + if (auto version = maybe_version.get()) + { + ecmascript_args.emplace_back("--version"); + ecmascript_args.emplace_back(*version); + } + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } if (selector == "port") @@ -63,6 +82,11 @@ namespace vcpkg VCPKG_LINE_INFO, msgAddPortRequiresManifest, msg::command_line = "vcpkg add port"); } + if (Util::Maps::contains(parsed.settings, OPTION_VERSION)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgAddVersionArtifactsOnly); + } + std::vector specs; specs.reserve(parsed.command_arguments.size() - 1); for (std::size_t idx = 1; idx < parsed.command_arguments.size(); ++idx) diff --git a/src/vcpkg/commands.deactivate.cpp b/src/vcpkg/commands.deactivate.cpp index 650813a412..8b3a601498 100644 --- a/src/vcpkg/commands.deactivate.cpp +++ b/src/vcpkg/commands.deactivate.cpp @@ -11,7 +11,8 @@ namespace vcpkg void command_deactivate_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { (void)args.parse_arguments(CommandDeactivateMetadata); + const std::string deactivate = "deactivate"; Checks::exit_with_code(VCPKG_LINE_INFO, - run_configure_environment_command(paths, "deactivate", View{})); + run_configure_environment_command(paths, View{&deactivate, 1})); } } diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 0d9ab8b2fb..1a598bfb0d 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -105,6 +105,11 @@ namespace {OPTION_FULLDESC, []() { return msg::format(msgHelpTextOptFullDesc); }}, {OPTION_JSON, []() { return msg::format(msgJsonSwitch); }}, }; + + constexpr StringLiteral OPTION_VERSION = "version"; + constexpr CommandSetting FindSettings[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; } // unnamed namespace namespace vcpkg @@ -119,7 +124,7 @@ namespace vcpkg }, 1, 2, - {FindSwitches, {}}, + {FindSwitches, FindSettings}, nullptr, }; @@ -207,7 +212,9 @@ namespace vcpkg Checks::exit_success(VCPKG_LINE_INFO); } - void perform_find_artifact_and_exit(const VcpkgPaths& paths, Optional filter) + void perform_find_artifact_and_exit(const VcpkgPaths& paths, + Optional filter, + Optional version) { std::vector ce_args; ce_args.emplace_back("find"); @@ -216,6 +223,12 @@ namespace vcpkg ce_args.emplace_back(filter_str->data(), filter_str->size()); } + if (auto v = version.get()) + { + ce_args.emplace_back("--version"); + ce_args.emplace_back(*v); + } + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args)); } @@ -244,7 +257,6 @@ namespace vcpkg } Optional filter_hash = filter.map(Hash::get_string_sha256); - auto args_hash = Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256); MetricsSubmission metrics; metrics.track_string(StringMetric::CommandContext, "artifact"); if (auto p_filter_hash = filter_hash.get()) @@ -253,11 +265,16 @@ namespace vcpkg } get_global_metrics_collector().track_submission(std::move(metrics)); - perform_find_artifact_and_exit(paths, filter); + perform_find_artifact_and_exit(paths, filter, Util::lookup_value(options.settings, OPTION_VERSION)); } if (selector == "port") { + if (Util::Maps::contains(options.settings, OPTION_VERSION)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgFindVersionArtifactsOnly); + } + Optional filter_hash = filter.map(Hash::get_string_sha256); MetricsSubmission metrics; metrics.track_string(StringMetric::CommandContext, "port"); diff --git a/src/vcpkg/commands.generate-msbuild-props.cpp b/src/vcpkg/commands.generate-msbuild-props.cpp index 3a0ba81401..79c707fa9c 100644 --- a/src/vcpkg/commands.generate-msbuild-props.cpp +++ b/src/vcpkg/commands.generate-msbuild-props.cpp @@ -1,15 +1,106 @@ #include +#include #include #include #include +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch GenerateMSBuildPropsSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* target_platforms[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; + + constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; + + constexpr CommandSetting GenerateMSBuildPropsOptions[] = { + {OPTION_MSBUILD_PROPS, [] { return msg::format(msgArtifactsOptionMSBuildProps); }}, + }; +} // unnamed namespace + namespace vcpkg { + constexpr CommandMetadata CommandGenerateMsbuildPropsMetadata{ + [] { return create_example_string("generate-msbuild-props --msbuild-props out.props"); }, + 0, + 0, + {{GenerateMSBuildPropsSwitches}, {GenerateMSBuildPropsOptions}, {}}, + nullptr, + }; + void command_generate_msbuild_props_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - Checks::exit_with_code( - VCPKG_LINE_INFO, - run_configure_environment_command(paths, "generate-msbuild-props", args.get_forwardable_arguments())); + auto parsed = args.parse_arguments(CommandGenerateMsbuildPropsMetadata); + std::vector ecmascript_args; + ecmascript_args.emplace_back("generate-msbuild-props"); + + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(operating_systems, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(host_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(target_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + for (auto&& parsed_option : parsed.settings) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); + ecmascript_args.push_back(parsed_option.second); + } + + if (!Util::Maps::contains(parsed.settings, OPTION_MSBUILD_PROPS)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgOptionRequiresAValue, msg::option = OPTION_MSBUILD_PROPS); + } + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } -} +} // namespace vcpkg diff --git a/src/vcpkg/commands.help.cpp b/src/vcpkg/commands.help.cpp index 9e0e197d2e..57b4df85b3 100644 --- a/src/vcpkg/commands.help.cpp +++ b/src/vcpkg/commands.help.cpp @@ -1,6 +1,9 @@ #include #include +#include +#include +#include #include #include #include @@ -39,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -112,6 +116,9 @@ namespace } constexpr Topic topics[] = { + {"acquire", command_topic_fn}, + {"acquire-project", command_topic_fn}, + {"activate", command_topic_fn}, {"add", command_topic_fn}, {"x-add-version", command_topic_fn}, {"assetcaching", [](const VcpkgPaths&) { msg::println(format_help_topic_asset_caching()); }}, @@ -156,6 +163,7 @@ namespace {"x-update-registry", command_topic_fn}, {"update", command_topic_fn}, {"upgrade", command_topic_fn}, + {"use", command_topic_fn}, {"version", command_topic_fn}, {"versioning", help_topic_versioning}, {"x-vs-instances", command_topic_fn}, diff --git a/src/vcpkg/commands.use.cpp b/src/vcpkg/commands.use.cpp index a2fa07b081..0be118dec1 100644 --- a/src/vcpkg/commands.use.cpp +++ b/src/vcpkg/commands.use.cpp @@ -1,14 +1,128 @@ #include +#include #include #include #include +#include + +using namespace vcpkg; + +namespace +{ + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch UseSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* target_platforms[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; + + constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; + + constexpr CommandSetting UseOptions[] = { + {OPTION_MSBUILD_PROPS, [] { return msg::format(msgArtifactsOptionMSBuildProps); }}, + }; + + constexpr StringLiteral OPTION_VERSION = "version"; + + constexpr CommandMultiSetting UseMultiOptions[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; +} // unnamed namespace + namespace vcpkg { + constexpr CommandMetadata CommandUseMetadata = { + [] { return create_example_string("use cmake"); }, + 1, + SIZE_MAX, + {{UseSwitches}, {UseOptions}, {UseMultiOptions}}, + nullptr, + }; + void command_use_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - Checks::exit_with_code(VCPKG_LINE_INFO, - run_configure_environment_command(paths, "use", args.get_forwardable_arguments())); + auto parsed = args.parse_arguments(CommandUseMetadata); + std::vector ecmascript_args; + ecmascript_args.emplace_back("use"); + + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(operating_systems, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(host_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(target_platforms, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + for (auto&& parsed_option : parsed.settings) + { + ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); + ecmascript_args.push_back(parsed_option.second); + } + + auto maybe_versions = Util::lookup_value(parsed.multisettings, OPTION_VERSION); + if (auto versions = maybe_versions.get()) + { + if (versions->size() != parsed.command_arguments.size()) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsOptionVersionMismatch); + } + + for (auto&& version : *versions) + { + ecmascript_args.push_back("--version"); + ecmascript_args.push_back(version); + } + } + + ecmascript_args.insert(ecmascript_args.end(), + std::make_move_iterator(parsed.command_arguments.begin()), + std::make_move_iterator(parsed.command_arguments.end())); + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } -} +} // namespace vcpkg diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index b6bac84dbe..4c6787c47d 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -206,13 +206,4 @@ namespace vcpkg return result; } - - int run_configure_environment_command(const VcpkgPaths& paths, StringView arg0, View args) - { - std::vector all_args; - all_args.reserve(args.size() + 1); - all_args.emplace_back(arg0.data(), arg0.size()); - all_args.insert(all_args.end(), args.begin(), args.end()); - return run_configure_environment_command(paths, all_args); - } } diff --git a/vcpkg-artifacts/cli/argument.ts b/vcpkg-artifacts/cli/argument.ts index 970022fc97..d9f64c99d8 100644 --- a/vcpkg-artifacts/cli/argument.ts +++ b/vcpkg-artifacts/cli/argument.ts @@ -2,12 +2,10 @@ // Licensed under the MIT License. import { Command } from './command'; -import { Help } from './command-line'; -export abstract class Argument implements Help { +export abstract class Argument { readonly abstract argument: string; readonly title = ''; - readonly abstract help: Array; constructor(protected command: Command) { command.arguments.push(this); diff --git a/vcpkg-artifacts/cli/command-line.ts b/vcpkg-artifacts/cli/command-line.ts index 4a3daafdb4..638739ca82 100644 --- a/vcpkg-artifacts/cli/command-line.ts +++ b/vcpkg-artifacts/cli/command-line.ts @@ -1,23 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { strict } from 'assert'; import { tmpdir } from 'os'; import { join, resolve } from 'path'; -import { i } from '../i18n'; import { intersect } from '../util/intersect'; import { Command } from './command'; -import { cmdSwitch } from './format'; export type switches = { [key: string]: Array; } -export interface Help { - readonly help: Array; - readonly title: string; -} - class Ctx { constructor(cmdline: CommandLine) { this.os = @@ -129,13 +121,11 @@ export class CommandLine { get language() { const l = this.switches['language'] || []; - strict.ok((l?.length || 0) < 2, i`Expected a single value for ${cmdSwitch('language')} - found multiple`); return l[0]; } get allLanguages(): boolean { const l = this.switches['all-languages'] || []; - strict.ok((l?.length || 0) < 2, i`Expected a single value for ${cmdSwitch('all-languages')} - found multiple`); return !!l[0]; } @@ -159,7 +149,7 @@ export class CommandLine { /** parses the command line and returns the command that has been requested */ get command() { - return this.commands.find(cmd => cmd.command === this.inputs[0] || !!cmd.aliases.find(alias => alias === this.inputs[0])); + return this.commands.find(cmd => cmd.command === this.inputs[0]); } constructor(args: Array) { diff --git a/vcpkg-artifacts/cli/command.ts b/vcpkg-artifacts/cli/command.ts index 4898b0c4bc..949dbf4d93 100644 --- a/vcpkg-artifacts/cli/command.ts +++ b/vcpkg-artifacts/cli/command.ts @@ -1,44 +1,23 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../i18n'; import { Argument } from './argument'; -import { CommandLine, Help } from './command-line'; -import { cli } from './constants'; -import { cmdSwitch, command, heading, optional } from './format'; +import { CommandLine } from './command-line'; import { Switch } from './switch'; import { Debug } from './switches/debug'; import { Force } from './switches/force'; /** @internal */ -export abstract class Command implements Help { +export abstract class Command { readonly abstract command: string; - readonly abstract argumentsHelp: Array; readonly switches = new Array(); readonly arguments = new Array(); - readonly abstract seeAlso: Array; - readonly abstract aliases: Array; - - abstract get summary(): string; - abstract get description(): Array; - readonly force = new Force(this); readonly debug = new Debug(this); - get synopsis(): Array { - return [ - heading(i`Synopsis`, 2), - ` ${command(`${cli} ${this.command} ${this.arguments.map(each => `<${each.argument}>`).join(' ')}`)}${this.switches.flatMap(each => optional(`[--${each.switch}]`)).join(' ')}` - ]; - } - - get title() { - return `${cli} ${this.command}`; - } - constructor(public commandLine: CommandLine) { commandLine.addCommand(this); } @@ -47,25 +26,6 @@ export abstract class Command implements Help { return this.commandLine.inputs.slice(1); } - get help() { - return [ - heading(this.title), - this.summary, - ...this.synopsis, - heading(i`Description`, 2), - ...this.description, - ...this.argumentsHelp, - ...(this.switches.length ? [ - heading(i`Switches`, 2), - ...this.switches.flatMap(each => ` ${cmdSwitch(each.switch)}: ${each.help.join(' ')}`) - ] : []), - ...(this.seeAlso.length ? [ - heading(i`See Also`, 2), - ...this.seeAlso.flatMap(each => each.title) - ] : []) - ]; - } - async run() { // do something return true; diff --git a/vcpkg-artifacts/cli/commands/acquire-project.ts b/vcpkg-artifacts/cli/commands/acquire-project.ts index e5e112bff7..948f5da0cd 100644 --- a/vcpkg-artifacts/cli/commands/acquire-project.ts +++ b/vcpkg-artifacts/cli/commands/acquire-project.ts @@ -11,9 +11,6 @@ import { Project } from '../switches/project'; export class AcquireProjectCommand extends Command { readonly command = 'acquire-project'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; project: Project = new Project(this); get summary() { diff --git a/vcpkg-artifacts/cli/commands/acquire.ts b/vcpkg-artifacts/cli/commands/acquire.ts index a8005e4495..2c23e71191 100644 --- a/vcpkg-artifacts/cli/commands/acquire.ts +++ b/vcpkg-artifacts/cli/commands/acquire.ts @@ -14,9 +14,6 @@ import { Version } from '../switches/version'; export class AcquireCommand extends Command { readonly command = 'acquire'; - readonly aliases = ['install']; - seeAlso = []; - argumentsHelp = []; version: Version = new Version(this); project: Project = new Project(this); @@ -38,7 +35,7 @@ export class AcquireCommand extends Command { const versions = this.version.values; if (versions.length && this.inputs.length !== versions.length) { - error(i`Multiple packages specified, but not an equal number of ${cmdSwitch('version')} switches`); + error(`Multiple packages specified, but not an equal number of ${cmdSwitch('version')} switches`); return false; } diff --git a/vcpkg-artifacts/cli/commands/activate.ts b/vcpkg-artifacts/cli/commands/activate.ts index 04d8103930..046e744b8b 100644 --- a/vcpkg-artifacts/cli/commands/activate.ts +++ b/vcpkg-artifacts/cli/commands/activate.ts @@ -16,9 +16,6 @@ import { Project } from '../switches/project'; export class ActivateCommand extends Command { readonly command = 'activate'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; project: Project = new Project(this); msbuildProps: MSBuildProps = new MSBuildProps(this); json : Json = new Json(this); diff --git a/vcpkg-artifacts/cli/commands/add.ts b/vcpkg-artifacts/cli/commands/add.ts index e298e96f0d..96037a854f 100644 --- a/vcpkg-artifacts/cli/commands/add.ts +++ b/vcpkg-artifacts/cli/commands/add.ts @@ -13,9 +13,6 @@ import { Version } from '../switches/version'; export class AddCommand extends Command { readonly command = 'add'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; version = new Version(this); project: Project = new Project(this); diff --git a/vcpkg-artifacts/cli/commands/cache.ts b/vcpkg-artifacts/cli/commands/cache.ts index cf0edbaa88..fb4bcb4946 100644 --- a/vcpkg-artifacts/cli/commands/cache.ts +++ b/vcpkg-artifacts/cli/commands/cache.ts @@ -13,9 +13,6 @@ import { Clear } from '../switches/clear'; export class CacheCommand extends Command { readonly command = 'cache'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; clear = new Clear(this); get summary() { diff --git a/vcpkg-artifacts/cli/commands/clean.ts b/vcpkg-artifacts/cli/commands/clean.ts index 0fead18649..367da68b12 100644 --- a/vcpkg-artifacts/cli/commands/clean.ts +++ b/vcpkg-artifacts/cli/commands/clean.ts @@ -10,36 +10,18 @@ import { Switch } from '../switch'; export class All extends Switch { switch = 'all'; - get help() { - return [ - i`cleans out everything (cache, installed artifacts)` - ]; - } } export class Downloads extends Switch { switch = 'downloads'; - get help() { - return [ - i`cleans out the downloads cache` - ]; - } } export class Artifacts extends Switch { switch = 'artifacts'; - get help() { - return [ - i`removes all the artifacts that are installed` - ]; - } } export class CleanCommand extends Command { readonly command = 'clean'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; all = new All(this); artifacts = new Artifacts(this); downloads = new Downloads(this); diff --git a/vcpkg-artifacts/cli/commands/deactivate.ts b/vcpkg-artifacts/cli/commands/deactivate.ts index 82c74261ed..54db24976e 100644 --- a/vcpkg-artifacts/cli/commands/deactivate.ts +++ b/vcpkg-artifacts/cli/commands/deactivate.ts @@ -8,9 +8,6 @@ import { Command } from '../command'; export class DeactivateCommand extends Command { readonly command = 'deactivate'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; get summary() { return i`Deactivates the current session`; diff --git a/vcpkg-artifacts/cli/commands/delete.ts b/vcpkg-artifacts/cli/commands/delete.ts index 13566cca2d..4e81ddf578 100644 --- a/vcpkg-artifacts/cli/commands/delete.ts +++ b/vcpkg-artifacts/cli/commands/delete.ts @@ -8,9 +8,6 @@ import { Version } from '../switches/version'; export class DeleteCommand extends Command { readonly command = 'delete'; - readonly aliases = ['uninstall']; - seeAlso = []; - argumentsHelp = []; version = new Version(this); get summary() { diff --git a/vcpkg-artifacts/cli/commands/find.ts b/vcpkg-artifacts/cli/commands/find.ts index 2a4228bc5b..8aab5ee0db 100644 --- a/vcpkg-artifacts/cli/commands/find.ts +++ b/vcpkg-artifacts/cli/commands/find.ts @@ -14,9 +14,7 @@ import { Version } from '../switches/version'; export class FindCommand extends Command { readonly command = 'find'; - readonly aliases = ['search']; - seeAlso = []; - argumentsHelp = []; + version = new Version(this); project = new Project(this); diff --git a/vcpkg-artifacts/cli/commands/generate-msbuild-props.ts b/vcpkg-artifacts/cli/commands/generate-msbuild-props.ts index 331d39af4e..e65d66e92f 100644 --- a/vcpkg-artifacts/cli/commands/generate-msbuild-props.ts +++ b/vcpkg-artifacts/cli/commands/generate-msbuild-props.ts @@ -13,9 +13,7 @@ import { Project } from '../switches/project'; export class GenerateMSBuildPropsCommand extends Command { readonly command = 'generate-msbuild-props'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; + project: Project = new Project(this); msbuildProps: MSBuildProps = new MSBuildProps(this, 'out'); @@ -23,11 +21,9 @@ export class GenerateMSBuildPropsCommand extends Command { return i`Generates MSBuild properties for an activation without downloading anything for a project`; } - get description() { return ['']; } - override async run() { if (!this.msbuildProps.active) { - error(i`generate-msbuild-props requires --msbuild-props`); + error('generate-msbuild-props requires --msbuild-props'); return false; } diff --git a/vcpkg-artifacts/cli/commands/help.ts b/vcpkg-artifacts/cli/commands/help.ts deleted file mode 100644 index b91e38ee14..0000000000 --- a/vcpkg-artifacts/cli/commands/help.ts +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { i } from '../../i18n'; -import { Argument } from '../argument'; -import { Command } from '../command'; -import { cli } from '../constants'; -import { command as formatCommand, heading, hint } from '../format'; -import { error, indent, log } from '../styling'; - -class CommandName extends Argument { - argument = 'command'; - - get help() { - return [ - i`the name of the command for which you want help` - ]; - } -} - -/**@internal */ -export class HelpCommand extends Command { - readonly command = 'help'; - readonly aliases = []; - seeAlso = []; - commandName: CommandName = new CommandName(this); - - get argumentsHelp() { - return [indent(i` <${this.commandName.argument}> : ${this.commandName.help.join(' ')}`)]; - } - - get summary() { - return i`get help on ${cli} or one of the commands`; - } - - get description() { - return [ - i`Gets detailed help on ${cli}, or one of the commands`, - i`Arguments:` - ]; - } - - override async run() { - const cmd = ['-h', '-help', '-?', '/?'].find(each => (this.commandLine.inputs.indexOf(each) > -1)) ? this.commandLine.inputs[0] : this.commandLine.inputs[1]; - // did they ask for help on a command? - - if (cmd) { - const target = this.commandLine.commands.find(each => each.command === cmd); - if (target) { - log(target.help.join('\n')); - return true; - } - - // I don't know the command - error(i`Unrecognized command '${cmd}'`); - log(hint(i`Use ${formatCommand(`${cli} ${this.command}`)} to get the list of available commands`)); - return false; - } - - // general help. return the general help info - - log(heading(i`Usage`, 2)); - log(indent(i`${cli} COMMAND [--switches]`)); - - log(heading(i`Available ${cli} commands:`, 2)); - const max = Math.max(...this.commandLine.commands.map(each => each.command.length)); - for (const command of this.commandLine.commands) { - if (command.command.startsWith('z-')) { - // don't show internal commands - continue; - } - log(indent(i`${formatCommand(command.command.padEnd(max))} : ${command.summary}`)); - } - - return true; - } -} diff --git a/vcpkg-artifacts/cli/commands/list.ts b/vcpkg-artifacts/cli/commands/list.ts index 9fea357cb0..48efcc0676 100644 --- a/vcpkg-artifacts/cli/commands/list.ts +++ b/vcpkg-artifacts/cli/commands/list.ts @@ -11,9 +11,6 @@ import { Installed } from '../switches/installed'; export class ListCommand extends Command { readonly command = 'list'; - readonly aliases = ['show']; - seeAlso = []; - argumentsHelp = []; installed = new Installed(this); get summary() { diff --git a/vcpkg-artifacts/cli/commands/regenerate-index.ts b/vcpkg-artifacts/cli/commands/regenerate-index.ts index 3cd918c0d0..6da9c1c88f 100644 --- a/vcpkg-artifacts/cli/commands/regenerate-index.ts +++ b/vcpkg-artifacts/cli/commands/regenerate-index.ts @@ -13,10 +13,7 @@ import { Normalize } from '../switches/normalize'; export class RegenerateCommand extends Command { readonly command = 'regenerate'; - readonly aliases = ['regen']; readonly normalize = new Normalize(this); - seeAlso = []; - argumentsHelp = []; get summary() { return i`regenerate the index for a registry`; diff --git a/vcpkg-artifacts/cli/commands/remove.ts b/vcpkg-artifacts/cli/commands/remove.ts index 33ba686017..240c74d376 100644 --- a/vcpkg-artifacts/cli/commands/remove.ts +++ b/vcpkg-artifacts/cli/commands/remove.ts @@ -9,9 +9,6 @@ import { Project } from '../switches/project'; export class RemoveCommand extends Command { readonly command = 'remove'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; project: Project = new Project(this); get summary() { diff --git a/vcpkg-artifacts/cli/commands/update.ts b/vcpkg-artifacts/cli/commands/update.ts index ad8d82124f..4cd72bb56a 100644 --- a/vcpkg-artifacts/cli/commands/update.ts +++ b/vcpkg-artifacts/cli/commands/update.ts @@ -35,9 +35,7 @@ async function updateRegistry(registry: Registry, displayName: string) : Promise export class UpdateCommand extends Command { readonly command = 'update'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; + project: Project = new Project(this); all = new All(this); diff --git a/vcpkg-artifacts/cli/commands/use.ts b/vcpkg-artifacts/cli/commands/use.ts index 127f4a8624..b5f9fb29b5 100644 --- a/vcpkg-artifacts/cli/commands/use.ts +++ b/vcpkg-artifacts/cli/commands/use.ts @@ -15,9 +15,6 @@ import { Version } from '../switches/version'; export class UseCommand extends Command { readonly command = 'use'; - readonly aliases = []; - seeAlso = []; - argumentsHelp = []; version = new Version(this); project = new Project(this); msbuildProps = new MSBuildProps(this); @@ -42,7 +39,7 @@ export class UseCommand extends Command { await buildRegistryResolver(session, (await this.project.manifest)?.metadata.registries)); const versions = this.version.values; if (versions.length && this.inputs.length !== versions.length) { - error(i`Multiple packages specified, but not an equal number of ${cmdSwitch('version')} switches`); + error(`Multiple packages specified, but not an equal number of ${cmdSwitch('version')} switches`); return false; } diff --git a/vcpkg-artifacts/cli/switch.ts b/vcpkg-artifacts/cli/switch.ts index f98f6b144b..0be431b717 100644 --- a/vcpkg-artifacts/cli/switch.ts +++ b/vcpkg-artifacts/cli/switch.ts @@ -4,20 +4,16 @@ import { strict } from 'assert'; import { i } from '../i18n'; import { Command } from './command'; -import { Help } from './command-line'; import { cmdSwitch } from './format'; -export abstract class Switch implements Help { +export abstract class Switch { readonly abstract switch: string; readonly title = ''; - readonly abstract help: Array; readonly required: boolean; - readonly multipleAllowed: boolean; - constructor(protected command: Command, options?: { multipleAllowed?: boolean, required?: boolean }) { + constructor(protected command: Command, options?: { required?: boolean }) { command.switches.push(this); - this.multipleAllowed = options?.multipleAllowed || false; this.required = options?.required || false; } diff --git a/vcpkg-artifacts/cli/switches/all.ts b/vcpkg-artifacts/cli/switches/all.ts index e06bb175f4..c50877799f 100644 --- a/vcpkg-artifacts/cli/switches/all.ts +++ b/vcpkg-artifacts/cli/switches/all.ts @@ -1,14 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class All extends Switch { switch = 'all'; - get help() { - return [ - i`Update all known artifact registries` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/clear.ts b/vcpkg-artifacts/cli/switches/clear.ts index 3bb39ad0c7..690613404d 100644 --- a/vcpkg-artifacts/cli/switches/clear.ts +++ b/vcpkg-artifacts/cli/switches/clear.ts @@ -1,14 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class Clear extends Switch { switch = 'clear'; - get help() { - return [ - i`removes all files in the local cache` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/debug.ts b/vcpkg-artifacts/cli/switches/debug.ts index 81b685af56..cb898370e1 100644 --- a/vcpkg-artifacts/cli/switches/debug.ts +++ b/vcpkg-artifacts/cli/switches/debug.ts @@ -1,15 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; -import { cli } from '../constants'; import { Switch } from '../switch'; export class Debug extends Switch { switch = 'debug'; - get help() { - return [ - i`enables debug mode, displays internal messsages about how ${cli} works` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/force.ts b/vcpkg-artifacts/cli/switches/force.ts index 4c22d2cccb..474bbfcf20 100644 --- a/vcpkg-artifacts/cli/switches/force.ts +++ b/vcpkg-artifacts/cli/switches/force.ts @@ -1,14 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class Force extends Switch { switch = 'force'; - get help() { - return [ - i`proceeds with the (potentially dangerous) action without confirmation` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/installed.ts b/vcpkg-artifacts/cli/switches/installed.ts index aa56fe8763..d2b1c8a2cc 100644 --- a/vcpkg-artifacts/cli/switches/installed.ts +++ b/vcpkg-artifacts/cli/switches/installed.ts @@ -1,14 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class Installed extends Switch { switch = 'installed'; - get help() { - return [ - i`shows the _installed_ artifacts` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/json.ts b/vcpkg-artifacts/cli/switches/json.ts index b29db7436c..00487d7840 100644 --- a/vcpkg-artifacts/cli/switches/json.ts +++ b/vcpkg-artifacts/cli/switches/json.ts @@ -2,19 +2,12 @@ // Licensed under the MIT License. import { resolve } from 'path'; -import { i } from '../../i18n'; import { session } from '../../main'; import { Uri } from '../../util/uri'; import { Switch } from '../switch'; export class Json extends Switch { switch = 'json'; - override multipleAllowed = false; - get help() { - return [ - i`Dump environment variables and other properties to a json file with the path provided by the user.` - ]; - } get resolvedValue(): Uri | undefined { const v = this.value; diff --git a/vcpkg-artifacts/cli/switches/msbuild-props.ts b/vcpkg-artifacts/cli/switches/msbuild-props.ts index 546bde6a17..37b50016ce 100644 --- a/vcpkg-artifacts/cli/switches/msbuild-props.ts +++ b/vcpkg-artifacts/cli/switches/msbuild-props.ts @@ -2,7 +2,6 @@ // Licensed under the MIT License. import { resolve } from 'path'; -import { i } from '../../i18n'; import { session } from '../../main'; import { Uri } from '../../util/uri'; import { Command } from '../command'; @@ -10,18 +9,11 @@ import { Switch } from '../switch'; export class MSBuildProps extends Switch { public readonly switch: string; - override multipleAllowed = false; constructor(command: Command, swName = 'msbuild-props') { super(command); this.switch = swName; } - get help() { - return [ - i`Full path to the file in which MSBuild properties will be written.` - ]; - } - get resolvedValue(): Uri | undefined { const v = this.value; if (v) { diff --git a/vcpkg-artifacts/cli/switches/normalize.ts b/vcpkg-artifacts/cli/switches/normalize.ts index 2343806d5c..47a65460fd 100644 --- a/vcpkg-artifacts/cli/switches/normalize.ts +++ b/vcpkg-artifacts/cli/switches/normalize.ts @@ -1,15 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class Normalize extends Switch { switch = 'normalize'; - override multipleAllowed = false; - get help() { - return [ - i`Apply any deprecation fixups.` - ]; - } } diff --git a/vcpkg-artifacts/cli/switches/project.ts b/vcpkg-artifacts/cli/switches/project.ts index 3680b78106..24ad5a409a 100644 --- a/vcpkg-artifacts/cli/switches/project.ts +++ b/vcpkg-artifacts/cli/switches/project.ts @@ -19,11 +19,6 @@ interface ResolvedProjectUri { export class Project extends Switch { switch = 'project'; - get help() { - return [ - i`override the path to the project folder` - ]; - } async resolveProjectUri() : Promise { const v = this.value; diff --git a/vcpkg-artifacts/cli/switches/verbose.ts b/vcpkg-artifacts/cli/switches/verbose.ts deleted file mode 100644 index 7eed7f7e05..0000000000 --- a/vcpkg-artifacts/cli/switches/verbose.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { i } from '../../i18n'; -import { Switch } from '../switch'; - -export class Verbose extends Switch { - switch = 'verbose'; - get help() { - return [ - i`enables verbose mode, displays verbose messsages about the process` - ]; - } -} diff --git a/vcpkg-artifacts/cli/switches/version.ts b/vcpkg-artifacts/cli/switches/version.ts index e697b91a7c..daf37dc62c 100644 --- a/vcpkg-artifacts/cli/switches/version.ts +++ b/vcpkg-artifacts/cli/switches/version.ts @@ -1,14 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { i } from '../../i18n'; import { Switch } from '../switch'; export class Version extends Switch { switch = 'version'; - get help() { - return [ - i`a version or version range to match` - ]; - } -} \ No newline at end of file +} diff --git a/vcpkg-artifacts/locales/messages.json b/vcpkg-artifacts/locales/messages.json index f567a0f303..0952d2c013 100644 --- a/vcpkg-artifacts/locales/messages.json +++ b/vcpkg-artifacts/locales/messages.json @@ -1,8 +1,4 @@ { - "UnrecognizedCommand$": "Unrecognized command '${p0}'", - "_UnrecognizedCommand$.comment": "\n'${p0}' (aka 'commandline.inputs[0]') is a parameter of type 'string'\n", - "Use$ToGetHelp": "Use ${p0} to get help", - "_Use$ToGetHelp.comment": "\n'${p0}' is a parameter of type 'string'\n", "FatalTheRootFolder$CannotBeCreated": "Fatal: The root folder '${p0}' cannot be created", "_FatalTheRootFolder$CannotBeCreated.comment": "\n'${p0}' (aka 'this.homeFolder.fsPath') is a parameter of type 'string'\n", "FatalTheGlobalConfigurationFile$CannotBeCreated": "Fatal: The global configuration file '${p0}' cannot be created", @@ -98,14 +94,10 @@ "_Unpacking$.comment": "\n'${p0}' (aka 'archiveUri.fsPath') is a parameter of type 'string'\n", "ErrorInstalling$$": "Error installing ${p0} - ${p1}", "_ErrorInstalling$$.comment": "\n'${p0}' is a parameter of type 'string'\n\n'${p1}' is a parameter of type 'any'\n", - "ExpectedASingleValueFor$FoundMultiple": "Expected a single value for ${p0} - found multiple", - "_ExpectedASingleValueFor$FoundMultiple.comment": "\n'${p0}' is a parameter of type 'string'\n", - "Synopsis": "Synopsis", - "Description": "Description", - "Switches": "Switches", - "SeeAlso": "See Also", "error": "error:", "warning": "warning:", + "ExpectedASingleValueFor$FoundMultiple": "Expected a single value for ${p0} - found multiple", + "_ExpectedASingleValueFor$FoundMultiple.comment": "\n'${p0}' is a parameter of type 'string'\n", "ExpectedASingleValueFor$": "Expected a single value for '--${p0}'.", "_ExpectedASingleValueFor$.comment": "\n'${p0}' (aka 'this.switch') is a parameter of type 'string'\n", "Assuming$IsCorrectSupplyAHashInTheArtifactMetadataToSuppressThisMessage": "Assuming '${p0}' is correct; supply a hash in the artifact metadata to suppress this message.", @@ -196,8 +188,6 @@ "AcquireArtifactsInTheRegistry": "Acquire artifacts in the registry", "ThisAllowsTheConsumerToAcquiredownloadAndUnpackArtifactsArtifactsMustBeActivatedToBeUsed": "This allows the consumer to acquire (download and unpack) artifacts. Artifacts must be activated to be used", "NoArtifactsSpecified": "No artifacts specified", - "MultiplePackagesSpecifiedButNotAnEqualNumberOf$Switches": "Multiple packages specified, but not an equal number of ${p0} switches", - "_MultiplePackagesSpecifiedButNotAnEqualNumberOf$Switches.comment": "\n'${p0}' is a parameter of type 'string'\n", "NoArtifactsAreAcquired": "No artifacts are acquired", "AllArtifactsAreAlreadyInstalled": "All artifacts are already installed", "$ArtifactsInstalledSuccessfully": "${p0} artifacts installed successfully", @@ -217,9 +207,6 @@ "ManagesTheDownloadCache": "Manages the download cache", "DownloadsFolderCleared$": "Downloads folder cleared (${p0}) ", "_DownloadsFolderCleared$.comment": "\n'${p0}' (aka 'session.downloads.fsPath') is a parameter of type 'string'\n", - "cleansOutEverythingcacheInstalledArtifacts": "cleans out everything (cache, installed artifacts)", - "cleansOutTheDownloadsCache": "cleans out the downloads cache", - "removesAllTheArtifactsThatAreInstalled": "removes all the artifacts that are installed", "cleansUp": "cleans up", "AllowsTheUserToCleanOutTheCacheInstalledArtifactsEtc": "Allows the user to clean out the cache, installed artifacts, etc.", "InstalledArtifactFolderCleared$": "Installed Artifact folder cleared (${p0}) ", @@ -237,21 +224,7 @@ "NoArtifactsFoundMatchingCriteria$": "No artifacts found matching criteria: ${p0}", "_NoArtifactsFoundMatchingCriteria$.comment": "\n'${p0}' is a parameter of type 'string'\n", "GeneratesMSBuildPropertiesForAnActivationWithoutDownloadingAnythingForAProject": "Generates MSBuild properties for an activation without downloading anything for a project", - "generatemsbuildpropsRequiresmsbuildprops": "generate-msbuild-props requires --msbuild-props", "UnableToActivateProject": "Unable to activate project", - "theNameOfTheCommandForWhichYouWantHelp": "the name of the command for which you want help", - "getHelpOn$OrOneOfTheCommands": "get help on ${p0} or one of the commands", - "_getHelpOn$OrOneOfTheCommands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "GetsDetailedHelpOn$OrOneOfTheCommands": "Gets detailed help on ${p0}, or one of the commands", - "_GetsDetailedHelpOn$OrOneOfTheCommands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "Arguments": "Arguments:", - "Use$ToGetTheListOfAvailableCommands": "Use ${p0} to get the list of available commands", - "_Use$ToGetTheListOfAvailableCommands.comment": "\n'${p0}' is a parameter of type 'string'\n", - "Usage": "Usage", - "$COMMANDargumentsswitches": "${p0} COMMAND [--switches]", - "_$COMMANDargumentsswitches.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "Available$Commands": "Available ${p0} commands:", - "_Available$Commands.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", "ListsTheArtifacts": "Lists the artifacts", "ThisAllowsTheConsumerToListArtifacts": "This allows the consumer to list artifacts.", "regenerateTheIndexForARegistry": "regenerate the index for a registry", @@ -286,18 +259,6 @@ "InstantlyActivatesAnArtifactOutsideOfTheProject": "Instantly activates an artifact outside of the project", "ThisWillInstantlyActivateAnArtifact": "This will instantly activate an artifact .", "NoArtifactsAreBeingAcquired": "No artifacts are being acquired", - "UpdateAllKnownArtifactRegistries": "Update all known artifact registries", - "removesAllFilesInTheLocalCache": "removes all files in the local cache", - "enablesDebugModeDisplaysInternalMesssagesAboutHow$Works": "enables debug mode, displays internal messsages about how ${p0} works", - "_enablesDebugModeDisplaysInternalMesssagesAboutHow$Works.comment": "\n'${p0}' is a parameter - it is expecting a value like: \"vcpkg\"", - "proceedsWithThepotentiallyDangerousActionWithoutConfirmation": "proceeds with the (potentially dangerous) action without confirmation", - "showsTheinstalledArtifacts": "shows the _installed_ artifacts", - "DumpEnvironmentVariablesAndOtherPropertiesToAJsonFileWithThePathProvidedByTheUser": "Dump environment variables and other properties to a json file with the path provided by the user.", - "FullPathToTheFileInWhichMSBuildPropertiesWillBeWritten": "Full path to the file in which MSBuild properties will be written.", - "ApplyAnyDeprecationFixups": "Apply any deprecation fixups.", - "overrideThePathToTheProjectFolder": "override the path to the project folder", "UnableToFindProjectEnvironment$": "Unable to find project environment ${p0}", - "_UnableToFindProjectEnvironment$.comment": "\n'${p0}' is a parameter of type 'string'\n", - "enablesVerboseModeDisplaysVerboseMesssagesAboutTheProcess": "enables verbose mode, displays verbose messsages about the process", - "aVersionOrVersionRangeToMatch": "a version or version range to match" + "_UnableToFindProjectEnvironment$.comment": "\n'${p0}' is a parameter of type 'string'\n" } \ No newline at end of file diff --git a/vcpkg-artifacts/main.ts b/vcpkg-artifacts/main.ts index 2a2ece42cc..a97708df54 100644 --- a/vcpkg-artifacts/main.ts +++ b/vcpkg-artifacts/main.ts @@ -16,16 +16,13 @@ import { DeactivateCommand } from './cli/commands/deactivate'; import { DeleteCommand } from './cli/commands/delete'; import { FindCommand } from './cli/commands/find'; import { GenerateMSBuildPropsCommand } from './cli/commands/generate-msbuild-props'; -import { HelpCommand } from './cli/commands/help'; import { ListCommand } from './cli/commands/list'; import { RegenerateCommand } from './cli/commands/regenerate-index'; import { RemoveCommand } from './cli/commands/remove'; import { UpdateCommand } from './cli/commands/update'; import { UseCommand } from './cli/commands/use'; -import { cli } from './cli/constants'; -import { command as formatCommand, hint } from './cli/format'; import { error, initStyling, log } from './cli/styling'; -import { i, setLocale } from './i18n'; +import { setLocale } from './i18n'; import { Session } from './session'; // parse the command line @@ -52,8 +49,6 @@ async function main() { // start up the session and init the channel listeners. await session.init(); - const help = new HelpCommand(commandline); - const find = new FindCommand(commandline); const list = new ListCommand(commandline); @@ -75,14 +70,6 @@ async function main() { const cache = new CacheCommand(commandline); const clean = new CleanCommand(commandline); - const needsHelp = !!(commandline.switches['help'] || commandline.switches['?'] || (['-h', '-help', '-?', '/?'].find(each => argv.includes(each)))); - // check if --help -h -? --? /? are asked for - if (needsHelp) { - // let's just run general help - await help.run(); - return process.exit(0); - } - const command = commandline.command; if (!command) { // no command recognized. @@ -90,13 +77,10 @@ async function main() { // did they specify inputs? if (commandline.inputs.length > 0) { // unrecognized command - error(i`Unrecognized command '${commandline.inputs[0]}'`); - log(hint(i`Use ${formatCommand(`${cli} ${help.command}`)} to get help`)); + error(`Unrecognized command '${commandline.inputs[0]}'`); return process.exitCode = 1; } - log(hint(i`Use ${formatCommand(`${cli} ${help.command}`)} to get help`)); - return process.exitCode = 0; } let result = true; diff --git a/vcpkg-artifacts/util/channels.ts b/vcpkg-artifacts/util/channels.ts index f06d0f84d8..0e98ade051 100644 --- a/vcpkg-artifacts/util/channels.ts +++ b/vcpkg-artifacts/util/channels.ts @@ -10,7 +10,6 @@ export interface ChannelEvents { error(text: string, msec: number): void; message(text: string, msec: number): void; debug(text: string, msec: number): void; - verbose(text: string, msec: number): void; } /** From c6d93620193b147a574ecd05c55e1974f23ea50d Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Wed, 23 Aug 2023 22:48:09 -0700 Subject: [PATCH 2/7] Add missing integrate install to the integrate install test. --- azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 b/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 index 7c6da526f5..e08d980954 100644 --- a/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 @@ -8,6 +8,7 @@ if (-not $IsLinux -and -not $IsMacOS) { # Test msbuild props and targets $Script:CurrentTest = "zlib:x86-windows msbuild $iiroot\..." Write-Host $Script:CurrentTest + Run-Vcpkg @CommonArgs integrate install Run-Vcpkg @CommonArgs install zlib:x86-windows Throw-IfFailed foreach ($project in @("Project1", "NoProps")) { From 94006e23391ad37089e6a3dc623d0a28ef4d0b48 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Wed, 23 Aug 2023 23:05:19 -0700 Subject: [PATCH 3/7] Fix MacOS warning --- src/vcpkg/commands.find.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 1a598bfb0d..8c5d77359c 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -110,23 +110,6 @@ namespace constexpr CommandSetting FindSettings[] = { {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, }; -} // unnamed namespace - -namespace vcpkg -{ - constexpr CommandMetadata CommandFindMetadata = { - [] { - return msg::format(msgFindHelp) - .append_raw('\n') - .append(create_example_string("find port png")) - .append_raw('\n') - .append(create_example_string("find artifact cmake")); - }, - 1, - 2, - {FindSwitches, FindSettings}, - nullptr, - }; void perform_find_port_and_exit(const VcpkgPaths& paths, bool full_description, @@ -231,6 +214,23 @@ namespace vcpkg Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args)); } +} // unnamed namespace + +namespace vcpkg +{ + constexpr CommandMetadata CommandFindMetadata = { + [] { + return msg::format(msgFindHelp) + .append_raw('\n') + .append(create_example_string("find port png")) + .append_raw('\n') + .append(create_example_string("find artifact cmake")); + }, + 1, + 2, + {FindSwitches, FindSettings}, + nullptr, + }; void command_find_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { From ece4a671cf39bda3e00bdb358cc6e7e055757fde Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Wed, 23 Aug 2023 23:06:22 -0700 Subject: [PATCH 4/7] Actually fix the macos warning. --- include/vcpkg/commands.find.h | 2 -- src/vcpkg/commands.find.cpp | 46 +++++++++++++++++------------------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/vcpkg/commands.find.h b/include/vcpkg/commands.find.h index f083f205ec..6d20209eb1 100644 --- a/include/vcpkg/commands.find.h +++ b/include/vcpkg/commands.find.h @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -16,7 +15,6 @@ namespace vcpkg bool enable_json, Optional filter, View overlay_ports); - void perform_find_artifact_and_exit(const VcpkgPaths& paths, Optional filter); extern const CommandMetadata CommandFindMetadata; void command_find_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 8c5d77359c..d0916b48fd 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -111,6 +111,29 @@ namespace {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, }; + void perform_find_artifact_and_exit(const VcpkgPaths& paths, + Optional filter, + Optional version) + { + std::vector ce_args; + ce_args.emplace_back("find"); + if (auto* filter_str = filter.get()) + { + ce_args.emplace_back(filter_str->data(), filter_str->size()); + } + + if (auto v = version.get()) + { + ce_args.emplace_back("--version"); + ce_args.emplace_back(*v); + } + + Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args)); + } +} // unnamed namespace + +namespace vcpkg +{ void perform_find_port_and_exit(const VcpkgPaths& paths, bool full_description, bool enable_json, @@ -195,29 +218,6 @@ namespace Checks::exit_success(VCPKG_LINE_INFO); } - void perform_find_artifact_and_exit(const VcpkgPaths& paths, - Optional filter, - Optional version) - { - std::vector ce_args; - ce_args.emplace_back("find"); - if (auto* filter_str = filter.get()) - { - ce_args.emplace_back(filter_str->data(), filter_str->size()); - } - - if (auto v = version.get()) - { - ce_args.emplace_back("--version"); - ce_args.emplace_back(*v); - } - - Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args)); - } -} // unnamed namespace - -namespace vcpkg -{ constexpr CommandMetadata CommandFindMetadata = { [] { return msg::format(msgFindHelp) From b95bd5d364cc1f0aec5eb68fa37ffcd380190085 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Thu, 24 Aug 2023 15:37:06 -0700 Subject: [PATCH 5/7] Deduplicate a bunch of the parameter handling. --- include/vcpkg/configure-environment.h | 32 +++--- src/vcpkg/commands.acquire-project.cpp | 75 +------------ src/vcpkg/commands.acquire.cpp | 64 +---------- src/vcpkg/commands.activate.cpp | 70 +----------- src/vcpkg/commands.add.cpp | 14 +-- src/vcpkg/commands.find.cpp | 10 +- src/vcpkg/commands.generate-msbuild-props.cpp | 68 +----------- src/vcpkg/commands.use.cpp | 70 +----------- src/vcpkg/configure-environment.cpp | 102 +++++++++++++++++- 9 files changed, 132 insertions(+), 373 deletions(-) diff --git a/include/vcpkg/configure-environment.h b/include/vcpkg/configure-environment.h index dbbf248c64..5898d84187 100644 --- a/include/vcpkg/configure-environment.h +++ b/include/vcpkg/configure-environment.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -20,24 +21,15 @@ namespace vcpkg int run_configure_environment_command(const VcpkgPaths& paths, View args); - template - bool more_than_one_mapped(const StringLiteral* const (&candidates)[N], - const std::set>& switches) - { - bool seen = false; - for (auto&& candidate : candidates) - { - if (Util::Sets::contains(switches, *candidate)) - { - if (seen) - { - return true; - } - - seen = true; - } - } - - return false; - } + bool more_than_one_mapped(View candidates, + const std::set>& switches); + + constexpr StringLiteral OPTION_VERSION = "version"; + + extern const View CommonAcquireArtifactSwitches; + extern const View CommonSelectArtifactVersionSettings; + + // Copies the switches and settings, but not multisettings from parsed to appended_to, and checks that the switches + // that apply to artifacts meet semantic rules like only one operating system being selected. + void forward_common_artifacts_arguments(std::vector& appended_to, const ParsedArguments& parsed); } diff --git a/src/vcpkg/commands.acquire-project.cpp b/src/vcpkg/commands.acquire-project.cpp index cb496d81d6..02a33375c8 100644 --- a/src/vcpkg/commands.acquire-project.cpp +++ b/src/vcpkg/commands.acquire-project.cpp @@ -5,55 +5,13 @@ #include #include -using namespace vcpkg; - -namespace -{ - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch AcquireProjectSwitches[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - - constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; - constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; - constexpr const StringLiteral* target_platforms[] = { - &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; -} // unnamed namespace - namespace vcpkg { - constexpr CommandMetadata CommandAcquireProjectMetadata{ + const CommandMetadata CommandAcquireProjectMetadata{ [] { return create_example_string("acquire-project"); }, 0, 0, - {{AcquireProjectSwitches}, {}, {}}, + {CommonAcquireArtifactSwitches, {}, {}}, nullptr, }; @@ -62,34 +20,7 @@ namespace vcpkg auto parsed = args.parse_arguments(CommandAcquireProjectMetadata); std::vector ecmascript_args; ecmascript_args.emplace_back("acquire-project"); - - auto&& switches = parsed.switches; - for (auto&& parsed_switch : switches) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); - } - - if (more_than_one_mapped(operating_systems, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); - } - - if (more_than_one_mapped(host_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); - } - - if (more_than_one_mapped(target_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); - } - - for (auto&& parsed_option : parsed.settings) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); - ecmascript_args.push_back(parsed_option.second); - } - + forward_common_artifacts_arguments(ecmascript_args, parsed); Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } } // namespace vcpkg diff --git a/src/vcpkg/commands.acquire.cpp b/src/vcpkg/commands.acquire.cpp index 569da8d0d4..c0a3cb071e 100644 --- a/src/vcpkg/commands.acquire.cpp +++ b/src/vcpkg/commands.acquire.cpp @@ -9,43 +9,6 @@ using namespace vcpkg; namespace { - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch AcquireSwitches[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - - constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; - constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; - constexpr const StringLiteral* target_platforms[] = { - &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - constexpr StringLiteral OPTION_VERSION = "version"; constexpr CommandMultiSetting AcquireMultiOptions[] = { @@ -55,11 +18,11 @@ namespace namespace vcpkg { - constexpr CommandMetadata CommandAcquireMetadata = { + const CommandMetadata CommandAcquireMetadata = { [] { return create_example_string("acquire cmake"); }, 1, SIZE_MAX, - {{AcquireSwitches}, {}, {AcquireMultiOptions}}, + {CommonAcquireArtifactSwitches, {}, {AcquireMultiOptions}}, nullptr, }; @@ -68,28 +31,7 @@ namespace vcpkg auto parsed = args.parse_arguments(CommandAcquireMetadata); std::vector ecmascript_args; ecmascript_args.emplace_back("acquire"); - - auto&& switches = parsed.switches; - for (auto&& parsed_switch : switches) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); - } - - if (more_than_one_mapped(operating_systems, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); - } - - if (more_than_one_mapped(host_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); - } - - if (more_than_one_mapped(target_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); - } - + forward_common_artifacts_arguments(ecmascript_args, parsed); auto maybe_versions = Util::lookup_value(parsed.multisettings, OPTION_VERSION); if (auto versions = maybe_versions.get()) { diff --git a/src/vcpkg/commands.activate.cpp b/src/vcpkg/commands.activate.cpp index b0f1c99129..9235001157 100644 --- a/src/vcpkg/commands.activate.cpp +++ b/src/vcpkg/commands.activate.cpp @@ -9,43 +9,6 @@ using namespace vcpkg; namespace { - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch ActivateSwitches[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - - constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; - constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; - constexpr const StringLiteral* target_platforms[] = { - &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; constexpr StringLiteral OPTION_JSON = "json"; @@ -57,11 +20,11 @@ namespace namespace vcpkg { - constexpr CommandMetadata CommandActivateMetadata{ + const CommandMetadata CommandActivateMetadata{ [] { return create_example_string("activate"); }, 0, 0, - {{ActivateSwitches}, {ActivateOptions}, {}}, + {CommonAcquireArtifactSwitches, {ActivateOptions}, {}}, nullptr, }; @@ -70,34 +33,7 @@ namespace vcpkg auto parsed = args.parse_arguments(CommandActivateMetadata); std::vector ecmascript_args; ecmascript_args.emplace_back("activate"); - - auto&& switches = parsed.switches; - for (auto&& parsed_switch : switches) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); - } - - if (more_than_one_mapped(operating_systems, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); - } - - if (more_than_one_mapped(host_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); - } - - if (more_than_one_mapped(target_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); - } - - for (auto&& parsed_option : parsed.settings) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); - ecmascript_args.push_back(parsed_option.second); - } - + forward_common_artifacts_arguments(ecmascript_args, parsed); Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ecmascript_args)); } } // namespace vcpkg diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index 51a78b4bc9..94fed4a61f 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -15,19 +15,9 @@ #include #include -using namespace vcpkg; - -namespace -{ - constexpr StringLiteral OPTION_VERSION = "version"; - constexpr CommandSetting AddOptions[] = { - {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, - }; -} - namespace vcpkg { - constexpr CommandMetadata CommandAddMetadata = { + const CommandMetadata CommandAddMetadata = { [] { return msg::format(msgAddHelp) .append_raw('\n') @@ -37,7 +27,7 @@ namespace vcpkg }, 2, SIZE_MAX, - {{}, {AddOptions}}, + {{}, CommonSelectArtifactVersionSettings}, nullptr, }; diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index d0916b48fd..591a718a35 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -106,11 +107,6 @@ namespace {OPTION_JSON, []() { return msg::format(msgJsonSwitch); }}, }; - constexpr StringLiteral OPTION_VERSION = "version"; - constexpr CommandSetting FindSettings[] = { - {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, - }; - void perform_find_artifact_and_exit(const VcpkgPaths& paths, Optional filter, Optional version) @@ -218,7 +214,7 @@ namespace vcpkg Checks::exit_success(VCPKG_LINE_INFO); } - constexpr CommandMetadata CommandFindMetadata = { + const CommandMetadata CommandFindMetadata = { [] { return msg::format(msgFindHelp) .append_raw('\n') @@ -228,7 +224,7 @@ namespace vcpkg }, 1, 2, - {FindSwitches, FindSettings}, + {FindSwitches, CommonSelectArtifactVersionSettings}, nullptr, }; diff --git a/src/vcpkg/commands.generate-msbuild-props.cpp b/src/vcpkg/commands.generate-msbuild-props.cpp index 79c707fa9c..7034230e0a 100644 --- a/src/vcpkg/commands.generate-msbuild-props.cpp +++ b/src/vcpkg/commands.generate-msbuild-props.cpp @@ -9,43 +9,6 @@ using namespace vcpkg; namespace { - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch GenerateMSBuildPropsSwitches[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - - constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; - constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; - constexpr const StringLiteral* target_platforms[] = { - &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; constexpr CommandSetting GenerateMSBuildPropsOptions[] = { @@ -55,11 +18,11 @@ namespace namespace vcpkg { - constexpr CommandMetadata CommandGenerateMsbuildPropsMetadata{ + const CommandMetadata CommandGenerateMsbuildPropsMetadata{ [] { return create_example_string("generate-msbuild-props --msbuild-props out.props"); }, 0, 0, - {{GenerateMSBuildPropsSwitches}, {GenerateMSBuildPropsOptions}, {}}, + {CommonAcquireArtifactSwitches, {GenerateMSBuildPropsOptions}, {}}, nullptr, }; @@ -69,32 +32,7 @@ namespace vcpkg std::vector ecmascript_args; ecmascript_args.emplace_back("generate-msbuild-props"); - auto&& switches = parsed.switches; - for (auto&& parsed_switch : switches) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); - } - - if (more_than_one_mapped(operating_systems, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); - } - - if (more_than_one_mapped(host_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); - } - - if (more_than_one_mapped(target_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); - } - - for (auto&& parsed_option : parsed.settings) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); - ecmascript_args.push_back(parsed_option.second); - } + forward_common_artifacts_arguments(ecmascript_args, parsed); if (!Util::Maps::contains(parsed.settings, OPTION_MSBUILD_PROPS)) { diff --git a/src/vcpkg/commands.use.cpp b/src/vcpkg/commands.use.cpp index 0be118dec1..9902495069 100644 --- a/src/vcpkg/commands.use.cpp +++ b/src/vcpkg/commands.use.cpp @@ -5,49 +5,12 @@ #include #include -#include +#include using namespace vcpkg; namespace { - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch UseSwitches[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - - constexpr const StringLiteral* operating_systems[] = {&SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; - constexpr const StringLiteral* host_platforms[] = {&SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; - constexpr const StringLiteral* target_platforms[] = { - &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - constexpr StringLiteral OPTION_MSBUILD_PROPS = "msbuild-props"; constexpr CommandSetting UseOptions[] = { @@ -63,11 +26,11 @@ namespace namespace vcpkg { - constexpr CommandMetadata CommandUseMetadata = { + const CommandMetadata CommandUseMetadata = { [] { return create_example_string("use cmake"); }, 1, SIZE_MAX, - {{UseSwitches}, {UseOptions}, {UseMultiOptions}}, + {CommonAcquireArtifactSwitches, {UseOptions}, {UseMultiOptions}}, nullptr, }; @@ -77,32 +40,7 @@ namespace vcpkg std::vector ecmascript_args; ecmascript_args.emplace_back("use"); - auto&& switches = parsed.switches; - for (auto&& parsed_switch : switches) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_switch)); - } - - if (more_than_one_mapped(operating_systems, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); - } - - if (more_than_one_mapped(host_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); - } - - if (more_than_one_mapped(target_platforms, parsed.switches)) - { - Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); - } - - for (auto&& parsed_option : parsed.settings) - { - ecmascript_args.push_back(fmt::format("--{}", parsed_option.first)); - ecmascript_args.push_back(parsed_option.second); - } + forward_common_artifacts_arguments(ecmascript_args, parsed); auto maybe_versions = Util::lookup_value(parsed.multisettings, OPTION_VERSION); if (auto versions = maybe_versions.get()) diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index 4c6787c47d..125190a1b7 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -18,9 +18,10 @@ #include #include +using namespace vcpkg; + namespace { - using namespace vcpkg; void track_telemetry(const Filesystem& fs, const Path& telemetry_file_path) { std::error_code ec; @@ -70,7 +71,50 @@ namespace Debug::println("No artifacts activated."); } } -} + + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch CommonAcquireArtifactSwitchesStorage[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr const StringLiteral* ArtifactOperatingSystemsSwitchNamesStorage[] = { + &SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; + constexpr const StringLiteral* ArtifactHostPlatformSwitchNamesStorage[] = { + &SWITCH_X86, &SWITCH_X64, &SWITCH_ARM, &SWITCH_ARM64}; + constexpr const StringLiteral* ArtifactTargetPlatformSwitchNamesStorage[] = { + &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; + + constexpr CommandSetting CommonSelectArtifactVersionSettingsStorage[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; +} // unnamed namespace namespace vcpkg { @@ -206,4 +250,56 @@ namespace vcpkg return result; } -} + + bool more_than_one_mapped(View candidates, const std::set>& switches) + { + bool seen = false; + for (auto&& candidate : candidates) + { + if (Util::Sets::contains(switches, *candidate)) + { + if (seen) + { + return true; + } + + seen = true; + } + } + + return false; + } + + constexpr View CommonAcquireArtifactSwitches = CommonAcquireArtifactSwitchesStorage; + constexpr View CommonSelectArtifactVersionSettings = CommonSelectArtifactVersionSettingsStorage; + + void forward_common_artifacts_arguments(std::vector& appended_to, const ParsedArguments& parsed) + { + auto&& switches = parsed.switches; + for (auto&& parsed_switch : switches) + { + appended_to.push_back(fmt::format("--{}", parsed_switch)); + } + + if (more_than_one_mapped(ArtifactOperatingSystemsSwitchNamesStorage, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneOperatingSystem); + } + + if (more_than_one_mapped(ArtifactHostPlatformSwitchNamesStorage, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneHostPlatform); + } + + if (more_than_one_mapped(ArtifactTargetPlatformSwitchNamesStorage, parsed.switches)) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgArtifactsSwitchOnlyOneTargetPlatform); + } + + for (auto&& parsed_option : parsed.settings) + { + appended_to.push_back(fmt::format("--{}", parsed_option.first)); + appended_to.push_back(parsed_option.second); + } + } +} // namespace vcpkg From d88a455eafcd1d2e77b25a4d76b20c8cea6b3caa Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Fri, 25 Aug 2023 16:39:08 -0700 Subject: [PATCH 6/7] Restore contexpr and make more_than_one_mapped have internal linkage. --- include/vcpkg/configure-environment.h | 43 +++++++++-- src/vcpkg/commands.acquire-project.cpp | 2 +- src/vcpkg/commands.acquire.cpp | 2 +- src/vcpkg/commands.activate.cpp | 2 +- src/vcpkg/commands.add.cpp | 2 +- src/vcpkg/commands.find.cpp | 2 +- src/vcpkg/commands.generate-msbuild-props.cpp | 2 +- src/vcpkg/commands.use.cpp | 2 +- src/vcpkg/configure-environment.cpp | 75 +++++-------------- 9 files changed, 62 insertions(+), 70 deletions(-) diff --git a/include/vcpkg/configure-environment.h b/include/vcpkg/configure-environment.h index 5898d84187..ee8ae6eb5f 100644 --- a/include/vcpkg/configure-environment.h +++ b/include/vcpkg/configure-environment.h @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -11,6 +10,8 @@ #include #include +#include + #include namespace vcpkg @@ -21,13 +22,43 @@ namespace vcpkg int run_configure_environment_command(const VcpkgPaths& paths, View args); - bool more_than_one_mapped(View candidates, - const std::set>& switches); - constexpr StringLiteral OPTION_VERSION = "version"; - extern const View CommonAcquireArtifactSwitches; - extern const View CommonSelectArtifactVersionSettings; + constexpr StringLiteral SWITCH_WINDOWS = "windows"; + constexpr StringLiteral SWITCH_OSX = "osx"; + constexpr StringLiteral SWITCH_LINUX = "linux"; + constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; + constexpr StringLiteral SWITCH_X86 = "x86"; + constexpr StringLiteral SWITCH_X64 = "x64"; + constexpr StringLiteral SWITCH_ARM = "arm"; + constexpr StringLiteral SWITCH_ARM64 = "arm64"; + constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; + constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; + constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; + constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; + constexpr StringLiteral SWITCH_FORCE = "force"; + constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; + + constexpr CommandSwitch CommonAcquireArtifactSwitches[] = { + {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, + {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, + {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, + {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, + {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, + {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, + {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, + {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, + {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, + {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, + {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, + {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, + {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, + {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, + }; + + constexpr CommandSetting CommonSelectArtifactVersionSettings[] = { + {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, + }; // Copies the switches and settings, but not multisettings from parsed to appended_to, and checks that the switches // that apply to artifacts meet semantic rules like only one operating system being selected. diff --git a/src/vcpkg/commands.acquire-project.cpp b/src/vcpkg/commands.acquire-project.cpp index 02a33375c8..bbf7ab0337 100644 --- a/src/vcpkg/commands.acquire-project.cpp +++ b/src/vcpkg/commands.acquire-project.cpp @@ -7,7 +7,7 @@ namespace vcpkg { - const CommandMetadata CommandAcquireProjectMetadata{ + constexpr CommandMetadata CommandAcquireProjectMetadata{ [] { return create_example_string("acquire-project"); }, 0, 0, diff --git a/src/vcpkg/commands.acquire.cpp b/src/vcpkg/commands.acquire.cpp index c0a3cb071e..c779e5d6e5 100644 --- a/src/vcpkg/commands.acquire.cpp +++ b/src/vcpkg/commands.acquire.cpp @@ -18,7 +18,7 @@ namespace namespace vcpkg { - const CommandMetadata CommandAcquireMetadata = { + constexpr CommandMetadata CommandAcquireMetadata = { [] { return create_example_string("acquire cmake"); }, 1, SIZE_MAX, diff --git a/src/vcpkg/commands.activate.cpp b/src/vcpkg/commands.activate.cpp index 9235001157..158c2afe47 100644 --- a/src/vcpkg/commands.activate.cpp +++ b/src/vcpkg/commands.activate.cpp @@ -20,7 +20,7 @@ namespace namespace vcpkg { - const CommandMetadata CommandActivateMetadata{ + constexpr CommandMetadata CommandActivateMetadata{ [] { return create_example_string("activate"); }, 0, 0, diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index 94fed4a61f..ac3b56d29f 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -17,7 +17,7 @@ namespace vcpkg { - const CommandMetadata CommandAddMetadata = { + constexpr CommandMetadata CommandAddMetadata = { [] { return msg::format(msgAddHelp) .append_raw('\n') diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 591a718a35..fce1dce964 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -214,7 +214,7 @@ namespace vcpkg Checks::exit_success(VCPKG_LINE_INFO); } - const CommandMetadata CommandFindMetadata = { + constexpr CommandMetadata CommandFindMetadata = { [] { return msg::format(msgFindHelp) .append_raw('\n') diff --git a/src/vcpkg/commands.generate-msbuild-props.cpp b/src/vcpkg/commands.generate-msbuild-props.cpp index 7034230e0a..e1b967facc 100644 --- a/src/vcpkg/commands.generate-msbuild-props.cpp +++ b/src/vcpkg/commands.generate-msbuild-props.cpp @@ -18,7 +18,7 @@ namespace namespace vcpkg { - const CommandMetadata CommandGenerateMsbuildPropsMetadata{ + constexpr CommandMetadata CommandGenerateMsbuildPropsMetadata{ [] { return create_example_string("generate-msbuild-props --msbuild-props out.props"); }, 0, 0, diff --git a/src/vcpkg/commands.use.cpp b/src/vcpkg/commands.use.cpp index 9902495069..cc6eec09b7 100644 --- a/src/vcpkg/commands.use.cpp +++ b/src/vcpkg/commands.use.cpp @@ -26,7 +26,7 @@ namespace namespace vcpkg { - const CommandMetadata CommandUseMetadata = { + constexpr CommandMetadata CommandUseMetadata = { [] { return create_example_string("use cmake"); }, 1, SIZE_MAX, diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index 125190a1b7..0360d6a8af 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -72,38 +72,6 @@ namespace } } - constexpr StringLiteral SWITCH_WINDOWS = "windows"; - constexpr StringLiteral SWITCH_OSX = "osx"; - constexpr StringLiteral SWITCH_LINUX = "linux"; - constexpr StringLiteral SWITCH_FREEBSD = "freebsd"; - constexpr StringLiteral SWITCH_X86 = "x86"; - constexpr StringLiteral SWITCH_X64 = "x64"; - constexpr StringLiteral SWITCH_ARM = "arm"; - constexpr StringLiteral SWITCH_ARM64 = "arm64"; - constexpr StringLiteral SWITCH_TARGET_X86 = "target:x86"; - constexpr StringLiteral SWITCH_TARGET_X64 = "target:x64"; - constexpr StringLiteral SWITCH_TARGET_ARM = "target:arm"; - constexpr StringLiteral SWITCH_TARGET_ARM64 = "target:arm64"; - constexpr StringLiteral SWITCH_FORCE = "force"; - constexpr StringLiteral SWITCH_ALL_LANGUAGES = "all-languages"; - - constexpr CommandSwitch CommonAcquireArtifactSwitchesStorage[] = { - {SWITCH_WINDOWS, [] { return msg::format(msgArtifactsSwitchWindows); }}, - {SWITCH_OSX, [] { return msg::format(msgArtifactsSwitchOsx); }}, - {SWITCH_LINUX, [] { return msg::format(msgArtifactsSwitchLinux); }}, - {SWITCH_FREEBSD, [] { return msg::format(msgArtifactsSwitchFreebsd); }}, - {SWITCH_X86, [] { return msg::format(msgArtifactsSwitchX86); }}, - {SWITCH_X64, [] { return msg::format(msgArtifactsSwitchX64); }}, - {SWITCH_ARM, [] { return msg::format(msgArtifactsSwitchARM); }}, - {SWITCH_ARM64, [] { return msg::format(msgArtifactsSwitchARM64); }}, - {SWITCH_TARGET_X86, [] { return msg::format(msgArtifactsSwitchTargetX86); }}, - {SWITCH_TARGET_X64, [] { return msg::format(msgArtifactsSwitchTargetX64); }}, - {SWITCH_TARGET_ARM, [] { return msg::format(msgArtifactsSwitchTargetARM); }}, - {SWITCH_TARGET_ARM64, [] { return msg::format(msgArtifactsSwitchTargetARM64); }}, - {SWITCH_FORCE, [] { return msg::format(msgArtifactsSwitchForce); }}, - {SWITCH_ALL_LANGUAGES, [] { return msg::format(msgArtifactsSwitchAllLanguages); }}, - }; - constexpr const StringLiteral* ArtifactOperatingSystemsSwitchNamesStorage[] = { &SWITCH_WINDOWS, &SWITCH_OSX, &SWITCH_LINUX, &SWITCH_FREEBSD}; constexpr const StringLiteral* ArtifactHostPlatformSwitchNamesStorage[] = { @@ -111,9 +79,24 @@ namespace constexpr const StringLiteral* ArtifactTargetPlatformSwitchNamesStorage[] = { &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - constexpr CommandSetting CommonSelectArtifactVersionSettingsStorage[] = { - {OPTION_VERSION, [] { return msg::format(msgArtifactsOptionVersion); }}, - }; + bool more_than_one_mapped(View candidates, const std::set>& switches) + { + bool seen = false; + for (auto&& candidate : candidates) + { + if (Util::Sets::contains(switches, *candidate)) + { + if (seen) + { + return true; + } + + seen = true; + } + } + + return false; + } } // unnamed namespace namespace vcpkg @@ -251,28 +234,6 @@ namespace vcpkg return result; } - bool more_than_one_mapped(View candidates, const std::set>& switches) - { - bool seen = false; - for (auto&& candidate : candidates) - { - if (Util::Sets::contains(switches, *candidate)) - { - if (seen) - { - return true; - } - - seen = true; - } - } - - return false; - } - - constexpr View CommonAcquireArtifactSwitches = CommonAcquireArtifactSwitchesStorage; - constexpr View CommonSelectArtifactVersionSettings = CommonSelectArtifactVersionSettingsStorage; - void forward_common_artifacts_arguments(std::vector& appended_to, const ParsedArguments& parsed) { auto&& switches = parsed.switches; From 7c750e3d6e7c7f4721fd49ba7fc7e9c451024e82 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Fri, 25 Aug 2023 16:59:27 -0700 Subject: [PATCH 7/7] Revert integrate install changes --- azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 b/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 index e08d980954..7c6da526f5 100644 --- a/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 @@ -8,7 +8,6 @@ if (-not $IsLinux -and -not $IsMacOS) { # Test msbuild props and targets $Script:CurrentTest = "zlib:x86-windows msbuild $iiroot\..." Write-Host $Script:CurrentTest - Run-Vcpkg @CommonArgs integrate install Run-Vcpkg @CommonArgs install zlib:x86-windows Throw-IfFailed foreach ($project in @("Project1", "NoProps")) {