OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can |
| 4 # be found in the LICENSE file. |
| 5 |
| 6 import re |
| 7 |
| 8 |
| 9 def LoadGypFile(gyp_filename): |
| 10 """Load the contents of a gyp file. |
| 11 |
| 12 Arguments: |
| 13 filename: filename of a .gyp file. |
| 14 Returns: |
| 15 Raw dict from .gyp file. |
| 16 """ |
| 17 return eval(open(gyp_filename).read(), {}, {}) |
| 18 |
| 19 |
| 20 def GypTargetSources(gyp_data, target_name, pattern): |
| 21 """Extract a sources from a target matching a given pattern. |
| 22 |
| 23 Arguments: |
| 24 gyp_data: dict previously load by LoadGypFile. |
| 25 target_name: target to extract from. |
| 26 pattern: re pattern that sources must match. |
| 27 Returns: |
| 28 A list of strings containing source filenames. |
| 29 """ |
| 30 targets = [target for target in gyp_data['targets'] |
| 31 if target['target_name'] == target_name] |
| 32 # Only one target should have this name. |
| 33 assert len(targets) == 1 |
| 34 desired_target = targets[0] |
| 35 # Extract source files that match. |
| 36 re_compiled = re.compile(pattern) |
| 37 return [source_file for source_file in desired_target['sources'] |
| 38 if re_compiled.match(source_file)] |
OLD | NEW |