Index: tools/gn/command_refs.cc |
diff --git a/tools/gn/command_refs.cc b/tools/gn/command_refs.cc |
index 832f53a7f29a957f11d0b6b121f308ef0b7578c8..2055b9925eb49e49a79158d9af31a6d9e8a80400 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,31 @@ 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 (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.
|
+ 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.
|
+ |
+ if (arg[0] == '@') { |
+ // The argument is as a path to a response file. |
+ std::string contents; |
+ std::vector<std::string> lines; |
+ 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.
|
+ &contents); |
+ if (!ret) { |
+ Err(Location(), "Response file " + arg.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(*it); |
+ } |
+ } |
// Get the matches for the command-line input. |
UniqueVector<const Target*> target_matches; |