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 filecmp | 10 import filecmp |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 ''' | 91 ''' |
92 | 92 |
93 def ShortDescription(self): | 93 def ShortDescription(self): |
94 return 'A tool that builds RC files for compilation.' | 94 return 'A tool that builds RC files for compilation.' |
95 | 95 |
96 def Run(self, opts, args): | 96 def Run(self, opts, args): |
97 self.output_directory = '.' | 97 self.output_directory = '.' |
98 first_ids_file = None | 98 first_ids_file = None |
99 whitelist_filenames = [] | 99 whitelist_filenames = [] |
100 target_platform = None | 100 target_platform = None |
101 (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:') | 101 deps_dir = None |
102 (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:', ('deps-dir=',)) | |
102 for (key, val) in own_opts: | 103 for (key, val) in own_opts: |
103 if key == '-o': | 104 if key == '-o': |
104 self.output_directory = val | 105 self.output_directory = val |
105 elif key == '-D': | 106 elif key == '-D': |
106 name, val = util.ParseDefine(val) | 107 name, val = util.ParseDefine(val) |
107 self.defines[name] = val | 108 self.defines[name] = val |
108 elif key == '-E': | 109 elif key == '-E': |
109 (env_name, env_value) = val.split('=', 1) | 110 (env_name, env_value) = val.split('=', 1) |
110 os.environ[env_name] = env_value | 111 os.environ[env_name] = env_value |
111 elif key == '-f': | 112 elif key == '-f': |
112 # TODO(joi@chromium.org): Remove this override once change | 113 # TODO(joi@chromium.org): Remove this override once change |
113 # lands in WebKit.grd to specify the first_ids_file in the | 114 # lands in WebKit.grd to specify the first_ids_file in the |
114 # .grd itself. | 115 # .grd itself. |
115 first_ids_file = val | 116 first_ids_file = val |
116 elif key == '-w': | 117 elif key == '-w': |
117 whitelist_filenames.append(val) | 118 whitelist_filenames.append(val) |
118 elif key == '-t': | 119 elif key == '-t': |
119 target_platform = val | 120 target_platform = val |
121 elif key == '--deps-dir': | |
122 deps_dir = val | |
120 | 123 |
121 if len(args): | 124 if len(args): |
122 print 'This tool takes no tool-specific arguments.' | 125 print 'This tool takes no tool-specific arguments.' |
123 return 2 | 126 return 2 |
124 self.SetOptions(opts) | 127 self.SetOptions(opts) |
125 if self.scons_targets: | 128 if self.scons_targets: |
126 self.VerboseOut('Using SCons targets to identify files to output.\n') | 129 self.VerboseOut('Using SCons targets to identify files to output.\n') |
127 else: | 130 else: |
128 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % | 131 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % |
129 (self.output_directory, | 132 (self.output_directory, |
(...skipping 10 matching lines...) Expand all Loading... | |
140 debug=opts.extra_verbose, | 143 debug=opts.extra_verbose, |
141 first_ids_file=first_ids_file, | 144 first_ids_file=first_ids_file, |
142 defines=self.defines, | 145 defines=self.defines, |
143 target_platform=target_platform) | 146 target_platform=target_platform) |
144 # Set an output context so that conditionals can use defines during the | 147 # Set an output context so that conditionals can use defines during the |
145 # gathering stage; we use a dummy language here since we are not outputting | 148 # gathering stage; we use a dummy language here since we are not outputting |
146 # a specific language. | 149 # a specific language. |
147 self.res.SetOutputLanguage('en') | 150 self.res.SetOutputLanguage('en') |
148 self.res.RunGatherers() | 151 self.res.RunGatherers() |
149 self.Process() | 152 self.Process() |
153 | |
154 if deps_dir: | |
155 self.GenerateDepsfile(opts.input, deps_dir) | |
Jói
2013/10/04 09:47:12
I can't find the word "depsfile" in general usage
Nico
2013/10/04 21:42:02
It's called "depfile" in ninja: http://martine.git
koz (OOO until 15th September)
2013/10/09 06:01:16
Renamed to depfile.
| |
156 | |
150 return 0 | 157 return 0 |
151 | 158 |
152 def __init__(self, defines=None): | 159 def __init__(self, defines=None): |
153 # Default file-creation function is built-in open(). Only done to allow | 160 # Default file-creation function is built-in open(). Only done to allow |
154 # overriding by unit test. | 161 # overriding by unit test. |
155 self.fo_create = open | 162 self.fo_create = open |
156 | 163 |
157 # key/value pairs of C-preprocessor like defines that are used for | 164 # key/value pairs of C-preprocessor like defines that are used for |
158 # conditional output of resources | 165 # conditional output of resources |
159 self.defines = defines or {} | 166 self.defines = defines or {} |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 else: | 251 else: |
245 # TODO(gfeher) modify here to set utf-8 encoding for admx/adml | 252 # TODO(gfeher) modify here to set utf-8 encoding for admx/adml |
246 encoding = 'utf_16' | 253 encoding = 'utf_16' |
247 | 254 |
248 # Set the context, for conditional inclusion of resources | 255 # Set the context, for conditional inclusion of resources |
249 self.res.SetOutputLanguage(output.GetLanguage()) | 256 self.res.SetOutputLanguage(output.GetLanguage()) |
250 self.res.SetOutputContext(output.GetContext()) | 257 self.res.SetOutputContext(output.GetContext()) |
251 self.res.SetDefines(self.defines) | 258 self.res.SetDefines(self.defines) |
252 | 259 |
253 # Make the output directory if it doesn't exist. | 260 # Make the output directory if it doesn't exist. |
254 outdir = os.path.split(output.GetOutputFilename())[0] | 261 self.MakeDirectoriesTo(output.GetOutputFilename()) |
255 if not os.path.exists(outdir): | |
256 os.makedirs(outdir) | |
257 | 262 |
258 # Write the results to a temporary file and only overwrite the original | 263 # Write the results to a temporary file and only overwrite the original |
259 # if the file changed. This avoids unnecessary rebuilds. | 264 # if the file changed. This avoids unnecessary rebuilds. |
260 outfile = self.fo_create(output.GetOutputFilename() + '.tmp', 'wb') | 265 outfile = self.fo_create(output.GetOutputFilename() + '.tmp', 'wb') |
261 | 266 |
262 if output.GetType() != 'data_package': | 267 if output.GetType() != 'data_package': |
263 outfile = util.WrapOutputStream(outfile, encoding) | 268 outfile = util.WrapOutputStream(outfile, encoding) |
264 | 269 |
265 # Iterate in-order through entire resource tree, calling formatters on | 270 # Iterate in-order through entire resource tree, calling formatters on |
266 # the entry into a node and on exit out of it. | 271 # the entry into a node and on exit out of it. |
(...skipping 30 matching lines...) Expand all Loading... | |
297 # Print out any fallback warnings, and missing translation errors, and | 302 # Print out any fallback warnings, and missing translation errors, and |
298 # exit with an error code if there are missing translations in a non-pseudo | 303 # exit with an error code if there are missing translations in a non-pseudo |
299 # and non-official build. | 304 # and non-official build. |
300 warnings = (self.res.UberClique().MissingTranslationsReport(). | 305 warnings = (self.res.UberClique().MissingTranslationsReport(). |
301 encode('ascii', 'replace')) | 306 encode('ascii', 'replace')) |
302 if warnings: | 307 if warnings: |
303 self.VerboseOut(warnings) | 308 self.VerboseOut(warnings) |
304 if self.res.UberClique().HasMissingTranslations(): | 309 if self.res.UberClique().HasMissingTranslations(): |
305 print self.res.UberClique().missing_translations_ | 310 print self.res.UberClique().missing_translations_ |
306 sys.exit(-1) | 311 sys.exit(-1) |
312 | |
313 # Generate a depsfile that contains the imlicit dependencies of the input grd. | |
Jói
2013/10/04 09:47:12
This should be a docstring, i.e. enclosed in """..
koz (OOO until 15th September)
2013/10/09 06:01:16
Done.
| |
314 # The deps file will be in the same format as a makefile, and will contain | |
315 # references to files relative to |deps_dir|. It will be put in the same | |
316 # directory as the generated outputs. | |
317 # | |
318 # For example, supposing we have three files in a directory src/ | |
319 # | |
320 # src/ | |
321 # blah.grd <- depends on input{1,2}.xtb | |
322 # input1.xtb | |
323 # input2.xtb | |
324 # | |
325 # and we run | |
326 # | |
327 # grit -i blah.grd -g ../out/gen --deps-dir ../out | |
328 # | |
329 # from the directory src/ we will generate a depsfile ../out/gen/blah.grd.d | |
330 # that has the contents | |
331 # | |
332 # gen/blah.grd.d: ../src/input1.xtb ../src/input2.xtb | |
333 # | |
334 # Note that all paths in the depsfile are relative to ../out, the deps-dir. | |
335 def GenerateDepsfile(self, input_filename, deps_dir): | |
336 depsfile_basename = os.path.basename(input_filename + '.d') | |
337 depsfile = os.path.abspath( | |
338 os.path.join(self.output_directory, depsfile_basename)) | |
339 deps_dir = os.path.abspath(deps_dir) | |
340 # The path prefix to prepend to dependencies in the depsfile. | |
341 prefix = os.path.relpath(os.getcwd(), deps_dir) | |
342 # The path that the depsfile refers to itself by in the depsfile. | |
343 self_ref_depsfile = os.path.relpath(depsfile, deps_dir) | |
344 infiles = self.res.GetInputFiles() | |
345 deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) | |
346 depsfile_contents = self_ref_depsfile + ': ' + deps_text | |
347 self.MakeDirectoriesTo(depsfile) | |
348 outfile = self.fo_create(depsfile, 'wb') | |
349 outfile.writelines(depsfile_contents) | |
350 | |
351 # Creates directories necessary to contain |file|. | |
Jói
2013/10/04 09:47:12
Move to docstring.
koz (OOO until 15th September)
2013/10/09 06:01:16
Done.
| |
352 def MakeDirectoriesTo(self, file): | |
Jói
2013/10/04 09:47:12
This can be an @staticmethod and skip the |self| p
koz (OOO until 15th September)
2013/10/09 06:01:16
Done.
| |
353 dir = os.path.split(file)[0] | |
354 if not os.path.exists(dir): | |
355 os.makedirs(dir) | |
OLD | NEW |