OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Converts a given gypi file to a python scope and writes the result to stdout. | 5 """Converts a given gypi file to a python scope and writes the result to stdout. |
6 | 6 |
7 It is assumed that the file contains a toplevel dictionary, and this script | 7 It is assumed that the file contains a toplevel dictionary, and this script |
8 will return that dictionary as a GN "scope" (see example below). This script | 8 will return that dictionary as a GN "scope" (see example below). This script |
9 does not know anything about GYP and it will not expand variables or execute | 9 does not know anything about GYP and it will not expand variables or execute |
10 conditions. | 10 conditions. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 except Exception, e: | 83 except Exception, e: |
84 raise Exception("Unexpected error while reading %s: %s" % (path, str(e))) | 84 raise Exception("Unexpected error while reading %s: %s" % (path, str(e))) |
85 | 85 |
86 assert isinstance(file_data, dict), "%s does not eval to a dictionary" % path | 86 assert isinstance(file_data, dict), "%s does not eval to a dictionary" % path |
87 | 87 |
88 # Flatten any variables to the top level. | 88 # Flatten any variables to the top level. |
89 if 'variables' in file_data: | 89 if 'variables' in file_data: |
90 file_data.update(file_data['variables']) | 90 file_data.update(file_data['variables']) |
91 del file_data['variables'] | 91 del file_data['variables'] |
92 | 92 |
93 # Strip any conditions. | 93 # Strip all elements that this script can't process. |
94 if 'conditions' in file_data: | 94 elements_to_strip = [ |
95 del file_data['conditions'] | 95 'conditions', |
96 if 'target_conditions' in file_data: | 96 'target_conditions', |
97 del file_data['target_conditions'] | 97 'targets', |
98 | 98 'includes', |
99 # Strip targets and includes in the toplevel, since some files define these | 99 'actions', |
100 # and we can't slurp them in. | 100 ] |
101 if 'targets' in file_data: | 101 for element in elements_to_strip: |
102 del file_data['targets'] | 102 if element in file_data: |
103 if 'includes' in file_data: | 103 del file_data[element] |
104 del file_data['includes'] | |
105 | 104 |
106 return file_data | 105 return file_data |
107 | 106 |
108 | 107 |
109 def ReplaceSubstrings(values, search_for, replace_with): | 108 def ReplaceSubstrings(values, search_for, replace_with): |
110 """Recursively replaces substrings in a value. | 109 """Recursively replaces substrings in a value. |
111 | 110 |
112 Replaces all substrings of the "search_for" with "repace_with" for all | 111 Replaces all substrings of the "search_for" with "repace_with" for all |
113 strings occurring in "values". This is done by recursively iterating into | 112 strings occurring in "values". This is done by recursively iterating into |
114 lists as well as the keys and values of dictionaries.""" | 113 lists as well as the keys and values of dictionaries.""" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 del data[key] | 159 del data[key] |
161 | 160 |
162 print gn_helpers.ToGNString(data) | 161 print gn_helpers.ToGNString(data) |
163 | 162 |
164 if __name__ == '__main__': | 163 if __name__ == '__main__': |
165 try: | 164 try: |
166 main() | 165 main() |
167 except Exception, e: | 166 except Exception, e: |
168 print str(e) | 167 print str(e) |
169 sys.exit(1) | 168 sys.exit(1) |
OLD | NEW |