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 from grit.util import RAW_TEXT | |
Lei Zhang
2016/06/29 22:51:32
Why is this on top?
| |
5 | 6 |
6 '''The 'grit build' tool along with integration for this tool with the | 7 '''The 'grit build' tool along with integration for this tool with the |
7 SCons build system. | 8 SCons build system. |
8 ''' | 9 ''' |
9 | 10 |
10 import codecs | 11 import codecs |
11 import filecmp | 12 import filecmp |
12 import getopt | 13 import getopt |
13 import os | 14 import os |
15 import shlex | |
14 import shutil | 16 import shutil |
15 import sys | 17 import sys |
16 | 18 |
17 from grit import grd_reader | 19 from grit import grd_reader |
18 from grit import util | 20 from grit import util |
19 from grit.tool import interface | 21 from grit.tool import interface |
20 from grit import shortcuts | 22 from grit import shortcuts |
21 | 23 |
22 | 24 |
23 # It would be cleaner to have each module register itself, but that would | 25 # It would be cleaner to have each module register itself, but that would |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 is different from the old file. This allows some build | 118 is different from the old file. This allows some build |
117 systems to realize that dependent build steps might be | 119 systems to realize that dependent build steps might be |
118 unnecessary, at the cost of comparing the output data at | 120 unnecessary, at the cost of comparing the output data at |
119 grit time. | 121 grit time. |
120 | 122 |
121 --depend-on-stamp | 123 --depend-on-stamp |
122 If specified along with --depfile and --depdir, the depfile | 124 If specified along with --depfile and --depdir, the depfile |
123 generated will depend on a stampfile instead of the first | 125 generated will depend on a stampfile instead of the first |
124 output in the input .grd file. | 126 output in the input .grd file. |
125 | 127 |
128 --moved-input-file | |
129 Specifies that a file referenced (directly or indirectly) by | |
130 the .grd file should be fetched from a different location. | |
131 The argument is of the form <original-path>:<actual-path>. | |
Lei Zhang
2016/06/29 22:51:32
nit: extra space, or s/ /: /
aberent
2016/07/14 15:41:36
Comment was wrong in other ways as well. Updated.
| |
132 Both paths must be absolute. | |
133 | |
126 Conditional inclusion of resources only affects the output of files which | 134 Conditional inclusion of resources only affects the output of files which |
127 control which resources get linked into a binary, e.g. it affects .rc files | 135 control which resources get linked into a binary, e.g. it affects .rc files |
128 meant for compilation but it does not affect resource header files (that define | 136 meant for compilation but it does not affect resource header files (that define |
129 IDs). This helps ensure that values of IDs stay the same, that all messages | 137 IDs). This helps ensure that values of IDs stay the same, that all messages |
130 are exported to translation interchange files (e.g. XMB files), etc. | 138 are exported to translation interchange files (e.g. XMB files), etc. |
131 ''' | 139 ''' |
132 | 140 |
133 def ShortDescription(self): | 141 def ShortDescription(self): |
134 return 'A tool that builds RC files for compilation.' | 142 return 'A tool that builds RC files for compilation.' |
135 | 143 |
136 def Run(self, opts, args): | 144 def Run(self, opts, args): |
137 self.output_directory = '.' | 145 self.output_directory = '.' |
138 first_ids_file = None | 146 first_ids_file = None |
139 whitelist_filenames = [] | 147 whitelist_filenames = [] |
140 assert_output_files = [] | 148 assert_output_files = [] |
141 target_platform = None | 149 target_platform = None |
142 depfile = None | 150 depfile = None |
143 depdir = None | 151 depdir = None |
144 rc_header_format = None | 152 rc_header_format = None |
145 output_all_resource_defines = None | 153 output_all_resource_defines = None |
146 write_only_new = False | 154 write_only_new = False |
147 depend_on_stamp = False | 155 depend_on_stamp = False |
156 replacement_paths = {} | |
148 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', | 157 (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', |
149 ('depdir=','depfile=','assert-file-list=', | 158 ('depdir=','depfile=','assert-file-list=', |
150 'output-all-resource-defines', | 159 'output-all-resource-defines', |
151 'no-output-all-resource-defines', | 160 'no-output-all-resource-defines', |
152 'depend-on-stamp', | 161 'depend-on-stamp', |
153 'write-only-new=')) | 162 'write-only-new=', |
163 'moved-input-file-list=')) | |
154 for (key, val) in own_opts: | 164 for (key, val) in own_opts: |
155 if key == '-a': | 165 if key == '-a': |
156 assert_output_files.append(val) | 166 assert_output_files.append(val) |
157 elif key == '--assert-file-list': | 167 elif key == '--assert-file-list': |
158 with open(val) as f: | 168 with open(val) as f: |
159 assert_output_files += f.read().splitlines() | 169 assert_output_files += f.read().splitlines() |
160 elif key == '-o': | 170 elif key == '-o': |
161 self.output_directory = val | 171 self.output_directory = val |
162 elif key == '-D': | 172 elif key == '-D': |
163 name, val = util.ParseDefine(val) | 173 name, val = util.ParseDefine(val) |
(...skipping 17 matching lines...) Expand all Loading... | |
181 elif key == '-h': | 191 elif key == '-h': |
182 rc_header_format = val | 192 rc_header_format = val |
183 elif key == '--depdir': | 193 elif key == '--depdir': |
184 depdir = val | 194 depdir = val |
185 elif key == '--depfile': | 195 elif key == '--depfile': |
186 depfile = val | 196 depfile = val |
187 elif key == '--write-only-new': | 197 elif key == '--write-only-new': |
188 write_only_new = val != '0' | 198 write_only_new = val != '0' |
189 elif key == '--depend-on-stamp': | 199 elif key == '--depend-on-stamp': |
190 depend_on_stamp = True | 200 depend_on_stamp = True |
201 elif key == '--moved-input-file-list': | |
202 moved_list = shlex.split(util.ReadFile(val, RAW_TEXT)) | |
203 for m in moved_list: | |
204 (oldpath, newpath) = str.split(m, ':') | |
205 replacement_paths[oldpath] = newpath | |
191 | 206 |
192 if len(args): | 207 if len(args): |
193 print 'This tool takes no tool-specific arguments.' | 208 print 'This tool takes no tool-specific arguments.' |
194 return 2 | 209 return 2 |
195 self.SetOptions(opts) | 210 self.SetOptions(opts) |
196 if self.scons_targets: | 211 if self.scons_targets: |
197 self.VerboseOut('Using SCons targets to identify files to output.\n') | 212 self.VerboseOut('Using SCons targets to identify files to output.\n') |
198 else: | 213 else: |
199 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % | 214 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % |
200 (self.output_directory, | 215 (self.output_directory, |
201 os.path.abspath(self.output_directory))) | 216 os.path.abspath(self.output_directory))) |
202 | 217 |
218 util.SetReplacementPaths(replacement_paths) | |
219 | |
203 if whitelist_filenames: | 220 if whitelist_filenames: |
204 self.whitelist_names = set() | 221 self.whitelist_names = set() |
205 for whitelist_filename in whitelist_filenames: | 222 for whitelist_filename in whitelist_filenames: |
206 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); | 223 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); |
207 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) | 224 whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT) |
208 self.whitelist_names.update(whitelist_contents.strip().split('\n')) | 225 self.whitelist_names.update(whitelist_contents.strip().split('\n')) |
209 | 226 |
210 self.write_only_new = write_only_new | 227 self.write_only_new = write_only_new |
211 | 228 |
212 self.res = grd_reader.Parse(opts.input, | 229 self.res = grd_reader.Parse(opts.input, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 self.MakeDirectoriesTo(depfile) | 507 self.MakeDirectoriesTo(depfile) |
491 outfile = self.fo_create(depfile, 'w', encoding='utf-8') | 508 outfile = self.fo_create(depfile, 'w', encoding='utf-8') |
492 outfile.writelines(depfile_contents) | 509 outfile.writelines(depfile_contents) |
493 | 510 |
494 @staticmethod | 511 @staticmethod |
495 def MakeDirectoriesTo(file): | 512 def MakeDirectoriesTo(file): |
496 '''Creates directories necessary to contain |file|.''' | 513 '''Creates directories necessary to contain |file|.''' |
497 dir = os.path.split(file)[0] | 514 dir = os.path.split(file)[0] |
498 if not os.path.exists(dir): | 515 if not os.path.exists(dir): |
499 os.makedirs(dir) | 516 os.makedirs(dir) |
OLD | NEW |