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 <stddef.h> | 7 #include <stddef.h> |
8 #include <iostream> | 8 #include <iostream> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 SourceFile import_file = | 631 SourceFile import_file = |
632 input_dir.ResolveRelativeFile(args[0], err, | 632 input_dir.ResolveRelativeFile(args[0], err, |
633 scope->settings()->build_settings()->root_path_utf8()); | 633 scope->settings()->build_settings()->root_path_utf8()); |
634 if (!err->has_error()) { | 634 if (!err->has_error()) { |
635 scope->settings()->import_manager().DoImport(import_file, function, | 635 scope->settings()->import_manager().DoImport(import_file, function, |
636 scope, err); | 636 scope, err); |
637 } | 637 } |
638 return Value(); | 638 return Value(); |
639 } | 639 } |
640 | 640 |
641 // not_needed ----------------------------------------------------------------- | |
642 | |
643 const char kNotNeeded[] = "not_needed"; | |
644 const char kNotNeeded_HelpShort[] = | |
645 "not_needed: Mark variables from scope as not needed."; | |
646 const char kNotNeeded_Help[] = | |
647 R"(not_needed: Mark variables from scope as not needed. | |
648 | |
649 not_needed(variable_list_or_star, variable_to_ignore_list = []) | |
650 not_needed(from_scope, variable_list_or_star, | |
651 variable_to_ignore_list = []) | |
652 | |
653 Mark the variables in the current or given scope as not needed, which means | |
654 you will not get an error about unused variables for these. | |
brettw
2017/06/28 20:16:49
Can you make more explicit here that variable_to_i
Petr Hosek
2017/06/28 23:21:32
Done.
| |
655 | |
656 Example | |
657 | |
658 not_needed("*", [ "config" ]) | |
659 not_needed([ "data_deps", "deps" ]) | |
660 not_needed(invoker, "*", [ "config" ]) | |
661 not_needed(invoker, [ "data_deps", "deps" ]) | |
662 )"; | |
663 | |
664 Value RunNotNeeded(Scope* scope, | |
665 const FunctionCallNode* function, | |
666 const ListNode* args_list, | |
667 Err* err) { | |
668 const auto& args_vector = args_list->contents(); | |
669 if (args_vector.size() < 1 && args_vector.size() > 3) { | |
670 *err = Err(function, "Wrong number of arguments.", | |
671 "Expecting one, two or three arguments."); | |
672 return Value(); | |
673 } | |
674 auto args_cur = args_vector.begin(); | |
675 | |
676 Value* value = nullptr; // Value to use, may point to result_value. | |
677 Value result_value; // Storage for the "evaluate" case. | |
678 const IdentifierNode* identifier = (*args_cur)->AsIdentifier(); | |
679 if (identifier) { | |
680 // Optimize the common case where the input scope is an identifier. This | |
681 // prevents a copy of a potentially large Scope object. | |
682 value = scope->GetMutableValue(identifier->value().value(), | |
683 Scope::SEARCH_NESTED, true); | |
684 if (!value) { | |
685 *err = Err(identifier, "Undefined identifier."); | |
686 return Value(); | |
687 } | |
688 } else { | |
689 // Non-optimized case, just evaluate the argument. | |
690 result_value = (*args_cur)->Execute(scope, err); | |
691 if (err->has_error()) | |
692 return Value(); | |
693 value = &result_value; | |
694 } | |
695 args_cur++; | |
696 | |
697 // Extract the source scope if different from current one. | |
698 Scope* source = scope; | |
699 if (value->type() == Value::SCOPE) { | |
700 source = value->scope_value(); | |
701 result_value = (*args_cur)->Execute(scope, err); | |
702 if (err->has_error()) | |
703 return Value(); | |
704 value = &result_value; | |
705 args_cur++; | |
706 } | |
707 | |
708 // Extract the exclusion list if defined. | |
709 std::set<std::string> exclusion_set; | |
710 if (args_cur != args_vector.end()) { | |
711 Value exclusion_value = (*args_cur)->Execute(scope, err); | |
712 if (err->has_error()) | |
713 return Value(); | |
714 | |
715 if (exclusion_value.type() != Value::LIST) { | |
716 *err = Err(exclusion_value, "Not a valid list of variables to exclude.", | |
717 "Expecting a list of strings."); | |
718 return Value(); | |
719 } | |
720 | |
721 for (const Value& cur : exclusion_value.list_value()) { | |
722 if (!cur.VerifyTypeIs(Value::STRING, err)) | |
723 return Value(); | |
724 | |
725 exclusion_set.insert(cur.string_value()); | |
726 } | |
727 } | |
728 | |
729 if (value->type() == Value::STRING) { | |
730 if (value->string_value() == "*") { | |
731 source->MarkAllUsed(exclusion_set); | |
732 return Value(); | |
733 } | |
734 } else { | |
brettw
2017/06/28 20:16:49
You can just do "else if" here and avoid the extra
Petr Hosek
2017/06/28 23:21:32
Done.
| |
735 if (value->type() == Value::LIST) { | |
brettw
2017/06/28 20:16:49
Can you throw an error here if an exclusion list i
Petr Hosek
2017/06/28 23:21:32
Done.
| |
736 for (const Value& cur : value->list_value()) { | |
737 if (!cur.VerifyTypeIs(Value::STRING, err)) | |
738 return Value(); | |
739 source->MarkUsed(cur.string_value()); | |
740 } | |
741 return Value(); | |
742 } | |
743 } | |
744 | |
745 // Not the right type of argument. | |
746 *err = Err(*value, "Not a valid list of variables.", | |
747 "Expecting either the string \"*\" or a list of strings."); | |
748 return Value(); | |
749 } | |
750 | |
641 // set_sources_assignment_filter ----------------------------------------------- | 751 // set_sources_assignment_filter ----------------------------------------------- |
642 | 752 |
643 const char kSetSourcesAssignmentFilter[] = "set_sources_assignment_filter"; | 753 const char kSetSourcesAssignmentFilter[] = "set_sources_assignment_filter"; |
644 const char kSetSourcesAssignmentFilter_HelpShort[] = | 754 const char kSetSourcesAssignmentFilter_HelpShort[] = |
645 "set_sources_assignment_filter: Set a pattern to filter source files."; | 755 "set_sources_assignment_filter: Set a pattern to filter source files."; |
646 const char kSetSourcesAssignmentFilter_Help[] = | 756 const char kSetSourcesAssignmentFilter_Help[] = |
647 R"(set_sources_assignment_filter: Set a pattern to filter source files. | 757 R"(set_sources_assignment_filter: Set a pattern to filter source files. |
648 | 758 |
649 The sources assignment filter is a list of patterns that remove files from | 759 The sources assignment filter is a list of patterns that remove files from |
650 the list implicitly whenever the "sources" variable is assigned to. This will | 760 the list implicitly whenever the "sources" variable is assigned to. This will |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 INSERT_FUNCTION(DeclareArgs, false) | 1143 INSERT_FUNCTION(DeclareArgs, false) |
1034 INSERT_FUNCTION(Defined, false) | 1144 INSERT_FUNCTION(Defined, false) |
1035 INSERT_FUNCTION(ExecScript, false) | 1145 INSERT_FUNCTION(ExecScript, false) |
1036 INSERT_FUNCTION(ForEach, false) | 1146 INSERT_FUNCTION(ForEach, false) |
1037 INSERT_FUNCTION(ForwardVariablesFrom, false) | 1147 INSERT_FUNCTION(ForwardVariablesFrom, false) |
1038 INSERT_FUNCTION(GetEnv, false) | 1148 INSERT_FUNCTION(GetEnv, false) |
1039 INSERT_FUNCTION(GetLabelInfo, false) | 1149 INSERT_FUNCTION(GetLabelInfo, false) |
1040 INSERT_FUNCTION(GetPathInfo, false) | 1150 INSERT_FUNCTION(GetPathInfo, false) |
1041 INSERT_FUNCTION(GetTargetOutputs, false) | 1151 INSERT_FUNCTION(GetTargetOutputs, false) |
1042 INSERT_FUNCTION(Import, false) | 1152 INSERT_FUNCTION(Import, false) |
1153 INSERT_FUNCTION(NotNeeded, false) | |
1043 INSERT_FUNCTION(Pool, false) | 1154 INSERT_FUNCTION(Pool, false) |
1044 INSERT_FUNCTION(Print, false) | 1155 INSERT_FUNCTION(Print, false) |
1045 INSERT_FUNCTION(ProcessFileTemplate, false) | 1156 INSERT_FUNCTION(ProcessFileTemplate, false) |
1046 INSERT_FUNCTION(ReadFile, false) | 1157 INSERT_FUNCTION(ReadFile, false) |
1047 INSERT_FUNCTION(RebasePath, false) | 1158 INSERT_FUNCTION(RebasePath, false) |
1048 INSERT_FUNCTION(SetDefaults, false) | 1159 INSERT_FUNCTION(SetDefaults, false) |
1049 INSERT_FUNCTION(SetDefaultToolchain, false) | 1160 INSERT_FUNCTION(SetDefaultToolchain, false) |
1050 INSERT_FUNCTION(SetSourcesAssignmentFilter, false) | 1161 INSERT_FUNCTION(SetSourcesAssignmentFilter, false) |
1051 INSERT_FUNCTION(SplitList, false) | 1162 INSERT_FUNCTION(SplitList, false) |
1052 INSERT_FUNCTION(Template, false) | 1163 INSERT_FUNCTION(Template, false) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 } | 1248 } |
1138 | 1249 |
1139 // Otherwise it's a no-block function. | 1250 // Otherwise it's a no-block function. |
1140 if (!VerifyNoBlockForFunctionCall(function, block, err)) | 1251 if (!VerifyNoBlockForFunctionCall(function, block, err)) |
1141 return Value(); | 1252 return Value(); |
1142 return found_function->second.no_block_runner(scope, function, | 1253 return found_function->second.no_block_runner(scope, function, |
1143 args.list_value(), err); | 1254 args.list_value(), err); |
1144 } | 1255 } |
1145 | 1256 |
1146 } // namespace functions | 1257 } // namespace functions |
OLD | NEW |