OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Tool to determine inputs and outputs of a grit file. | 6 '''Tool to determine inputs and outputs of a grit file. |
7 ''' | 7 ''' |
8 | 8 |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import posixpath | 11 import posixpath |
12 import types | 12 import types |
13 import sys | 13 import sys |
| 14 |
14 from grit import grd_reader | 15 from grit import grd_reader |
15 from grit import util | 16 from grit import util |
16 | 17 |
17 ############################################################################## | 18 ############################################################################## |
18 # os.path.relpath is python 2.6 only. Some bots still run 2.5 only, so I took | 19 # os.path.relpath is python 2.6 only. Some bots still run 2.5 only, so I took |
19 # the relpath implementation from the python source. | 20 # the relpath implementation from the python source. |
20 # TODO(thakis): Once we're on 2.6 everywhere, remove this and use | 21 # TODO(thakis): Once we're on 2.6 everywhere, remove this and use |
21 # os.path.relpath directly. | 22 # os.path.relpath directly. |
22 | 23 |
23 # http://docs.python.org/license.html | 24 # http://docs.python.org/license.html |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 raise ValueError("no path specified") | 87 raise ValueError("no path specified") |
87 | 88 |
88 start_list = os.path.abspath(start).split(os.path.sep) | 89 start_list = os.path.abspath(start).split(os.path.sep) |
89 path_list = os.path.abspath(path).split(os.path.sep) | 90 path_list = os.path.abspath(path).split(os.path.sep) |
90 | 91 |
91 # Work out how much of the filepath is shared by start and path. | 92 # Work out how much of the filepath is shared by start and path. |
92 i = len(commonprefix([start_list, path_list])) | 93 i = len(commonprefix([start_list, path_list])) |
93 | 94 |
94 rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] | 95 rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] |
95 if not rel_list: | 96 if not rel_list: |
96 return curdir | 97 return os.path.curdir |
97 return os.path.join(*rel_list) | 98 return os.path.join(*rel_list) |
98 ############################################################################## | 99 ############################################################################## |
99 | 100 |
100 | 101 |
101 class WrongNumberOfArguments(Exception): | 102 class WrongNumberOfArguments(Exception): |
102 pass | 103 pass |
103 | 104 |
104 | 105 |
105 def Outputs(filename, defines): | 106 def Outputs(filename, defines): |
106 grd = grd_reader.Parse( | 107 grd = grd_reader.Parse( |
(...skipping 25 matching lines...) Expand all Loading... |
132 target.append(path) | 133 target.append(path) |
133 | 134 |
134 return [t.replace('\\', '/') for t in target] | 135 return [t.replace('\\', '/') for t in target] |
135 | 136 |
136 | 137 |
137 def GritSourceFiles(): | 138 def GritSourceFiles(): |
138 files = [] | 139 files = [] |
139 grit_root_dir = relpath(os.path.dirname(__file__), os.getcwd()) | 140 grit_root_dir = relpath(os.path.dirname(__file__), os.getcwd()) |
140 for root, dirs, filenames in os.walk(grit_root_dir): | 141 for root, dirs, filenames in os.walk(grit_root_dir): |
141 grit_src = [os.path.join(root, f) for f in filenames | 142 grit_src = [os.path.join(root, f) for f in filenames |
142 if f.endswith('.py') or f == 'resource_ids'] | 143 if f.endswith('.py')] |
143 files.extend(grit_src) | 144 files.extend(grit_src) |
| 145 # TODO(joi@chromium.org): Once we switch to specifying the |
| 146 # resource_ids file via a .grd attribute, it should be considered an |
| 147 # input of grit and this bit should no longer be necessary. |
| 148 default_resource_ids = relpath( |
| 149 os.path.join(grit_root_dir, '..', 'gritsettings', 'resource_ids'), |
| 150 os.getcwd()) |
| 151 if os.path.exists(default_resource_ids): |
| 152 files.append(default_resource_ids) |
144 return files | 153 return files |
145 | 154 |
146 | 155 |
147 def Inputs(filename, defines): | 156 def Inputs(filename, defines): |
148 grd = grd_reader.Parse( | 157 grd = grd_reader.Parse( |
149 filename, debug=False, defines=defines, tags_to_ignore=set(['messages'])) | 158 filename, debug=False, defines=defines, tags_to_ignore=set(['messages'])) |
150 files = [] | 159 files = [] |
151 for node in grd: | 160 for node in grd: |
152 if (node.name == 'structure' or node.name == 'skeleton' or | 161 if (node.name == 'structure' or node.name == 'skeleton' or |
153 (node.name == 'file' and node.parent and | 162 (node.name == 'file' and node.parent and |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 except WrongNumberOfArguments, e: | 231 except WrongNumberOfArguments, e: |
223 PrintUsage() | 232 PrintUsage() |
224 print e | 233 print e |
225 return 1 | 234 return 1 |
226 print result | 235 print result |
227 return 0 | 236 return 0 |
228 | 237 |
229 | 238 |
230 if __name__ == '__main__': | 239 if __name__ == '__main__': |
231 sys.exit(main(sys.argv)) | 240 sys.exit(main(sys.argv)) |
OLD | NEW |