Index: site_scons/gyp_extract.py |
=================================================================== |
--- site_scons/gyp_extract.py (revision 0) |
+++ site_scons/gyp_extract.py (revision 0) |
@@ -0,0 +1,38 @@ |
+#!/usr/bin/python |
+# Copyright 2010 The Native Client Authors. All rights reserved. |
Mark Seaborn
2011/03/23 18:51:32
2011?
|
+# Use of this source code is governed by a BSD-style license that can |
+# be found in the LICENSE file. |
+ |
+import re |
+ |
+ |
+def LoadGypFile(gyp_filename): |
+ """Load the contents of a gyp file. |
+ |
+ Arguments: |
+ filename: filename of a .gyp file. |
+ Returns: |
+ Raw dict from .gyp file. |
+ """ |
+ return eval(open(gyp_filename).read(), {}, {}) |
+ |
+ |
+def GypTargetSources(gyp_data, target_name, pattern): |
+ """Extract a sources from a target matching a given pattern. |
+ |
+ Arguments: |
+ gyp_data: dict previously load by LoadGypFile. |
+ target_name: target to extract from. |
+ pattern: re pattern that sources must match. |
+ Returns: |
+ A list of strings containing source filenames. |
+ """ |
+ targets = [target for target in gyp_data['targets'] |
+ if target['target_name'] == target_name] |
+ # Only one target should have this name. |
+ assert len(targets) == 1 |
+ desired_target = targets[0] |
+ # Extract source files that match. |
+ re_compiled = re.compile(pattern) |
+ return [source_file for source_file in desired_target['sources'] |
+ if re_compiled.match(source_file)] |
Property changes on: site_scons/gyp_extract.py |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |