| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
| 10 #include "tools/gn/label_pattern.h" | 10 #include "tools/gn/label_pattern.h" |
| 11 #include "tools/gn/setup.h" | 11 #include "tools/gn/setup.h" |
| 12 #include "tools/gn/standard_out.h" | 12 #include "tools/gn/standard_out.h" |
| 13 #include "tools/gn/switches.h" |
| 13 #include "tools/gn/target.h" | 14 #include "tools/gn/target.h" |
| 14 | 15 |
| 15 namespace commands { | 16 namespace commands { |
| 16 | 17 |
| 17 const char kLs[] = "ls"; | 18 const char kLs[] = "ls"; |
| 18 const char kLs_HelpShort[] = | 19 const char kLs_HelpShort[] = |
| 19 "ls: List matching targets."; | 20 "ls: List matching targets."; |
| 20 const char kLs_Help[] = | 21 const char kLs_Help[] = |
| 21 "gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...]\n" | 22 "gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...]\n" |
| 22 " [--type=...] [--testonly=...]\n" | 23 " [--type=...] [--testonly=...]\n" |
| 23 "\n" | 24 "\n" |
| 24 " Lists all targets matching the given pattern for the given build\n" | 25 " Lists all targets matching the given pattern for the given build\n" |
| 25 " directory. By default, only targets in the default toolchain will\n" | 26 " directory. By default, only targets in the default toolchain will\n" |
| 26 " be matched unless a toolchain is explicitly supplied.\n" | 27 " be matched unless a toolchain is explicitly supplied.\n" |
| 27 "\n" | 28 "\n" |
| 28 " If the label pattern is unspecified, list all targets. The label\n" | 29 " If the label pattern is unspecified, list all targets. The label\n" |
| 29 " pattern is not a general regular expression (see\n" | 30 " pattern is not a general regular expression (see\n" |
| 30 " \"gn help label_pattern\"). If you need more complex expressions,\n" | 31 " \"gn help label_pattern\"). If you need more complex expressions,\n" |
| 31 " pipe the result through grep.\n" | 32 " pipe the result through grep.\n" |
| 32 "\n" | 33 "\n" |
| 33 "Options\n" | 34 "Options\n" |
| 34 "\n" | 35 "\n" |
| 35 TARGET_PRINTING_MODE_COMMAND_LINE_HELP | 36 TARGET_PRINTING_MODE_COMMAND_LINE_HELP |
| 36 "\n" | 37 "\n" |
| 37 " --all-toolchains\n" | 38 ALL_TOOLCHAINS_SWITCH_HELP |
| 38 " Matches all toolchains. When set, if the label pattern does not\n" | |
| 39 " specify an explicit toolchain, labels from all toolchains will be\n" | |
| 40 " matched. When unset, only targets in the default toolchain will\n" | |
| 41 " be matched unless an explicit toolchain in the label is set.\n" | |
| 42 "\n" | 39 "\n" |
| 43 TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP | 40 TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP |
| 44 "\n" | 41 "\n" |
| 45 TARGET_TYPE_FILTER_COMMAND_LINE_HELP | 42 TARGET_TYPE_FILTER_COMMAND_LINE_HELP |
| 46 "\n" | 43 "\n" |
| 47 "Examples\n" | 44 "Examples\n" |
| 48 "\n" | 45 "\n" |
| 49 " gn ls out/Debug\n" | 46 " gn ls out/Debug\n" |
| 50 " Lists all targets in the default toolchain.\n" | 47 " Lists all targets in the default toolchain.\n" |
| 51 "\n" | 48 "\n" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 "Usage: \"gn ls <build dir> [<label_pattern>]*\"").PrintToStdout(); | 71 "Usage: \"gn ls <build dir> [<label_pattern>]*\"").PrintToStdout(); |
| 75 return 1; | 72 return 1; |
| 76 } | 73 } |
| 77 | 74 |
| 78 Setup* setup = new Setup; | 75 Setup* setup = new Setup; |
| 79 setup->build_settings().set_check_for_bad_items(false); | 76 setup->build_settings().set_check_for_bad_items(false); |
| 80 if (!setup->DoSetup(args[0], false) || !setup->Run()) | 77 if (!setup->DoSetup(args[0], false) || !setup->Run()) |
| 81 return 1; | 78 return 1; |
| 82 | 79 |
| 83 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 80 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 84 bool all_toolchains = cmdline->HasSwitch("all-toolchains"); | 81 bool all_toolchains = cmdline->HasSwitch(switches::kAllToolchains); |
| 85 | 82 |
| 86 std::vector<const Target*> matches; | 83 std::vector<const Target*> matches; |
| 87 if (args.size() > 1) { | 84 if (args.size() > 1) { |
| 88 // Some patterns or explicit labels were specified. | 85 // Some patterns or explicit labels were specified. |
| 89 std::vector<std::string> inputs(args.begin() + 1, args.end()); | 86 std::vector<std::string> inputs(args.begin() + 1, args.end()); |
| 90 | 87 |
| 91 UniqueVector<const Target*> target_matches; | 88 UniqueVector<const Target*> target_matches; |
| 92 UniqueVector<const Config*> config_matches; | 89 UniqueVector<const Config*> config_matches; |
| 93 UniqueVector<const Toolchain*> toolchain_matches; | 90 UniqueVector<const Toolchain*> toolchain_matches; |
| 94 UniqueVector<SourceFile> file_matches; | 91 UniqueVector<SourceFile> file_matches; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 for (const auto& target : setup->builder()->GetAllResolvedTargets()) { | 103 for (const auto& target : setup->builder()->GetAllResolvedTargets()) { |
| 107 if (target->settings()->is_default()) | 104 if (target->settings()->is_default()) |
| 108 matches.push_back(target); | 105 matches.push_back(target); |
| 109 } | 106 } |
| 110 } | 107 } |
| 111 FilterAndPrintTargets(false, &matches); | 108 FilterAndPrintTargets(false, &matches); |
| 112 return 0; | 109 return 0; |
| 113 } | 110 } |
| 114 | 111 |
| 115 } // namespace commands | 112 } // namespace commands |
| OLD | NEW |