OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <set> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "tools/gn/commands.h" |
| 10 #include "tools/gn/config.h" |
| 11 #include "tools/gn/config_values_extractors.h" |
| 12 #include "tools/gn/deps_iterator.h" |
| 13 #include "tools/gn/desc_builder.h" |
| 14 #include "tools/gn/input_file.h" |
| 15 #include "tools/gn/parse_tree.h" |
| 16 #include "tools/gn/runtime_deps.h" |
| 17 #include "tools/gn/substitution_writer.h" |
| 18 #include "tools/gn/variables.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 std::string FormatSourceDir(const SourceDir& dir) { |
| 23 #if defined(OS_WIN) |
| 24 // On Windows we fix up system absolute paths to look like native ones. |
| 25 // Internally, they'll look like "/C:\foo\bar/" |
| 26 if (dir.is_system_absolute()) { |
| 27 std::string buf = dir.value(); |
| 28 if (buf.size() > 3 && buf[2] == ':') { |
| 29 buf.erase(buf.begin()); // Erase beginning slash. |
| 30 return buf; |
| 31 } |
| 32 } |
| 33 #endif |
| 34 return dir.value(); |
| 35 } |
| 36 |
| 37 void RecursiveCollectChildDeps(const Target* target, |
| 38 std::set<const Target*>* result); |
| 39 |
| 40 void RecursiveCollectDeps(const Target* target, |
| 41 std::set<const Target*>* result) { |
| 42 if (result->find(target) != result->end()) |
| 43 return; // Already did this target. |
| 44 result->insert(target); |
| 45 |
| 46 RecursiveCollectChildDeps(target, result); |
| 47 } |
| 48 |
| 49 void RecursiveCollectChildDeps(const Target* target, |
| 50 std::set<const Target*>* result) { |
| 51 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) |
| 52 RecursiveCollectDeps(pair.ptr, result); |
| 53 } |
| 54 |
| 55 // Common functionality for target and config description builder |
| 56 class BaseDescBuilder { |
| 57 public: |
| 58 typedef std::unique_ptr<base::Value> ValuePtr; |
| 59 |
| 60 BaseDescBuilder(const std::set<std::string>& what, |
| 61 bool all, |
| 62 bool tree, |
| 63 bool blame) |
| 64 : what_(what), all_(all), tree_(tree), blame_(blame) {} |
| 65 |
| 66 protected: |
| 67 virtual Label GetToolchainLabel() const = 0; |
| 68 |
| 69 bool what(const std::string& w) const { |
| 70 return what_.empty() || what_.find(w) != what_.end(); |
| 71 } |
| 72 |
| 73 template <typename T> |
| 74 ValuePtr RenderValue(const std::vector<T>& vector) { |
| 75 auto res = new base::ListValue(); |
| 76 for (const auto& v : vector) { |
| 77 res->Append(RenderValue(v)); |
| 78 } |
| 79 return base::WrapUnique(res); |
| 80 } |
| 81 |
| 82 ValuePtr RenderValue(const std::string& s, bool optional = false) { |
| 83 return (s.empty() && optional) ? base::Value::CreateNullValue() |
| 84 : ValuePtr(new base::StringValue(s)); |
| 85 } |
| 86 |
| 87 ValuePtr RenderValue(const SourceDir& d) { |
| 88 return d.is_null() ? base::Value::CreateNullValue() |
| 89 : ValuePtr(new base::StringValue(FormatSourceDir(d))); |
| 90 } |
| 91 |
| 92 ValuePtr RenderValue(const SourceFile& f) { |
| 93 return f.is_null() ? base::Value::CreateNullValue() |
| 94 : ValuePtr(new base::StringValue(f.value())); |
| 95 } |
| 96 |
| 97 ValuePtr RenderValue(const LibFile& lib) { |
| 98 if (lib.is_source_file()) |
| 99 return RenderValue(lib.source_file()); |
| 100 else |
| 101 return RenderValue(lib.value()); |
| 102 } |
| 103 |
| 104 template <class VectorType> |
| 105 void FillInConfigVector(base::ListValue* out, |
| 106 const VectorType& configs, |
| 107 int indent = 0) { |
| 108 for (const auto& config : configs) { |
| 109 std::string name(indent * 2, ' '); |
| 110 name.append(config.label.GetUserVisibleName(GetToolchainLabel())); |
| 111 out->AppendString(name); |
| 112 if (tree_) { |
| 113 FillInConfigVector(out, config.ptr->configs(), indent + 1); |
| 114 } |
| 115 } |
| 116 } |
| 117 |
| 118 void FillInPrecompiledHeader(base::DictionaryValue* out, |
| 119 const ConfigValues& values) { |
| 120 if (what(variables::kPrecompiledHeader) && |
| 121 !values.precompiled_header().empty()) { |
| 122 out->Set(variables::kPrecompiledHeader, |
| 123 RenderValue(values.precompiled_header(), true)); |
| 124 } |
| 125 if (what(variables::kPrecompiledSource) && |
| 126 !values.precompiled_source().is_null()) { |
| 127 out->Set(variables::kPrecompiledSource, |
| 128 RenderValue(values.precompiled_source())); |
| 129 } |
| 130 } |
| 131 |
| 132 std::set<std::string> what_; |
| 133 bool all_; |
| 134 bool tree_; |
| 135 bool blame_; |
| 136 }; |
| 137 |
| 138 class ConfigDescBuilder : public BaseDescBuilder { |
| 139 public: |
| 140 ConfigDescBuilder(const Config* config, const std::set<std::string>& what) |
| 141 : config_(config), BaseDescBuilder(what, false, false, false) {} |
| 142 |
| 143 std::unique_ptr<base::DictionaryValue> BuildDescription() { |
| 144 auto res = new base::DictionaryValue(); |
| 145 const ConfigValues& values = config_->resolved_values(); |
| 146 |
| 147 if (what_.empty()) { |
| 148 res->SetString( |
| 149 "toolchain", |
| 150 config_->label().GetToolchainLabel().GetUserVisibleName(false)); |
| 151 } |
| 152 |
| 153 if (what(variables::kConfigs) && !config_->configs().empty()) { |
| 154 auto configs = new base::ListValue(); |
| 155 FillInConfigVector(configs, config_->configs().vector()); |
| 156 res->Set(variables::kConfigs, configs); |
| 157 } |
| 158 |
| 159 #define CONFIG_VALUE_ARRAY_HANDLER(name, type) \ |
| 160 if (what(#name)) { \ |
| 161 ValuePtr ptr = \ |
| 162 render_config_value_array<type>(values, &ConfigValues::name); \ |
| 163 if (ptr) { \ |
| 164 res->Set(#name, std::move(ptr)); \ |
| 165 } \ |
| 166 } |
| 167 CONFIG_VALUE_ARRAY_HANDLER(arflags, std::string) |
| 168 CONFIG_VALUE_ARRAY_HANDLER(asmflags, std::string) |
| 169 CONFIG_VALUE_ARRAY_HANDLER(cflags, std::string) |
| 170 CONFIG_VALUE_ARRAY_HANDLER(cflags_c, std::string) |
| 171 CONFIG_VALUE_ARRAY_HANDLER(cflags_cc, std::string) |
| 172 CONFIG_VALUE_ARRAY_HANDLER(cflags_objc, std::string) |
| 173 CONFIG_VALUE_ARRAY_HANDLER(cflags_objcc, std::string) |
| 174 CONFIG_VALUE_ARRAY_HANDLER(defines, std::string) |
| 175 CONFIG_VALUE_ARRAY_HANDLER(include_dirs, SourceDir) |
| 176 CONFIG_VALUE_ARRAY_HANDLER(ldflags, std::string) |
| 177 CONFIG_VALUE_ARRAY_HANDLER(lib_dirs, SourceDir) |
| 178 CONFIG_VALUE_ARRAY_HANDLER(libs, LibFile) |
| 179 |
| 180 #undef CONFIG_VALUE_ARRAY_HANDLER |
| 181 |
| 182 FillInPrecompiledHeader(res, values); |
| 183 |
| 184 return base::WrapUnique(res); |
| 185 } |
| 186 |
| 187 protected: |
| 188 Label GetToolchainLabel() const override { |
| 189 return config_->label().GetToolchainLabel(); |
| 190 } |
| 191 |
| 192 private: |
| 193 template <typename T> |
| 194 ValuePtr render_config_value_array( |
| 195 const ConfigValues& values, |
| 196 const std::vector<T>& (ConfigValues::*getter)() const) { |
| 197 auto res = base::WrapUnique(new base::ListValue()); |
| 198 |
| 199 for (const T& cur : (values.*getter)()) { |
| 200 res->Append(RenderValue(cur)); |
| 201 } |
| 202 |
| 203 return res->empty() ? nullptr : std::move(res); |
| 204 } |
| 205 |
| 206 const Config* config_; |
| 207 }; |
| 208 |
| 209 class TargetDescBuilder : public BaseDescBuilder { |
| 210 public: |
| 211 TargetDescBuilder(const Target* target, |
| 212 const std::set<std::string>& what, |
| 213 bool all, |
| 214 bool tree, |
| 215 bool blame) |
| 216 : target_(target), BaseDescBuilder(what, all, tree, blame) {} |
| 217 |
| 218 std::unique_ptr<base::DictionaryValue> BuildDescription() { |
| 219 auto res = new base::DictionaryValue(); |
| 220 bool is_binary_output = target_->IsBinary(); |
| 221 |
| 222 if (what_.empty()) { |
| 223 res->SetString( |
| 224 "type", DescBuilder::GetStringForOutputType(target_->output_type())); |
| 225 res->SetString( |
| 226 "toolchain", |
| 227 target_->label().GetToolchainLabel().GetUserVisibleName(false)); |
| 228 } |
| 229 |
| 230 // General target meta variables. |
| 231 if (what(variables::kVisibility)) { |
| 232 res->Set(variables::kVisibility, target_->visibility().AsValue()); |
| 233 } |
| 234 if (what(variables::kTestonly)) { |
| 235 res->SetBoolean(variables::kTestonly, target_->testonly()); |
| 236 } |
| 237 |
| 238 if (is_binary_output) { |
| 239 if (what(variables::kCheckIncludes)) { |
| 240 res->SetBoolean(variables::kCheckIncludes, target_->check_includes()); |
| 241 } |
| 242 if (what(variables::kAllowCircularIncludesFrom)) { |
| 243 auto labels = new base::ListValue(); |
| 244 for (const auto& cur : target_->allow_circular_includes_from()) { |
| 245 labels->AppendString(cur.GetUserVisibleName(GetToolchainLabel())); |
| 246 } |
| 247 res->Set(variables::kAllowCircularIncludesFrom, labels); |
| 248 } |
| 249 } |
| 250 |
| 251 if (what(variables::kSources) && !target_->sources().empty()) { |
| 252 res->Set(variables::kSources, RenderValue(target_->sources())); |
| 253 } |
| 254 |
| 255 if (what(variables::kPublic)) { |
| 256 if (target_->all_headers_public()) |
| 257 res->SetString(variables::kPublic, "*"); |
| 258 else |
| 259 res->Set(variables::kPublic, RenderValue(target_->public_headers())); |
| 260 } |
| 261 |
| 262 if (what(variables::kInputs) && !target_->inputs().empty()) { |
| 263 res->Set(variables::kInputs, RenderValue(target_->inputs())); |
| 264 } |
| 265 |
| 266 if (is_binary_output && what(variables::kConfigs) && |
| 267 !target_->configs().empty()) { |
| 268 auto configs = new base::ListValue(); |
| 269 FillInConfigVector(configs, target_->configs().vector()); |
| 270 res->Set(variables::kConfigs, configs); |
| 271 } |
| 272 |
| 273 if (what(variables::kPublicConfigs) && !target_->public_configs().empty()) { |
| 274 auto configs = new base::ListValue(); |
| 275 FillInConfigVector(configs, target_->public_configs()); |
| 276 res->Set(variables::kPublicConfigs, configs); |
| 277 } |
| 278 |
| 279 if (what(variables::kAllDependentConfigs) && |
| 280 !target_->all_dependent_configs().empty()) { |
| 281 auto configs = new base::ListValue(); |
| 282 FillInConfigVector(configs, target_->all_dependent_configs()); |
| 283 res->Set(variables::kAllDependentConfigs, configs); |
| 284 } |
| 285 |
| 286 // Action |
| 287 if (target_->output_type() == Target::ACTION || |
| 288 target_->output_type() == Target::ACTION_FOREACH) { |
| 289 if (what(variables::kScript)) { |
| 290 res->SetString(variables::kScript, |
| 291 target_->action_values().script().value()); |
| 292 } |
| 293 if (what(variables::kArgs)) { |
| 294 auto args = new base::ListValue(); |
| 295 for (const auto& elem : target_->action_values().args().list()) { |
| 296 args->AppendString(elem.AsString()); |
| 297 } |
| 298 res->Set(variables::kArgs, args); |
| 299 } |
| 300 if (what(variables::kDepfile) && |
| 301 !target_->action_values().depfile().empty()) { |
| 302 res->SetString(variables::kDepfile, |
| 303 target_->action_values().depfile().AsString()); |
| 304 } |
| 305 } |
| 306 |
| 307 if (target_->output_type() == Target::ACTION || |
| 308 target_->output_type() == Target::ACTION_FOREACH || |
| 309 target_->output_type() == Target::COPY_FILES || |
| 310 target_->output_type() == Target::CREATE_BUNDLE) { |
| 311 if (what(variables::kOutputs)) { |
| 312 FillInOutputs(res, target_); |
| 313 } |
| 314 } |
| 315 |
| 316 if (target_->output_type() == Target::CREATE_BUNDLE && |
| 317 what("bundle_data")) { |
| 318 FillInBundle(res, target_); |
| 319 } |
| 320 |
| 321 if (is_binary_output) { |
| 322 #define CONFIG_VALUE_ARRAY_HANDLER(name, type) \ |
| 323 if (what(#name)) { \ |
| 324 ValuePtr ptr = RenderConfigValues<type>(&ConfigValues::name); \ |
| 325 if (ptr) { \ |
| 326 res->Set(#name, std::move(ptr)); \ |
| 327 } \ |
| 328 } |
| 329 CONFIG_VALUE_ARRAY_HANDLER(arflags, std::string) |
| 330 CONFIG_VALUE_ARRAY_HANDLER(asmflags, std::string) |
| 331 CONFIG_VALUE_ARRAY_HANDLER(cflags, std::string) |
| 332 CONFIG_VALUE_ARRAY_HANDLER(cflags_c, std::string) |
| 333 CONFIG_VALUE_ARRAY_HANDLER(cflags_cc, std::string) |
| 334 CONFIG_VALUE_ARRAY_HANDLER(cflags_objc, std::string) |
| 335 CONFIG_VALUE_ARRAY_HANDLER(cflags_objcc, std::string) |
| 336 CONFIG_VALUE_ARRAY_HANDLER(defines, std::string) |
| 337 CONFIG_VALUE_ARRAY_HANDLER(include_dirs, SourceDir) |
| 338 CONFIG_VALUE_ARRAY_HANDLER(ldflags, std::string) |
| 339 #undef CONFIG_VALUE_ARRAY_HANDLER |
| 340 |
| 341 // Libs and lib_dirs are handled specially below. |
| 342 |
| 343 FillInPrecompiledHeader(res, target_->config_values()); |
| 344 } |
| 345 |
| 346 if (what(variables::kDeps)) { |
| 347 res->Set(variables::kDeps, RenderDeps()); |
| 348 } |
| 349 |
| 350 // Runtime deps are special, print only when explicitly asked for and not in |
| 351 // overview mode. |
| 352 if (what_.find("runtime_deps") != what_.end()) { |
| 353 res->Set("runtime_deps", RenderRuntimeDeps()); |
| 354 } |
| 355 |
| 356 // libs and lib_dirs are special in that they're inherited. We don't |
| 357 // currently |
| 358 // implement a blame feature for this since the bottom-up inheritance makes |
| 359 // this difficult. |
| 360 |
| 361 // Libs can be part of any target and get recursively pushed up the chain, |
| 362 // so display them regardless of target type. |
| 363 if (what(variables::kLibs)) { |
| 364 const OrderedSet<LibFile>& all_libs = target_->all_libs(); |
| 365 if (!all_libs.empty()) { |
| 366 auto libs = new base::ListValue(); |
| 367 for (size_t i = 0; i < all_libs.size(); i++) |
| 368 libs->AppendString(all_libs[i].value()); |
| 369 res->Set(variables::kLibs, libs); |
| 370 } |
| 371 } |
| 372 |
| 373 if (what(variables::kLibDirs)) { |
| 374 const OrderedSet<SourceDir>& all_lib_dirs = target_->all_lib_dirs(); |
| 375 if (!all_lib_dirs.empty()) { |
| 376 auto lib_dirs = new base::ListValue(); |
| 377 for (size_t i = 0; i < all_lib_dirs.size(); i++) |
| 378 lib_dirs->AppendString(FormatSourceDir(all_lib_dirs[i])); |
| 379 res->Set(variables::kLibDirs, lib_dirs); |
| 380 } |
| 381 } |
| 382 |
| 383 return base::WrapUnique(res); |
| 384 } |
| 385 |
| 386 private: |
| 387 // Prints dependencies of the given target (not the target itself). If the |
| 388 // set is non-null, new targets encountered will be added to the set, and if |
| 389 // a dependency is in the set already, it will not be recused into. When the |
| 390 // set is null, all dependencies will be printed. |
| 391 void RecursivePrintDeps(base::ListValue* out, |
| 392 const Target* target, |
| 393 std::set<const Target*>* seen_targets, |
| 394 int indent_level) { |
| 395 // Combine all deps into one sorted list. |
| 396 std::vector<LabelTargetPair> sorted_deps; |
| 397 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) |
| 398 sorted_deps.push_back(pair); |
| 399 std::sort(sorted_deps.begin(), sorted_deps.end(), |
| 400 LabelPtrLabelLess<Target>()); |
| 401 |
| 402 std::string indent(indent_level * 2, ' '); |
| 403 |
| 404 for (const auto& pair : sorted_deps) { |
| 405 const Target* cur_dep = pair.ptr; |
| 406 std::string str = |
| 407 indent + cur_dep->label().GetUserVisibleName(GetToolchainLabel()); |
| 408 |
| 409 bool print_children = true; |
| 410 if (seen_targets) { |
| 411 if (seen_targets->find(cur_dep) == seen_targets->end()) { |
| 412 // New target, mark it visited. |
| 413 seen_targets->insert(cur_dep); |
| 414 } else { |
| 415 // Already seen. |
| 416 print_children = false; |
| 417 // Only print "..." if something is actually elided, which means that |
| 418 // the current target has children. |
| 419 if (!cur_dep->public_deps().empty() || |
| 420 !cur_dep->private_deps().empty() || !cur_dep->data_deps().empty()) |
| 421 str += "..."; |
| 422 } |
| 423 } |
| 424 |
| 425 out->AppendString(str); |
| 426 |
| 427 if (print_children) { |
| 428 RecursivePrintDeps(out, cur_dep, seen_targets, indent_level + 1); |
| 429 } |
| 430 } |
| 431 } |
| 432 |
| 433 ValuePtr RenderDeps() { |
| 434 auto res = new base::ListValue(); |
| 435 |
| 436 // Tree mode is separate. |
| 437 if (tree_) { |
| 438 if (all_) { |
| 439 // Show all tree deps with no eliding. |
| 440 RecursivePrintDeps(res, target_, nullptr, 0); |
| 441 } else { |
| 442 // Don't recurse into duplicates. |
| 443 std::set<const Target*> seen_targets; |
| 444 RecursivePrintDeps(res, target_, &seen_targets, 0); |
| 445 } |
| 446 } else { // not tree |
| 447 |
| 448 // Collect the deps to display. |
| 449 if (all_) { |
| 450 // Show all dependencies. |
| 451 std::set<const Target*> all_deps; |
| 452 RecursiveCollectChildDeps(target_, &all_deps); |
| 453 commands::FilterAndPrintTargetSet(all_deps, res); |
| 454 } else { |
| 455 // Show direct dependencies only. |
| 456 std::vector<const Target*> deps; |
| 457 for (const auto& pair : target_->GetDeps(Target::DEPS_ALL)) |
| 458 deps.push_back(pair.ptr); |
| 459 std::sort(deps.begin(), deps.end()); |
| 460 commands::FilterAndPrintTargets(&deps, res); |
| 461 } |
| 462 } |
| 463 |
| 464 return base::WrapUnique(res); |
| 465 } |
| 466 |
| 467 ValuePtr RenderRuntimeDeps() { |
| 468 auto res = new base::ListValue(); |
| 469 |
| 470 const Target* previous_from = NULL; |
| 471 for (const auto& pair : ComputeRuntimeDeps(target_)) { |
| 472 std::string str; |
| 473 if (blame_) { |
| 474 // Generally a target's runtime deps will be listed sequentially, so |
| 475 // group them and don't duplicate the "from" label for two in a row. |
| 476 if (previous_from == pair.second) { |
| 477 str = " "; |
| 478 } else { |
| 479 previous_from = pair.second; |
| 480 res->AppendString( |
| 481 str + "From " + |
| 482 pair.second->label().GetUserVisibleName(GetToolchainLabel())); |
| 483 str = " "; |
| 484 } |
| 485 } |
| 486 |
| 487 res->AppendString(str + pair.first.value()); |
| 488 } |
| 489 |
| 490 return base::WrapUnique(res); |
| 491 } |
| 492 |
| 493 void FillInBundle(base::DictionaryValue* res, const Target* target) { |
| 494 auto data = new base::DictionaryValue(); |
| 495 const BundleData& bundle_data = target->bundle_data(); |
| 496 const Settings* settings = target->settings(); |
| 497 BundleData::SourceFiles sources; |
| 498 bundle_data.GetSourceFiles(&sources); |
| 499 data->Set("source_files", RenderValue(sources)); |
| 500 data->SetString("root_dir_output", |
| 501 bundle_data.GetBundleRootDirOutput(settings).value()); |
| 502 data->Set("root_dir", RenderValue(bundle_data.root_dir())); |
| 503 data->Set("resources_dir", RenderValue(bundle_data.resources_dir())); |
| 504 data->Set("executable_dir", RenderValue(bundle_data.executable_dir())); |
| 505 data->Set("plugins_dir", RenderValue(bundle_data.plugins_dir())); |
| 506 data->SetString("product_type", bundle_data.product_type()); |
| 507 |
| 508 auto deps = new base::ListValue(); |
| 509 for (const auto* dep : bundle_data.bundle_deps()) { |
| 510 deps->AppendString(dep->label().GetUserVisibleName(GetToolchainLabel())); |
| 511 } |
| 512 data->Set("deps", deps); |
| 513 res->Set("bundle_data", data); |
| 514 } |
| 515 |
| 516 void FillInOutputs(base::DictionaryValue* res, const Target* target) { |
| 517 if (target->output_type() == Target::ACTION) { |
| 518 auto list = new base::ListValue(); |
| 519 for (const auto& elem : target->action_values().outputs().list()) { |
| 520 list->AppendString(elem.AsString()); |
| 521 } |
| 522 res->Set(variables::kOutputs, list); |
| 523 } else if (target->output_type() == Target::CREATE_BUNDLE) { |
| 524 std::vector<SourceFile> output_files; |
| 525 target->bundle_data().GetOutputsAsSourceFiles(target->settings(), |
| 526 &output_files); |
| 527 res->Set(variables::kOutputs, RenderValue(output_files)); |
| 528 } else { |
| 529 const SubstitutionList& outputs = target->action_values().outputs(); |
| 530 if (!outputs.required_types().empty()) { |
| 531 auto patterns = new base::ListValue(); |
| 532 for (const auto& elem : outputs.list()) { |
| 533 patterns->AppendString(elem.AsString()); |
| 534 } |
| 535 res->Set("output_patterns", patterns); |
| 536 } |
| 537 std::vector<SourceFile> output_files; |
| 538 SubstitutionWriter::ApplyListToSources(target->settings(), outputs, |
| 539 target->sources(), &output_files); |
| 540 res->Set(variables::kOutputs, RenderValue(output_files)); |
| 541 } |
| 542 } |
| 543 |
| 544 // Writes a given config value type to the string, optionally with |
| 545 // attribution. |
| 546 // This should match RecursiveTargetConfigToStream in the order it traverses. |
| 547 template <class T> |
| 548 ValuePtr RenderConfigValues(const std::vector<T>& (ConfigValues::*getter)() |
| 549 const) { |
| 550 auto res = base::WrapUnique(new base::ListValue()); |
| 551 for (ConfigValuesIterator iter(target_); !iter.done(); iter.Next()) { |
| 552 const std::vector<T>& vec = (iter.cur().*getter)(); |
| 553 |
| 554 if (vec.empty()) |
| 555 continue; |
| 556 |
| 557 if (blame_) { |
| 558 const Config* config = iter.GetCurrentConfig(); |
| 559 if (config) { |
| 560 // Source of this value is a config. |
| 561 std::string from = |
| 562 "From " + config->label().GetUserVisibleName(false); |
| 563 res->AppendString(from); |
| 564 if (iter.origin()) { |
| 565 Location location = iter.origin()->GetRange().begin(); |
| 566 from = " (Added by " + location.file()->name().value() + ":" + |
| 567 base::IntToString(location.line_number()) + ")"; |
| 568 res->AppendString(from); |
| 569 } |
| 570 } else { |
| 571 // Source of this value is the target itself. |
| 572 std::string from = |
| 573 "From " + target_->label().GetUserVisibleName(false); |
| 574 res->AppendString(from); |
| 575 } |
| 576 } |
| 577 |
| 578 for (const T& val : vec) { |
| 579 ValuePtr rendered = RenderValue(val); |
| 580 std::string str; |
| 581 // Indent string values in blame mode |
| 582 if (blame_ && rendered->GetAsString(&str)) { |
| 583 str = " " + str; |
| 584 rendered = base::WrapUnique(new base::StringValue(str)); |
| 585 } |
| 586 res->Append(std::move(rendered)); |
| 587 } |
| 588 } |
| 589 return res->empty() ? nullptr : std::move(res); |
| 590 } |
| 591 |
| 592 Label GetToolchainLabel() const override { |
| 593 return target_->label().GetToolchainLabel(); |
| 594 } |
| 595 |
| 596 const Target* target_; |
| 597 }; |
| 598 |
| 599 } // Namespace |
| 600 |
| 601 const char* DescBuilder::GetStringForOutputType(Target::OutputType type) { |
| 602 #define CASE(C) \ |
| 603 case Target::C: \ |
| 604 return #C |
| 605 switch (type) { |
| 606 CASE(UNKNOWN); |
| 607 CASE(GROUP); |
| 608 CASE(EXECUTABLE); |
| 609 CASE(LOADABLE_MODULE); |
| 610 CASE(SHARED_LIBRARY); |
| 611 CASE(STATIC_LIBRARY); |
| 612 CASE(SOURCE_SET); |
| 613 CASE(COPY_FILES); |
| 614 CASE(ACTION); |
| 615 CASE(ACTION_FOREACH); |
| 616 CASE(BUNDLE_DATA); |
| 617 CASE(CREATE_BUNDLE); |
| 618 } |
| 619 #undef CASE |
| 620 } |
| 621 |
| 622 Target::OutputType DescBuilder::GetOutputTypeForString( |
| 623 const std::string& type) { |
| 624 #define CASE(C) \ |
| 625 if (type == #C) \ |
| 626 return Target::C |
| 627 CASE(GROUP); |
| 628 CASE(EXECUTABLE); |
| 629 CASE(LOADABLE_MODULE); |
| 630 CASE(SHARED_LIBRARY); |
| 631 CASE(STATIC_LIBRARY); |
| 632 CASE(SOURCE_SET); |
| 633 CASE(COPY_FILES); |
| 634 CASE(ACTION); |
| 635 CASE(ACTION_FOREACH); |
| 636 CASE(BUNDLE_DATA); |
| 637 CASE(CREATE_BUNDLE); |
| 638 return Target::UNKNOWN; |
| 639 #undef CASE |
| 640 } |
| 641 |
| 642 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForTarget( |
| 643 const Target* target, |
| 644 const std::string& what, |
| 645 bool all, |
| 646 bool tree, |
| 647 bool blame) { |
| 648 std::set<std::string> w; |
| 649 if (!what.empty()) |
| 650 w.insert(what); |
| 651 TargetDescBuilder b(target, w, all, tree, blame); |
| 652 return b.BuildDescription(); |
| 653 } |
| 654 |
| 655 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForConfig( |
| 656 const Config* config, |
| 657 const std::string& what) { |
| 658 std::set<std::string> w; |
| 659 if (!what.empty()) |
| 660 w.insert(what); |
| 661 ConfigDescBuilder b(config, w); |
| 662 return b.BuildDescription(); |
| 663 } |
OLD | NEW |