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

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

Issue 2156173003: Re-land r406064 "[GN] Add JSON project writer". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clear dependency Created 4 years, 5 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 | « tools/gn/commands.h ('k') | tools/gn/desc_builder.h » ('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 "tools/gn/commands.h" 5 #include "tools/gn/commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/values.h"
9 #include "tools/gn/builder.h" 10 #include "tools/gn/builder.h"
10 #include "tools/gn/filesystem_utils.h" 11 #include "tools/gn/filesystem_utils.h"
11 #include "tools/gn/item.h" 12 #include "tools/gn/item.h"
12 #include "tools/gn/label.h" 13 #include "tools/gn/label.h"
13 #include "tools/gn/label_pattern.h" 14 #include "tools/gn/label_pattern.h"
14 #include "tools/gn/setup.h" 15 #include "tools/gn/setup.h"
15 #include "tools/gn/standard_out.h" 16 #include "tools/gn/standard_out.h"
16 #include "tools/gn/target.h" 17 #include "tools/gn/target.h"
17 18
18 namespace commands { 19 namespace commands {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 274
274 targets->swap(result); 275 targets->swap(result);
275 return true; 276 return true;
276 } 277 }
277 278
278 // Returns the file path generating this item. 279 // Returns the file path generating this item.
279 base::FilePath BuildFileForItem(const Item* item) { 280 base::FilePath BuildFileForItem(const Item* item) {
280 return item->defined_from()->GetRange().begin().file()->physical_name(); 281 return item->defined_from()->GetRange().begin().file()->physical_name();
281 } 282 }
282 283
283 void PrintTargetsAsBuildfiles(bool indent, 284 void PrintTargetsAsBuildfiles(const std::vector<const Target*>& targets,
284 const std::vector<const Target*>& targets) { 285 base::ListValue* out) {
285 // Output the set of unique source files. 286 // Output the set of unique source files.
286 std::set<std::string> unique_files; 287 std::set<std::string> unique_files;
287 for (const Target* target : targets) 288 for (const Target* target : targets)
288 unique_files.insert(FilePathToUTF8(BuildFileForItem(target))); 289 unique_files.insert(FilePathToUTF8(BuildFileForItem(target)));
289 290
290 for (const std::string& file : unique_files) { 291 for (const std::string& file : unique_files) {
291 if (indent) 292 out->AppendString(file);
292 OutputString(" ");
293 OutputString(file + "\n");
294 } 293 }
295 } 294 }
296 295
297 void PrintTargetsAsLabels(bool indent, 296 void PrintTargetsAsLabels(const std::vector<const Target*>& targets,
298 const std::vector<const Target*>& targets) { 297 base::ListValue* out) {
299 // Putting the labels into a set automatically sorts them for us. 298 // Putting the labels into a set automatically sorts them for us.
300 std::set<Label> unique_labels; 299 std::set<Label> unique_labels;
301 for (auto* target : targets) 300 for (auto* target : targets)
302 unique_labels.insert(target->label()); 301 unique_labels.insert(target->label());
303 302
304 // Grab the label of the default toolchain from the first target. 303 // Grab the label of the default toolchain from the first target.
305 Label default_tc_label = 304 Label default_tc_label =
306 targets[0]->settings()->default_toolchain_label(); 305 targets[0]->settings()->default_toolchain_label();
307 306
308 for (const Label& label : unique_labels) { 307 for (const Label& label : unique_labels) {
309 // Print toolchain only for ones not in the default toolchain. 308 // Print toolchain only for ones not in the default toolchain.
310 if (indent) 309 out->AppendString(label.GetUserVisibleName(label.GetToolchainLabel() !=
311 OutputString(" "); 310 default_tc_label));
312 OutputString(label.GetUserVisibleName(
313 label.GetToolchainLabel() != default_tc_label));
314 OutputString("\n");
315 } 311 }
316 } 312 }
317 313
318 void PrintTargetsAsOutputs(bool indent, 314 void PrintTargetsAsOutputs(const std::vector<const Target*>& targets,
319 const std::vector<const Target*>& targets) { 315 base::ListValue* out) {
320 if (targets.empty()) 316 if (targets.empty())
321 return; 317 return;
322 318
323 // Grab the build settings from a random target. 319 // Grab the build settings from a random target.
324 const BuildSettings* build_settings = 320 const BuildSettings* build_settings =
325 targets[0]->settings()->build_settings(); 321 targets[0]->settings()->build_settings();
326 322
327 for (const Target* target : targets) { 323 for (const Target* target : targets) {
328 // Use the link output file if there is one, otherwise fall back to the 324 // Use the link output file if there is one, otherwise fall back to the
329 // dependency output file (for actions, for example). 325 // dependency output file (for actions, for example).
330 OutputFile output_file = target->link_output_file(); 326 OutputFile output_file = target->link_output_file();
331 if (output_file.value().empty()) 327 if (output_file.value().empty())
332 output_file = target->dependency_output_file(); 328 output_file = target->dependency_output_file();
333 329
334 SourceFile output_as_source = 330 SourceFile output_as_source =
335 output_file.AsSourceFile(build_settings); 331 output_file.AsSourceFile(build_settings);
336 std::string result = RebasePath(output_as_source.value(), 332 std::string result = RebasePath(output_as_source.value(),
337 build_settings->build_dir(), 333 build_settings->build_dir(),
338 build_settings->root_path_utf8()); 334 build_settings->root_path_utf8());
339 if (indent) 335 out->AppendString(result);
340 OutputString(" ");
341 OutputString(result);
342 OutputString("\n");
343 } 336 }
344 } 337 }
345 338
346 } // namespace 339 } // namespace
347 340
348 CommandInfo::CommandInfo() 341 CommandInfo::CommandInfo()
349 : help_short(nullptr), 342 : help_short(nullptr),
350 help(nullptr), 343 help(nullptr),
351 runner(nullptr) { 344 runner(nullptr) {
352 } 345 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 LabelPattern pattern = 476 LabelPattern pattern =
484 LabelPattern::GetPattern(root_dir, Value(nullptr, token), err); 477 LabelPattern::GetPattern(root_dir, Value(nullptr, token), err);
485 if (err->has_error()) 478 if (err->has_error())
486 return false; 479 return false;
487 filters->push_back(pattern); 480 filters->push_back(pattern);
488 } 481 }
489 482
490 return true; 483 return true;
491 } 484 }
492 485
493 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) { 486 void FilterAndPrintTargets(std::vector<const Target*>* targets,
487 base::ListValue* out) {
494 if (targets->empty()) 488 if (targets->empty())
495 return; 489 return;
496 490
497 if (!ApplyTestonlyFilter(targets)) 491 if (!ApplyTestonlyFilter(targets))
498 return; 492 return;
499 if (!ApplyTypeFilter(targets)) 493 if (!ApplyTypeFilter(targets))
500 return; 494 return;
501 495
502 TargetPrintingMode printing_mode = TARGET_PRINT_LABEL; 496 TargetPrintingMode printing_mode = TARGET_PRINT_LABEL;
503 if (targets->empty() || !GetTargetPrintingMode(&printing_mode)) 497 if (targets->empty() || !GetTargetPrintingMode(&printing_mode))
504 return; 498 return;
505 switch (printing_mode) { 499 switch (printing_mode) {
506 case TARGET_PRINT_BUILDFILE: 500 case TARGET_PRINT_BUILDFILE:
507 PrintTargetsAsBuildfiles(indent, *targets); 501 PrintTargetsAsBuildfiles(*targets, out);
508 break; 502 break;
509 case TARGET_PRINT_LABEL: 503 case TARGET_PRINT_LABEL:
510 PrintTargetsAsLabels(indent, *targets); 504 PrintTargetsAsLabels(*targets, out);
511 break; 505 break;
512 case TARGET_PRINT_OUTPUT: 506 case TARGET_PRINT_OUTPUT:
513 PrintTargetsAsOutputs(indent, *targets); 507 PrintTargetsAsOutputs(*targets, out);
514 break; 508 break;
515 } 509 }
516 } 510 }
517 511
512 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) {
513 base::ListValue tmp;
514 FilterAndPrintTargets(targets, &tmp);
515 for (const auto& value : tmp) {
516 std::string string;
517 value->GetAsString(&string);
518 if (indent)
519 OutputString(" ");
520 OutputString(string);
521 OutputString("\n");
522 }
523 }
524
518 void FilterAndPrintTargetSet(bool indent, 525 void FilterAndPrintTargetSet(bool indent,
519 const std::set<const Target*>& targets) { 526 const std::set<const Target*>& targets) {
520 std::vector<const Target*> target_vector(targets.begin(), targets.end()); 527 std::vector<const Target*> target_vector(targets.begin(), targets.end());
521 FilterAndPrintTargets(indent, &target_vector); 528 FilterAndPrintTargets(indent, &target_vector);
522 } 529 }
523 530
531 void FilterAndPrintTargetSet(const std::set<const Target*>& targets,
532 base::ListValue* out) {
533 std::vector<const Target*> target_vector(targets.begin(), targets.end());
534 FilterAndPrintTargets(&target_vector, out);
535 }
536
524 } // namespace commands 537 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/commands.h ('k') | tools/gn/desc_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698