summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-14 12:33:17 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-05-14 12:33:29 (GMT)
commite2c52095326c2540d334c936ba73ec0be47d5e34 (patch)
treebce6cb3a405dd0c36511f7bbd1f03093d0508d00 /Source
parent02e50a4c0ac2b06e5706e05c4b4ed71679658ed4 (diff)
parentf78b167a2364d81fe8effab5face0ff888f6d9c2 (diff)
downloadCMake-e2c52095326c2540d334c936ba73ec0be47d5e34.zip
CMake-e2c52095326c2540d334c936ba73ec0be47d5e34.tar.gz
CMake-e2c52095326c2540d334c936ba73ec0be47d5e34.tar.bz2
Merge topic 'cmake_build_and_install_command_error_when_given_bad_arguments'
f78b167a23 cmCommandLineArgument: Provide more information syntax error messages 5aa0dec6b0 cmake: `--build` and `--install` error out when encountering bad flags 928cdb17c5 cmCommandLineArgument: Correctly record parsing failures Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6119
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommandLineArgument.h15
-rw-r--r--Source/cmakemain.cxx26
2 files changed, 30 insertions, 11 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h
index b14cfc2..5031c65 100644
--- a/Source/cmCommandLineArgument.h
+++ b/Source/cmCommandLineArgument.h
@@ -25,7 +25,7 @@ struct cmCommandLineArgument
template <typename FunctionType>
cmCommandLineArgument(std::string n, Values t, FunctionType&& func)
- : InvalidSyntaxMessage(cmStrCat("Invalid syntax used with ", n))
+ : InvalidSyntaxMessage(cmStrCat(" is invalid syntax for ", n))
, InvalidValueMessage(cmStrCat("Invalid value used with ", n))
, Name(std::move(n))
, Type(t)
@@ -36,7 +36,7 @@ struct cmCommandLineArgument
template <typename FunctionType>
cmCommandLineArgument(std::string n, std::string failedMsg, Values t,
FunctionType&& func)
- : InvalidSyntaxMessage(cmStrCat("Invalid syntax used with ", n))
+ : InvalidSyntaxMessage(cmStrCat(" is invalid syntax for ", n))
, InvalidValueMessage(std::move(failedMsg))
, Name(std::move(n))
, Type(t)
@@ -98,17 +98,11 @@ struct cmCommandLineArgument
// parse the string to get the value
auto possible_value = cm::string_view(input).substr(this->Name.size());
if (possible_value.empty()) {
- parseState = ParseMode::SyntaxError;
parseState = ParseMode::ValueError;
} else if (possible_value[0] == '=') {
possible_value.remove_prefix(1);
if (possible_value.empty()) {
parseState = ParseMode::ValueError;
- } else {
- parseState = this->StoreCall(std::string(possible_value),
- std::forward<CallState>(state)...)
- ? ParseMode::Valid
- : ParseMode::Invalid;
}
}
if (parseState == ParseMode::Valid) {
@@ -154,11 +148,14 @@ struct cmCommandLineArgument
: ParseMode::Invalid;
index = (nextValueIndex - 1);
}
+ } else {
+ parseState = ParseMode::SyntaxError;
}
}
if (parseState == ParseMode::SyntaxError) {
- cmSystemTools::Error(this->InvalidSyntaxMessage);
+ cmSystemTools::Error(
+ cmStrCat("'", input, "'", this->InvalidSyntaxMessage));
} else if (parseState == ParseMode::ValueError) {
cmSystemTools::Error(this->InvalidValueMessage);
}
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 88ba011..ad64818 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -532,11 +532,22 @@ int do_build(int ac, char const* const* av)
for (; i < inputArgs.size() && !nativeOptionsPassed; ++i) {
std::string const& arg = inputArgs[i];
+ bool matched = false;
+ bool parsed = false;
for (auto const& m : arguments) {
- if (m.matches(arg) && m.parse(arg, i, inputArgs)) {
+ matched = m.matches(arg);
+ if (matched) {
+ parsed = m.parse(arg, i, inputArgs);
break;
}
}
+ if (!(matched && parsed)) {
+ dir.clear();
+ if (!matched) {
+ std::cerr << "Unknown argument " << arg << std::endl;
+ }
+ break;
+ }
}
if (nativeOptionsPassed) {
@@ -806,11 +817,22 @@ int do_install(int ac, char const* const* av)
for (decltype(inputArgs.size()) i = 0; i < inputArgs.size(); ++i) {
std::string const& arg = inputArgs[i];
+ bool matched = false;
+ bool parsed = false;
for (auto const& m : arguments) {
- if (m.matches(arg) && m.parse(arg, i, inputArgs)) {
+ matched = m.matches(arg);
+ if (matched) {
+ parsed = m.parse(arg, i, inputArgs);
break;
}
}
+ if (!(matched && parsed)) {
+ dir.clear();
+ if (!matched) {
+ std::cerr << "Unknown argument " << arg << std::endl;
+ }
+ break;
+ }
}
}