diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-24 16:51:39 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-24 18:40:44 (GMT) |
commit | ec7928ef266599f1de08b30da84a42d7da3fd6a0 (patch) | |
tree | 6971f37ffafd1b7dade611b18d1f7bd39c1c3b1d /Source | |
parent | 94de927cab19609aeeff032c64f16cfd257fca2f (diff) | |
download | CMake-ec7928ef266599f1de08b30da84a42d7da3fd6a0.zip CMake-ec7928ef266599f1de08b30da84a42d7da3fd6a0.tar.gz CMake-ec7928ef266599f1de08b30da84a42d7da3fd6a0.tar.bz2 |
use _s to construct static string_views at several places
This should avoid the runtime strlen() call.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 60 | ||||
-rw-r--r-- | Source/cmCTest.cxx | 129 | ||||
-rw-r--r-- | Source/cmCTest.h | 6 | ||||
-rw-r--r-- | Source/cmake.cxx | 27 |
4 files changed, 116 insertions, 106 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 77641c6..1feac3a 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -18,12 +18,14 @@ #include <utility> #include <cm/memory> +#include <cm/string_view> #include "cmsys/FStream.hxx" #include <cmsys/Base64.h> #include <cmsys/Directory.hxx> #include <cmsys/RegularExpression.hxx> +#include "cm_static_string_view.hxx" #include "cm_utf8.h" #include "cmAlgorithms.h" @@ -2154,7 +2156,7 @@ bool cmCTestTestHandler::SetTestsProperties( for (std::string const& t : tests) { for (cmCTestTestProperties& rt : this->TestList) { if (t == rt.Name) { - if (key == "_BACKTRACE_TRIPLES") { + if (key == "_BACKTRACE_TRIPLES"_s) { std::vector<std::string> triples; // allow empty args in the triples cmExpandList(val, triples, true); @@ -2178,70 +2180,70 @@ bool cmCTestTestHandler::SetTestsProperties( rt.Backtrace = rt.Backtrace.Push(fc); } } - } else if (key == "WILL_FAIL") { + } else if (key == "WILL_FAIL"_s) { rt.WillFail = cmIsOn(val); - } else if (key == "DISABLED") { + } else if (key == "DISABLED"_s) { rt.Disabled = cmIsOn(val); - } else if (key == "ATTACHED_FILES") { + } else if (key == "ATTACHED_FILES"_s) { cmExpandList(val, rt.AttachedFiles); - } else if (key == "ATTACHED_FILES_ON_FAIL") { + } else if (key == "ATTACHED_FILES_ON_FAIL"_s) { cmExpandList(val, rt.AttachOnFail); - } else if (key == "RESOURCE_LOCK") { + } else if (key == "RESOURCE_LOCK"_s) { std::vector<std::string> lval = cmExpandedList(val); rt.LockedResources.insert(lval.begin(), lval.end()); - } else if (key == "FIXTURES_SETUP") { + } else if (key == "FIXTURES_SETUP"_s) { std::vector<std::string> lval = cmExpandedList(val); rt.FixturesSetup.insert(lval.begin(), lval.end()); - } else if (key == "FIXTURES_CLEANUP") { + } else if (key == "FIXTURES_CLEANUP"_s) { std::vector<std::string> lval = cmExpandedList(val); rt.FixturesCleanup.insert(lval.begin(), lval.end()); - } else if (key == "FIXTURES_REQUIRED") { + } else if (key == "FIXTURES_REQUIRED"_s) { std::vector<std::string> lval = cmExpandedList(val); rt.FixturesRequired.insert(lval.begin(), lval.end()); - } else if (key == "TIMEOUT") { + } else if (key == "TIMEOUT"_s) { rt.Timeout = cmDuration(atof(val.c_str())); rt.ExplicitTimeout = true; - } else if (key == "COST") { + } else if (key == "COST"_s) { rt.Cost = static_cast<float>(atof(val.c_str())); - } else if (key == "REQUIRED_FILES") { + } else if (key == "REQUIRED_FILES"_s) { cmExpandList(val, rt.RequiredFiles); - } else if (key == "RUN_SERIAL") { + } else if (key == "RUN_SERIAL"_s) { rt.RunSerial = cmIsOn(val); - } else if (key == "FAIL_REGULAR_EXPRESSION") { + } else if (key == "FAIL_REGULAR_EXPRESSION"_s) { std::vector<std::string> lval = cmExpandedList(val); for (std::string const& cr : lval) { rt.ErrorRegularExpressions.emplace_back(cr, cr); } - } else if (key == "SKIP_REGULAR_EXPRESSION") { + } else if (key == "SKIP_REGULAR_EXPRESSION"_s) { std::vector<std::string> lval = cmExpandedList(val); for (std::string const& cr : lval) { rt.SkipRegularExpressions.emplace_back(cr, cr); } - } else if (key == "PROCESSORS") { + } else if (key == "PROCESSORS"_s) { rt.Processors = atoi(val.c_str()); if (rt.Processors < 1) { rt.Processors = 1; } - } else if (key == "PROCESSOR_AFFINITY") { + } else if (key == "PROCESSOR_AFFINITY"_s) { rt.WantAffinity = cmIsOn(val); - } else if (key == "RESOURCE_GROUPS") { + } else if (key == "RESOURCE_GROUPS"_s) { if (!ParseResourceGroupsProperty(val, rt.ResourceGroups)) { return false; } - } else if (key == "SKIP_RETURN_CODE") { + } else if (key == "SKIP_RETURN_CODE"_s) { rt.SkipReturnCode = atoi(val.c_str()); if (rt.SkipReturnCode < 0 || rt.SkipReturnCode > 255) { rt.SkipReturnCode = -1; } - } else if (key == "DEPENDS") { + } else if (key == "DEPENDS"_s) { cmExpandList(val, rt.Depends); - } else if (key == "ENVIRONMENT") { + } else if (key == "ENVIRONMENT"_s) { cmExpandList(val, rt.Environment); - } else if (key == "LABELS") { + } else if (key == "LABELS"_s) { std::vector<std::string> Labels = cmExpandedList(val); rt.Labels.insert(rt.Labels.end(), Labels.begin(), Labels.end()); // sort the array @@ -2249,7 +2251,7 @@ bool cmCTestTestHandler::SetTestsProperties( // remove duplicates auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end()); rt.Labels.erase(new_end, rt.Labels.end()); - } else if (key == "MEASUREMENT") { + } else if (key == "MEASUREMENT"_s) { size_t pos = val.find_first_of('='); if (pos != std::string::npos) { std::string mKey = val.substr(0, pos); @@ -2258,14 +2260,14 @@ bool cmCTestTestHandler::SetTestsProperties( } else { rt.Measurements[val] = "1"; } - } else if (key == "PASS_REGULAR_EXPRESSION") { + } else if (key == "PASS_REGULAR_EXPRESSION"_s) { std::vector<std::string> lval = cmExpandedList(val); for (std::string const& cr : lval) { rt.RequiredRegularExpressions.emplace_back(cr, cr); } - } else if (key == "WORKING_DIRECTORY") { + } else if (key == "WORKING_DIRECTORY"_s) { rt.Directory = val; - } else if (key == "TIMEOUT_AFTER_MATCH") { + } else if (key == "TIMEOUT_AFTER_MATCH"_s) { std::vector<std::string> propArgs = cmExpandedList(val); if (propArgs.size() != 2) { cmCTestLog(this->CTest, WARNING, @@ -2305,16 +2307,16 @@ bool cmCTestTestHandler::SetDirectoryProperties( } ++it; // skip PROPERTIES for (; it != args.end(); ++it) { - std::string key = *it; + std::string const& key = *it; ++it; if (it == args.end()) { break; } - std::string val = *it; + std::string const& val = *it; for (cmCTestTestProperties& rt : this->TestList) { std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); if (cwd == rt.Directory) { - if (key == "LABELS") { + if (key == "LABELS"_s) { std::vector<std::string> DirectoryLabels = cmExpandedList(val); rt.Labels.insert(rt.Labels.end(), DirectoryLabels.begin(), DirectoryLabels.end()); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 01c5131..b9fb4a0 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -36,6 +36,8 @@ # include <unistd.h> // IWYU pragma: keep #endif +#include "cm_static_string_view.hxx" + #include "cmCTestBuildAndTestHandler.h" #include "cmCTestBuildHandler.h" #include "cmCTestConfigureHandler.h" @@ -1815,10 +1817,10 @@ void cmCTest::ErrorMessageUnknownDashDValue(std::string& val) << " ctest -D NightlyMemoryCheck" << std::endl); } -bool cmCTest::CheckArgument(const std::string& arg, const char* varg1, +bool cmCTest::CheckArgument(const std::string& arg, cm::string_view varg1, const char* varg2) { - return (varg1 && arg == varg1) || (varg2 && arg == varg2); + return (arg == varg1) || (varg2 && arg == varg2); } // Processes one command line argument (and its arguments if any) @@ -1828,9 +1830,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, std::string& errormsg) { std::string arg = args[i]; - if (this->CheckArgument(arg, "-F")) { + if (this->CheckArgument(arg, "-F"_s)) { this->Impl->Failover = true; - } else if (this->CheckArgument(arg, "-j", "--parallel") && + } else if (this->CheckArgument(arg, "-j"_s, "--parallel") && i < args.size() - 1) { i++; int plevel = atoi(args[i].c_str()); @@ -1842,7 +1844,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, this->Impl->ParallelLevelSetInCli = true; } - else if (this->CheckArgument(arg, "--repeat-until-fail")) { + else if (this->CheckArgument(arg, "--repeat-until-fail"_s)) { if (i >= args.size() - 1) { errormsg = "'--repeat-until-fail' requires an argument"; return false; @@ -1854,8 +1856,8 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, i++; long repeat = 1; if (!cmStrToLong(args[i], &repeat)) { - errormsg = - "'--repeat-until-fail' given non-integer value '" + args[i] + "'"; + errormsg = cmStrCat("'--repeat-until-fail' given non-integer value '", + args[i], "'"); return false; } this->Impl->RepeatCount = static_cast<int>(repeat); @@ -1864,7 +1866,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } } - else if (this->CheckArgument(arg, "--repeat")) { + else if (this->CheckArgument(arg, "--repeat"_s)) { if (i >= args.size() - 1) { errormsg = "'--repeat' requires an argument"; return false; @@ -1892,12 +1894,12 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } } } else { - errormsg = "'--repeat' given invalid value '" + args[i] + "'"; + errormsg = cmStrCat("'--repeat' given invalid value '", args[i], "'"); return false; } } - else if (this->CheckArgument(arg, "--test-load") && i < args.size() - 1) { + else if (this->CheckArgument(arg, "--test-load"_s) && i < args.size() - 1) { i++; unsigned long load; if (cmStrToULong(args[i], &load)) { @@ -1908,65 +1910,65 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } } - else if (this->CheckArgument(arg, "--no-compress-output")) { + else if (this->CheckArgument(arg, "--no-compress-output"_s)) { this->Impl->CompressTestOutput = false; } - else if (this->CheckArgument(arg, "--print-labels")) { + else if (this->CheckArgument(arg, "--print-labels"_s)) { this->Impl->PrintLabels = true; } - else if (this->CheckArgument(arg, "--http1.0")) { + else if (this->CheckArgument(arg, "--http1.0"_s)) { this->Impl->UseHTTP10 = true; } - else if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) { + else if (this->CheckArgument(arg, "--timeout"_s) && i < args.size() - 1) { i++; auto timeout = cmDuration(atof(args[i].c_str())); this->Impl->GlobalTimeout = timeout; } - else if (this->CheckArgument(arg, "--stop-time") && i < args.size() - 1) { + else if (this->CheckArgument(arg, "--stop-time"_s) && i < args.size() - 1) { i++; this->SetStopTime(args[i]); } - else if (this->CheckArgument(arg, "-C", "--build-config") && + else if (this->CheckArgument(arg, "-C"_s, "--build-config") && i < args.size() - 1) { i++; this->SetConfigType(args[i].c_str()); } - else if (this->CheckArgument(arg, "--debug")) { + else if (this->CheckArgument(arg, "--debug"_s)) { this->Impl->Debug = true; this->Impl->ShowLineNumbers = true; - } else if (this->CheckArgument(arg, "--group") && i < args.size() - 1) { + } else if (this->CheckArgument(arg, "--group"_s) && i < args.size() - 1) { i++; this->Impl->SpecificGroup = args[i]; } // This is an undocumented / deprecated option. // "Track" has been renamed to "Group". - else if (this->CheckArgument(arg, "--track") && i < args.size() - 1) { + else if (this->CheckArgument(arg, "--track"_s) && i < args.size() - 1) { i++; this->Impl->SpecificGroup = args[i]; - } else if (this->CheckArgument(arg, "--show-line-numbers")) { + } else if (this->CheckArgument(arg, "--show-line-numbers"_s)) { this->Impl->ShowLineNumbers = true; - } else if (this->CheckArgument(arg, "--no-label-summary")) { + } else if (this->CheckArgument(arg, "--no-label-summary"_s)) { this->Impl->LabelSummary = false; - } else if (this->CheckArgument(arg, "--no-subproject-summary")) { + } else if (this->CheckArgument(arg, "--no-subproject-summary"_s)) { this->Impl->SubprojectSummary = false; - } else if (this->CheckArgument(arg, "-Q", "--quiet")) { + } else if (this->CheckArgument(arg, "-Q"_s, "--quiet")) { this->Impl->Quiet = true; - } else if (this->CheckArgument(arg, "--progress")) { + } else if (this->CheckArgument(arg, "--progress"_s)) { this->Impl->TestProgressOutput = true; - } else if (this->CheckArgument(arg, "-V", "--verbose")) { + } else if (this->CheckArgument(arg, "-V"_s, "--verbose")) { this->Impl->Verbose = true; - } else if (this->CheckArgument(arg, "-VV", "--extra-verbose")) { + } else if (this->CheckArgument(arg, "-VV"_s, "--extra-verbose")) { this->Impl->ExtraVerbose = true; this->Impl->Verbose = true; - } else if (this->CheckArgument(arg, "--output-on-failure")) { + } else if (this->CheckArgument(arg, "--output-on-failure"_s)) { this->Impl->OutputTestOutputOnTestFailure = true; - } else if (this->CheckArgument(arg, "--test-output-size-passed") && + } else if (this->CheckArgument(arg, "--test-output-size-passed"_s) && i < args.size() - 1) { i++; long outputSize; @@ -1977,7 +1979,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, "Invalid value for '--test-output-size-passed': " << args[i] << "\n"); } - } else if (this->CheckArgument(arg, "--test-output-size-failed") && + } else if (this->CheckArgument(arg, "--test-output-size-failed"_s) && i < args.size() - 1) { i++; long outputSize; @@ -1988,7 +1990,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, "Invalid value for '--test-output-size-failed': " << args[i] << "\n"); } - } else if (this->CheckArgument(arg, "-N", "--show-only")) { + } else if (this->CheckArgument(arg, "-N"_s, "--show-only")) { this->Impl->ShowOnly = true; } else if (cmHasLiteralPrefix(arg, "--show-only=")) { this->Impl->ShowOnly = true; @@ -2008,25 +2010,25 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } } - else if (this->CheckArgument(arg, "-O", "--output-log") && + else if (this->CheckArgument(arg, "-O"_s, "--output-log") && i < args.size() - 1) { i++; this->SetOutputLogFileName(args[i].c_str()); } - else if (this->CheckArgument(arg, "--tomorrow-tag")) { + else if (this->CheckArgument(arg, "--tomorrow-tag"_s)) { this->Impl->TomorrowTag = true; - } else if (this->CheckArgument(arg, "--force-new-ctest-process")) { + } else if (this->CheckArgument(arg, "--force-new-ctest-process"_s)) { this->Impl->ForceNewCTestProcess = true; - } else if (this->CheckArgument(arg, "-W", "--max-width") && + } else if (this->CheckArgument(arg, "-W"_s, "--max-width") && i < args.size() - 1) { i++; this->Impl->MaxTestNameWidth = atoi(args[i].c_str()); - } else if (this->CheckArgument(arg, "--interactive-debug-mode") && + } else if (this->CheckArgument(arg, "--interactive-debug-mode"_s) && i < args.size() - 1) { i++; this->Impl->InteractiveDebugMode = cmIsOn(args[i]); - } else if (this->CheckArgument(arg, "--submit-index") && + } else if (this->CheckArgument(arg, "--submit-index"_s) && i < args.size() - 1) { i++; this->Impl->SubmitIndex = atoi(args[i].c_str()); @@ -2035,10 +2037,10 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } } - else if (this->CheckArgument(arg, "--overwrite") && i < args.size() - 1) { + else if (this->CheckArgument(arg, "--overwrite"_s) && i < args.size() - 1) { i++; this->AddCTestConfigurationOverwrite(args[i]); - } else if (this->CheckArgument(arg, "-A", "--add-notes") && + } else if (this->CheckArgument(arg, "-A"_s, "--add-notes") && i < args.size() - 1) { this->Impl->ProduceXML = true; this->SetTest("Notes"); @@ -2063,31 +2065,31 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, } // options that control what tests are run - else if (this->CheckArgument(arg, "-I", "--tests-information") && + else if (this->CheckArgument(arg, "-I"_s, "--tests-information") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption("TestsToRunInformation", args[i].c_str()); this->GetMemCheckHandler()->SetPersistentOption("TestsToRunInformation", args[i].c_str()); - } else if (this->CheckArgument(arg, "-U", "--union")) { + } else if (this->CheckArgument(arg, "-U"_s, "--union")) { this->GetTestHandler()->SetPersistentOption("UseUnion", "true"); this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true"); - } else if (this->CheckArgument(arg, "-R", "--tests-regex") && + } else if (this->CheckArgument(arg, "-R"_s, "--tests-regex") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption("IncludeRegularExpression", args[i].c_str()); this->GetMemCheckHandler()->SetPersistentOption("IncludeRegularExpression", args[i].c_str()); - } else if (this->CheckArgument(arg, "-L", "--label-regex") && + } else if (this->CheckArgument(arg, "-L"_s, "--label-regex") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption("LabelRegularExpression", args[i].c_str()); this->GetMemCheckHandler()->SetPersistentOption("LabelRegularExpression", args[i].c_str()); - } else if (this->CheckArgument(arg, "-LE", "--label-exclude") && + } else if (this->CheckArgument(arg, "-LE"_s, "--label-exclude") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption( @@ -2096,7 +2098,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, "ExcludeLabelRegularExpression", args[i].c_str()); } - else if (this->CheckArgument(arg, "-E", "--exclude-regex") && + else if (this->CheckArgument(arg, "-E"_s, "--exclude-regex") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption("ExcludeRegularExpression", @@ -2105,21 +2107,21 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, args[i].c_str()); } - else if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") && + else if (this->CheckArgument(arg, "-FA"_s, "--fixture-exclude-any") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption( "ExcludeFixtureRegularExpression", args[i].c_str()); this->GetMemCheckHandler()->SetPersistentOption( "ExcludeFixtureRegularExpression", args[i].c_str()); - } else if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") && + } else if (this->CheckArgument(arg, "-FS"_s, "--fixture-exclude-setup") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption( "ExcludeFixtureSetupRegularExpression", args[i].c_str()); this->GetMemCheckHandler()->SetPersistentOption( "ExcludeFixtureSetupRegularExpression", args[i].c_str()); - } else if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") && + } else if (this->CheckArgument(arg, "-FC"_s, "--fixture-exclude-cleanup") && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption( @@ -2128,7 +2130,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, "ExcludeFixtureCleanupRegularExpression", args[i].c_str()); } - else if (this->CheckArgument(arg, "--resource-spec-file") && + else if (this->CheckArgument(arg, "--resource-spec-file"_s) && i < args.size() - 1) { i++; this->GetTestHandler()->SetPersistentOption("ResourceSpecFile", @@ -2137,7 +2139,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, args[i].c_str()); } - else if (this->CheckArgument(arg, "--rerun-failed")) { + else if (this->CheckArgument(arg, "--rerun-failed"_s)) { this->GetTestHandler()->SetPersistentOption("RerunFailed", "true"); this->GetMemCheckHandler()->SetPersistentOption("RerunFailed", "true"); } @@ -2189,7 +2191,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, bool& SRArgumentSpecified) { std::string arg = args[i]; - if (this->CheckArgument(arg, "-SP", "--script-new-process") && + if (this->CheckArgument(arg, "-SP"_s, "--script-new-process") && i < args.size() - 1) { this->Impl->RunConfigurationScript = true; i++; @@ -2200,7 +2202,8 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, } } - if (this->CheckArgument(arg, "-SR", "--script-run") && i < args.size() - 1) { + if (this->CheckArgument(arg, "-SR"_s, "--script-run") && + i < args.size() - 1) { SRArgumentSpecified = true; this->Impl->RunConfigurationScript = true; i++; @@ -2208,7 +2211,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, ch->AddConfigurationScript(args[i].c_str(), true); } - if (this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1) { + if (this->CheckArgument(arg, "-S"_s, "--script") && i < args.size() - 1) { this->Impl->RunConfigurationScript = true; i++; cmCTestScriptHandler* ch = this->GetScriptHandler(); @@ -2258,7 +2261,8 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) // --dashboard: handle a request for a dashboard std::string arg = args[i]; - if (this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1) { + if (this->CheckArgument(arg, "-D"_s, "--dashboard") && + i < args.size() - 1) { this->Impl->ProduceXML = true; i++; std::string targ = args[i]; @@ -2294,7 +2298,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) } // --extra-submit - if (this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1) { + if (this->CheckArgument(arg, "--extra-submit"_s) && i < args.size() - 1) { this->Impl->ProduceXML = true; this->SetTest("Submit"); i++; @@ -2304,12 +2308,13 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) } // --build-and-test options - if (this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1) { + if (this->CheckArgument(arg, "--build-and-test"_s) && + i < args.size() - 1) { cmakeAndTest = true; } // --schedule-random - if (this->CheckArgument(arg, "--schedule-random")) { + if (this->CheckArgument(arg, "--schedule-random"_s)) { this->Impl->ScheduleType = "Random"; } @@ -2364,7 +2369,7 @@ bool cmCTest::HandleTestActionArgument(const char* ctestExec, size_t& i, { bool success = true; std::string arg = args[i]; - if (this->CheckArgument(arg, "-T", "--test-action") && + if (this->CheckArgument(arg, "-T"_s, "--test-action") && (i < args.size() - 1)) { this->Impl->ProduceXML = true; i++; @@ -2396,15 +2401,15 @@ bool cmCTest::HandleTestModelArgument(const char* ctestExec, size_t& i, { bool success = true; std::string arg = args[i]; - if (this->CheckArgument(arg, "-M", "--test-model") && + if (this->CheckArgument(arg, "-M"_s, "--test-model") && (i < args.size() - 1)) { i++; std::string const& str = args[i]; - if (cmSystemTools::LowerCase(str) == "nightly") { + if (cmSystemTools::LowerCase(str) == "nightly"_s) { this->SetTestModel(cmCTest::NIGHTLY); - } else if (cmSystemTools::LowerCase(str) == "continuous") { + } else if (cmSystemTools::LowerCase(str) == "continuous"_s) { this->SetTestModel(cmCTest::CONTINUOUS); - } else if (cmSystemTools::LowerCase(str) == "experimental") { + } else if (cmSystemTools::LowerCase(str) == "experimental"_s) { this->SetTestModel(cmCTest::EXPERIMENTAL); } else { success = false; @@ -2722,7 +2727,7 @@ std::string cmCTest::GetSubmitURL() std::string site = this->GetCTestConfiguration("DropSite"); std::string location = this->GetCTestConfiguration("DropLocation"); - url = cmStrCat(method.empty() ? "http" : method, "://"); + url = cmStrCat(method.empty() ? "http" : method, "://"_s); if (!user.empty()) { url += user; if (!password.empty()) { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 7177b76..984be13 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -13,6 +13,8 @@ #include <string> #include <vector> +#include <cm/string_view> + #include "cmDuration.h" #include "cmProcessOutput.h" @@ -507,8 +509,8 @@ private: std::vector<std::string> const& files); /** Check if the argument is the one specified */ - bool CheckArgument(const std::string& arg, const char* varg1, - const char* varg2 = nullptr); + static bool CheckArgument(const std::string& arg, cm::string_view varg1, + const char* varg2 = nullptr); /** Output errors from a test */ void OutputTestErrors(std::vector<char> const& process_output); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 4be4820..59e7a37 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -24,6 +24,7 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" +#include "cm_static_string_view.hxx" #include "cm_sys_stat.h" #include "cmAlgorithms.h" @@ -524,11 +525,11 @@ bool cmake::FindPackage(const std::vector<std::string>& args) if (!quiet) { printf("%s not found.\n", packageName.c_str()); } - } else if (mode == "EXIST") { + } else if (mode == "EXIST"_s) { if (!quiet) { printf("%s found.\n", packageName.c_str()); } - } else if (mode == "COMPILE") { + } else if (mode == "COMPILE"_s) { std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); std::vector<std::string> includeDirs = cmExpandedList(includes); @@ -539,7 +540,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args) std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); - } else if (mode == "LINK") { + } else if (mode == "LINK"_s) { const char* targetName = "dummy"; std::vector<std::string> srcs; cmTarget* tgt = mf->AddExecutable(targetName, srcs, true); @@ -671,7 +672,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) } else if ((i < args.size() - 1) && cmHasLiteralPrefix(arg, "--check-stamp-list")) { this->CheckStampList = args[++i]; - } else if (arg == "--regenerate-during-build") { + } else if (arg == "--regenerate-during-build"_s) { this->RegenerateDuringBuild = true; } #if defined(CMAKE_HAVE_VS_GENERATORS) @@ -745,7 +746,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) } this->SetLogLevel(logLevel); this->LogLevelWasSetViaCLI = true; - } else if (arg == "--log-context") { + } else if (arg == "--log-context"_s) { this->SetShowLogContext(true); } else if (cmHasLiteralPrefix(arg, "--debug-find")) { std::cout << "Running with debug output on for the `find` commands.\n"; @@ -886,7 +887,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) "--profiling-format specified but no --profiling-output!"); return; } - if (profilingFormat == "google-trace") { + if (profilingFormat == "google-trace"_s) { try { this->ProfilingOutput = cm::make_unique<cmMakefileProfilingData>(profilingOutput); @@ -1037,9 +1038,9 @@ void cmake::SetDirectoriesFromFile(const std::string& arg) std::string fullPath = cmSystemTools::CollapseFullPath(arg); std::string name = cmSystemTools::GetFilenameName(fullPath); name = cmSystemTools::LowerCase(name); - if (name == "cmakecache.txt") { + if (name == "cmakecache.txt"_s) { cachePath = cmSystemTools::GetFilenamePath(fullPath); - } else if (name == "cmakelists.txt") { + } else if (name == "cmakelists.txt"_s) { listPath = cmSystemTools::GetFilenamePath(fullPath); } } else { @@ -1048,7 +1049,7 @@ void cmake::SetDirectoriesFromFile(const std::string& arg) std::string fullPath = cmSystemTools::CollapseFullPath(arg); std::string name = cmSystemTools::GetFilenameName(fullPath); name = cmSystemTools::LowerCase(name); - if (name == "cmakecache.txt" || name == "cmakelists.txt") { + if (name == "cmakecache.txt"_s || name == "cmakelists.txt"_s) { argIsFile = true; listPath = cmSystemTools::GetFilenamePath(fullPath); } else { @@ -1936,13 +1937,13 @@ void cmake::AddCacheEntry(const std::string& key, const char* value, cmStateEnums::CacheEntryType(type)); this->UnwatchUnusedCli(key); - if (key == "CMAKE_WARN_DEPRECATED") { + if (key == "CMAKE_WARN_DEPRECATED"_s) { this->Messenger->SetSuppressDeprecatedWarnings(value && cmIsOff(value)); - } else if (key == "CMAKE_ERROR_DEPRECATED") { + } else if (key == "CMAKE_ERROR_DEPRECATED"_s) { this->Messenger->SetDeprecatedWarningsAsErrors(cmIsOn(value)); - } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") { + } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS"_s) { this->Messenger->SetSuppressDevWarnings(cmIsOn(value)); - } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") { + } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS"_s) { this->Messenger->SetDevWarningsAsErrors(value && cmIsOff(value)); } } |