Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: tools/gn/desc_builder.cc

Issue 2880093002: gn desc: printing public_deps without --all and --tree
Patch Set: fixing documentation indentation Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/command_desc.cc ('k') | tools/gn/target.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "tools/gn/commands.h" 9 #include "tools/gn/commands.h"
10 #include "tools/gn/config.h" 10 #include "tools/gn/config.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 std::set<const Target*>* result) { 83 std::set<const Target*>* result) {
84 if (result->find(target) != result->end()) 84 if (result->find(target) != result->end())
85 return; // Already did this target. 85 return; // Already did this target.
86 result->insert(target); 86 result->insert(target);
87 87
88 RecursiveCollectChildDeps(target, result); 88 RecursiveCollectChildDeps(target, result);
89 } 89 }
90 90
91 void RecursiveCollectChildDeps(const Target* target, 91 void RecursiveCollectChildDeps(const Target* target,
92 std::set<const Target*>* result) { 92 std::set<const Target*>* result) {
93 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 93 for (const auto& pair : target->GetDeps(Target::DEPS_LINKED))
94 RecursiveCollectDeps(pair.ptr, result); 94 RecursiveCollectDeps(pair.ptr, result);
95 } 95 }
96 96
97 // Common functionality for target and config description builder 97 // Common functionality for target and config description builder
98 class BaseDescBuilder { 98 class BaseDescBuilder {
99 public: 99 public:
100 typedef std::unique_ptr<base::Value> ValuePtr; 100 typedef std::unique_ptr<base::Value> ValuePtr;
101 101
102 BaseDescBuilder(const std::set<std::string>& what, 102 BaseDescBuilder(const std::set<std::string>& what,
103 bool all, 103 bool all,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 #undef CONFIG_VALUE_ARRAY_HANDLER 399 #undef CONFIG_VALUE_ARRAY_HANDLER
400 400
401 // Libs and lib_dirs are handled specially below. 401 // Libs and lib_dirs are handled specially below.
402 402
403 FillInPrecompiledHeader(res.get(), target_->config_values()); 403 FillInPrecompiledHeader(res.get(), target_->config_values());
404 } 404 }
405 405
406 if (what(variables::kDeps)) 406 if (what(variables::kDeps))
407 res->SetWithoutPathExpansion(variables::kDeps, RenderDeps()); 407 res->SetWithoutPathExpansion(variables::kDeps, RenderDeps());
408 408
409 // By default RenderDeps only renders Target::DEPS_PRIVATE, in that case
410 // the output should be enriched also with Target::DEPS_PUBLIC.
411 if (!tree_ && !all_) {
412 if (what(variables::kPublicDeps)) {
413 res->SetWithoutPathExpansion(variables::kPublicDeps,
414 RenderDepsOf(Target::DEPS_PUBLIC));
415 }
416 }
417
418 if (what(variables::kDataDeps)) {
419 res->SetWithoutPathExpansion(variables::kDataDeps,
420 RenderDepsOf(Target::DEPS_DATA));
421 }
422
423 if (what(variables::kLinkedDeps)) {
424 res->SetWithoutPathExpansion(variables::kLinkedDeps,
425 RenderDepsOf(Target::DEPS_LINKED));
426 }
427
409 // Runtime deps are special, print only when explicitly asked for and not in 428 // Runtime deps are special, print only when explicitly asked for and not in
410 // overview mode. 429 // overview mode.
411 if (what_.find("runtime_deps") != what_.end()) 430 if (what_.find("runtime_deps") != what_.end())
412 res->SetWithoutPathExpansion("runtime_deps", RenderRuntimeDeps()); 431 res->SetWithoutPathExpansion("runtime_deps", RenderRuntimeDeps());
413 432
414 // libs and lib_dirs are special in that they're inherited. We don't 433 // libs and lib_dirs are special in that they're inherited. We don't
415 // currently 434 // currently
416 // implement a blame feature for this since the bottom-up inheritance makes 435 // implement a blame feature for this since the bottom-up inheritance makes
417 // this difficult. 436 // this difficult.
418 437
(...skipping 26 matching lines...) Expand all
445 // Prints dependencies of the given target (not the target itself). If the 464 // Prints dependencies of the given target (not the target itself). If the
446 // set is non-null, new targets encountered will be added to the set, and if 465 // set is non-null, new targets encountered will be added to the set, and if
447 // a dependency is in the set already, it will not be recused into. When the 466 // a dependency is in the set already, it will not be recused into. When the
448 // set is null, all dependencies will be printed. 467 // set is null, all dependencies will be printed.
449 void RecursivePrintDeps(base::ListValue* out, 468 void RecursivePrintDeps(base::ListValue* out,
450 const Target* target, 469 const Target* target,
451 std::set<const Target*>* seen_targets, 470 std::set<const Target*>* seen_targets,
452 int indent_level) { 471 int indent_level) {
453 // Combine all deps into one sorted list. 472 // Combine all deps into one sorted list.
454 std::vector<LabelTargetPair> sorted_deps; 473 std::vector<LabelTargetPair> sorted_deps;
455 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 474 for (const auto& pair : target->GetDeps(Target::DEPS_LINKED))
456 sorted_deps.push_back(pair); 475 sorted_deps.push_back(pair);
457 std::sort(sorted_deps.begin(), sorted_deps.end(), 476 std::sort(sorted_deps.begin(), sorted_deps.end(),
458 LabelPtrLabelLess<Target>()); 477 LabelPtrLabelLess<Target>());
459 478
460 std::string indent(indent_level * 2, ' '); 479 std::string indent(indent_level * 2, ' ');
461 480
462 for (const auto& pair : sorted_deps) { 481 for (const auto& pair : sorted_deps) {
463 const Target* cur_dep = pair.ptr; 482 const Target* cur_dep = pair.ptr;
464 std::string str = 483 std::string str =
465 indent + cur_dep->label().GetUserVisibleName(GetToolchainLabel()); 484 indent + cur_dep->label().GetUserVisibleName(GetToolchainLabel());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 523
505 // Collect the deps to display. 524 // Collect the deps to display.
506 if (all_) { 525 if (all_) {
507 // Show all dependencies. 526 // Show all dependencies.
508 std::set<const Target*> all_deps; 527 std::set<const Target*> all_deps;
509 RecursiveCollectChildDeps(target_, &all_deps); 528 RecursiveCollectChildDeps(target_, &all_deps);
510 commands::FilterAndPrintTargetSet(all_deps, res.get()); 529 commands::FilterAndPrintTargetSet(all_deps, res.get());
511 } else { 530 } else {
512 // Show direct dependencies only. 531 // Show direct dependencies only.
513 std::vector<const Target*> deps; 532 std::vector<const Target*> deps;
514 for (const auto& pair : target_->GetDeps(Target::DEPS_ALL)) 533 for (const auto& pair : target_->GetDeps(Target::DEPS_PRIVATE))
515 deps.push_back(pair.ptr); 534 deps.push_back(pair.ptr);
516 std::sort(deps.begin(), deps.end());
517 commands::FilterAndPrintTargets(&deps, res.get()); 535 commands::FilterAndPrintTargets(&deps, res.get());
518 } 536 }
519 } 537 }
520 538
521 return std::move(res); 539 return std::move(res);
522 } 540 }
523 541
542 ValuePtr RenderDepsOf(Target::DepsIterationType type) {
543 auto res = base::MakeUnique<base::ListValue>();
544
545 std::vector<const Target*> deps;
546 for (const auto& pair : target_->GetDeps(type))
547 deps.push_back(pair.ptr);
548
549 commands::FilterAndPrintTargets(&deps, res.get());
550
551 return std::move(res);
552 }
553
524 ValuePtr RenderRuntimeDeps() { 554 ValuePtr RenderRuntimeDeps() {
525 auto res = base::MakeUnique<base::ListValue>(); 555 auto res = base::MakeUnique<base::ListValue>();
526 556
527 const Target* previous_from = NULL; 557 const Target* previous_from = NULL;
528 for (const auto& pair : ComputeRuntimeDeps(target_)) { 558 for (const auto& pair : ComputeRuntimeDeps(target_)) {
529 std::string str; 559 std::string str;
530 if (blame_) { 560 if (blame_) {
531 // Generally a target's runtime deps will be listed sequentially, so 561 // Generally a target's runtime deps will be listed sequentially, so
532 // group them and don't duplicate the "from" label for two in a row. 562 // group them and don't duplicate the "from" label for two in a row.
533 if (previous_from == pair.second) { 563 if (previous_from == pair.second) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 741
712 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForConfig( 742 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForConfig(
713 const Config* config, 743 const Config* config,
714 const std::string& what) { 744 const std::string& what) {
715 std::set<std::string> w; 745 std::set<std::string> w;
716 if (!what.empty()) 746 if (!what.empty())
717 w.insert(what); 747 w.insert(what);
718 ConfigDescBuilder b(config, w); 748 ConfigDescBuilder b(config, w);
719 return b.BuildDescription(); 749 return b.BuildDescription();
720 } 750 }
OLDNEW
« no previous file with comments | « tools/gn/command_desc.cc ('k') | tools/gn/target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698