From 4ebe9c4ce15734ee9a167f7b48b8ed8931adb0ca Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 21 Sep 2020 14:53:10 -0400 Subject: cmake_language(EVAL): Factor out internal helper --- Source/cmCMakeLanguageCommand.cxx | 56 ++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx index d513611..ae80066 100644 --- a/Source/cmCMakeLanguageCommand.cxx +++ b/Source/cmCMakeLanguageCommand.cxx @@ -28,6 +28,37 @@ std::array InvalidCommands{ "foreach"_s, "endforeach"_s } // clang-format on }; + +bool cmCMakeLanguageCommandEVAL(std::vector const& args, + cmExecutionStatus& status) +{ + cmMakefile& makefile = status.GetMakefile(); + cmListFileContext context = makefile.GetBacktrace().Top(); + std::vector expandedArgs; + makefile.ExpandArguments(args, expandedArgs); + + if (expandedArgs.size() < 2) { + status.SetError("called with incorrect number of arguments"); + return false; + } + + if (expandedArgs[1] != "CODE") { + auto code_iter = + std::find(expandedArgs.begin() + 2, expandedArgs.end(), "CODE"); + if (code_iter == expandedArgs.end()) { + status.SetError("called without CODE argument"); + } else { + status.SetError( + "called with unsupported arguments between EVAL and CODE arguments"); + } + return false; + } + + const std::string code = + cmJoin(cmMakeRange(expandedArgs.begin() + 2, expandedArgs.end()), " "); + return makefile.ReadListFileAsString( + code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL")); +} } bool cmCMakeLanguageCommand(std::vector const& args, @@ -105,30 +136,7 @@ bool cmCMakeLanguageCommand(std::vector const& args, result = makefile.ExecuteCommand(func, status); } else if (dispatchExpandedArgs[0] == "EVAL") { - std::vector expandedArgs; - makefile.ExpandArguments(args, expandedArgs); - - if (expandedArgs.size() < 2) { - status.SetError("called with incorrect number of arguments"); - return false; - } - - if (expandedArgs[1] != "CODE") { - auto code_iter = - std::find(expandedArgs.begin() + 2, expandedArgs.end(), "CODE"); - if (code_iter == expandedArgs.end()) { - status.SetError("called without CODE argument"); - } else { - status.SetError( - "called with unsupported arguments between EVAL and CODE arguments"); - } - return false; - } - - const std::string code = - cmJoin(cmMakeRange(expandedArgs.begin() + 2, expandedArgs.end()), " "); - result = makefile.ReadListFileAsString( - code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL")); + return cmCMakeLanguageCommandEVAL(args, status); } else { status.SetError("called with unknown meta-operation"); } -- cgit v0.12