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/filesystem_utils.h" | 13 #include "tools/gn/filesystem_utils.h" |
14 #include "tools/gn/item.h" | 14 #include "tools/gn/item.h" |
15 #include "tools/gn/label.h" | 15 #include "tools/gn/label.h" |
16 #include "tools/gn/setup.h" | 16 #include "tools/gn/setup.h" |
17 #include "tools/gn/standard_out.h" | 17 #include "tools/gn/standard_out.h" |
18 #include "tools/gn/substitution_writer.h" | 18 #include "tools/gn/substitution_writer.h" |
19 #include "tools/gn/target.h" | 19 #include "tools/gn/target.h" |
| 20 #include "tools/gn/variables.h" |
20 | 21 |
21 namespace commands { | 22 namespace commands { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // Prints the given directory in a nice way for the user to view. | 26 // Prints the given directory in a nice way for the user to view. |
26 std::string FormatSourceDir(const SourceDir& dir) { | 27 std::string FormatSourceDir(const SourceDir& dir) { |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 // On Windows we fix up system absolute paths to look like native ones. | 29 // On Windows we fix up system absolute paths to look like native ones. |
29 // Internally, they'll look like "/C:\foo\bar/" | 30 // Internally, they'll look like "/C:\foo\bar/" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 OutputString(" [All headers listed in the sources are public.]\n"); | 219 OutputString(" [All headers listed in the sources are public.]\n"); |
219 return; | 220 return; |
220 } | 221 } |
221 | 222 |
222 Target::FileList public_headers = target->public_headers(); | 223 Target::FileList public_headers = target->public_headers(); |
223 std::sort(public_headers.begin(), public_headers.end()); | 224 std::sort(public_headers.begin(), public_headers.end()); |
224 for (size_t i = 0; i < public_headers.size(); i++) | 225 for (size_t i = 0; i < public_headers.size(); i++) |
225 OutputString(" " + public_headers[i].value() + "\n"); | 226 OutputString(" " + public_headers[i].value() + "\n"); |
226 } | 227 } |
227 | 228 |
| 229 void PrintCheckIncludes(const Target* target, bool display_header) { |
| 230 if (display_header) |
| 231 OutputString("\ncheck_includes:\n"); |
| 232 |
| 233 if (target->check_includes()) |
| 234 OutputString(" true\n"); |
| 235 else |
| 236 OutputString(" false\n"); |
| 237 } |
| 238 |
| 239 void PrintAllowCircularIncludesFrom(const Target* target, bool display_header) { |
| 240 if (display_header) |
| 241 OutputString("\nallow_circular_includes_from:\n"); |
| 242 |
| 243 Label toolchain_label = target->label().GetToolchainLabel(); |
| 244 const std::set<Label>& allow = target->allow_circular_includes_from(); |
| 245 for (std::set<Label>::const_iterator iter = allow.begin(); |
| 246 iter != allow.end(); ++iter) |
| 247 OutputString(" " + iter->GetUserVisibleName(toolchain_label) + "\n"); |
| 248 } |
| 249 |
228 void PrintVisibility(const Target* target, bool display_header) { | 250 void PrintVisibility(const Target* target, bool display_header) { |
229 if (display_header) | 251 if (display_header) |
230 OutputString("\nvisibility:\n"); | 252 OutputString("\nvisibility:\n"); |
231 | 253 |
232 OutputString(target->visibility().Describe(2, false)); | 254 OutputString(target->visibility().Describe(2, false)); |
233 } | 255 } |
234 | 256 |
| 257 void PrintTestonly(const Target* target, bool display_header) { |
| 258 if (display_header) |
| 259 OutputString("\ntestonly:\n"); |
| 260 |
| 261 if (target->testonly()) |
| 262 OutputString(" true\n"); |
| 263 else |
| 264 OutputString(" false\n"); |
| 265 } |
| 266 |
235 void PrintConfigsVector(const Target* target, | 267 void PrintConfigsVector(const Target* target, |
236 const LabelConfigVector& configs, | 268 const LabelConfigVector& configs, |
237 const std::string& heading, | 269 const std::string& heading, |
238 bool display_header) { | 270 bool display_header) { |
239 if (configs.empty()) | 271 if (configs.empty()) |
240 return; | 272 return; |
241 | 273 |
242 // Don't sort since the order determines how things are processed. | 274 // Don't sort since the order determines how things are processed. |
243 if (display_header) | 275 if (display_header) |
244 OutputString("\n" + heading + " (in order applying):\n"); | 276 OutputString("\n" + heading + " (in order applying):\n"); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 "\n" | 479 "\n" |
448 " sources\n" | 480 " sources\n" |
449 " Source files.\n" | 481 " Source files.\n" |
450 "\n" | 482 "\n" |
451 " inputs\n" | 483 " inputs\n" |
452 " Additional input dependencies.\n" | 484 " Additional input dependencies.\n" |
453 "\n" | 485 "\n" |
454 " public\n" | 486 " public\n" |
455 " Public header files.\n" | 487 " Public header files.\n" |
456 "\n" | 488 "\n" |
| 489 " check_includes\n" |
| 490 " Whether \"gn check\" checks this target for include usage.\n" |
| 491 "\n" |
| 492 " allow_circular_includes_from\n" |
| 493 " Permit includes from these targets.\n" |
| 494 "\n" |
457 " visibility\n" | 495 " visibility\n" |
458 " Prints which targets can depend on this one.\n" | 496 " Prints which targets can depend on this one.\n" |
459 "\n" | 497 "\n" |
| 498 " testonly\n" |
| 499 " Whether this target may only be used in tests.\n" |
| 500 "\n" |
460 " configs\n" | 501 " configs\n" |
461 " Shows configs applied to the given target, sorted in the order\n" | 502 " Shows configs applied to the given target, sorted in the order\n" |
462 " they're specified. This includes both configs specified in the\n" | 503 " they're specified. This includes both configs specified in the\n" |
463 " \"configs\" variable, as well as configs pushed onto this target\n" | 504 " \"configs\" variable, as well as configs pushed onto this target\n" |
464 " via dependencies specifying \"all\" or \"direct\" dependent\n" | 505 " via dependencies specifying \"all\" or \"direct\" dependent\n" |
465 " configs.\n" | 506 " configs.\n" |
466 "\n" | 507 "\n" |
467 " deps [--all | --tree]\n" | 508 " deps [--all | --tree]\n" |
468 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" | 509 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" |
469 " recursive) dependencies of the given target. \"--tree\" shows them\n" | 510 " recursive) dependencies of the given target. \"--tree\" shows them\n" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 const Target* target = ResolveTargetFromCommandLineString(setup, args[1]); | 587 const Target* target = ResolveTargetFromCommandLineString(setup, args[1]); |
547 if (!target) | 588 if (!target) |
548 return 1; | 589 return 1; |
549 | 590 |
550 #define CONFIG_VALUE_HANDLER(name, type) \ | 591 #define CONFIG_VALUE_HANDLER(name, type) \ |
551 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) | 592 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) |
552 | 593 |
553 if (args.size() == 3) { | 594 if (args.size() == 3) { |
554 // User specified one thing to display. | 595 // User specified one thing to display. |
555 const std::string& what = args[2]; | 596 const std::string& what = args[2]; |
556 if (what == "configs") { | 597 if (what == variables::kConfigs) { |
557 PrintConfigs(target, false); | 598 PrintConfigs(target, false); |
558 } else if (what == "direct_dependent_configs") { | 599 } else if (what == variables::kDirectDependentConfigs) { |
559 PrintDirectDependentConfigs(target, false); | 600 PrintDirectDependentConfigs(target, false); |
560 } else if (what == "all_dependent_configs") { | 601 } else if (what == variables::kAllDependentConfigs) { |
561 PrintAllDependentConfigs(target, false); | 602 PrintAllDependentConfigs(target, false); |
562 } else if (what == "forward_dependent_configs_from") { | 603 } else if (what == variables::kForwardDependentConfigsFrom) { |
563 PrintForwardDependentConfigsFrom(target, false); | 604 PrintForwardDependentConfigsFrom(target, false); |
564 } else if (what == "sources") { | 605 } else if (what == variables::kSources) { |
565 PrintSources(target, false); | 606 PrintSources(target, false); |
566 } else if (what == "public") { | 607 } else if (what == variables::kPublic) { |
567 PrintPublic(target, false); | 608 PrintPublic(target, false); |
568 } else if (what == "visibility") { | 609 } else if (what == variables::kCheckIncludes) { |
| 610 PrintCheckIncludes(target, false); |
| 611 } else if (what == variables::kAllowCircularIncludesFrom) { |
| 612 PrintAllowCircularIncludesFrom(target, false); |
| 613 } else if (what == variables::kVisibility) { |
569 PrintVisibility(target, false); | 614 PrintVisibility(target, false); |
570 } else if (what == "inputs") { | 615 } else if (what == variables::kTestonly) { |
| 616 PrintTestonly(target, false); |
| 617 } else if (what == variables::kInputs) { |
571 PrintInputs(target, false); | 618 PrintInputs(target, false); |
572 } else if (what == "script") { | 619 } else if (what == variables::kScript) { |
573 PrintScript(target, false); | 620 PrintScript(target, false); |
574 } else if (what == "args") { | 621 } else if (what == variables::kArgs) { |
575 PrintArgs(target, false); | 622 PrintArgs(target, false); |
576 } else if (what == "depfile") { | 623 } else if (what == variables::kDepfile) { |
577 PrintDepfile(target, false); | 624 PrintDepfile(target, false); |
578 } else if (what == "outputs") { | 625 } else if (what == variables::kOutputs) { |
579 PrintOutputs(target, false); | 626 PrintOutputs(target, false); |
580 } else if (what == "deps") { | 627 } else if (what == variables::kDeps) { |
581 PrintDeps(target, false); | 628 PrintDeps(target, false); |
582 } else if (what == "lib_dirs") { | 629 } else if (what == variables::kLibDirs) { |
583 PrintLibDirs(target, false); | 630 PrintLibDirs(target, false); |
584 } else if (what == "libs") { | 631 } else if (what == variables::kLibs) { |
585 PrintLibs(target, false); | 632 PrintLibs(target, false); |
586 | 633 |
587 CONFIG_VALUE_HANDLER(defines, std::string) | 634 CONFIG_VALUE_HANDLER(defines, std::string) |
588 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) | 635 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) |
589 CONFIG_VALUE_HANDLER(cflags, std::string) | 636 CONFIG_VALUE_HANDLER(cflags, std::string) |
590 CONFIG_VALUE_HANDLER(cflags_c, std::string) | 637 CONFIG_VALUE_HANDLER(cflags_c, std::string) |
591 CONFIG_VALUE_HANDLER(cflags_cc, std::string) | 638 CONFIG_VALUE_HANDLER(cflags_cc, std::string) |
592 CONFIG_VALUE_HANDLER(cflags_objc, std::string) | 639 CONFIG_VALUE_HANDLER(cflags_objc, std::string) |
593 CONFIG_VALUE_HANDLER(cflags_objcc, std::string) | 640 CONFIG_VALUE_HANDLER(cflags_objcc, std::string) |
594 CONFIG_VALUE_HANDLER(ldflags, std::string) | 641 CONFIG_VALUE_HANDLER(ldflags, std::string) |
(...skipping 24 matching lines...) Expand all Loading... |
619 // Header. | 666 // Header. |
620 OutputString("Target: ", DECORATION_YELLOW); | 667 OutputString("Target: ", DECORATION_YELLOW); |
621 OutputString(target->label().GetUserVisibleName(false) + "\n"); | 668 OutputString(target->label().GetUserVisibleName(false) + "\n"); |
622 OutputString("Type: ", DECORATION_YELLOW); | 669 OutputString("Type: ", DECORATION_YELLOW); |
623 OutputString(std::string( | 670 OutputString(std::string( |
624 Target::GetStringForOutputType(target->output_type())) + "\n"); | 671 Target::GetStringForOutputType(target->output_type())) + "\n"); |
625 OutputString("Toolchain: ", DECORATION_YELLOW); | 672 OutputString("Toolchain: ", DECORATION_YELLOW); |
626 OutputString(target_toolchain.GetUserVisibleName(false) + "\n"); | 673 OutputString(target_toolchain.GetUserVisibleName(false) + "\n"); |
627 | 674 |
628 PrintSources(target, true); | 675 PrintSources(target, true); |
629 if (is_binary_output) | 676 if (is_binary_output) { |
630 PrintPublic(target, true); | 677 PrintPublic(target, true); |
| 678 PrintCheckIncludes(target, true); |
| 679 PrintAllowCircularIncludesFrom(target, true); |
| 680 } |
631 PrintVisibility(target, true); | 681 PrintVisibility(target, true); |
632 if (is_binary_output) | 682 if (is_binary_output) { |
| 683 PrintTestonly(target, true); |
633 PrintConfigs(target, true); | 684 PrintConfigs(target, true); |
| 685 } |
634 | 686 |
635 PrintDirectDependentConfigs(target, true); | 687 PrintDirectDependentConfigs(target, true); |
636 PrintAllDependentConfigs(target, true); | 688 PrintAllDependentConfigs(target, true); |
637 PrintForwardDependentConfigsFrom(target, true); | 689 PrintForwardDependentConfigsFrom(target, true); |
638 | 690 |
639 PrintInputs(target, true); | 691 PrintInputs(target, true); |
640 | 692 |
641 if (is_binary_output) { | 693 if (is_binary_output) { |
642 OUTPUT_CONFIG_VALUE(defines, std::string) | 694 OUTPUT_CONFIG_VALUE(defines, std::string) |
643 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) | 695 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) |
(...skipping 22 matching lines...) Expand all Loading... |
666 // so always display them, even for groups and such. | 718 // so always display them, even for groups and such. |
667 PrintLibs(target, true); | 719 PrintLibs(target, true); |
668 PrintLibDirs(target, true); | 720 PrintLibDirs(target, true); |
669 | 721 |
670 PrintDeps(target, true); | 722 PrintDeps(target, true); |
671 | 723 |
672 return 0; | 724 return 0; |
673 } | 725 } |
674 | 726 |
675 } // namespace commands | 727 } // namespace commands |
OLD | NEW |