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

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

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang warning Created 6 years, 4 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 | Annotate | Revision Log
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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "tools/gn/commands.h" 10 #include "tools/gn/commands.h"
11 #include "tools/gn/config.h" 11 #include "tools/gn/config.h"
12 #include "tools/gn/config_values_extractors.h" 12 #include "tools/gn/config_values_extractors.h"
13 #include "tools/gn/file_template.h"
14 #include "tools/gn/filesystem_utils.h" 13 #include "tools/gn/filesystem_utils.h"
15 #include "tools/gn/item.h" 14 #include "tools/gn/item.h"
16 #include "tools/gn/label.h" 15 #include "tools/gn/label.h"
17 #include "tools/gn/setup.h" 16 #include "tools/gn/setup.h"
18 #include "tools/gn/standard_out.h" 17 #include "tools/gn/standard_out.h"
18 #include "tools/gn/substitution_writer.h"
19 #include "tools/gn/target.h" 19 #include "tools/gn/target.h"
20 20
21 namespace commands { 21 namespace commands {
22 22
23 namespace { 23 namespace {
24 24
25 // Prints the given directory in a nice way for the user to view. 25 // Prints the given directory in a nice way for the user to view.
26 std::string FormatSourceDir(const SourceDir& dir) { 26 std::string FormatSourceDir(const SourceDir& dir) {
27 #if defined(OS_WIN) 27 #if defined(OS_WIN)
28 // On Windows we fix up system absolute paths to look like native ones. 28 // On Windows we fix up system absolute paths to look like native ones.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 OutputString("\n" + header + ":\n"); 241 OutputString("\n" + header + ":\n");
242 242
243 std::string indent = indent_extra ? " " : " "; 243 std::string indent = indent_extra ? " " : " ";
244 244
245 Target::FileList sorted = files; 245 Target::FileList sorted = files;
246 std::sort(sorted.begin(), sorted.end()); 246 std::sort(sorted.begin(), sorted.end());
247 for (size_t i = 0; i < sorted.size(); i++) 247 for (size_t i = 0; i < sorted.size(); i++)
248 OutputString(indent + sorted[i].value() + "\n"); 248 OutputString(indent + sorted[i].value() + "\n");
249 } 249 }
250 250
251 // This sorts the list.
252 void PrintStringList(const std::vector<std::string>& strings,
253 const std::string& header,
254 bool indent_extra,
255 bool display_header) {
256 if (strings.empty())
257 return;
258
259 if (display_header)
260 OutputString("\n" + header + ":\n");
261
262 std::string indent = indent_extra ? " " : " ";
263
264 std::vector<std::string> sorted = strings;
265 std::sort(sorted.begin(), sorted.end());
266 for (size_t i = 0; i < sorted.size(); i++)
267 OutputString(indent + sorted[i] + "\n");
268 }
269
270 void PrintSources(const Target* target, bool display_header) { 251 void PrintSources(const Target* target, bool display_header) {
271 PrintFileList(target->sources(), "sources", false, display_header); 252 PrintFileList(target->sources(), "sources", false, display_header);
272 } 253 }
273 254
274 void PrintInputs(const Target* target, bool display_header) { 255 void PrintInputs(const Target* target, bool display_header) {
275 PrintFileList(target->inputs(), "inputs", false, display_header); 256 PrintFileList(target->inputs(), "inputs", false, display_header);
276 } 257 }
277 258
278 void PrintOutputs(const Target* target, bool display_header) { 259 void PrintOutputs(const Target* target, bool display_header) {
260 if (display_header)
261 OutputString("\noutputs:\n");
262
279 if (target->output_type() == Target::ACTION) { 263 if (target->output_type() == Target::ACTION) {
280 // Just display the outputs directly. 264 // Action, print out outputs, don't apply sources to it.
281 PrintStringList(target->action_values().outputs(), "outputs", false, 265 for (size_t i = 0; i < target->action_values().outputs().list().size();
282 display_header); 266 i++) {
283 } else if (target->output_type() == Target::ACTION_FOREACH || 267 OutputString(" " +
284 target->output_type() == Target::COPY_FILES) { 268 target->action_values().outputs().list()[i].AsString() +
285 // Display both the output pattern and resolved list. 269 "\n");
286 if (display_header) 270 }
287 OutputString("\noutputs:\n"); 271 } else {
272 const SubstitutionList& outputs = target->action_values().outputs();
273 if (!outputs.required_types().empty()) {
274 // Display the pattern and resolved pattern separately, since there are
275 // subtitutions used.
276 OutputString(" Output pattern:\n");
277 for (size_t i = 0; i < outputs.list().size(); i++)
278 OutputString(" " + outputs.list()[i].AsString() + "\n");
288 279
289 // Display the pattern. 280 // Now display what that resolves to given the sources.
290 OutputString(" Output pattern:\n"); 281 OutputString("\n Resolved output file list:\n");
291 PrintStringList(target->action_values().outputs(), "", true, false); 282 }
292 283
293 // Now display what that resolves to given the sources. 284 // Resolved output list.
294 OutputString("\n Resolved output file list:\n"); 285 std::vector<SourceFile> output_files;
295 286 SubstitutionWriter::ApplyListToSources(target->settings(), outputs,
296 std::vector<std::string> output_strings; 287 target->sources(), &output_files);
297 FileTemplate file_template = FileTemplate::GetForTargetOutputs(target); 288 PrintFileList(output_files, "", true, false);
298 for (size_t i = 0; i < target->sources().size(); i++)
299 file_template.Apply(target->sources()[i], &output_strings);
300 PrintStringList(output_strings, "", true, false);
301 } 289 }
302 } 290 }
303 291
304 void PrintScript(const Target* target, bool display_header) { 292 void PrintScript(const Target* target, bool display_header) {
305 if (display_header) 293 if (display_header)
306 OutputString("\nscript:\n"); 294 OutputString("\nscript:\n");
307 OutputString(" " + target->action_values().script().value() + "\n"); 295 OutputString(" " + target->action_values().script().value() + "\n");
308 } 296 }
309 297
310 void PrintArgs(const Target* target, bool display_header) { 298 void PrintArgs(const Target* target, bool display_header) {
311 if (display_header) 299 if (display_header)
312 OutputString("\nargs:\n"); 300 OutputString("\nargs:\n");
313 for (size_t i = 0; i < target->action_values().args().size(); i++) 301 for (size_t i = 0; i < target->action_values().args().list().size(); i++) {
314 OutputString(" " + target->action_values().args()[i] + "\n"); 302 OutputString(" " +
303 target->action_values().args().list()[i].AsString() + "\n");
304 }
315 } 305 }
316 306
317 void PrintDepfile(const Target* target, bool display_header) { 307 void PrintDepfile(const Target* target, bool display_header) {
318 if (target->action_values().depfile().value().empty()) 308 if (target->action_values().depfile().empty())
319 return; 309 return;
320 if (display_header) 310 if (display_header)
321 OutputString("\ndepfile:\n"); 311 OutputString("\ndepfile:\n");
322 OutputString(" " + target->action_values().depfile().value() + "\n"); 312 OutputString(" " + target->action_values().depfile().AsString() + "\n");
323 } 313 }
324 314
325 // Attribute the origin for attributing from where a target came from. Does 315 // Attribute the origin for attributing from where a target came from. Does
326 // nothing if the input is null or it does not have a location. 316 // nothing if the input is null or it does not have a location.
327 void OutputSourceOfDep(const ParseNode* origin, std::ostream& out) { 317 void OutputSourceOfDep(const ParseNode* origin, std::ostream& out) {
328 if (!origin) 318 if (!origin)
329 return; 319 return;
330 Location location = origin->GetRange().begin(); 320 Location location = origin->GetRange().begin();
331 out << " (Added by " + location.file()->name().value() << ":" 321 out << " (Added by " + location.file()->name().value() << ":"
332 << location.line_number() << ")\n"; 322 << location.line_number() << ")\n";
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // so always display them, even for groups and such. 599 // so always display them, even for groups and such.
610 PrintLibs(target, true); 600 PrintLibs(target, true);
611 PrintLibDirs(target, true); 601 PrintLibDirs(target, true);
612 602
613 PrintDeps(target, true); 603 PrintDeps(target, true);
614 604
615 return 0; 605 return 0;
616 } 606 }
617 607
618 } // namespace commands 608 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/action_values.h ('k') | tools/gn/command_help.cc » ('j') | tools/gn/command_help.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698