diff options
author | Brad King <brad.king@kitware.com> | 2022-07-20 14:24:35 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-28 08:25:00 -0400 |
commit | 4368a524c64b4ea31f7f578cc4972116c9c20780 (patch) | |
tree | b7c0320a9232c9da4dfe48b7a8be7a45bf6d8291 /Source/cmCMakePathCommand.cxx | |
parent | 7ca8d9f0f854acd71f2a2134d86a1e182496c4cc (diff) | |
download | cmake-4368a524c64b4ea31f7f578cc4972116c9c20780.tar.gz |
cmCMakePathCommand: Enforce non-empty string arguments via binding type
Diffstat (limited to 'Source/cmCMakePathCommand.cxx')
-rw-r--r-- | Source/cmCMakePathCommand.cxx | 44 |
1 files changed, 5 insertions, 39 deletions
diff --git a/Source/cmCMakePathCommand.cxx b/Source/cmCMakePathCommand.cxx index b955bcf287..7755082236 100644 --- a/Source/cmCMakePathCommand.cxx +++ b/Source/cmCMakePathCommand.cxx @@ -15,6 +15,7 @@ #include <cmext/string_view> #include "cmArgumentParser.h" +#include "cmArgumentParserTypes.h" #include "cmCMakePath.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -82,22 +83,11 @@ public: return this->CMakePathArgumentParser<Result>::template Parse<Advance>( args); } - - bool checkOutputVariable(const Result& arguments, - cmExecutionStatus& status) const - { - if (arguments.Output && arguments.Output->empty()) { - status.SetError("Invalid name for output variable."); - return false; - } - - return true; - } }; struct OutputVariable : public ArgumentParser::ParseResult { - cm::optional<std::string> Output; + cm::optional<ArgumentParser::NonEmpty<std::string>> Output; }; // Usable when OUTPUT_VARIABLE is the only option class OutputVariableParser @@ -270,9 +260,6 @@ bool HandleAppendCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } cmCMakePath path(status.GetMakefile().GetSafeDefinition(args[1])); for (const auto& input : parser.GetInputs()) { @@ -295,9 +282,6 @@ bool HandleAppendStringCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } std::string inputPath; if (!getInputPath(args[1], status, inputPath)) { @@ -325,9 +309,6 @@ bool HandleRemoveFilenameCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (!parser.GetInputs().empty()) { status.SetError("REMOVE_FILENAME called with unexpected arguments."); @@ -358,9 +339,6 @@ bool HandleReplaceFilenameCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (parser.GetInputs().size() > 1) { status.SetError("REPLACE_FILENAME called with unexpected arguments."); @@ -387,7 +365,7 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args, { struct Arguments : public ArgumentParser::ParseResult { - cm::optional<std::string> Output; + cm::optional<ArgumentParser::NonEmpty<std::string>> Output; bool LastOnly = false; }; @@ -400,9 +378,6 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (!parser.GetInputs().empty()) { status.SetError("REMOVE_EXTENSION called with unexpected arguments."); @@ -433,7 +408,7 @@ bool HandleReplaceExtensionCommand(std::vector<std::string> const& args, { struct Arguments : public ArgumentParser::ParseResult { - cm::optional<std::string> Output; + cm::optional<ArgumentParser::NonEmpty<std::string>> Output; bool LastOnly = false; }; @@ -446,9 +421,6 @@ bool HandleReplaceExtensionCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (parser.GetInputs().size() > 1) { status.SetError("REPLACE_EXTENSION called with unexpected arguments."); @@ -486,9 +458,6 @@ bool HandleNormalPathCommand(std::vector<std::string> const& args, if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (!parser.GetInputs().empty()) { status.SetError("NORMAL_PATH called with unexpected arguments."); @@ -516,7 +485,7 @@ bool HandleTransformPathCommand( { struct Arguments : public ArgumentParser::ParseResult { - cm::optional<std::string> Output; + cm::optional<ArgumentParser::NonEmpty<std::string>> Output; cm::optional<std::string> BaseDirectory; bool Normalize = false; }; @@ -532,9 +501,6 @@ bool HandleTransformPathCommand( if (arguments.MaybeReportError(status.GetMakefile())) { return true; } - if (!parser.checkOutputVariable(arguments, status)) { - return false; - } if (!parser.GetInputs().empty()) { status.SetError(cmStrCat(args[0], " called with unexpected arguments.")); |