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 "tools/gn/builder.h" | 9 #include "tools/gn/builder.h" |
9 #include "tools/gn/filesystem_utils.h" | 10 #include "tools/gn/filesystem_utils.h" |
10 #include "tools/gn/item.h" | 11 #include "tools/gn/item.h" |
11 #include "tools/gn/label.h" | 12 #include "tools/gn/label.h" |
12 #include "tools/gn/label_pattern.h" | 13 #include "tools/gn/label_pattern.h" |
13 #include "tools/gn/setup.h" | 14 #include "tools/gn/setup.h" |
14 #include "tools/gn/standard_out.h" | 15 #include "tools/gn/standard_out.h" |
15 #include "tools/gn/target.h" | 16 #include "tools/gn/target.h" |
16 | 17 |
17 namespace commands { | 18 namespace commands { |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 for (const auto& target : input) { | 462 for (const auto& target : input) { |
462 for (const auto& pattern : filter) { | 463 for (const auto& pattern : filter) { |
463 if (pattern.Matches(target->label())) { | 464 if (pattern.Matches(target->label())) { |
464 output->push_back(target); | 465 output->push_back(target); |
465 break; | 466 break; |
466 } | 467 } |
467 } | 468 } |
468 } | 469 } |
469 } | 470 } |
470 | 471 |
| 472 bool FilterPatternsFromString(const BuildSettings* build_settings, |
| 473 const std::string& label_list_string, |
| 474 std::vector<LabelPattern>* filters, |
| 475 Err* err) { |
| 476 std::vector<std::string> tokens = base::SplitString( |
| 477 label_list_string, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 478 SourceDir root_dir = |
| 479 SourceDirForCurrentDirectory(build_settings->root_path()); |
| 480 |
| 481 filters->reserve(tokens.size()); |
| 482 for (const std::string& token : tokens) { |
| 483 LabelPattern pattern = |
| 484 LabelPattern::GetPattern(root_dir, Value(nullptr, token), err); |
| 485 if (err->has_error()) |
| 486 return false; |
| 487 filters->push_back(pattern); |
| 488 } |
| 489 |
| 490 return true; |
| 491 } |
| 492 |
471 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) { | 493 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) { |
472 if (targets->empty()) | 494 if (targets->empty()) |
473 return; | 495 return; |
474 | 496 |
475 if (!ApplyTestonlyFilter(targets)) | 497 if (!ApplyTestonlyFilter(targets)) |
476 return; | 498 return; |
477 if (!ApplyTypeFilter(targets)) | 499 if (!ApplyTypeFilter(targets)) |
478 return; | 500 return; |
479 | 501 |
480 TargetPrintingMode printing_mode = TARGET_PRINT_LABEL; | 502 TargetPrintingMode printing_mode = TARGET_PRINT_LABEL; |
(...skipping 12 matching lines...) Expand all Loading... |
493 } | 515 } |
494 } | 516 } |
495 | 517 |
496 void FilterAndPrintTargetSet(bool indent, | 518 void FilterAndPrintTargetSet(bool indent, |
497 const std::set<const Target*>& targets) { | 519 const std::set<const Target*>& targets) { |
498 std::vector<const Target*> target_vector(targets.begin(), targets.end()); | 520 std::vector<const Target*> target_vector(targets.begin(), targets.end()); |
499 FilterAndPrintTargets(indent, &target_vector); | 521 FilterAndPrintTargets(indent, &target_vector); |
500 } | 522 } |
501 | 523 |
502 } // namespace commands | 524 } // namespace commands |
OLD | NEW |