| 140 | } // anonymous namespace |
| 141 | |
| 142 | bool cmBlockCommand(std::vector<std::string> const& args, |
| 143 | cmExecutionStatus& status) |
| 144 | { |
| 145 | struct Arguments : public ArgumentParser::ParseResult |
| 146 | { |
| 147 | cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>> ScopeFor; |
| 148 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Propagate; |
| 149 | }; |
| 150 | static auto const parser = cmArgumentParser<Arguments>{} |
| 151 | .Bind("SCOPE_FOR"_s, &Arguments::ScopeFor) |
| 152 | .Bind("PROPAGATE"_s, &Arguments::Propagate); |
| 153 | std::vector<std::string> unrecognizedArguments; |
| 154 | auto parsedArgs = parser.Parse(args, &unrecognizedArguments); |
| 155 | |
| 156 | if (!unrecognizedArguments.empty()) { |
| 157 | status.SetError(cmStrCat("called with unsupported argument \"", |
| 158 | unrecognizedArguments[0], '"')); |
| 159 | cmSystemTools::SetFatalErrorOccurred(); |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | if (parsedArgs.MaybeReportError(status.GetMakefile())) { |
| 164 | cmSystemTools::SetFatalErrorOccurred(); |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | ScopeSet scopes; |
| 169 | |
| 170 | if (parsedArgs.ScopeFor) { |
| 171 | for (auto const& scope : *parsedArgs.ScopeFor) { |
| 172 | if (scope == "VARIABLES"_s) { |
| 173 | scopes.insert(ScopeType::VARIABLES); |
| 174 | continue; |
| 175 | } |
| 176 | if (scope == "POLICIES"_s) { |
| 177 | scopes.insert(ScopeType::POLICIES); |
| 178 | continue; |
| 179 | } |
| 180 | status.SetError(cmStrCat("SCOPE_FOR unsupported scope \"", scope, '"')); |
| 181 | cmSystemTools::SetFatalErrorOccurred(); |
| 182 | return false; |
| 183 | } |
| 184 | } else { |
| 185 | scopes = { ScopeType::VARIABLES, ScopeType::POLICIES }; |
| 186 | } |
| 187 | if (!scopes.contains(ScopeType::VARIABLES) && |
| 188 | !parsedArgs.Propagate.empty()) { |
| 189 | status.SetError( |
| 190 | "PROPAGATE cannot be specified without a new scope for VARIABLES"); |
| 191 | cmSystemTools::SetFatalErrorOccurred(); |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | // create a function blocker |
| 196 | auto fb = cm::make_unique<cmBlockFunctionBlocker>( |
| 197 | &status.GetMakefile(), scopes, parsedArgs.Propagate); |
| 198 | status.GetMakefile().AddFunctionBlocker(std::move(fb)); |
| 199 |
nothing calls this directly
no test coverage detected
searching dependent graphs…