| 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/functions.h" | 5 #include "tools/gn/functions.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 const char kSetSourcesAssignmentFilter_Help[] = | 482 const char kSetSourcesAssignmentFilter_Help[] = |
| 483 "set_sources_assignment_filter: Set a pattern to filter source files.\n" | 483 "set_sources_assignment_filter: Set a pattern to filter source files.\n" |
| 484 "\n" | 484 "\n" |
| 485 " The sources assignment filter is a list of patterns that remove files\n" | 485 " The sources assignment filter is a list of patterns that remove files\n" |
| 486 " from the list implicitly whenever the \"sources\" variable is\n" | 486 " from the list implicitly whenever the \"sources\" variable is\n" |
| 487 " assigned to. This is intended to be used to globally filter out files\n" | 487 " assigned to. This is intended to be used to globally filter out files\n" |
| 488 " with platform-specific naming schemes when they don't apply, for\n" | 488 " with platform-specific naming schemes when they don't apply, for\n" |
| 489 " example, you may want to filter out all \"*_win.cc\" files on non-\n" | 489 " example, you may want to filter out all \"*_win.cc\" files on non-\n" |
| 490 " Windows platforms.\n" | 490 " Windows platforms.\n" |
| 491 "\n" | 491 "\n" |
| 492 " See \"gn help patterns\" for specifics on patterns.\n" | |
| 493 "\n" | |
| 494 " Typically this will be called once in the master build config script\n" | 492 " Typically this will be called once in the master build config script\n" |
| 495 " to set up the filter for the current platform. Subsequent calls will\n" | 493 " to set up the filter for the current platform. Subsequent calls will\n" |
| 496 " overwrite the previous values.\n" | 494 " overwrite the previous values.\n" |
| 497 "\n" | 495 "\n" |
| 498 " If you want to bypass the filter and add a file even if it might\n" | 496 " If you want to bypass the filter and add a file even if it might\n" |
| 499 " be filtered out, call set_sources_assignment_filter([]) to clear the\n" | 497 " be filtered out, call set_sources_assignment_filter([]) to clear the\n" |
| 500 " list of filters. This will apply until the current scope exits\n" | 498 " list of filters. This will apply until the current scope exits\n" |
| 501 "\n" | 499 "\n" |
| 502 "Example:\n" | 500 "How to use patterns\n" |
| 501 "\n" |
| 502 " File patterns are VERY limited regular expressions. They must match\n" |
| 503 " the entire input string to be counted as a match. In regular\n" |
| 504 " expression parlance, there is an implicit \"^...$\" surrounding your\n" |
| 505 " input. If you want to match a substring, you need to use wildcards at\n" |
| 506 " the beginning and end.\n" |
| 507 "\n" |
| 508 " There are only two special tokens understood by the pattern matcher.\n" |
| 509 " Everything else is a literal.\n" |
| 510 "\n" |
| 511 " * Matches zero or more of any character. It does not depend on the\n" |
| 512 " preceding character (in regular expression parlance it is\n" |
| 513 " equivalent to \".*\").\n" |
| 514 "\n" |
| 515 " \\b Matches a path boundary. This will match the beginning or end of\n" |
| 516 " a string, or a slash.\n" |
| 517 "\n" |
| 518 "Pattern examples\n" |
| 519 "\n" |
| 520 " \"*asdf*\"\n" |
| 521 " Matches a string containing \"asdf\" anywhere.\n" |
| 522 "\n" |
| 523 " \"asdf\"\n" |
| 524 " Matches only the exact string \"asdf\".\n" |
| 525 "\n" |
| 526 " \"*.cc\"\n" |
| 527 " Matches strings ending in the literal \".cc\".\n" |
| 528 "\n" |
| 529 " \"\\bwin/*\"\n" |
| 530 " Matches \"win/foo\" and \"foo/win/bar.cc\" but not \"iwin/foo\".\n" |
| 531 "\n" |
| 532 "Sources assignment example\n" |
| 533 "\n" |
| 503 " # Filter out all _win files.\n" | 534 " # Filter out all _win files.\n" |
| 504 " set_sources_assignment_filter([ \"*_win.cc\", \"*_win.h\" ])\n"; | 535 " set_sources_assignment_filter([ \"*_win.cc\", \"*_win.h\" ])\n" |
| 536 " sources = [ \"a.cc\", \"b_win.cc\" ]\n" |
| 537 " print(sources)\n" |
| 538 " # Will print [ \"a.cc\" ]. b_win one was filtered out.\n"; |
| 505 | 539 |
| 506 Value RunSetSourcesAssignmentFilter(Scope* scope, | 540 Value RunSetSourcesAssignmentFilter(Scope* scope, |
| 507 const FunctionCallNode* function, | 541 const FunctionCallNode* function, |
| 508 const std::vector<Value>& args, | 542 const std::vector<Value>& args, |
| 509 Err* err) { | 543 Err* err) { |
| 510 if (args.size() != 1) { | 544 if (args.size() != 1) { |
| 511 *err = Err(function, "set_sources_assignment_filter takes one argument."); | 545 *err = Err(function, "set_sources_assignment_filter takes one argument."); |
| 512 } else { | 546 } else { |
| 513 scoped_ptr<PatternList> f(new PatternList); | 547 scoped_ptr<PatternList> f(new PatternList); |
| 514 f->SetFromValue(args[0], err); | 548 f->SetFromValue(args[0], err); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 return Value(); | 781 return Value(); |
| 748 return result; | 782 return result; |
| 749 } | 783 } |
| 750 | 784 |
| 751 // Otherwise it's a no-block function. | 785 // Otherwise it's a no-block function. |
| 752 return found_function->second.no_block_runner(scope, function, | 786 return found_function->second.no_block_runner(scope, function, |
| 753 args.list_value(), err); | 787 args.list_value(), err); |
| 754 } | 788 } |
| 755 | 789 |
| 756 } // namespace functions | 790 } // namespace functions |
| OLD | NEW |