Chromium Code Reviews| Index: grit/tool/build.py |
| diff --git a/grit/tool/build.py b/grit/tool/build.py |
| index 596feb0a0f0d0ef7be4692375eb1fe62e9e6eb38..60fd3fa4a3e6da740026c62351fbbe0c5dd068d5 100644 |
| --- a/grit/tool/build.py |
| +++ b/grit/tool/build.py |
| @@ -98,7 +98,8 @@ are exported to translation interchange files (e.g. XMB files), etc. |
| first_ids_file = None |
| whitelist_filenames = [] |
| target_platform = None |
| - (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:') |
| + deps_dir = None |
| + (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:', ('deps-dir=',)) |
| for (key, val) in own_opts: |
| if key == '-o': |
| self.output_directory = val |
| @@ -117,6 +118,8 @@ are exported to translation interchange files (e.g. XMB files), etc. |
| whitelist_filenames.append(val) |
| elif key == '-t': |
| target_platform = val |
| + elif key == '--deps-dir': |
| + deps_dir = val |
| if len(args): |
| print 'This tool takes no tool-specific arguments.' |
| @@ -147,6 +150,10 @@ are exported to translation interchange files (e.g. XMB files), etc. |
| self.res.SetOutputLanguage('en') |
| self.res.RunGatherers() |
| self.Process() |
| + |
| + if deps_dir: |
| + 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.
|
| + |
| return 0 |
| def __init__(self, defines=None): |
| @@ -251,9 +258,7 @@ are exported to translation interchange files (e.g. XMB files), etc. |
| self.res.SetDefines(self.defines) |
| # Make the output directory if it doesn't exist. |
| - outdir = os.path.split(output.GetOutputFilename())[0] |
| - if not os.path.exists(outdir): |
| - os.makedirs(outdir) |
| + self.MakeDirectoriesTo(output.GetOutputFilename()) |
| # Write the results to a temporary file and only overwrite the original |
| # if the file changed. This avoids unnecessary rebuilds. |
| @@ -304,3 +309,47 @@ are exported to translation interchange files (e.g. XMB files), etc. |
| if self.res.UberClique().HasMissingTranslations(): |
| print self.res.UberClique().missing_translations_ |
| sys.exit(-1) |
| + |
| + # 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.
|
| + # The deps file will be in the same format as a makefile, and will contain |
| + # references to files relative to |deps_dir|. It will be put in the same |
| + # directory as the generated outputs. |
| + # |
| + # For example, supposing we have three files in a directory src/ |
| + # |
| + # src/ |
| + # blah.grd <- depends on input{1,2}.xtb |
| + # input1.xtb |
| + # input2.xtb |
| + # |
| + # and we run |
| + # |
| + # grit -i blah.grd -g ../out/gen --deps-dir ../out |
| + # |
| + # from the directory src/ we will generate a depsfile ../out/gen/blah.grd.d |
| + # that has the contents |
| + # |
| + # gen/blah.grd.d: ../src/input1.xtb ../src/input2.xtb |
| + # |
| + # Note that all paths in the depsfile are relative to ../out, the deps-dir. |
| + def GenerateDepsfile(self, input_filename, deps_dir): |
| + depsfile_basename = os.path.basename(input_filename + '.d') |
| + depsfile = os.path.abspath( |
| + os.path.join(self.output_directory, depsfile_basename)) |
| + deps_dir = os.path.abspath(deps_dir) |
| + # The path prefix to prepend to dependencies in the depsfile. |
| + prefix = os.path.relpath(os.getcwd(), deps_dir) |
| + # The path that the depsfile refers to itself by in the depsfile. |
| + self_ref_depsfile = os.path.relpath(depsfile, deps_dir) |
| + infiles = self.res.GetInputFiles() |
| + deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) |
| + depsfile_contents = self_ref_depsfile + ': ' + deps_text |
| + self.MakeDirectoriesTo(depsfile) |
| + outfile = self.fo_create(depsfile, 'wb') |
| + outfile.writelines(depsfile_contents) |
| + |
| + # 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.
|
| + 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.
|
| + dir = os.path.split(file)[0] |
| + if not os.path.exists(dir): |
| + os.makedirs(dir) |