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

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: 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
« no previous file with comments | « tools/gn/action_values.h ('k') | tools/gn/command_help.cc » ('j') | 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 <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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 OutputString("\n" + header + ":\n"); 275 OutputString("\n" + header + ":\n");
276 276
277 std::string indent = indent_extra ? " " : " "; 277 std::string indent = indent_extra ? " " : " ";
278 278
279 Target::FileList sorted = files; 279 Target::FileList sorted = files;
280 std::sort(sorted.begin(), sorted.end()); 280 std::sort(sorted.begin(), sorted.end());
281 for (size_t i = 0; i < sorted.size(); i++) 281 for (size_t i = 0; i < sorted.size(); i++)
282 OutputString(indent + sorted[i].value() + "\n"); 282 OutputString(indent + sorted[i].value() + "\n");
283 } 283 }
284 284
285 // This sorts the list.
286 void PrintStringList(const std::vector<std::string>& strings,
287 const std::string& header,
288 bool indent_extra,
289 bool display_header) {
290 if (strings.empty())
291 return;
292
293 if (display_header)
294 OutputString("\n" + header + ":\n");
295
296 std::string indent = indent_extra ? " " : " ";
297
298 std::vector<std::string> sorted = strings;
299 std::sort(sorted.begin(), sorted.end());
300 for (size_t i = 0; i < sorted.size(); i++)
301 OutputString(indent + sorted[i] + "\n");
302 }
303
304 void PrintSources(const Target* target, bool display_header) { 285 void PrintSources(const Target* target, bool display_header) {
305 PrintFileList(target->sources(), "sources", false, display_header); 286 PrintFileList(target->sources(), "sources", false, display_header);
306 } 287 }
307 288
308 void PrintInputs(const Target* target, bool display_header) { 289 void PrintInputs(const Target* target, bool display_header) {
309 PrintFileList(target->inputs(), "inputs", false, display_header); 290 PrintFileList(target->inputs(), "inputs", false, display_header);
310 } 291 }
311 292
312 void PrintOutputs(const Target* target, bool display_header) { 293 void PrintOutputs(const Target* target, bool display_header) {
294 if (display_header)
295 OutputString("\noutputs:\n");
296
313 if (target->output_type() == Target::ACTION) { 297 if (target->output_type() == Target::ACTION) {
314 // Just display the outputs directly. 298 // Action, print out outputs, don't apply sources to it.
315 PrintStringList(target->action_values().outputs(), "outputs", false, 299 for (size_t i = 0; i < target->action_values().outputs().list().size();
316 display_header); 300 i++) {
317 } else if (target->output_type() == Target::ACTION_FOREACH || 301 OutputString(" " +
318 target->output_type() == Target::COPY_FILES) { 302 target->action_values().outputs().list()[i].AsString() +
319 // Display both the output pattern and resolved list. 303 "\n");
320 if (display_header) 304 }
321 OutputString("\noutputs:\n"); 305 } else {
306 const SubstitutionList& outputs = target->action_values().outputs();
307 if (!outputs.required_types().empty()) {
308 // Display the pattern and resolved pattern separately, since there are
309 // subtitutions used.
310 OutputString(" Output pattern:\n");
311 for (size_t i = 0; i < outputs.list().size(); i++)
312 OutputString(" " + outputs.list()[i].AsString() + "\n");
322 313
323 // Display the pattern. 314 // Now display what that resolves to given the sources.
324 OutputString(" Output pattern:\n"); 315 OutputString("\n Resolved output file list:\n");
325 PrintStringList(target->action_values().outputs(), "", true, false); 316 }
326 317
327 // Now display what that resolves to given the sources. 318 // Resolved output list.
328 OutputString("\n Resolved output file list:\n"); 319 std::vector<SourceFile> output_files;
329 320 SubstitutionWriter::ApplyListToSources(target->settings(), outputs,
330 std::vector<std::string> output_strings; 321 target->sources(), &output_files);
331 FileTemplate file_template = FileTemplate::GetForTargetOutputs(target); 322 PrintFileList(output_files, "", true, false);
332 for (size_t i = 0; i < target->sources().size(); i++)
333 file_template.Apply(target->sources()[i], &output_strings);
334 PrintStringList(output_strings, "", true, false);
335 } 323 }
336 } 324 }
337 325
338 void PrintScript(const Target* target, bool display_header) { 326 void PrintScript(const Target* target, bool display_header) {
339 if (display_header) 327 if (display_header)
340 OutputString("\nscript:\n"); 328 OutputString("\nscript:\n");
341 OutputString(" " + target->action_values().script().value() + "\n"); 329 OutputString(" " + target->action_values().script().value() + "\n");
342 } 330 }
343 331
344 void PrintArgs(const Target* target, bool display_header) { 332 void PrintArgs(const Target* target, bool display_header) {
345 if (display_header) 333 if (display_header)
346 OutputString("\nargs:\n"); 334 OutputString("\nargs:\n");
347 for (size_t i = 0; i < target->action_values().args().size(); i++) 335 for (size_t i = 0; i < target->action_values().args().list().size(); i++) {
348 OutputString(" " + target->action_values().args()[i] + "\n"); 336 OutputString(" " +
337 target->action_values().args().list()[i].AsString() + "\n");
338 }
349 } 339 }
350 340
351 void PrintDepfile(const Target* target, bool display_header) { 341 void PrintDepfile(const Target* target, bool display_header) {
352 if (target->action_values().depfile().value().empty()) 342 if (target->action_values().depfile().empty())
353 return; 343 return;
354 if (display_header) 344 if (display_header)
355 OutputString("\ndepfile:\n"); 345 OutputString("\ndepfile:\n");
356 OutputString(" " + target->action_values().depfile().value() + "\n"); 346 OutputString(" " + target->action_values().depfile().AsString() + "\n");
357 } 347 }
358 348
359 // Attribute the origin for attributing from where a target came from. Does 349 // Attribute the origin for attributing from where a target came from. Does
360 // nothing if the input is null or it does not have a location. 350 // nothing if the input is null or it does not have a location.
361 void OutputSourceOfDep(const ParseNode* origin, std::ostream& out) { 351 void OutputSourceOfDep(const ParseNode* origin, std::ostream& out) {
362 if (!origin) 352 if (!origin)
363 return; 353 return;
364 Location location = origin->GetRange().begin(); 354 Location location = origin->GetRange().begin();
365 out << " (Added by " + location.file()->name().value() << ":" 355 out << " (Added by " + location.file()->name().value() << ":"
366 << location.line_number() << ")\n"; 356 << location.line_number() << ")\n";
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 // so always display them, even for groups and such. 635 // so always display them, even for groups and such.
646 PrintLibs(target, true); 636 PrintLibs(target, true);
647 PrintLibDirs(target, true); 637 PrintLibDirs(target, true);
648 638
649 PrintDeps(target, true); 639 PrintDeps(target, true);
650 640
651 return 0; 641 return 0;
652 } 642 }
653 643
654 } // namespace commands 644 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/action_values.h ('k') | tools/gn/command_help.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698