Commit 1c59d48c authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

win: Make chrome/installer/util/prebuild/create_string_rc write a depfile.

create_string_rc.py globs a bunch of xtb files off disk behind gn's and
ninja's back, so that they didn't know that create_string_rc.py needs to
rerun when the xtb files are updated. Make the script write a depfile so
that ninja knows to re-run the script if an xtb file is udpated.

(This is incomplete: if an xtb file is added or removed and nothing else
changes, the step still won't re-run. The Right Fix is to list all the xtb
files in the gn file and pass them to the script, then make the script assert
that the glob matches the passed-in line. That way, if an xtb is added or
removed, the command-line tracking will make sure that the command re-runs.
But xtb files being added or removed is super rare, so let's punt on this for
now.)

Bug: 910465
Change-Id: I7050dee3c62d997b750d8b150504a04d086518b8
Reviewed-on: https://chromium-review.googlesource.com/c/1359087Reviewed-by: default avatarRobert Shield <robertshield@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613222}
parent 254181fa
......@@ -224,6 +224,8 @@ action("generate_strings") {
"$target_gen_dir/installer_util_strings.rc",
]
depfile = "$target_gen_dir/installer_util_strings.d"
args = [
"-b",
"$branding_path_component",
......@@ -233,6 +235,8 @@ action("generate_strings") {
"installer_util_strings",
"-o",
rebase_path(target_gen_dir, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
......
......@@ -220,7 +220,7 @@ class GrdHandler(sax.handler.ContentHandler):
class XtbHandler(sax.handler.ContentHandler):
"""Extracts selected translations from an .xrd file.
"""Extracts selected translations from an .xtd file.
Populates the |lang| and |translations| attributes with the language and
selected strings of an .xtb file. Instances may be re-used to read the same
......@@ -295,7 +295,7 @@ class XtbHandler(sax.handler.ContentHandler):
class StringRcMaker(object):
"""Makes .h and .rc files containing strings and translations."""
def __init__(self, name, inputs, outdir, brand):
def __init__(self, name, inputs, outdir, depfile, brand):
"""Constructs a maker.
Args:
......@@ -307,13 +307,16 @@ class StringRcMaker(object):
self.name = name
self.inputs = inputs
self.outdir = outdir
self.depfile = depfile
self.brand = brand
def MakeFiles(self):
string_id_set = self.__BuildStringIds()
translated_strings = self.__ReadSourceAndTranslatedStrings(string_id_set)
translated_strings, xtb_files = self.__ReadSourceAndTranslatedStrings(
string_id_set)
self.__WriteRCFile(translated_strings)
self.__WriteHeaderFile(string_id_set, translated_strings)
self.__WriteDepfile(xtb_files)
class __TranslationData(object):
"""A container of information about a single translation."""
......@@ -350,11 +353,12 @@ class StringRcMaker(object):
# Compute a glob for the translation files.
xtb_pattern = os.path.join(os.path.dirname(grd_file), xtb_dir,
'%s*.xtb' % source_name)
xtb_files = glob.glob(xtb_pattern)
translated_strings.extend(
self.__ReadSourceAndTranslationsFrom(string_id_set, grd_file,
glob.glob(xtb_pattern)))
xtb_files))
translated_strings.sort()
return translated_strings
return translated_strings, xtb_files
def __ReadSourceAndTranslationsFrom(self, string_id_set, grd_file, xtb_files):
"""Reads source strings and translations for a .grd file.
......@@ -438,6 +442,9 @@ class StringRcMaker(object):
escaped_text))
outfile.write(FOOTER_TEXT)
def __HeaderFileName(self):
return os.path.join(self.outdir, self.name + '.h')
def __WriteHeaderFile(self, string_id_set, translated_strings):
"""Writes a .h file with resource ids."""
# TODO(grt): Stream the lines to the file rather than building this giant
......@@ -489,7 +496,7 @@ class StringRcMaker(object):
installer_string_mapping_lines.append(' HANDLE_STRING(%s_BASE, %s)'
% (string_id, string_id))
with open(os.path.join(self.outdir, self.name + '.h'), 'wb') as outfile:
with open(self.__HeaderFileName(), 'wb') as outfile:
outfile.write('\n'.join(lines))
outfile.write('\n#ifndef RC_INVOKED')
outfile.write(' \\\n'.join(do_languages_lines))
......@@ -498,6 +505,11 @@ class StringRcMaker(object):
# .rc files must end in a new line
outfile.write('\n#endif // ndef RC_INVOKED\n')
def __WriteDepfile(self, xtb_files):
with open(self.depfile, 'wb') as outfile:
outfile.write('%s: ' % self.__HeaderFileName())
outfile.write(' '.join(sorted(xtb_files)))
def ParseCommandLine():
def GrdPathAndXtbDirPair(string):
......@@ -530,12 +542,16 @@ def ParseCommandLine():
required=True,
help='base name of generated .rc and .h files',
dest='name')
parser.add_argument('--depfile',
required=True,
help='path to depfile to write')
return parser.parse_args()
def main():
args = ParseCommandLine()
StringRcMaker(args.name, args.inputs, args.outdir, args.brand).MakeFiles()
StringRcMaker(args.name, args.inputs, args.outdir, args.depfile,
args.brand).MakeFiles()
return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment