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 '''The 'grit build' tool along with integration for this tool with the | 6 '''The 'grit build' tool along with integration for this tool with the |
7 SCons build system. | 7 SCons build system. |
8 ''' | 8 ''' |
9 | 9 |
10 import codecs | 10 import codecs |
11 import filecmp | 11 import filecmp |
12 import getopt | 12 import getopt |
13 import os | 13 import os |
14 import shutil | 14 import shutil |
15 import sys | 15 import sys |
16 | 16 |
17 from grit import grd_reader | 17 from grit import grd_reader |
18 from grit import shortcuts | 18 from grit import shortcuts |
19 from grit import util | 19 from grit import util |
| 20 from grit.format import minifier |
20 from grit.node import include | 21 from grit.node import include |
21 from grit.node import message | 22 from grit.node import message |
22 from grit.node import structure | 23 from grit.node import structure |
23 from grit.tool import interface | 24 from grit.tool import interface |
24 | 25 |
25 | 26 |
26 # It would be cleaner to have each module register itself, but that would | 27 # It would be cleaner to have each module register itself, but that would |
27 # require importing all of them on every run of GRIT. | 28 # require importing all of them on every run of GRIT. |
28 '''Map from <output> node types to modules under grit.format.''' | 29 '''Map from <output> node types to modules under grit.format.''' |
29 _format_modules = { | 30 _format_modules = { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 is different from the old file. This allows some build | 120 is different from the old file. This allows some build |
120 systems to realize that dependent build steps might be | 121 systems to realize that dependent build steps might be |
121 unnecessary, at the cost of comparing the output data at | 122 unnecessary, at the cost of comparing the output data at |
122 grit time. | 123 grit time. |
123 | 124 |
124 --depend-on-stamp | 125 --depend-on-stamp |
125 If specified along with --depfile and --depdir, the depfile | 126 If specified along with --depfile and --depdir, the depfile |
126 generated will depend on a stampfile instead of the first | 127 generated will depend on a stampfile instead of the first |
127 output in the input .grd file. | 128 output in the input .grd file. |
128 | 129 |
| 130 --js-minifier A command to run the Javascript minifier. If not set then |
| 131 Javascript won't be minified. The command should read the |
| 132 original Javascript from standard input, and output the |
| 133 minified Javascript to standard output. A non-zero exit |
| 134 status will be taken as indicating failure. |
| 135 |
129 Conditional inclusion of resources only affects the output of files which | 136 Conditional inclusion of resources only affects the output of files which |
130 control which resources get linked into a binary, e.g. it affects .rc files | 137 control which resources get linked into a binary, e.g. it affects .rc files |
131 meant for compilation but it does not affect resource header files (that define | 138 meant for compilation but it does not affect resource header files (that define |
132 IDs). This helps ensure that values of IDs stay the same, that all messages | 139 IDs). This helps ensure that values of IDs stay the same, that all messages |
133 are exported to translation interchange files (e.g. XMB files), etc. | 140 are exported to translation interchange files (e.g. XMB files), etc. |
134 ''' | 141 ''' |
135 | 142 |
136 def ShortDescription(self): | 143 def ShortDescription(self): |
137 return 'A tool that builds RC files for compilation.' | 144 return 'A tool that builds RC files for compilation.' |
138 | 145 |
139 def Run(self, opts, args): | 146 def Run(self, opts, args): |
140 self.output_directory = '.' | 147 self.output_directory = '.' |
141 first_ids_file = None | 148 first_ids_file = None |
142 whitelist_filenames = [] | 149 whitelist_filenames = [] |
143 assert_output_files = [] | 150 assert_output_files = [] |
144 target_platform = None | 151 target_platform = None |
145 depfile = None | 152 depfile = None |
146 depdir = None | 153 depdir = None |
147 rc_header_format = None | 154 rc_header_format = None |
148 output_all_resource_defines = None | 155 output_all_resource_defines = None |
149 write_only_new = False | 156 write_only_new = False |
150 depend_on_stamp = False | 157 depend_on_stamp = False |
| 158 js_minifier = None |
151 replace_ellipsis = True | 159 replace_ellipsis = True |
152 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', | 160 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', |
153 ('depdir=','depfile=','assert-file-list=', | 161 ('depdir=','depfile=','assert-file-list=', |
154 'output-all-resource-defines', | 162 'output-all-resource-defines', |
155 'no-output-all-resource-defines', | 163 'no-output-all-resource-defines', |
156 'no-replace-ellipsis', | 164 'no-replace-ellipsis', |
157 'depend-on-stamp', | 165 'depend-on-stamp', |
| 166 'js-minifier=', |
158 'write-only-new=')) | 167 'write-only-new=')) |
159 for (key, val) in own_opts: | 168 for (key, val) in own_opts: |
160 if key == '-a': | 169 if key == '-a': |
161 assert_output_files.append(val) | 170 assert_output_files.append(val) |
162 elif key == '--assert-file-list': | 171 elif key == '--assert-file-list': |
163 with open(val) as f: | 172 with open(val) as f: |
164 assert_output_files += f.read().splitlines() | 173 assert_output_files += f.read().splitlines() |
165 elif key == '-o': | 174 elif key == '-o': |
166 self.output_directory = val | 175 self.output_directory = val |
167 elif key == '-D': | 176 elif key == '-D': |
(...skipping 20 matching lines...) Expand all Loading... |
188 elif key == '-h': | 197 elif key == '-h': |
189 rc_header_format = val | 198 rc_header_format = val |
190 elif key == '--depdir': | 199 elif key == '--depdir': |
191 depdir = val | 200 depdir = val |
192 elif key == '--depfile': | 201 elif key == '--depfile': |
193 depfile = val | 202 depfile = val |
194 elif key == '--write-only-new': | 203 elif key == '--write-only-new': |
195 write_only_new = val != '0' | 204 write_only_new = val != '0' |
196 elif key == '--depend-on-stamp': | 205 elif key == '--depend-on-stamp': |
197 depend_on_stamp = True | 206 depend_on_stamp = True |
| 207 elif key == '--js-minifier': |
| 208 js_minifier = val |
198 | 209 |
199 if len(args): | 210 if len(args): |
200 print 'This tool takes no tool-specific arguments.' | 211 print 'This tool takes no tool-specific arguments.' |
201 return 2 | 212 return 2 |
202 self.SetOptions(opts) | 213 self.SetOptions(opts) |
203 if self.scons_targets: | 214 if self.scons_targets: |
204 self.VerboseOut('Using SCons targets to identify files to output.\n') | 215 self.VerboseOut('Using SCons targets to identify files to output.\n') |
205 else: | 216 else: |
206 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % | 217 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % |
207 (self.output_directory, | 218 (self.output_directory, |
208 os.path.abspath(self.output_directory))) | 219 os.path.abspath(self.output_directory))) |
209 | 220 |
210 if whitelist_filenames: | 221 if whitelist_filenames: |
211 self.whitelist_names = set() | 222 self.whitelist_names = set() |
212 for whitelist_filename in whitelist_filenames: | 223 for whitelist_filename in whitelist_filenames: |
213 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); | 224 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); |
214 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) | 225 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) |
215 self.whitelist_names.update(whitelist_contents.strip().split('\n')) | 226 self.whitelist_names.update(whitelist_contents.strip().split('\n')) |
216 | 227 |
| 228 if js_minifier: |
| 229 minifier.SetJsMinifier(js_minifier) |
| 230 |
217 self.write_only_new = write_only_new | 231 self.write_only_new = write_only_new |
218 | 232 |
219 self.res = grd_reader.Parse(opts.input, | 233 self.res = grd_reader.Parse(opts.input, |
220 debug=opts.extra_verbose, | 234 debug=opts.extra_verbose, |
221 first_ids_file=first_ids_file, | 235 first_ids_file=first_ids_file, |
222 defines=self.defines, | 236 defines=self.defines, |
223 target_platform=target_platform) | 237 target_platform=target_platform) |
224 | 238 |
225 # If the output_all_resource_defines option is specified, override the value | 239 # If the output_all_resource_defines option is specified, override the value |
226 # found in the grd file. | 240 # found in the grd file. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 self.MakeDirectoriesTo(depfile) | 515 self.MakeDirectoriesTo(depfile) |
502 outfile = self.fo_create(depfile, 'w', encoding='utf-8') | 516 outfile = self.fo_create(depfile, 'w', encoding='utf-8') |
503 outfile.writelines(depfile_contents) | 517 outfile.writelines(depfile_contents) |
504 | 518 |
505 @staticmethod | 519 @staticmethod |
506 def MakeDirectoriesTo(file): | 520 def MakeDirectoriesTo(file): |
507 '''Creates directories necessary to contain |file|.''' | 521 '''Creates directories necessary to contain |file|.''' |
508 dir = os.path.split(file)[0] | 522 dir = os.path.split(file)[0] |
509 if not os.path.exists(dir): | 523 if not os.path.exists(dir): |
510 os.makedirs(dir) | 524 os.makedirs(dir) |
OLD | NEW |