| 108 | } |
| 109 | |
| 110 | bool cmForEachFunctionBlocker::ReplayItems( |
| 111 | std::vector<cmListFileFunction> const& functions, |
| 112 | cmExecutionStatus& inStatus) |
| 113 | { |
| 114 | assert("Unexpected number of iteration variables" && |
| 115 | this->IterationVarsCount == 1); |
| 116 | |
| 117 | auto& mf = inStatus.GetMakefile(); |
| 118 | |
| 119 | // At end of for each execute recorded commands |
| 120 | // store the old value |
| 121 | cm::optional<std::string> oldDef; |
| 122 | if (mf.GetPolicyStatus(cmPolicies::CMP0124) != cmPolicies::NEW) { |
| 123 | oldDef = mf.GetSafeDefinition(this->Args.front()); |
| 124 | } else if (mf.IsNormalDefinitionSet(this->Args.front())) { |
| 125 | oldDef = *mf.GetDefinition(this->Args.front()); |
| 126 | } |
| 127 | |
| 128 | auto restore = false; |
| 129 | for (std::string const& arg : cmMakeRange(this->Args).advance(1)) { |
| 130 | // Set the variable to the loop value |
| 131 | mf.AddDefinition(this->Args.front(), arg); |
| 132 | // Invoke all the functions that were collected in the block. |
| 133 | auto r = this->invoke(functions, inStatus, mf); |
| 134 | restore = r.Restore; |
| 135 | if (r.Break) { |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (restore) { |
| 141 | if (oldDef) { |
| 142 | // restore the variable to its prior value |
| 143 | mf.AddDefinition(this->Args.front(), *oldDef); |
| 144 | } else { |
| 145 | mf.RemoveDefinition(this->Args.front()); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | bool cmForEachFunctionBlocker::ReplayZipLists( |
| 153 | std::vector<cmListFileFunction> const& functions, |
no test coverage detected