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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | |
10 #include "base/strings/string_split.h" | |
9 #include "tools/gn/commands.h" | 11 #include "tools/gn/commands.h" |
10 #include "tools/gn/deps_iterator.h" | 12 #include "tools/gn/deps_iterator.h" |
11 #include "tools/gn/filesystem_utils.h" | 13 #include "tools/gn/filesystem_utils.h" |
12 #include "tools/gn/input_file.h" | 14 #include "tools/gn/input_file.h" |
13 #include "tools/gn/item.h" | 15 #include "tools/gn/item.h" |
14 #include "tools/gn/setup.h" | 16 #include "tools/gn/setup.h" |
15 #include "tools/gn/standard_out.h" | 17 #include "tools/gn/standard_out.h" |
16 #include "tools/gn/target.h" | 18 #include "tools/gn/target.h" |
17 | 19 |
18 namespace commands { | 20 namespace commands { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 FilterAndPrintTargetSet(false, results); | 261 FilterAndPrintTargetSet(false, results); |
260 return results.size(); | 262 return results.size(); |
261 } | 263 } |
262 | 264 |
263 } // namespace | 265 } // namespace |
264 | 266 |
265 const char kRefs[] = "refs"; | 267 const char kRefs[] = "refs"; |
266 const char kRefs_HelpShort[] = | 268 const char kRefs_HelpShort[] = |
267 "refs: Find stuff referencing a target or file."; | 269 "refs: Find stuff referencing a target or file."; |
268 const char kRefs_Help[] = | 270 const char kRefs_Help[] = |
269 "gn refs <out_dir> (<label_pattern>|<label>|<file>)* [--all]\n" | 271 "gn refs <out_dir> (<label_pattern>|<label>|<file>|@<response_file>)* " |
272 "[--all]\n" | |
270 " [--all-toolchains] [--as=...] [--testonly=...] [--type=...]\n" | 273 " [--all-toolchains] [--as=...] [--testonly=...] [--type=...]\n" |
271 "\n" | 274 "\n" |
272 " Finds reverse dependencies (which targets reference something). The\n" | 275 " Finds reverse dependencies (which targets reference something). The\n" |
273 " input is a list containing:\n" | 276 " input is a list containing:\n" |
274 "\n" | 277 "\n" |
275 " - Target label: The result will be which targets depend on it.\n" | 278 " - Target label: The result will be which targets depend on it.\n" |
276 "\n" | 279 "\n" |
277 " - Config label: The result will be which targets list the given\n" | 280 " - Config label: The result will be which targets list the given\n" |
278 " config in its \"configs\" or \"public_configs\" list.\n" | 281 " config in its \"configs\" or \"public_configs\" list.\n" |
279 "\n" | 282 "\n" |
280 " - Label pattern: The result will be which targets depend on any\n" | 283 " - Label pattern: The result will be which targets depend on any\n" |
281 " target matching the given pattern. Patterns will not match\n" | 284 " target matching the given pattern. Patterns will not match\n" |
282 " configs. These are not general regular expressions, see\n" | 285 " configs. These are not general regular expressions, see\n" |
283 " \"gn help label_pattern\" for details.\n" | 286 " \"gn help label_pattern\" for details.\n" |
284 "\n" | 287 "\n" |
285 " - File name: The result will be which targets list the given file in\n" | 288 " - File name: The result will be which targets list the given file in\n" |
286 " its \"inputs\", \"sources\", \"public\", or \"data\". Any input\n" | 289 " its \"inputs\", \"sources\", \"public\", or \"data\". Any input\n" |
287 " that does not contain wildcards and does not match a target or a\n" | 290 " that does not contain wildcards and does not match a target or a\n" |
288 " config will be treated as a file.\n" | 291 " config will be treated as a file.\n" |
289 "\n" | 292 "\n" |
293 " - Response file: If the input starts with an \"@\", it will be\n" | |
294 " interpreted as a path to a file containing a list of labels or\n" | |
295 " file names, one per line. This allows us to handle long lists\n" | |
296 " of inputs without worrying about command line limits.\n" | |
297 "\n" | |
290 "Options\n" | 298 "Options\n" |
291 "\n" | 299 "\n" |
292 " --all\n" | 300 " --all\n" |
293 " When used without --tree, will recurse and display all unique\n" | 301 " When used without --tree, will recurse and display all unique\n" |
294 " dependencies of the given targets. For example, if the input is\n" | 302 " dependencies of the given targets. For example, if the input is\n" |
295 " a target, this will output all targets that depend directly or\n" | 303 " a target, this will output all targets that depend directly or\n" |
296 " indirectly on the input. If the input is a file, this will output\n" | 304 " indirectly on the input. If the input is a file, this will output\n" |
297 " all targets that depend directly or indirectly on that file.\n" | 305 " all targets that depend directly or indirectly on that file.\n" |
298 "\n" | 306 "\n" |
299 " When used with --tree, turns off eliding to show a complete tree.\n" | 307 " When used with --tree, turns off eliding to show a complete tree.\n" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 bool tree = cmdline->HasSwitch("tree"); | 389 bool tree = cmdline->HasSwitch("tree"); |
382 bool all = cmdline->HasSwitch("all"); | 390 bool all = cmdline->HasSwitch("all"); |
383 bool all_toolchains = cmdline->HasSwitch("all-toolchains"); | 391 bool all_toolchains = cmdline->HasSwitch("all-toolchains"); |
384 | 392 |
385 Setup* setup = new Setup; | 393 Setup* setup = new Setup; |
386 setup->set_check_for_bad_items(false); | 394 setup->set_check_for_bad_items(false); |
387 if (!setup->DoSetup(args[0], false) || !setup->Run()) | 395 if (!setup->DoSetup(args[0], false) || !setup->Run()) |
388 return 1; | 396 return 1; |
389 | 397 |
390 // The inputs are everything but the first arg (which is the build dir). | 398 // The inputs are everything but the first arg (which is the build dir). |
391 std::vector<std::string> inputs(args.begin() + 1, args.end()); | 399 std::vector<std::string> inputs; |
400 for (auto it = args.begin() + 1; it != args.end(); it++) { | |
brettw
2015/04/17 21:23:25
I think this case is much clearer as an integer it
Dirk Pranke
2015/04/17 21:35:16
Done.
| |
401 auto arg = *it; | |
brettw
2015/04/17 21:23:25
This is secretly hiding a string copy. You could m
Dirk Pranke
2015/04/17 21:35:16
True. Done.
| |
402 | |
403 if (arg[0] == '@') { | |
404 // The argument is as a path to a response file. | |
405 std::string contents; | |
406 std::vector<std::string> lines; | |
407 bool ret = base::ReadFileToString(base::FilePath(arg.substr(1)), | |
brettw
2015/04/17 21:23:25
This will fail on Windows. You'll want UTF8ToFileP
Dirk Pranke
2015/04/17 21:35:15
Done.
| |
408 &contents); | |
409 if (!ret) { | |
410 Err(Location(), "Response file " + arg.substr(1) + " not found.") | |
411 .PrintToStdout(); | |
412 return 1; | |
413 } | |
414 base::SplitString(contents, '\n', &lines); | |
415 for (const auto& line : lines) { | |
416 if (!line.empty()) | |
417 inputs.push_back(line); | |
418 } | |
419 } else { | |
420 // The argument is a label or a path. | |
421 inputs.push_back(*it); | |
422 } | |
423 } | |
392 | 424 |
393 // Get the matches for the command-line input. | 425 // Get the matches for the command-line input. |
394 UniqueVector<const Target*> target_matches; | 426 UniqueVector<const Target*> target_matches; |
395 UniqueVector<const Config*> config_matches; | 427 UniqueVector<const Config*> config_matches; |
396 UniqueVector<const Toolchain*> toolchain_matches; | 428 UniqueVector<const Toolchain*> toolchain_matches; |
397 UniqueVector<SourceFile> file_matches; | 429 UniqueVector<SourceFile> file_matches; |
398 if (!ResolveFromCommandLineInput(setup, inputs, all_toolchains, | 430 if (!ResolveFromCommandLineInput(setup, inputs, all_toolchains, |
399 &target_matches, &config_matches, | 431 &target_matches, &config_matches, |
400 &toolchain_matches, &file_matches)) | 432 &toolchain_matches, &file_matches)) |
401 return 1; | 433 return 1; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 476 |
445 // If you ask for the references of a valid target, but that target has | 477 // If you ask for the references of a valid target, but that target has |
446 // nothing referencing it, we'll get here without having printed anything. | 478 // nothing referencing it, we'll get here without having printed anything. |
447 if (!quiet && cnt == 0) | 479 if (!quiet && cnt == 0) |
448 OutputString("Nothing references this.\n", DECORATION_YELLOW); | 480 OutputString("Nothing references this.\n", DECORATION_YELLOW); |
449 | 481 |
450 return 0; | 482 return 0; |
451 } | 483 } |
452 | 484 |
453 } // namespace commands | 485 } // namespace commands |
OLD | NEW |