OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 sys | 12 import sys |
13 | 13 |
14 from grit import grd_reader | 14 from grit import grd_reader |
15 from grit import util | 15 from grit import util |
16 | 16 |
17 class WrongNumberOfArguments(Exception): | 17 class WrongNumberOfArguments(Exception): |
18 pass | 18 pass |
19 | 19 |
20 | 20 |
21 def Outputs(filename, defines, ids_file): | 21 def Outputs(filename, defines, ids_file, target_platform): |
22 grd = grd_reader.Parse( | 22 grd = grd_reader.Parse( |
23 filename, defines=defines, tags_to_ignore=set(['messages']), | 23 filename, defines=defines, tags_to_ignore=set(['messages']), |
24 first_ids_file=ids_file) | 24 first_ids_file=ids_file, target_platform=target_platform) |
25 | 25 |
26 target = [] | 26 target = [] |
27 lang_folders = {} | 27 lang_folders = {} |
28 # Add all explicitly-specified output files | 28 # Add all explicitly-specified output files |
29 for output in grd.GetOutputFiles(): | 29 for output in grd.GetOutputFiles(): |
30 path = output.GetFilename() | 30 path = output.GetFilename() |
31 target.append(path) | 31 target.append(path) |
32 | 32 |
33 if path.endswith('.h'): | 33 if path.endswith('.h'): |
34 path, filename = os.path.split(path) | 34 path, filename = os.path.split(path) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if options.whitelist_files: | 148 if options.whitelist_files: |
149 inputs.extend(options.whitelist_files) | 149 inputs.extend(options.whitelist_files) |
150 return '\n'.join(inputs) | 150 return '\n'.join(inputs) |
151 elif options.outputs: | 151 elif options.outputs: |
152 if len(args) != 2: | 152 if len(args) != 2: |
153 raise WrongNumberOfArguments( | 153 raise WrongNumberOfArguments( |
154 "Expected exactly 2 arguments for --outputs.") | 154 "Expected exactly 2 arguments for --outputs.") |
155 | 155 |
156 prefix, filename = args | 156 prefix, filename = args |
157 outputs = [posixpath.join(prefix, f) | 157 outputs = [posixpath.join(prefix, f) |
158 for f in Outputs(filename, defines, options.ids_file)] | 158 for f in Outputs(filename, defines, |
| 159 options.ids_file, options.target_platform)] |
159 return '\n'.join(outputs) | 160 return '\n'.join(outputs) |
160 else: | 161 else: |
161 raise WrongNumberOfArguments("Expected --inputs or --outputs.") | 162 raise WrongNumberOfArguments("Expected --inputs or --outputs.") |
162 | 163 |
163 | 164 |
164 def main(argv): | 165 def main(argv): |
165 if sys.version_info < (2, 6): | 166 if sys.version_info < (2, 6): |
166 print "GRIT requires Python 2.6 or later." | 167 print "GRIT requires Python 2.6 or later." |
167 return 1 | 168 return 1 |
168 | 169 |
169 try: | 170 try: |
170 result = DoMain(argv[1:]) | 171 result = DoMain(argv[1:]) |
171 except WrongNumberOfArguments, e: | 172 except WrongNumberOfArguments, e: |
172 PrintUsage() | 173 PrintUsage() |
173 print e | 174 print e |
174 return 1 | 175 return 1 |
175 print result | 176 print result |
176 return 0 | 177 return 0 |
177 | 178 |
178 | 179 |
179 if __name__ == '__main__': | 180 if __name__ == '__main__': |
180 sys.exit(main(sys.argv)) | 181 sys.exit(main(sys.argv)) |
OLD | NEW |