diff options
author | Android Chromium Automerger <chromium-automerger@android> | 2014-07-22 18:16:34 +0000 |
---|---|---|
committer | Android Chromium Automerger <chromium-automerger@android> | 2014-07-22 18:16:34 +0000 |
commit | d03bdcbfaf49bb1da4bd4346503fcf6baff6830b (patch) | |
tree | 4aa2fa3610908d6d65bce7221aca46767504b72c | |
parent | 8d835902938db62442bf9e699decb799650010e5 (diff) | |
parent | 856ff33a9069bf62462ea2a2b88281974f97dba2 (diff) | |
download | grit-d03bdcbfaf49bb1da4bd4346503fcf6baff6830b.tar.gz |
Merge tools/grit from https://chromium.googlesource.com/external/grit-i18n.git at 856ff33a9069bf62462ea2a2b88281974f97dba2
This commit was generated by merge_from_chromium.py.
Change-Id: Ic7a79c893cc3e31636116c687951e7f3a79135e3
-rw-r--r-- | grit/tool/build.py | 75 | ||||
-rw-r--r-- | grit/tool/build_unittest.py | 34 |
2 files changed, 96 insertions, 13 deletions
diff --git a/grit/tool/build.py b/grit/tool/build.py index 87ee412..537e2c6 100644 --- a/grit/tool/build.py +++ b/grit/tool/build.py @@ -63,6 +63,20 @@ option). Options: + -a FILE Assert that the given file is an output. There can be + multiple "-a" flags listed for multiple outputs. If a "-a" + or "--assert-file-list" argument is present, then the list + of asserted files must match the output files or the tool + will fail. The use-case is for the build system to maintain + separate lists of output files and to catch errors if the + build system's list and the grit list are out-of-sync. + + --assert-file-list Provide a file listing multiple asserted output files. + There is one file name per line. This acts like specifying + each file with "-a" on the command line, but without the + possibility of running into OS line-length limits for very + long lists. + -o OUTPUTDIR Specify what directory output paths are relative to. Defaults to the current directory. @@ -104,13 +118,20 @@ are exported to translation interchange files (e.g. XMB files), etc. self.output_directory = '.' first_ids_file = None whitelist_filenames = [] + assert_output_files = [] target_platform = None depfile = None depdir = None rc_header_format = None - (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:h:', ('depdir=','depfile=')) + (own_opts, args) = getopt.getopt(args, 'a:o:D:E:f:w:t:h:', + ('depdir=','depfile=','assert-file-list=')) for (key, val) in own_opts: - if key == '-o': + if key == '-a': + assert_output_files.append(val) + elif key == '--assert-file-list': + with open(val) as f: + assert_output_files += f.read().splitlines() + elif key == '-o': self.output_directory = val elif key == '-D': name, val = util.ParseDefine(val) @@ -166,8 +187,12 @@ are exported to translation interchange files (e.g. XMB files), etc. self.res.RunGatherers() self.Process() + if assert_output_files: + if not self.CheckAssertedOutputFiles(assert_output_files): + return 2 + if depfile and depdir: - self.GenerateDepfile(opts.input, depfile, depdir) + self.GenerateDepfile(depfile, depdir) return 0 @@ -324,7 +349,31 @@ are exported to translation interchange files (e.g. XMB files), etc. print self.res.UberClique().missing_translations_ sys.exit(-1) - def GenerateDepfile(self, input_filename, depfile, depdir): + + def CheckAssertedOutputFiles(self, assert_output_files): + '''Checks that the asserted output files are specified in the given list. + + Returns true if the asserted files are present. If they are not, returns + False and prints the failure. + ''' + # Compare the absolute path names, sorted. + asserted = sorted([os.path.abspath(i) for i in assert_output_files]) + actual = sorted([ + os.path.abspath(os.path.join(self.output_directory, i.GetFilename())) + for i in self.res.GetOutputFiles()]) + + if asserted != actual: + print '''Asserted file list does not match. + +Expected output files: %s + +Actual output files: %s +''' % (asserted, actual) + return False + return True + + + def GenerateDepfile(self, depfile, depdir): '''Generate a depfile that contains the imlicit dependencies of the input grd. The depfile will be in the same format as a makefile, and will contain references to files relative to |depdir|. It will be put in |depfile|. @@ -343,19 +392,27 @@ are exported to translation interchange files (e.g. XMB files), etc. from the directory src/ we will generate a depfile ../out/gen/blah.grd.d that has the contents - gen/blah.grd.d: ../src/input1.xtb ../src/input2.xtb + gen/blah.h: ../src/input1.xtb ../src/input2.xtb + + Where "gen/blah.h" is the first output (Ninja expects the .d file to list + the first output in cases where there is more than one). Note that all paths in the depfile are relative to ../out, the depdir. ''' depfile = os.path.abspath(depfile) depdir = os.path.abspath(depdir) + infiles = self.res.GetInputFiles() + + # Get the first output file relative to the depdir. + outputs = self.res.GetOutputFiles() + output_file = os.path.relpath(os.path.join( + self.output_directory, outputs[0].GetFilename()), depdir) + # The path prefix to prepend to dependencies in the depfile. prefix = os.path.relpath(os.getcwd(), depdir) - # The path that the depfile refers to itself by. - self_ref_depfile = os.path.relpath(depfile, depdir) - infiles = self.res.GetInputFiles() deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) - depfile_contents = self_ref_depfile + ': ' + deps_text + + depfile_contents = output_file + ': ' + deps_text self.MakeDirectoriesTo(depfile) outfile = self.fo_create(depfile, 'wb') outfile.writelines(depfile_contents) diff --git a/grit/tool/build_unittest.py b/grit/tool/build_unittest.py index fd640f7..debe4d4 100644 --- a/grit/tool/build_unittest.py +++ b/grit/tool/build_unittest.py @@ -49,15 +49,41 @@ class BuildUnittest(unittest.TestCase): self.failUnless(os.path.isfile(expected_dep_file)) with open(expected_dep_file) as f: line = f.readline() - (dep_file_name, deps_string) = line.split(': ') + (dep_output_file, deps_string) = line.split(': ') deps = deps_string.split(' ') - self.failUnlessEqual(os.path.abspath(expected_dep_file), - os.path.abspath(os.path.join(output_dir, dep_file_name)), - "depfile should refer to itself as the depended upon file") + + self.failUnlessEqual("resource.h", dep_output_file) self.failUnlessEqual(1, len(deps)) self.failUnlessEqual(deps[0], util.PathFromRoot('grit/testdata/substitute.xmb')) + def testAssertOutputs(self): + output_dir = tempfile.mkdtemp() + class DummyOpts(object): + def __init__(self): + self.input = util.PathFromRoot('grit/testdata/substitute.grd') + self.verbose = False + self.extra_verbose = False + + # Incomplete output file list should fail. + builder_fail = build.RcBuilder() + self.failUnlessEqual(2, + builder_fail.Run(DummyOpts(), [ + '-o', output_dir, + '-a', os.path.abspath( + os.path.join(output_dir, 'en_generated_resources.rc'))])) + + # Complete output file list should succeed. + builder_ok = build.RcBuilder() + self.failUnlessEqual(0, + builder_ok.Run(DummyOpts(), [ + '-o', output_dir, + '-a', os.path.abspath( + os.path.join(output_dir, 'en_generated_resources.rc')), + '-a', os.path.abspath( + os.path.join(output_dir, 'sv_generated_resources.rc')), + '-a', os.path.abspath( + os.path.join(output_dir, 'resource.h'))])) if __name__ == '__main__': unittest.main() |