Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: tools/gn/command_refs.cc

Issue 1098603002: Add the ability to pass long lists of inputs to 'gn refs'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update w/ more review feedback Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 (size_t i = 1; i < args.size(); i++) {
401 if (args[i][0] == '@') {
402 // The argument is as a path to a response file.
403 std::string contents;
404 std::vector<std::string> lines;
405 bool ret = base::ReadFileToString(UTF8ToFilePath(args[i].substr(1)),
406 &contents);
407 if (!ret) {
408 Err(Location(), "Response file " + args[i].substr(1) + " not found.")
409 .PrintToStdout();
410 return 1;
411 }
412 base::SplitString(contents, '\n', &lines);
413 for (const auto& line : lines) {
414 if (!line.empty())
415 inputs.push_back(line);
416 }
417 } else {
418 // The argument is a label or a path.
419 inputs.push_back(args[i]);
420 }
421 }
392 422
393 // Get the matches for the command-line input. 423 // Get the matches for the command-line input.
394 UniqueVector<const Target*> target_matches; 424 UniqueVector<const Target*> target_matches;
395 UniqueVector<const Config*> config_matches; 425 UniqueVector<const Config*> config_matches;
396 UniqueVector<const Toolchain*> toolchain_matches; 426 UniqueVector<const Toolchain*> toolchain_matches;
397 UniqueVector<SourceFile> file_matches; 427 UniqueVector<SourceFile> file_matches;
398 if (!ResolveFromCommandLineInput(setup, inputs, all_toolchains, 428 if (!ResolveFromCommandLineInput(setup, inputs, all_toolchains,
399 &target_matches, &config_matches, 429 &target_matches, &config_matches,
400 &toolchain_matches, &file_matches)) 430 &toolchain_matches, &file_matches))
401 return 1; 431 return 1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 474
445 // 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
446 // nothing referencing it, we'll get here without having printed anything. 476 // nothing referencing it, we'll get here without having printed anything.
447 if (!quiet && cnt == 0) 477 if (!quiet && cnt == 0)
448 OutputString("Nothing references this.\n", DECORATION_YELLOW); 478 OutputString("Nothing references this.\n", DECORATION_YELLOW);
449 479
450 return 0; 480 return 0;
451 } 481 }
452 482
453 } // namespace commands 483 } // namespace commands
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698