From bfda089e3405c6241639dcbfdcc86ad03aff2026 Mon Sep 17 00:00:00 2001 From: Thomas1664 <46387399+Thomas1664@users.noreply.github.com> Date: Wed, 20 Dec 2023 07:35:38 +0100 Subject: [PATCH] StringLiteral for command switches and settings (#1308) --- include/vcpkg/commands.build.h | 3 +- include/vcpkg/commands.z-extract.h | 2 +- .../vcpkg/commands.z-generate-message-map.h | 6 ++-- include/vcpkg/vcpkgcmdarguments.h | 8 ++--- src/vcpkg-test/arguments.cpp | 4 +-- src/vcpkg-test/commands.extract.cpp | 2 +- src/vcpkg-test/dependencies.cpp | 17 +++++----- src/vcpkg/binarycaching.cpp | 1 + src/vcpkg/commands.build.cpp | 1 + src/vcpkg/commands.ci.cpp | 2 +- src/vcpkg/commands.cpp | 1 + src/vcpkg/commands.export.cpp | 1 + src/vcpkg/commands.help.cpp | 6 ++-- src/vcpkg/commands.install.cpp | 1 + src/vcpkg/commands.remove.cpp | 1 + src/vcpkg/commands.z-applocal.cpp | 2 +- src/vcpkg/commands.z-extract.cpp | 2 +- src/vcpkg/commands.z-generate-message-map.cpp | 2 ++ src/vcpkg/configure-environment.cpp | 3 +- src/vcpkg/vcpkgcmdarguments.cpp | 32 +++++++++---------- 20 files changed, 54 insertions(+), 43 deletions(-) diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index 8929386791..a0b49ac316 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -3,9 +3,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -19,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/include/vcpkg/commands.z-extract.h b/include/vcpkg/commands.z-extract.h index fed76b78fd..b68f46fe24 100644 --- a/include/vcpkg/commands.z-extract.h +++ b/include/vcpkg/commands.z-extract.h @@ -39,7 +39,7 @@ namespace vcpkg } }; - ExpectedL get_strip_setting(std::map> settings); + ExpectedL get_strip_setting(const std::map>& settings); struct ExtractedArchive { diff --git a/include/vcpkg/commands.z-generate-message-map.h b/include/vcpkg/commands.z-generate-message-map.h index ce010ddc4a..4c65224c99 100644 --- a/include/vcpkg/commands.z-generate-message-map.h +++ b/include/vcpkg/commands.z-generate-message-map.h @@ -1,11 +1,11 @@ #pragma once +#include #include -#include -#include +#include -#include +#include #include diff --git a/include/vcpkg/vcpkgcmdarguments.h b/include/vcpkg/vcpkgcmdarguments.h index 546cb249cf..42f7b2316b 100644 --- a/include/vcpkg/vcpkgcmdarguments.h +++ b/include/vcpkg/vcpkgcmdarguments.h @@ -22,9 +22,9 @@ namespace vcpkg { struct ParsedArguments { - std::set> switches; - std::map> settings; - std::map, std::less<>> multisettings; + std::set> switches; + std::map> settings; + std::map, std::less<>> multisettings; const std::string* read_setting(StringLiteral setting) const noexcept; @@ -374,7 +374,7 @@ namespace vcpkg ParsedArguments parse_arguments(const CommandMetadata& command_metadata) const; void imbue_from_environment(); - void imbue_from_fake_environment(const std::map>& env); + void imbue_from_fake_environment(const std::map>& env); // Applies recursive settings from the environment or sets a global environment variable // to be consumed by subprocesses; may only be called once per process. diff --git a/src/vcpkg-test/arguments.cpp b/src/vcpkg-test/arguments.cpp index 3c1abd7483..33f4d6df99 100644 --- a/src/vcpkg-test/arguments.cpp +++ b/src/vcpkg-test/arguments.cpp @@ -160,8 +160,8 @@ TEST_CASE ("Combine asset cache params", "[arguments]") v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size()); REQUIRE(v.asset_sources_template() == "x-azurl,value"); - std::map> envmap = { - {VcpkgCmdArguments::ASSET_SOURCES_ENV.to_string(), "x-azurl,value1"}, + std::map> envmap = { + {VcpkgCmdArguments::ASSET_SOURCES_ENV, "x-azurl,value1"}, }; v = VcpkgCmdArguments::create_from_arg_sequence(nullptr, nullptr); v.imbue_from_fake_environment(envmap); diff --git a/src/vcpkg-test/commands.extract.cpp b/src/vcpkg-test/commands.extract.cpp index 85ed401587..917011c425 100644 --- a/src/vcpkg-test/commands.extract.cpp +++ b/src/vcpkg-test/commands.extract.cpp @@ -129,7 +129,7 @@ TEST_CASE ("Testing strip auto's get_common_prefix_count", "z-extract") TEST_CASE ("Testing get_strip_setting", "z-extract") { - std::map> settings; + std::map> settings; SECTION ("Test no strip") { diff --git a/src/vcpkg-test/dependencies.cpp b/src/vcpkg-test/dependencies.cpp index d5e6a34984..d1ae9e2102 100644 --- a/src/vcpkg-test/dependencies.cpp +++ b/src/vcpkg-test/dependencies.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -2466,14 +2467,14 @@ TEST_CASE ("dependency graph API snapshot: host and target") ActionPlan plan; plan.install_actions.push_back(std::move(install_a)); plan.install_actions.push_back(std::move(install_a_host)); - std::map> envmap = { - {VcpkgCmdArguments::GITHUB_JOB_ENV.to_string(), "123"}, - {VcpkgCmdArguments::GITHUB_RUN_ID_ENV.to_string(), "123"}, - {VcpkgCmdArguments::GITHUB_REF_ENV.to_string(), "refs/heads/main"}, - {VcpkgCmdArguments::GITHUB_REPOSITORY_ENV.to_string(), "owner/repo"}, - {VcpkgCmdArguments::GITHUB_SHA_ENV.to_string(), "abc123"}, - {VcpkgCmdArguments::GITHUB_TOKEN_ENV.to_string(), "abc"}, - {VcpkgCmdArguments::GITHUB_WORKFLOW_ENV.to_string(), "test"}, + std::map> envmap = { + {VcpkgCmdArguments::GITHUB_JOB_ENV, "123"}, + {VcpkgCmdArguments::GITHUB_RUN_ID_ENV, "123"}, + {VcpkgCmdArguments::GITHUB_REF_ENV, "refs/heads/main"}, + {VcpkgCmdArguments::GITHUB_REPOSITORY_ENV, "owner/repo"}, + {VcpkgCmdArguments::GITHUB_SHA_ENV, "abc123"}, + {VcpkgCmdArguments::GITHUB_TOKEN_ENV, "abc"}, + {VcpkgCmdArguments::GITHUB_WORKFLOW_ENV, "test"}, }; auto v = VcpkgCmdArguments::create_from_arg_sequence(nullptr, nullptr); v.imbue_from_fake_environment(envmap); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 7838b9ac38..b94f537381 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 4532230711..ea84b78582 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include diff --git a/src/vcpkg/commands.ci.cpp b/src/vcpkg/commands.ci.cpp index 90199ea1f8..fb649587ea 100644 --- a/src/vcpkg/commands.ci.cpp +++ b/src/vcpkg/commands.ci.cpp @@ -249,7 +249,7 @@ namespace }); } - void parse_exclusions(const std::map>& settings, + void parse_exclusions(const std::map>& settings, StringLiteral opt, Triplet triplet, ExclusionsMap& exclusions_map) diff --git a/src/vcpkg/commands.cpp b/src/vcpkg/commands.cpp index 5187b62bef..299a996c73 100644 --- a/src/vcpkg/commands.cpp +++ b/src/vcpkg/commands.cpp @@ -53,6 +53,7 @@ #include #include #include +#include namespace vcpkg { diff --git a/src/vcpkg/commands.export.cpp b/src/vcpkg/commands.export.cpp index ebc8c7798a..a6b06cb1e8 100644 --- a/src/vcpkg/commands.export.cpp +++ b/src/vcpkg/commands.export.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/src/vcpkg/commands.help.cpp b/src/vcpkg/commands.help.cpp index 173e0bff68..930cac4891 100644 --- a/src/vcpkg/commands.help.cpp +++ b/src/vcpkg/commands.help.cpp @@ -116,9 +116,9 @@ namespace vcpkg void help_topic_valid_triplet(const TripletDatabase& database) { std::map> triplets_per_location; - vcpkg::Util::group_by(database.available_triplets, - &triplets_per_location, - [](const TripletFile& triplet_file) -> StringView { return triplet_file.location; }); + Util::group_by(database.available_triplets, + &triplets_per_location, + [](const TripletFile& triplet_file) -> StringView { return triplet_file.location; }); LocalizedString result; result.append(msgBuiltInTriplets).append_raw('\n'); diff --git a/src/vcpkg/commands.install.cpp b/src/vcpkg/commands.install.cpp index e82f2b8087..e7ba1ac53b 100644 --- a/src/vcpkg/commands.install.cpp +++ b/src/vcpkg/commands.install.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/vcpkg/commands.remove.cpp b/src/vcpkg/commands.remove.cpp index 15def992a4..9e489dfd35 100644 --- a/src/vcpkg/commands.remove.cpp +++ b/src/vcpkg/commands.remove.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/vcpkg/commands.z-applocal.cpp b/src/vcpkg/commands.z-applocal.cpp index 4f19f7e5b4..9dd8e5efee 100644 --- a/src/vcpkg/commands.z-applocal.cpp +++ b/src/vcpkg/commands.z-applocal.cpp @@ -18,7 +18,7 @@ using namespace vcpkg; namespace { - WriteFilePointer maybe_create_log(const std::map>& settings, + WriteFilePointer maybe_create_log(const std::map>& settings, StringLiteral setting, const Filesystem& fs) { diff --git a/src/vcpkg/commands.z-extract.cpp b/src/vcpkg/commands.z-extract.cpp index d09f96d8a4..5d6ac633bc 100644 --- a/src/vcpkg/commands.z-extract.cpp +++ b/src/vcpkg/commands.z-extract.cpp @@ -33,7 +33,7 @@ namespace vcpkg nullptr, }; - ExpectedL get_strip_setting(std::map> settings) + ExpectedL get_strip_setting(const std::map>& settings) { auto iter = settings.find(OPTION_STRIP); if (iter == settings.end()) diff --git a/src/vcpkg/commands.z-generate-message-map.cpp b/src/vcpkg/commands.z-generate-message-map.cpp index f3cb71060f..c8de01a4a0 100644 --- a/src/vcpkg/commands.z-generate-message-map.cpp +++ b/src/vcpkg/commands.z-generate-message-map.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,6 +6,7 @@ #include #include +#include using namespace vcpkg; diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index 5f13e0231d..c2558fc3d6 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -79,7 +79,8 @@ namespace constexpr const StringLiteral* ArtifactTargetPlatformSwitchNamesStorage[] = { &SWITCH_TARGET_X86, &SWITCH_TARGET_X64, &SWITCH_TARGET_ARM, &SWITCH_TARGET_ARM64}; - bool more_than_one_mapped(View candidates, const std::set>& switches) + bool more_than_one_mapped(View candidates, + const std::set>& switches) { bool seen = false; for (auto&& candidate : candidates) diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 3902394a06..9418046c1c 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -84,16 +84,16 @@ namespace for (const auto& switch_ : command_metadata.options.switches) { bool parse_result; - auto name = switch_.name.to_string(); + ZStringView name = switch_.name; StabilityTag tag = StabilityTag::Standard; if (Strings::starts_with(name, "x-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::Experimental; } else if (Strings::starts_with(name, "z-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::ImplementationDetail; } @@ -101,14 +101,14 @@ namespace { if (cmd_parser.parse_switch(name, tag, parse_result, switch_.helpmsg.to_string()) && parse_result) { - output.switches.emplace(switch_.name.to_string()); + output.switches.emplace(switch_.name); } } else { if (cmd_parser.parse_switch(name, tag, parse_result) && parse_result) { - output.switches.emplace(switch_.name.to_string()); + output.switches.emplace(switch_.name); } } } @@ -117,16 +117,16 @@ namespace std::string maybe_parse_result; for (const auto& option : command_metadata.options.settings) { - auto name = option.name.to_string(); + ZStringView name = option.name; StabilityTag tag = StabilityTag::Standard; if (Strings::starts_with(name, "x-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::Experimental; } else if (Strings::starts_with(name, "z-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::ImplementationDetail; } @@ -134,14 +134,14 @@ namespace { if (cmd_parser.parse_option(name, tag, maybe_parse_result, option.helpmsg.to_string())) { - output.settings.emplace(option.name.to_string(), std::move(maybe_parse_result)); + output.settings.emplace(option.name, std::move(maybe_parse_result)); } } else { if (cmd_parser.parse_option(name, tag, maybe_parse_result)) { - output.settings.emplace(option.name.to_string(), std::move(maybe_parse_result)); + output.settings.emplace(option.name, std::move(maybe_parse_result)); } } } @@ -149,16 +149,16 @@ namespace for (const auto& option : command_metadata.options.multisettings) { - auto name = option.name.to_string(); + ZStringView name = option.name; StabilityTag tag = StabilityTag::Standard; if (Strings::starts_with(name, "x-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::Experimental; } else if (Strings::starts_with(name, "z-")) { - name.erase(0, 2); + name = name.substr(2); tag = StabilityTag::ImplementationDetail; } @@ -167,14 +167,14 @@ namespace { if (cmd_parser.parse_multi_option(name, tag, maybe_parse_result, option.helpmsg.to_string())) { - output.multisettings.emplace(option.name.to_string(), std::move(maybe_parse_result)); + output.multisettings.emplace(option.name, std::move(maybe_parse_result)); } } else { if (cmd_parser.parse_multi_option(name, tag, maybe_parse_result)) { - output.multisettings.emplace(option.name.to_string(), std::move(maybe_parse_result)); + output.multisettings.emplace(option.name, std::move(maybe_parse_result)); } } } @@ -519,7 +519,7 @@ namespace vcpkg } void VcpkgCmdArguments::imbue_from_environment() { imbue_from_environment_impl(&vcpkg::get_environment_variable); } - void VcpkgCmdArguments::imbue_from_fake_environment(const std::map>& env) + void VcpkgCmdArguments::imbue_from_fake_environment(const std::map>& env) { imbue_from_environment_impl([&env](ZStringView var) -> Optional { auto it = env.find(var);