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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "tools/gn/commands.h" | 13 #include "tools/gn/commands.h" |
14 #include "tools/gn/deps_iterator.h" | 14 #include "tools/gn/deps_iterator.h" |
15 #include "tools/gn/filesystem_utils.h" | 15 #include "tools/gn/filesystem_utils.h" |
16 #include "tools/gn/input_file.h" | 16 #include "tools/gn/input_file.h" |
17 #include "tools/gn/item.h" | 17 #include "tools/gn/item.h" |
18 #include "tools/gn/setup.h" | 18 #include "tools/gn/setup.h" |
19 #include "tools/gn/standard_out.h" | 19 #include "tools/gn/standard_out.h" |
| 20 #include "tools/gn/switches.h" |
20 #include "tools/gn/target.h" | 21 #include "tools/gn/target.h" |
21 | 22 |
22 namespace commands { | 23 namespace commands { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 typedef std::set<const Target*> TargetSet; | 27 typedef std::set<const Target*> TargetSet; |
27 typedef std::vector<const Target*> TargetVector; | 28 typedef std::vector<const Target*> TargetVector; |
28 | 29 |
29 // Maps targets to the list of targets that depend on them. | 30 // Maps targets to the list of targets that depend on them. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 "\n" | 309 "\n" |
309 " --all\n" | 310 " --all\n" |
310 " When used without --tree, will recurse and display all unique\n" | 311 " When used without --tree, will recurse and display all unique\n" |
311 " dependencies of the given targets. For example, if the input is\n" | 312 " dependencies of the given targets. For example, if the input is\n" |
312 " a target, this will output all targets that depend directly or\n" | 313 " a target, this will output all targets that depend directly or\n" |
313 " indirectly on the input. If the input is a file, this will output\n" | 314 " indirectly on the input. If the input is a file, this will output\n" |
314 " all targets that depend directly or indirectly on that file.\n" | 315 " all targets that depend directly or indirectly on that file.\n" |
315 "\n" | 316 "\n" |
316 " When used with --tree, turns off eliding to show a complete tree.\n" | 317 " When used with --tree, turns off eliding to show a complete tree.\n" |
317 "\n" | 318 "\n" |
318 " --all-toolchains\n" | 319 ALL_TOOLCHAINS_SWITCH_HELP |
319 " Normally only inputs in the default toolchain will be included.\n" | |
320 " This switch will turn on matching all toolchains.\n" | |
321 "\n" | |
322 " For example, a file is in a target might be compiled twice:\n" | |
323 " once in the default toolchain and once in a secondary one. Without\n" | |
324 " this flag, only the default toolchain one will be matched and\n" | |
325 " printed (potentially with its recursive dependencies, depending on\n" | |
326 " the other options). With this flag, both will be printed\n" | |
327 " (potentially with both of their recursive dependencies).\n" | |
328 "\n" | 320 "\n" |
329 TARGET_PRINTING_MODE_COMMAND_LINE_HELP | 321 TARGET_PRINTING_MODE_COMMAND_LINE_HELP |
330 "\n" | 322 "\n" |
331 " -q\n" | 323 " -q\n" |
332 " Quiet. If nothing matches, don't print any output. Without this\n" | 324 " Quiet. If nothing matches, don't print any output. Without this\n" |
333 " option, if there are no matches there will be an informational\n" | 325 " option, if there are no matches there will be an informational\n" |
334 " message printed which might interfere with scripts processing the\n" | 326 " message printed which might interfere with scripts processing the\n" |
335 " output.\n" | 327 " output.\n" |
336 "\n" | 328 "\n" |
337 TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP | 329 TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 if (args.size() <= 1) { | 382 if (args.size() <= 1) { |
391 Err(Location(), "You're holding it wrong.", | 383 Err(Location(), "You're holding it wrong.", |
392 "Usage: \"gn refs <out_dir> (<label_pattern>|<file>)*\"") | 384 "Usage: \"gn refs <out_dir> (<label_pattern>|<file>)*\"") |
393 .PrintToStdout(); | 385 .PrintToStdout(); |
394 return 1; | 386 return 1; |
395 } | 387 } |
396 | 388 |
397 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 389 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
398 bool tree = cmdline->HasSwitch("tree"); | 390 bool tree = cmdline->HasSwitch("tree"); |
399 bool all = cmdline->HasSwitch("all"); | 391 bool all = cmdline->HasSwitch("all"); |
400 bool all_toolchains = cmdline->HasSwitch("all-toolchains"); | 392 bool all_toolchains = cmdline->HasSwitch(switches::kAllToolchains); |
401 | 393 |
402 Setup* setup = new Setup; | 394 Setup* setup = new Setup; |
403 setup->build_settings().set_check_for_bad_items(false); | 395 setup->build_settings().set_check_for_bad_items(false); |
404 if (!setup->DoSetup(args[0], false) || !setup->Run()) | 396 if (!setup->DoSetup(args[0], false) || !setup->Run()) |
405 return 1; | 397 return 1; |
406 | 398 |
407 // The inputs are everything but the first arg (which is the build dir). | 399 // The inputs are everything but the first arg (which is the build dir). |
408 std::vector<std::string> inputs; | 400 std::vector<std::string> inputs; |
409 for (size_t i = 1; i < args.size(); i++) { | 401 for (size_t i = 1; i < args.size(); i++) { |
410 if (args[i][0] == '@') { | 402 if (args[i][0] == '@') { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 474 |
483 // If you ask for the references of a valid target, but that target has | 475 // If you ask for the references of a valid target, but that target has |
484 // nothing referencing it, we'll get here without having printed anything. | 476 // nothing referencing it, we'll get here without having printed anything. |
485 if (!quiet && cnt == 0) | 477 if (!quiet && cnt == 0) |
486 OutputString("Nothing references this.\n", DECORATION_YELLOW); | 478 OutputString("Nothing references this.\n", DECORATION_YELLOW); |
487 | 479 |
488 return 0; | 480 return 0; |
489 } | 481 } |
490 | 482 |
491 } // namespace commands | 483 } // namespace commands |
OLD | NEW |