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

Side by Side Diff: pylib/gyp/input.py

Issue 739303003: Cleanup pylint errors (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: it's clean now Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. 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 from compiler.ast import Const 5 from compiler.ast import Const
6 from compiler.ast import Dict 6 from compiler.ast import Dict
7 from compiler.ast import Discard 7 from compiler.ast import Discard
8 from compiler.ast import List 8 from compiler.ast import List
9 from compiler.ast import Module 9 from compiler.ast import Module
10 from compiler.ast import Node 10 from compiler.ast import Node
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 c = node.getChildren() 203 c = node.getChildren()
204 children = [] 204 children = []
205 for index, child in enumerate(c): 205 for index, child in enumerate(c):
206 kp = list(keypath) # Copy list. 206 kp = list(keypath) # Copy list.
207 kp.append(repr(index)) 207 kp.append(repr(index))
208 children.append(CheckNode(child, kp)) 208 children.append(CheckNode(child, kp))
209 return children 209 return children
210 elif isinstance(node, Const): 210 elif isinstance(node, Const):
211 return node.getChildren()[0] 211 return node.getChildren()[0]
212 else: 212 else:
213 raise TypeError, "Unknown AST node at key path '" + '.'.join(keypath) + \ 213 raise TypeError("Unknown AST node at key path '" + '.'.join(keypath) +
214 "': " + repr(node) 214 "': " + repr(node))
215 215
216 216
217 def LoadOneBuildFile(build_file_path, data, aux_data, includes, 217 def LoadOneBuildFile(build_file_path, data, aux_data, includes,
218 is_target, check): 218 is_target, check):
219 if build_file_path in data: 219 if build_file_path in data:
220 return data[build_file_path] 220 return data[build_file_path]
221 221
222 if os.path.exists(build_file_path): 222 if os.path.exists(build_file_path):
223 build_file_contents = open(build_file_path).read() 223 build_file_contents = open(build_file_path).read()
224 else: 224 else:
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 data_keys = set(data) 479 data_keys = set(data)
480 aux_data_keys = set(aux_data) 480 aux_data_keys = set(aux_data)
481 481
482 SetGeneratorGlobals(generator_input_info) 482 SetGeneratorGlobals(generator_input_info)
483 result = LoadTargetBuildFile(build_file_path, data, 483 result = LoadTargetBuildFile(build_file_path, data,
484 aux_data, variables, 484 aux_data, variables,
485 includes, depth, check, False) 485 includes, depth, check, False)
486 if not result: 486 if not result:
487 return result 487 return result
488 488
489 # pylint: disable=unpacking-non-sequence
489 (build_file_path, dependencies) = result 490 (build_file_path, dependencies) = result
490 491
491 data_out = {} 492 data_out = {}
492 for key in data: 493 for key in data:
493 if key == 'target_build_files': 494 if key == 'target_build_files':
494 continue 495 continue
495 if key not in data_keys: 496 if key not in data_keys:
496 data_out[key] = data[key] 497 data_out[key] = data[key]
497 aux_data_out = {} 498 aux_data_out = {}
498 for key in aux_data: 499 for key in aux_data:
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if '1' <= string[0] <= '9': 669 if '1' <= string[0] <= '9':
669 return string.isdigit() 670 return string.isdigit()
670 671
671 return False 672 return False
672 673
673 674
674 # This matches things like "<(asdf)", "<!(cmd)", "<!@(cmd)", "<|(list)", 675 # This matches things like "<(asdf)", "<!(cmd)", "<!@(cmd)", "<|(list)",
675 # "<!interpreter(arguments)", "<([list])", and even "<([)" and "<(<())". 676 # "<!interpreter(arguments)", "<([list])", and even "<([)" and "<(<())".
676 # In the last case, the inner "<()" is captured in match['content']. 677 # In the last case, the inner "<()" is captured in match['content'].
677 early_variable_re = re.compile( 678 early_variable_re = re.compile(
678 '(?P<replace>(?P<type><(?:(?:!?@?)|\|)?)' 679 r'(?P<replace>(?P<type><(?:(?:!?@?)|\|)?)'
679 '(?P<command_string>[-a-zA-Z0-9_.]+)?' 680 r'(?P<command_string>[-a-zA-Z0-9_.]+)?'
680 '\((?P<is_array>\s*\[?)' 681 r'\((?P<is_array>\s*\[?)'
681 '(?P<content>.*?)(\]?)\))') 682 r'(?P<content>.*?)(\]?)\))')
682 683
683 # This matches the same as early_variable_re, but with '>' instead of '<'. 684 # This matches the same as early_variable_re, but with '>' instead of '<'.
684 late_variable_re = re.compile( 685 late_variable_re = re.compile(
685 '(?P<replace>(?P<type>>(?:(?:!?@?)|\|)?)' 686 r'(?P<replace>(?P<type>>(?:(?:!?@?)|\|)?)'
686 '(?P<command_string>[-a-zA-Z0-9_.]+)?' 687 r'(?P<command_string>[-a-zA-Z0-9_.]+)?'
687 '\((?P<is_array>\s*\[?)' 688 r'\((?P<is_array>\s*\[?)'
688 '(?P<content>.*?)(\]?)\))') 689 r'(?P<content>.*?)(\]?)\))')
689 690
690 # This matches the same as early_variable_re, but with '^' instead of '<'. 691 # This matches the same as early_variable_re, but with '^' instead of '<'.
691 latelate_variable_re = re.compile( 692 latelate_variable_re = re.compile(
692 '(?P<replace>(?P<type>[\^](?:(?:!?@?)|\|)?)' 693 r'(?P<replace>(?P<type>[\^](?:(?:!?@?)|\|)?)'
693 '(?P<command_string>[-a-zA-Z0-9_.]+)?' 694 r'(?P<command_string>[-a-zA-Z0-9_.]+)?'
694 '\((?P<is_array>\s*\[?)' 695 r'\((?P<is_array>\s*\[?)'
695 '(?P<content>.*?)(\]?)\))') 696 r'(?P<content>.*?)(\]?)\))')
696 697
697 # Global cache of results from running commands so they don't have to be run 698 # Global cache of results from running commands so they don't have to be run
698 # more then once. 699 # more then once.
699 cached_command_results = {} 700 cached_command_results = {}
700 701
701 702
702 def FixupPlatformCommand(cmd): 703 def FixupPlatformCommand(cmd):
703 if sys.platform == 'win32': 704 if sys.platform == 'win32':
704 if type(cmd) is list: 705 if type(cmd) is list:
705 cmd = [re.sub('^cat ', 'type ', cmd[0])] + cmd[1:] 706 cmd = [re.sub('^cat ', 'type ', cmd[0])] + cmd[1:]
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 cond_expr, true_dict, false_dict, phase, variables, build_file): 1073 cond_expr, true_dict, false_dict, phase, variables, build_file):
1073 """Returns true_dict if cond_expr evaluates to true, and false_dict 1074 """Returns true_dict if cond_expr evaluates to true, and false_dict
1074 otherwise.""" 1075 otherwise."""
1075 # Do expansions on the condition itself. Since the conditon can naturally 1076 # Do expansions on the condition itself. Since the conditon can naturally
1076 # contain variable references without needing to resort to GYP expansion 1077 # contain variable references without needing to resort to GYP expansion
1077 # syntax, this is of dubious value for variables, but someone might want to 1078 # syntax, this is of dubious value for variables, but someone might want to
1078 # use a command expansion directly inside a condition. 1079 # use a command expansion directly inside a condition.
1079 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, 1080 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables,
1080 build_file) 1081 build_file)
1081 if type(cond_expr_expanded) not in (str, int): 1082 if type(cond_expr_expanded) not in (str, int):
1082 raise ValueError, \ 1083 raise ValueError(
1083 'Variable expansion in this context permits str and int ' + \ 1084 'Variable expansion in this context permits str and int ' + \
1084 'only, found ' + cond_expr_expanded.__class__.__name__ 1085 'only, found ' + cond_expr_expanded.__class__.__name__)
1085 1086
1086 try: 1087 try:
1087 if cond_expr_expanded in cached_conditions_asts: 1088 if cond_expr_expanded in cached_conditions_asts:
1088 ast_code = cached_conditions_asts[cond_expr_expanded] 1089 ast_code = cached_conditions_asts[cond_expr_expanded]
1089 else: 1090 else:
1090 ast_code = compile(cond_expr_expanded, '<string>', 'eval') 1091 ast_code = compile(cond_expr_expanded, '<string>', 'eval')
1091 cached_conditions_asts[cond_expr_expanded] = ast_code 1092 cached_conditions_asts[cond_expr_expanded] = ast_code
1092 if eval(ast_code, {'__builtins__': None}, variables): 1093 if eval(ast_code, {'__builtins__': None}, variables):
1093 return true_dict 1094 return true_dict
1094 return false_dict 1095 return false_dict
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 ProcessVariablesAndConditionsInDict(the_dict['variables'], phase, 1217 ProcessVariablesAndConditionsInDict(the_dict['variables'], phase,
1217 variables, build_file, 'variables') 1218 variables, build_file, 'variables')
1218 1219
1219 LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key) 1220 LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key)
1220 1221
1221 for key, value in the_dict.iteritems(): 1222 for key, value in the_dict.iteritems():
1222 # Skip "variables", which was already processed if present. 1223 # Skip "variables", which was already processed if present.
1223 if key != 'variables' and type(value) is str: 1224 if key != 'variables' and type(value) is str:
1224 expanded = ExpandVariables(value, phase, variables, build_file) 1225 expanded = ExpandVariables(value, phase, variables, build_file)
1225 if type(expanded) not in (str, int): 1226 if type(expanded) not in (str, int):
1226 raise ValueError, \ 1227 raise ValueError(
1227 'Variable expansion in this context permits str and int ' + \ 1228 'Variable expansion in this context permits str and int ' + \
1228 'only, found ' + expanded.__class__.__name__ + ' for ' + key 1229 'only, found ' + expanded.__class__.__name__ + ' for ' + key)
1229 the_dict[key] = expanded 1230 the_dict[key] = expanded
1230 1231
1231 # Variable expansion may have resulted in changes to automatics. Reload. 1232 # Variable expansion may have resulted in changes to automatics. Reload.
1232 # TODO(mark): Optimization: only reload if no changes were made. 1233 # TODO(mark): Optimization: only reload if no changes were made.
1233 variables = variables_in.copy() 1234 variables = variables_in.copy()
1234 LoadAutomaticVariablesFromDict(variables, the_dict) 1235 LoadAutomaticVariablesFromDict(variables, the_dict)
1235 LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key) 1236 LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key)
1236 1237
1237 # Process conditions in this dict. This is done after variable expansion 1238 # Process conditions in this dict. This is done after variable expansion
1238 # so that conditions may take advantage of expanded variables. For example, 1239 # so that conditions may take advantage of expanded variables. For example,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 ProcessVariablesAndConditionsInDict(value, phase, variables, 1288 ProcessVariablesAndConditionsInDict(value, phase, variables,
1288 build_file, key) 1289 build_file, key)
1289 elif type(value) is list: 1290 elif type(value) is list:
1290 # The list itself can't influence the variables dict, and 1291 # The list itself can't influence the variables dict, and
1291 # ProcessVariablesAndConditionsInList will make copies of the variables 1292 # ProcessVariablesAndConditionsInList will make copies of the variables
1292 # dict if it needs to pass it to something that can influence it. No 1293 # dict if it needs to pass it to something that can influence it. No
1293 # copy is necessary here. 1294 # copy is necessary here.
1294 ProcessVariablesAndConditionsInList(value, phase, variables, 1295 ProcessVariablesAndConditionsInList(value, phase, variables,
1295 build_file) 1296 build_file)
1296 elif type(value) is not int: 1297 elif type(value) is not int:
1297 raise TypeError, 'Unknown type ' + value.__class__.__name__ + \ 1298 raise TypeError('Unknown type ' + value.__class__.__name__ + \
1298 ' for ' + key 1299 ' for ' + key)
1299 1300
1300 1301
1301 def ProcessVariablesAndConditionsInList(the_list, phase, variables, 1302 def ProcessVariablesAndConditionsInList(the_list, phase, variables,
1302 build_file): 1303 build_file):
1303 # Iterate using an index so that new values can be assigned into the_list. 1304 # Iterate using an index so that new values can be assigned into the_list.
1304 index = 0 1305 index = 0
1305 while index < len(the_list): 1306 while index < len(the_list):
1306 item = the_list[index] 1307 item = the_list[index]
1307 if type(item) is dict: 1308 if type(item) is dict:
1308 # Make a copy of the variables dict so that it won't influence anything 1309 # Make a copy of the variables dict so that it won't influence anything
1309 # outside of its own scope. 1310 # outside of its own scope.
1310 ProcessVariablesAndConditionsInDict(item, phase, variables, build_file) 1311 ProcessVariablesAndConditionsInDict(item, phase, variables, build_file)
1311 elif type(item) is list: 1312 elif type(item) is list:
1312 ProcessVariablesAndConditionsInList(item, phase, variables, build_file) 1313 ProcessVariablesAndConditionsInList(item, phase, variables, build_file)
1313 elif type(item) is str: 1314 elif type(item) is str:
1314 expanded = ExpandVariables(item, phase, variables, build_file) 1315 expanded = ExpandVariables(item, phase, variables, build_file)
1315 if type(expanded) in (str, int): 1316 if type(expanded) in (str, int):
1316 the_list[index] = expanded 1317 the_list[index] = expanded
1317 elif type(expanded) is list: 1318 elif type(expanded) is list:
1318 the_list[index:index+1] = expanded 1319 the_list[index:index+1] = expanded
1319 index += len(expanded) 1320 index += len(expanded)
1320 1321
1321 # index now identifies the next item to examine. Continue right now 1322 # index now identifies the next item to examine. Continue right now
1322 # without falling into the index increment below. 1323 # without falling into the index increment below.
1323 continue 1324 continue
1324 else: 1325 else:
1325 raise ValueError, \ 1326 raise ValueError(
1326 'Variable expansion in this context permits strings and ' + \ 1327 'Variable expansion in this context permits strings and ' + \
1327 'lists only, found ' + expanded.__class__.__name__ + ' at ' + \ 1328 'lists only, found ' + expanded.__class__.__name__ + ' at ' + \
1328 index 1329 index)
1329 elif type(item) is not int: 1330 elif type(item) is not int:
1330 raise TypeError, 'Unknown type ' + item.__class__.__name__ + \ 1331 raise TypeError('Unknown type ' + item.__class__.__name__ + \
1331 ' at index ' + index 1332 ' at index ' + index)
1332 index = index + 1 1333 index = index + 1
1333 1334
1334 1335
1335 def BuildTargetsDict(data): 1336 def BuildTargetsDict(data):
1336 """Builds a dict mapping fully-qualified target names to their target dicts. 1337 """Builds a dict mapping fully-qualified target names to their target dicts.
1337 1338
1338 |data| is a dict mapping loaded build files by pathname relative to the 1339 |data| is a dict mapping loaded build files by pathname relative to the
1339 current directory. Values in |data| are build file contents. For each 1340 current directory. Values in |data| are build file contents. For each
1340 |data| value with a "targets" key, the value of the "targets" key is taken 1341 |data| value with a "targets" key, the value of the "targets" key is taken
1341 as a list containing target dicts. Each target's fully-qualified name is 1342 as a list containing target dicts. Each target's fully-qualified name is
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 MergeDicts(to_item, item, to_file, fro_file) 2075 MergeDicts(to_item, item, to_file, fro_file)
2075 elif type(item) is list: 2076 elif type(item) is list:
2076 # Recurse, making a copy of the list. If the list contains any 2077 # Recurse, making a copy of the list. If the list contains any
2077 # descendant dicts, path fixing will occur. Note that here, custom 2078 # descendant dicts, path fixing will occur. Note that here, custom
2078 # values for is_paths and append are dropped; those are only to be 2079 # values for is_paths and append are dropped; those are only to be
2079 # applied to |to| and |fro|, not sublists of |fro|. append shouldn't 2080 # applied to |to| and |fro|, not sublists of |fro|. append shouldn't
2080 # matter anyway because the new |to_item| list is empty. 2081 # matter anyway because the new |to_item| list is empty.
2081 to_item = [] 2082 to_item = []
2082 MergeLists(to_item, item, to_file, fro_file) 2083 MergeLists(to_item, item, to_file, fro_file)
2083 else: 2084 else:
2084 raise TypeError, \ 2085 raise TypeError(
2085 'Attempt to merge list item of unsupported type ' + \ 2086 'Attempt to merge list item of unsupported type ' + \
2086 item.__class__.__name__ 2087 item.__class__.__name__)
2087 2088
2088 if append: 2089 if append:
2089 # If appending a singleton that's already in the list, don't append. 2090 # If appending a singleton that's already in the list, don't append.
2090 # This ensures that the earliest occurrence of the item will stay put. 2091 # This ensures that the earliest occurrence of the item will stay put.
2091 if not singleton or not is_in_set_or_list(to_item, hashable_to_set, to): 2092 if not singleton or not is_in_set_or_list(to_item, hashable_to_set, to):
2092 to.append(to_item) 2093 to.append(to_item)
2093 if is_hashable(to_item): 2094 if is_hashable(to_item):
2094 hashable_to_set.add(to_item) 2095 hashable_to_set.add(to_item)
2095 else: 2096 else:
2096 # If prepending a singleton that's already in the list, remove the 2097 # If prepending a singleton that's already in the list, remove the
(...skipping 21 matching lines...) Expand all
2118 # modified. 2119 # modified.
2119 if k in to: 2120 if k in to:
2120 bad_merge = False 2121 bad_merge = False
2121 if type(v) in (str, int): 2122 if type(v) in (str, int):
2122 if type(to[k]) not in (str, int): 2123 if type(to[k]) not in (str, int):
2123 bad_merge = True 2124 bad_merge = True
2124 elif type(v) is not type(to[k]): 2125 elif type(v) is not type(to[k]):
2125 bad_merge = True 2126 bad_merge = True
2126 2127
2127 if bad_merge: 2128 if bad_merge:
2128 raise TypeError, \ 2129 raise TypeError(
2129 'Attempt to merge dict value of type ' + v.__class__.__name__ + \ 2130 'Attempt to merge dict value of type ' + v.__class__.__name__ + \
2130 ' into incompatible type ' + to[k].__class__.__name__ + \ 2131 ' into incompatible type ' + to[k].__class__.__name__ + \
2131 ' for key ' + k 2132 ' for key ' + k)
2132 if type(v) in (str, int): 2133 if type(v) in (str, int):
2133 # Overwrite the existing value, if any. Cheap and easy. 2134 # Overwrite the existing value, if any. Cheap and easy.
2134 is_path = IsPathSection(k) 2135 is_path = IsPathSection(k)
2135 if is_path: 2136 if is_path:
2136 to[k] = MakePathRelative(to_file, fro_file, v) 2137 to[k] = MakePathRelative(to_file, fro_file, v)
2137 else: 2138 else:
2138 to[k] = v 2139 to[k] = v
2139 elif type(v) is dict: 2140 elif type(v) is dict:
2140 # Recurse, guaranteeing copies will be made of objects that require it. 2141 # Recurse, guaranteeing copies will be made of objects that require it.
2141 if not k in to: 2142 if not k in to:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 list_incompatible) 2181 list_incompatible)
2181 2182
2182 if list_base in to: 2183 if list_base in to:
2183 if ext == '?': 2184 if ext == '?':
2184 # If the key ends in "?", the list will only be merged if it doesn't 2185 # If the key ends in "?", the list will only be merged if it doesn't
2185 # already exist. 2186 # already exist.
2186 continue 2187 continue
2187 elif type(to[list_base]) is not list: 2188 elif type(to[list_base]) is not list:
2188 # This may not have been checked above if merging in a list with an 2189 # This may not have been checked above if merging in a list with an
2189 # extension character. 2190 # extension character.
2190 raise TypeError, \ 2191 raise TypeError(
2191 'Attempt to merge dict value of type ' + v.__class__.__name__ + \ 2192 'Attempt to merge dict value of type ' + v.__class__.__name__ + \
2192 ' into incompatible type ' + to[list_base].__class__.__name__ + \ 2193 ' into incompatible type ' + to[list_base].__class__.__name__ + \
2193 ' for key ' + list_base + '(' + k + ')' 2194 ' for key ' + list_base + '(' + k + ')')
2194 else: 2195 else:
2195 to[list_base] = [] 2196 to[list_base] = []
2196 2197
2197 # Call MergeLists, which will make copies of objects that require it. 2198 # Call MergeLists, which will make copies of objects that require it.
2198 # MergeLists can recurse back into MergeDicts, although this will be 2199 # MergeLists can recurse back into MergeDicts, although this will be
2199 # to make copies of dicts (with paths fixed), there will be no 2200 # to make copies of dicts (with paths fixed), there will be no
2200 # subsequent dict "merging" once entering a list because lists are 2201 # subsequent dict "merging" once entering a list because lists are
2201 # always replaced, appended to, or prepended to. 2202 # always replaced, appended to, or prepended to.
2202 is_paths = IsPathSection(list_base) 2203 is_paths = IsPathSection(list_base)
2203 MergeLists(to[list_base], v, to_file, fro_file, is_paths, append) 2204 MergeLists(to[list_base], v, to_file, fro_file, is_paths, append)
2204 else: 2205 else:
2205 raise TypeError, \ 2206 raise TypeError(
2206 'Attempt to merge dict value of unsupported type ' + \ 2207 'Attempt to merge dict value of unsupported type ' + \
2207 v.__class__.__name__ + ' for key ' + k 2208 v.__class__.__name__ + ' for key ' + k)
2208 2209
2209 2210
2210 def MergeConfigWithInheritance(new_configuration_dict, build_file, 2211 def MergeConfigWithInheritance(new_configuration_dict, build_file,
2211 target_dict, configuration, visited): 2212 target_dict, configuration, visited):
2212 # Skip if previously visted. 2213 # Skip if previously visted.
2213 if configuration in visited: 2214 if configuration in visited:
2214 return 2215 return
2215 2216
2216 # Look at this configuration. 2217 # Look at this configuration.
2217 configuration_dict = target_dict['configurations'][configuration] 2218 configuration_dict = target_dict['configurations'][configuration]
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 # can't be done while iterating through it. 2343 # can't be done while iterating through it.
2343 2344
2344 lists = [] 2345 lists = []
2345 del_lists = [] 2346 del_lists = []
2346 for key, value in the_dict.iteritems(): 2347 for key, value in the_dict.iteritems():
2347 operation = key[-1] 2348 operation = key[-1]
2348 if operation != '!' and operation != '/': 2349 if operation != '!' and operation != '/':
2349 continue 2350 continue
2350 2351
2351 if type(value) is not list: 2352 if type(value) is not list:
2352 raise ValueError, name + ' key ' + key + ' must be list, not ' + \ 2353 raise ValueError(name + ' key ' + key + ' must be list, not ' + \
2353 value.__class__.__name__ 2354 value.__class__.__name__)
2354 2355
2355 list_key = key[:-1] 2356 list_key = key[:-1]
2356 if list_key not in the_dict: 2357 if list_key not in the_dict:
2357 # This happens when there's a list like "sources!" but no corresponding 2358 # This happens when there's a list like "sources!" but no corresponding
2358 # "sources" list. Since there's nothing for it to operate on, queue up 2359 # "sources" list. Since there's nothing for it to operate on, queue up
2359 # the "sources!" list for deletion now. 2360 # the "sources!" list for deletion now.
2360 del_lists.append(key) 2361 del_lists.append(key)
2361 continue 2362 continue
2362 2363
2363 if type(the_dict[list_key]) is not list: 2364 if type(the_dict[list_key]) is not list:
2364 value = the_dict[list_key] 2365 value = the_dict[list_key]
2365 raise ValueError, name + ' key ' + list_key + \ 2366 raise ValueError(name + ' key ' + list_key + \
2366 ' must be list, not ' + \ 2367 ' must be list, not ' + \
2367 value.__class__.__name__ + ' when applying ' + \ 2368 value.__class__.__name__ + ' when applying ' + \
2368 {'!': 'exclusion', '/': 'regex'}[operation] 2369 {'!': 'exclusion', '/': 'regex'}[operation])
2369 2370
2370 if not list_key in lists: 2371 if not list_key in lists:
2371 lists.append(list_key) 2372 lists.append(list_key)
2372 2373
2373 # Delete the lists that are known to be unneeded at this point. 2374 # Delete the lists that are known to be unneeded at this point.
2374 for del_list in del_lists: 2375 for del_list in del_lists:
2375 del the_dict[del_list] 2376 del the_dict[del_list]
2376 2377
2377 for list_key in lists: 2378 for list_key in lists:
2378 the_list = the_dict[list_key] 2379 the_list = the_dict[list_key]
(...skipping 28 matching lines...) Expand all
2407 pattern_re = re.compile(pattern) 2408 pattern_re = re.compile(pattern)
2408 2409
2409 if action == 'exclude': 2410 if action == 'exclude':
2410 # This item matches an exclude regex, so set its value to 0 (exclude). 2411 # This item matches an exclude regex, so set its value to 0 (exclude).
2411 action_value = 0 2412 action_value = 0
2412 elif action == 'include': 2413 elif action == 'include':
2413 # This item matches an include regex, so set its value to 1 (include). 2414 # This item matches an include regex, so set its value to 1 (include).
2414 action_value = 1 2415 action_value = 1
2415 else: 2416 else:
2416 # This is an action that doesn't make any sense. 2417 # This is an action that doesn't make any sense.
2417 raise ValueError, 'Unrecognized action ' + action + ' in ' + name + \ 2418 raise ValueError('Unrecognized action ' + action + ' in ' + name + \
2418 ' key ' + regex_key 2419 ' key ' + regex_key)
2419 2420
2420 for index in xrange(0, len(the_list)): 2421 for index in xrange(0, len(the_list)):
2421 list_item = the_list[index] 2422 list_item = the_list[index]
2422 if list_actions[index] == action_value: 2423 if list_actions[index] == action_value:
2423 # Even if the regex matches, nothing will change so continue (regex 2424 # Even if the regex matches, nothing will change so continue (regex
2424 # searches are expensive). 2425 # searches are expensive).
2425 continue 2426 continue
2426 if pattern_re.search(list_item): 2427 if pattern_re.search(list_item):
2427 # Regular expression match. 2428 # Regular expression match.
2428 list_actions[index] = action_value 2429 list_actions[index] = action_value
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 ValidateRunAsInTarget(target, target_dict, build_file) 2858 ValidateRunAsInTarget(target, target_dict, build_file)
2858 ValidateActionsInTarget(target, target_dict, build_file) 2859 ValidateActionsInTarget(target, target_dict, build_file)
2859 2860
2860 # Generators might not expect ints. Turn them into strs. 2861 # Generators might not expect ints. Turn them into strs.
2861 TurnIntIntoStrInDict(data) 2862 TurnIntIntoStrInDict(data)
2862 2863
2863 # TODO(mark): Return |data| for now because the generator needs a list of 2864 # TODO(mark): Return |data| for now because the generator needs a list of
2864 # build files that came in. In the future, maybe it should just accept 2865 # build files that came in. In the future, maybe it should just accept
2865 # a list, and not the whole data dict. 2866 # a list, and not the whole data dict.
2866 return [flat_list, targets, data] 2867 return [flat_list, targets, data]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698