diff options
4 files changed, 15 insertions, 5 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index 6b75da0..b14cfc2 100644 --- a/Source/cmCommandLineArgument.h +++ b/Source/cmCommandLineArgument.h @@ -76,8 +76,9 @@ struct cmCommandLineArgument } else if (this->Type == Values::One || this->Type == Values::ZeroOrOne) { if (input.size() == this->Name.size()) { - ++index; - if (index >= allArgs.size() || allArgs[index][0] == '-') { + auto nextValueIndex = index + 1; + if (nextValueIndex >= allArgs.size() || + allArgs[nextValueIndex][0] == '-') { if (this->Type == Values::ZeroOrOne) { parseState = this->StoreCall(std::string{}, std::forward<CallState>(state)...) @@ -87,10 +88,11 @@ struct cmCommandLineArgument parseState = ParseMode::ValueError; } } else { - parseState = - this->StoreCall(allArgs[index], std::forward<CallState>(state)...) + parseState = this->StoreCall(allArgs[nextValueIndex], + std::forward<CallState>(state)...) ? ParseMode::Valid : ParseMode::Invalid; + index = nextValueIndex; } } else { // parse the string to get the value @@ -137,7 +139,8 @@ struct cmCommandLineArgument } else if (this->Type == Values::OneOrMore) { if (input.size() == this->Name.size()) { auto nextValueIndex = index + 1; - if (nextValueIndex >= allArgs.size() || allArgs[index + 1][0] == '-') { + if (nextValueIndex >= allArgs.size() || + allArgs[nextValueIndex][0] == '-') { parseState = ParseMode::ValueError; } else { std::string buffer = allArgs[nextValueIndex++]; @@ -149,6 +152,7 @@ struct cmCommandLineArgument this->StoreCall(buffer, std::forward<CallState>(state)...) ? ParseMode::Valid : ParseMode::Invalid; + index = (nextValueIndex - 1); } } } diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-result.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-result.txt new file mode 100644 index 0000000..3beecb0 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-result.txt @@ -0,0 +1 @@ +(1|2) diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-stderr.txt new file mode 100644 index 0000000..ee4bcc0 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-jobs-no-number-trailing--invalid-target-stderr.txt @@ -0,0 +1 @@ +.*(ninja: error: unknown target 'invalid-target'|No rule to make target [`']invalid-target').* diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index a2b2044..c497472 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -212,6 +212,10 @@ function(run_BuildDir) ${CMAKE_COMMAND} --build BuildDir-build -j) run_cmake_command(BuildDir--build-jobs-no-number-trailing--target ${CMAKE_COMMAND} -E chdir .. ${CMAKE_COMMAND} --build BuildDir-build -j --target CustomTarget) + if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja") + run_cmake_command(BuildDir--build-jobs-no-number-trailing--invalid-target ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build -j --target invalid-target) + endif() run_cmake_command(BuildDir--build--parallel-no-number ${CMAKE_COMMAND} -E chdir .. ${CMAKE_COMMAND} --build BuildDir-build --parallel) run_cmake_command(BuildDir--build--parallel-no-number-trailing--target ${CMAKE_COMMAND} -E chdir .. |