| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "tools/gn/commands.h" | 10 #include "tools/gn/commands.h" |
| 11 #include "tools/gn/config.h" | 11 #include "tools/gn/config.h" |
| 12 #include "tools/gn/config_values_extractors.h" | 12 #include "tools/gn/config_values_extractors.h" |
| 13 #include "tools/gn/deps_iterator.h" | 13 #include "tools/gn/deps_iterator.h" |
| 14 #include "tools/gn/filesystem_utils.h" | 14 #include "tools/gn/filesystem_utils.h" |
| 15 #include "tools/gn/item.h" | 15 #include "tools/gn/item.h" |
| 16 #include "tools/gn/label.h" | 16 #include "tools/gn/label.h" |
| 17 #include "tools/gn/runtime_deps.h" |
| 17 #include "tools/gn/setup.h" | 18 #include "tools/gn/setup.h" |
| 18 #include "tools/gn/standard_out.h" | 19 #include "tools/gn/standard_out.h" |
| 19 #include "tools/gn/substitution_writer.h" | 20 #include "tools/gn/substitution_writer.h" |
| 20 #include "tools/gn/target.h" | 21 #include "tools/gn/target.h" |
| 21 #include "tools/gn/variables.h" | 22 #include "tools/gn/variables.h" |
| 22 | 23 |
| 23 namespace commands { | 24 namespace commands { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 // The switch for displaying blame. |
| 29 const char kBlame[] = "blame"; |
| 30 |
| 27 // Prints the given directory in a nice way for the user to view. | 31 // Prints the given directory in a nice way for the user to view. |
| 28 std::string FormatSourceDir(const SourceDir& dir) { | 32 std::string FormatSourceDir(const SourceDir& dir) { |
| 29 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 30 // On Windows we fix up system absolute paths to look like native ones. | 34 // On Windows we fix up system absolute paths to look like native ones. |
| 31 // Internally, they'll look like "/C:\foo\bar/" | 35 // Internally, they'll look like "/C:\foo\bar/" |
| 32 if (dir.is_system_absolute()) { | 36 if (dir.is_system_absolute()) { |
| 33 std::string buf = dir.value(); | 37 std::string buf = dir.value(); |
| 34 if (buf.size() > 3 && buf[2] == ':') { | 38 if (buf.size() > 3 && buf[2] == ':') { |
| 35 buf.erase(buf.begin()); // Erase beginning slash. | 39 buf.erase(buf.begin()); // Erase beginning slash. |
| 36 return buf; | 40 return buf; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 401 } |
| 398 }; | 402 }; |
| 399 | 403 |
| 400 // Writes a given config value type to the string, optionally with attribution. | 404 // Writes a given config value type to the string, optionally with attribution. |
| 401 // This should match RecursiveTargetConfigToStream in the order it traverses. | 405 // This should match RecursiveTargetConfigToStream in the order it traverses. |
| 402 template<typename T> void OutputRecursiveTargetConfig( | 406 template<typename T> void OutputRecursiveTargetConfig( |
| 403 const Target* target, | 407 const Target* target, |
| 404 const char* header_name, | 408 const char* header_name, |
| 405 const std::vector<T>& (ConfigValues::* getter)() const) { | 409 const std::vector<T>& (ConfigValues::* getter)() const) { |
| 406 bool display_blame = | 410 bool display_blame = |
| 407 base::CommandLine::ForCurrentProcess()->HasSwitch("blame"); | 411 base::CommandLine::ForCurrentProcess()->HasSwitch(kBlame); |
| 408 | 412 |
| 409 DescValueWriter<T> writer; | 413 DescValueWriter<T> writer; |
| 410 std::ostringstream out; | 414 std::ostringstream out; |
| 411 | 415 |
| 412 for (ConfigValuesIterator iter(target); !iter.done(); iter.Next()) { | 416 for (ConfigValuesIterator iter(target); !iter.done(); iter.Next()) { |
| 413 if ((iter.cur().*getter)().empty()) | 417 if ((iter.cur().*getter)().empty()) |
| 414 continue; | 418 continue; |
| 415 | 419 |
| 416 // Optional blame sub-head. | 420 // Optional blame sub-head. |
| 417 if (display_blame) { | 421 if (display_blame) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 430 ConfigValuesToStream(iter.cur(), getter, writer, out); | 434 ConfigValuesToStream(iter.cur(), getter, writer, out); |
| 431 } | 435 } |
| 432 | 436 |
| 433 std::string out_str = out.str(); | 437 std::string out_str = out.str(); |
| 434 if (!out_str.empty()) { | 438 if (!out_str.empty()) { |
| 435 OutputString("\n" + std::string(header_name) + "\n"); | 439 OutputString("\n" + std::string(header_name) + "\n"); |
| 436 OutputString(out_str); | 440 OutputString(out_str); |
| 437 } | 441 } |
| 438 } | 442 } |
| 439 | 443 |
| 444 void PrintRuntimeDeps(const Target* target) { |
| 445 bool display_blame = |
| 446 base::CommandLine::ForCurrentProcess()->HasSwitch(kBlame); |
| 447 Label toolchain = target->label().GetToolchainLabel(); |
| 448 |
| 449 const Target* previous_from = NULL; |
| 450 for (const auto& pair : ComputeRuntimeDeps(target)) { |
| 451 if (display_blame) { |
| 452 // Generally a target's runtime deps will be listed sequentially, so |
| 453 // group them and don't duplicate the "from" label for two in a row. |
| 454 if (previous_from == pair.second) { |
| 455 OutputString(" "); // Just indent. |
| 456 } else { |
| 457 previous_from = pair.second; |
| 458 OutputString("From "); |
| 459 OutputString(pair.second->label().GetUserVisibleName(toolchain)); |
| 460 OutputString("\n "); // Make the file name indented. |
| 461 } |
| 462 } |
| 463 OutputString(pair.first.value()); |
| 464 OutputString("\n"); |
| 465 } |
| 466 } |
| 467 |
| 440 } // namespace | 468 } // namespace |
| 441 | 469 |
| 442 // desc ------------------------------------------------------------------------ | 470 // desc ------------------------------------------------------------------------ |
| 443 | 471 |
| 444 const char kDesc[] = "desc"; | 472 const char kDesc[] = "desc"; |
| 445 const char kDesc_HelpShort[] = | 473 const char kDesc_HelpShort[] = |
| 446 "desc: Show lots of insightful information about a target."; | 474 "desc: Show lots of insightful information about a target."; |
| 447 const char kDesc_Help[] = | 475 const char kDesc_Help[] = |
| 448 "gn desc <out_dir> <target label> [<what to show>] [--blame]\n" | 476 "gn desc <out_dir> <target label> [<what to show>] [--blame]\n" |
| 449 "\n" | 477 "\n" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 " include_dirs [--blame]\n" | 535 " include_dirs [--blame]\n" |
| 508 " cflags [--blame]\n" | 536 " cflags [--blame]\n" |
| 509 " cflags_cc [--blame]\n" | 537 " cflags_cc [--blame]\n" |
| 510 " cflags_cxx [--blame]\n" | 538 " cflags_cxx [--blame]\n" |
| 511 " ldflags [--blame]\n" | 539 " ldflags [--blame]\n" |
| 512 " lib_dirs\n" | 540 " lib_dirs\n" |
| 513 " libs\n" | 541 " libs\n" |
| 514 " Shows the given values taken from the target and all configs\n" | 542 " Shows the given values taken from the target and all configs\n" |
| 515 " applying. See \"--blame\" below.\n" | 543 " applying. See \"--blame\" below.\n" |
| 516 "\n" | 544 "\n" |
| 545 " runtime_deps\n" |
| 546 " Compute all runtime deps for the given target. This is a\n" |
| 547 " computed list and does not correspond to any GN variable, unlike\n" |
| 548 " most other values here.\n" |
| 549 "\n" |
| 550 " The output is a list of file names relative to the build\n" |
| 551 " directory. See \"gn help runtime_deps\" for how this is computed.\n" |
| 552 " This also works with \"--blame\" to see the source of the\n" |
| 553 " dependency.\n" |
| 554 "\n" |
| 555 "Shared flags\n" |
| 556 "\n" |
| 517 " --blame\n" | 557 " --blame\n" |
| 518 " Used with any value specified by a config, this will name\n" | 558 " Used with any value specified by a config, this will name\n" |
| 519 " the config that specified the value. This doesn't currently work\n" | 559 " the config that specified the value. This doesn't currently work\n" |
| 520 " for libs and lib_dirs because those are inherited and are more\n" | 560 " for libs and lib_dirs because those are inherited and are more\n" |
| 521 " complicated to figure out the blame (patches welcome).\n" | 561 " complicated to figure out the blame (patches welcome).\n" |
| 522 "\n" | 562 "\n" |
| 523 "Flags that control how deps are printed\n" | 563 "Flags that control how deps are printed\n" |
| 524 "\n" | 564 "\n" |
| 525 " --all\n" | 565 " --all\n" |
| 526 " Collects all recursive dependencies and prints a sorted flat list.\n" | 566 " Collects all recursive dependencies and prints a sorted flat list.\n" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } else if (what == variables::kDepfile) { | 661 } else if (what == variables::kDepfile) { |
| 622 PrintDepfile(target, false); | 662 PrintDepfile(target, false); |
| 623 } else if (what == variables::kOutputs) { | 663 } else if (what == variables::kOutputs) { |
| 624 PrintOutputs(target, false); | 664 PrintOutputs(target, false); |
| 625 } else if (what == variables::kDeps) { | 665 } else if (what == variables::kDeps) { |
| 626 PrintDeps(target, false); | 666 PrintDeps(target, false); |
| 627 } else if (what == variables::kLibDirs) { | 667 } else if (what == variables::kLibDirs) { |
| 628 PrintLibDirs(target, false); | 668 PrintLibDirs(target, false); |
| 629 } else if (what == variables::kLibs) { | 669 } else if (what == variables::kLibs) { |
| 630 PrintLibs(target, false); | 670 PrintLibs(target, false); |
| 671 } else if (what == "runtime_deps") { |
| 672 PrintRuntimeDeps(target); |
| 631 | 673 |
| 632 CONFIG_VALUE_HANDLER(defines, std::string) | 674 CONFIG_VALUE_HANDLER(defines, std::string) |
| 633 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) | 675 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) |
| 634 CONFIG_VALUE_HANDLER(cflags, std::string) | 676 CONFIG_VALUE_HANDLER(cflags, std::string) |
| 635 CONFIG_VALUE_HANDLER(cflags_c, std::string) | 677 CONFIG_VALUE_HANDLER(cflags_c, std::string) |
| 636 CONFIG_VALUE_HANDLER(cflags_cc, std::string) | 678 CONFIG_VALUE_HANDLER(cflags_cc, std::string) |
| 637 CONFIG_VALUE_HANDLER(cflags_objc, std::string) | 679 CONFIG_VALUE_HANDLER(cflags_objc, std::string) |
| 638 CONFIG_VALUE_HANDLER(cflags_objcc, std::string) | 680 CONFIG_VALUE_HANDLER(cflags_objcc, std::string) |
| 639 CONFIG_VALUE_HANDLER(ldflags, std::string) | 681 CONFIG_VALUE_HANDLER(ldflags, std::string) |
| 640 | 682 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // so always display them, even for groups and such. | 758 // so always display them, even for groups and such. |
| 717 PrintLibs(target, true); | 759 PrintLibs(target, true); |
| 718 PrintLibDirs(target, true); | 760 PrintLibDirs(target, true); |
| 719 | 761 |
| 720 PrintDeps(target, true); | 762 PrintDeps(target, true); |
| 721 | 763 |
| 722 return 0; | 764 return 0; |
| 723 } | 765 } |
| 724 | 766 |
| 725 } // namespace commands | 767 } // namespace commands |
| OLD | NEW |