| 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/switches.h" | 
| 14 #include "tools/gn/target.h" | 14 #include "tools/gn/target.h" | 
| 15 | 15 | 
| 16 namespace commands { | 16 namespace commands { | 
| 17 | 17 | 
| 18 const char kLs[] = "ls"; | 18 const char kLs[] = "ls"; | 
| 19 const char kLs_HelpShort[] = | 19 const char kLs_HelpShort[] = | 
| 20     "ls: List matching targets."; | 20     "ls: List matching targets."; | 
| 21 const char kLs_Help[] = | 21 const char kLs_Help[] = | 
| 22     "gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...]\n" | 22     R"(gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...] | 
| 23     "      [--type=...] [--testonly=...]\n" | 23       [--type=...] [--testonly=...] | 
| 24     "\n" | 24 | 
| 25     "  Lists all targets matching the given pattern for the given build\n" | 25   Lists all targets matching the given pattern for the given build directory. | 
| 26     "  directory. By default, only targets in the default toolchain will\n" | 26   By default, only targets in the default toolchain will be matched unless a | 
| 27     "  be matched unless a toolchain is explicitly supplied.\n" | 27   toolchain is explicitly supplied. | 
| 28     "\n" | 28 | 
| 29     "  If the label pattern is unspecified, list all targets. The label\n" | 29   If the label pattern is unspecified, list all targets. The label pattern is | 
| 30     "  pattern is not a general regular expression (see\n" | 30   not a general regular expression (see "gn help label_pattern"). If you need | 
| 31     "  \"gn help label_pattern\"). If you need more complex expressions,\n" | 31   more complex expressions, pipe the result through grep. | 
| 32     "  pipe the result through grep.\n" | 32 | 
| 33     "\n" | 33 Options | 
| 34     "Options\n" | 34 | 
| 35     "\n" | 35 )" | 
| 36     TARGET_PRINTING_MODE_COMMAND_LINE_HELP | 36     TARGET_PRINTING_MODE_COMMAND_LINE_HELP | 
| 37     "\n" | 37 "\n" | 
| 38     ALL_TOOLCHAINS_SWITCH_HELP | 38     ALL_TOOLCHAINS_SWITCH_HELP | 
| 39     "\n" | 39 "\n" | 
| 40     TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP | 40     TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP | 
| 41     "\n" | 41 "\n" | 
| 42     TARGET_TYPE_FILTER_COMMAND_LINE_HELP | 42     TARGET_TYPE_FILTER_COMMAND_LINE_HELP | 
| 43     "\n" | 43 R"( | 
| 44     "Examples\n" | 44 Examples | 
| 45     "\n" | 45 | 
| 46     "  gn ls out/Debug\n" | 46   gn ls out/Debug | 
| 47     "      Lists all targets in the default toolchain.\n" | 47       Lists all targets in the default toolchain. | 
| 48     "\n" | 48 | 
| 49     "  gn ls out/Debug \"//base/*\"\n" | 49   gn ls out/Debug "//base/*" | 
| 50     "      Lists all targets in the directory base and all subdirectories.\n" | 50       Lists all targets in the directory base and all subdirectories. | 
| 51     "\n" | 51 | 
| 52     "  gn ls out/Debug \"//base:*\"\n" | 52   gn ls out/Debug "//base:*" | 
| 53     "      Lists all targets defined in //base/BUILD.gn.\n" | 53       Lists all targets defined in //base/BUILD.gn. | 
| 54     "\n" | 54 | 
| 55     "  gn ls out/Debug //base --as=output\n" | 55   gn ls out/Debug //base --as=output | 
| 56     "      Lists the build output file for //base:base\n" | 56       Lists the build output file for //base:base | 
| 57     "\n" | 57 | 
| 58     "  gn ls out/Debug --type=executable\n" | 58   gn ls out/Debug --type=executable | 
| 59     "      Lists all executables produced by the build.\n" | 59       Lists all executables produced by the build. | 
| 60     "\n" | 60 | 
| 61     "  gn ls out/Debug \"//base/*\" --as=output | xargs ninja -C out/Debug\n" | 61   gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug | 
| 62     "      Builds all targets in //base and all subdirectories.\n" | 62       Builds all targets in //base and all subdirectories. | 
| 63     "\n" | 63 | 
| 64     "  gn ls out/Debug //base --all-toolchains\n" | 64   gn ls out/Debug //base --all-toolchains | 
| 65     "      Lists all variants of the target //base:base (it may be referenced\n" | 65       Lists all variants of the target //base:base (it may be referenced | 
| 66     "      in multiple toolchains).\n"; | 66       in multiple toolchains). | 
|  | 67 )"; | 
| 67 | 68 | 
| 68 int RunLs(const std::vector<std::string>& args) { | 69 int RunLs(const std::vector<std::string>& args) { | 
| 69   if (args.size() == 0) { | 70   if (args.size() == 0) { | 
| 70     Err(Location(), "You're holding it wrong.", | 71     Err(Location(), "You're holding it wrong.", | 
| 71         "Usage: \"gn ls <build dir> [<label_pattern>]*\"").PrintToStdout(); | 72         "Usage: \"gn ls <build dir> [<label_pattern>]*\"").PrintToStdout(); | 
| 72     return 1; | 73     return 1; | 
| 73   } | 74   } | 
| 74 | 75 | 
| 75   Setup* setup = new Setup; | 76   Setup* setup = new Setup; | 
| 76   setup->build_settings().set_check_for_bad_items(false); | 77   setup->build_settings().set_check_for_bad_items(false); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 103     for (auto* target : setup->builder().GetAllResolvedTargets()) { | 104     for (auto* target : setup->builder().GetAllResolvedTargets()) { | 
| 104       if (target->settings()->is_default()) | 105       if (target->settings()->is_default()) | 
| 105         matches.push_back(target); | 106         matches.push_back(target); | 
| 106     } | 107     } | 
| 107   } | 108   } | 
| 108   FilterAndPrintTargets(false, &matches); | 109   FilterAndPrintTargets(false, &matches); | 
| 109   return 0; | 110   return 0; | 
| 110 } | 111 } | 
| 111 | 112 | 
| 112 }  // namespace commands | 113 }  // namespace commands | 
| OLD | NEW | 
|---|