OLD | NEW |
---|---|
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 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2183 extra_sources_for_rules: a list of keys to scan for rule matches in | 2183 extra_sources_for_rules: a list of keys to scan for rule matches in |
2184 addition to 'sources'. | 2184 addition to 'sources'. |
2185 """ | 2185 """ |
2186 | 2186 |
2187 # Dicts to map between values found in rules' 'rule_name' and 'extension' | 2187 # Dicts to map between values found in rules' 'rule_name' and 'extension' |
2188 # keys and the rule dicts themselves. | 2188 # keys and the rule dicts themselves. |
2189 rule_names = {} | 2189 rule_names = {} |
2190 rule_extensions = {} | 2190 rule_extensions = {} |
2191 | 2191 |
2192 rules = target_dict.get('rules', []) | 2192 rules = target_dict.get('rules', []) |
2193 | |
2194 # Gather the outputs for all rules with process_outputs_as_sources so we can | |
2195 # validate that they're not chained below. | |
2196 processed_outputs = [] | |
2197 for rule in rules: | |
2198 if rule.get('process_outputs_as_sources', False): | |
2199 for output in rule['outputs']: | |
2200 processed_outputs.append((rule, output)) | |
Evan Martin
2012/05/18 22:53:36
Why not a map of output extension => other stuff,
| |
2201 | |
2193 for rule in rules: | 2202 for rule in rules: |
2194 # Make sure that there's no conflict among rule names and extensions. | 2203 # Make sure that there's no conflict among rule names and extensions. |
2195 rule_name = rule['rule_name'] | 2204 rule_name = rule['rule_name'] |
2196 if rule_name in rule_names: | 2205 if rule_name in rule_names: |
2197 raise KeyError, 'rule %s exists in duplicate, target %s' % \ | 2206 raise KeyError, 'rule %s exists in duplicate, target %s' % \ |
2198 (rule_name, target) | 2207 (rule_name, target) |
2199 rule_names[rule_name] = rule | 2208 rule_names[rule_name] = rule |
2200 | 2209 |
2201 rule_extension = rule['extension'] | 2210 rule_extension = rule['extension'] |
2202 if rule_extension in rule_extensions: | 2211 if rule_extension in rule_extensions: |
2203 raise KeyError, ('extension %s associated with multiple rules, ' + | 2212 raise KeyError, ('extension %s associated with multiple rules, ' + |
2204 'target %s rules %s and %s') % \ | 2213 'target %s rules %s and %s') % \ |
2205 (rule_extension, target, | 2214 (rule_extension, target, |
2206 rule_extensions[rule_extension]['rule_name'], | 2215 rule_extensions[rule_extension]['rule_name'], |
2207 rule_name) | 2216 rule_name) |
2208 rule_extensions[rule_extension] = rule | 2217 rule_extensions[rule_extension] = rule |
2209 | 2218 |
2219 # Make sure rules aren't chained (i.e. the output of one rule with | |
2220 # process_outputs_as_sources is the input for another rule). Some | |
2221 # generators can't reasonably support this. | |
2222 for other, output in processed_outputs: | |
2223 if other == rule: | |
2224 continue | |
2225 if output.endswith('.' + rule_extension): | |
2226 raise KeyError, ('target %s contains "%s" rule that would handle ' | |
2227 'the output of other rule %s (processing %s)' % | |
2228 (target, rule_extension, other['rule_name'], output)) | |
2229 | |
2210 # Make sure rule_sources isn't already there. It's going to be | 2230 # Make sure rule_sources isn't already there. It's going to be |
2211 # created below if needed. | 2231 # created below if needed. |
2212 if 'rule_sources' in rule: | 2232 if 'rule_sources' in rule: |
2213 raise KeyError, \ | 2233 raise KeyError, \ |
2214 'rule_sources must not exist in input, target %s rule %s' % \ | 2234 'rule_sources must not exist in input, target %s rule %s' % \ |
2215 (target, rule_name) | 2235 (target, rule_name) |
2216 extension = rule['extension'] | 2236 extension = rule['extension'] |
2217 | 2237 |
2218 rule_sources = [] | 2238 rule_sources = [] |
2219 source_keys = ['sources'] | 2239 source_keys = ['sources'] |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2481 ValidateRunAsInTarget(target, target_dict, build_file) | 2501 ValidateRunAsInTarget(target, target_dict, build_file) |
2482 ValidateActionsInTarget(target, target_dict, build_file) | 2502 ValidateActionsInTarget(target, target_dict, build_file) |
2483 | 2503 |
2484 # Generators might not expect ints. Turn them into strs. | 2504 # Generators might not expect ints. Turn them into strs. |
2485 TurnIntIntoStrInDict(data) | 2505 TurnIntIntoStrInDict(data) |
2486 | 2506 |
2487 # TODO(mark): Return |data| for now because the generator needs a list of | 2507 # TODO(mark): Return |data| for now because the generator needs a list of |
2488 # build files that came in. In the future, maybe it should just accept | 2508 # build files that came in. In the future, maybe it should just accept |
2489 # a list, and not the whole data dict. | 2509 # a list, and not the whole data dict. |
2490 return [flat_list, targets, data] | 2510 return [flat_list, targets, data] |
OLD | NEW |