cmake_command: Preserve arguments to INVOKE function

Fixes: #20630
This commit is contained in:
Cristian Adam
2020-05-12 21:19:31 +02:00
parent 4dc9552686
commit 549599bf32
5 changed files with 40 additions and 8 deletions

View File

@@ -4,6 +4,9 @@
#include <algorithm>
#include <cstddef>
#include <iosfwd>
#include <memory>
#include <string>
#include "cmExecutionStatus.h"
#include "cmListFileCache.h"
@@ -11,7 +14,14 @@
#include "cmRange.h"
#include "cmStringAlgorithms.h"
bool cmCMakeCommand(std::vector<std::string> const& args,
inline std::ostream& operator<<(std::ostream& os,
cmListFileArgument const& arg)
{
os << arg.Value;
return os;
}
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
if (args.empty()) {
@@ -24,7 +34,7 @@ bool cmCMakeCommand(std::vector<std::string> const& args,
bool result = false;
if (args[0] == "INVOKE") {
if (args[0].Value == "INVOKE") {
if (args.size() == 1) {
status.SetError("called with incorrect number of arguments");
return false;
@@ -32,26 +42,29 @@ bool cmCMakeCommand(std::vector<std::string> const& args,
// First argument is the name of the function to call
cmListFileFunction func;
func.Name = args[1];
func.Name = args[1].Value;
func.Line = context.Line;
// The rest of the arguments are passed to the function call above
func.Arguments.resize(args.size() - 1);
for (size_t i = 2; i < args.size(); ++i) {
cmListFileArgument lfarg;
lfarg.Delim = args[i].Delim;
lfarg.Line = context.Line;
lfarg.Value = args[i];
lfarg.Value = args[i].Value;
func.Arguments.emplace_back(lfarg);
}
result = makefile.ExecuteCommand(func, status);
} else if (args[0] == "EVAL") {
} else if (args[0].Value == "EVAL") {
if (args.size() < 2) {
status.SetError("called with incorrect number of arguments");
return false;
}
auto code_iter = std::find(args.begin(), args.end(), "CODE");
auto code_iter = std::find_if(
args.begin(), args.end(),
[](cmListFileArgument const& arg) { return arg.Value == "CODE"; });
if (code_iter == args.end()) {
status.SetError("called without CODE argument");
return false;

View File

@@ -5,16 +5,16 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
class cmExecutionStatus;
struct cmListFileArgument;
/**
* \brief Calls a scripted or build-in command
*
*/
bool cmCMakeCommand(std::vector<std::string> const& args,
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status);
#endif

View File

@@ -5,6 +5,7 @@ run_cmake(cmake_command_unknown_meta_operation)
run_cmake(cmake_command_invoke_message)
run_cmake(cmake_command_invoke_message_fatal_error)
run_cmake(cmake_command_invoke_no_parameters)
run_cmake(cmake_command_invoke_preserve_arguments)
run_cmake(cmake_command_invoke_unknown_function)
run_cmake(cmake_command_eval_message)
run_cmake(cmake_command_eval_message_fatal_error)

View File

@@ -0,0 +1,6 @@
foo\(...\)
\[a;b\]
\[c;d\]
cmake_command\(INVOKE foo ...\)
\[a;b\]
\[c;d\]

View File

@@ -0,0 +1,12 @@
function(foo arg1 arg2)
math(EXPR last "${ARGC} - 1")
foreach(i RANGE 0 ${last})
message("[${ARGV${i}}]")
endforeach()
endfunction()
message("foo(...)")
foo("a;b" "c;d")
message("cmake_command(INVOKE foo ...)")
cmake_command(INVOKE foo "a;b" "c;d")