| 62 | } |
| 63 | |
| 64 | bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions, |
| 65 | cmExecutionStatus& inStatus) |
| 66 | { |
| 67 | auto& mf = inStatus.GetMakefile(); |
| 68 | |
| 69 | cmListFileBacktrace whileBT = |
| 70 | mf.GetBacktrace().Push(this->GetStartingContext()); |
| 71 | |
| 72 | std::vector<cmExpandedCommandArgument> expandedArguments; |
| 73 | // At least same size expected for `expandedArguments` as `Args` |
| 74 | expandedArguments.reserve(this->Args.size()); |
| 75 | |
| 76 | auto expandArgs = [&mf](std::vector<cmListFileArgument> const& args, |
| 77 | std::vector<cmExpandedCommandArgument>& out) |
| 78 | -> std::vector<cmExpandedCommandArgument>& { |
| 79 | out.clear(); |
| 80 | mf.ExpandArguments(args, out); |
| 81 | return out; |
| 82 | }; |
| 83 | |
| 84 | // For compatibility with projects that do not set CMP0130 to NEW, |
| 85 | // we tolerate condition errors that evaluate to false. |
| 86 | bool enforceError = true; |
| 87 | std::string errorString; |
| 88 | MessageType messageType; |
| 89 | |
| 90 | for (cmConditionEvaluator conditionEvaluator(mf, whileBT); |
| 91 | (enforceError = /* enforce condition errors that evaluate to true */ |
| 92 | conditionEvaluator.IsTrue(expandArgs(this->Args, expandedArguments), |
| 93 | errorString, messageType));) { |
| 94 | // Invoke all the functions that were collected in the block. |
| 95 | for (cmListFileFunction const& fn : functions) { |
| 96 | cmExecutionStatus status(mf); |
| 97 | mf.ExecuteCommand(fn, status); |
| 98 | if (status.GetReturnInvoked()) { |
| 99 | inStatus.SetReturnInvoked(status.GetReturnVariables()); |
| 100 | return true; |
| 101 | } |
| 102 | if (status.GetBreakInvoked()) { |
| 103 | return true; |
| 104 | } |
| 105 | if (status.GetContinueInvoked()) { |
| 106 | break; |
| 107 | } |
| 108 | if (status.HasExitCode()) { |
| 109 | inStatus.SetExitCode(status.GetExitCode()); |
| 110 | return true; |
| 111 | } |
| 112 | if (cmSystemTools::GetFatalErrorOccurred()) { |
| 113 | return true; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if (!errorString.empty() && !enforceError) { |
| 119 | // This error should only be enforced if CMP0130 is NEW. |
| 120 | switch (mf.GetPolicyStatus(cmPolicies::CMP0130)) { |
| 121 | case cmPolicies::WARN: |
nothing calls this directly
no test coverage detected