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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/command_refs.cc
diff --git a/tools/gn/command_refs.cc b/tools/gn/command_refs.cc
index 832f53a7f29a957f11d0b6b121f308ef0b7578c8..57ea82477342c892dd8a3a70f02e1d145ef473a5 100644
--- a/tools/gn/command_refs.cc
+++ b/tools/gn/command_refs.cc
@@ -6,6 +6,8 @@
#include <set>
#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/strings/string_split.h"
#include "tools/gn/commands.h"
#include "tools/gn/deps_iterator.h"
#include "tools/gn/filesystem_utils.h"
@@ -266,7 +268,8 @@ const char kRefs[] = "refs";
const char kRefs_HelpShort[] =
"refs: Find stuff referencing a target or file.";
const char kRefs_Help[] =
- "gn refs <out_dir> (<label_pattern>|<label>|<file>)* [--all]\n"
+ "gn refs <out_dir> (<label_pattern>|<label>|<file>|@<response_file>)* "
+ "[--all]\n"
" [--all-toolchains] [--as=...] [--testonly=...] [--type=...]\n"
"\n"
" Finds reverse dependencies (which targets reference something). The\n"
@@ -287,6 +290,11 @@ const char kRefs_Help[] =
" that does not contain wildcards and does not match a target or a\n"
" config will be treated as a file.\n"
"\n"
+ " - Response file: If the input starts with an \"@\", it will be\n"
+ " interpreted as a path to a file containing a list of labels or\n"
+ " file names, one per line. This allows us to handle long lists\n"
+ " of inputs without worrying about command line limits.\n"
+ "\n"
"Options\n"
"\n"
" --all\n"
@@ -388,7 +396,29 @@ int RunRefs(const std::vector<std::string>& args) {
return 1;
// The inputs are everything but the first arg (which is the build dir).
- std::vector<std::string> inputs(args.begin() + 1, args.end());
+ std::vector<std::string> inputs;
+ for (size_t i = 1; i < args.size(); i++) {
+ if (args[i][0] == '@') {
+ // The argument is as a path to a response file.
+ std::string contents;
+ std::vector<std::string> lines;
+ bool ret = base::ReadFileToString(UTF8ToFilePath(args[i].substr(1)),
+ &contents);
+ if (!ret) {
+ Err(Location(), "Response file " + args[i].substr(1) + " not found.")
+ .PrintToStdout();
+ return 1;
+ }
+ base::SplitString(contents, '\n', &lines);
+ for (const auto& line : lines) {
+ if (!line.empty())
+ inputs.push_back(line);
+ }
+ } else {
+ // The argument is a label or a path.
+ inputs.push_back(args[i]);
+ }
+ }
// Get the matches for the command-line input.
UniqueVector<const Target*> target_matches;
« 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