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