Bug 1074258 - Expand entities at build time when generating strings.xml. r?glandium draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 27 Oct 2015 09:10:05 -0700
changeset 321765 9bdfc8bca9c166b6970115a84b0d442119685b1f
parent 321764 2c23bb770b54555a7320dd87cec45dfc7eaafa31
child 512966 2818b934fe82dc587e48d74d314654fdb1a3027b
push id9455
push usernalexander@mozilla.com
push dateThu, 14 Jan 2016 18:14:51 +0000
reviewersglandium
bugs1074258
milestone46.0a1
Bug 1074258 - Expand entities at build time when generating strings.xml. r?glandium IntelliJ does not correctly handle &entity; definitions in Android strings.xml files. Strings with entities (in Fennec, all of them) are rendered in the IDE as blank. This patch expands the entities at build time, improving the IntelliJ integration.
mobile/android/base/locales/Makefile.in
python/mozbuild/mozbuild/action/expand_xml_entities.py
--- a/mobile/android/base/locales/Makefile.in
+++ b/mobile/android/base/locales/Makefile.in
@@ -58,31 +58,40 @@ strings-xml-preqs =\
   $(SEARCHSTRINGSPATH) \
   $(SYNCSTRINGSPATH) \
   $(if $(IS_LANGUAGE_REPACK),FORCE) \
   $(NULL)
 
 $(if $(MOZ_ANDROID_SHARED_ACCOUNT_TYPE),,$(error Missing MOZ_ANDROID_SHARED_ACCOUNT_TYPE))
 $(if $(MOZ_ANDROID_SHARED_FXACCOUNT_TYPE),,$(error Missing MOZ_ANDROID_SHARED_FXACCOUNT_TYPE))
 
-$(dir-strings-xml)/strings.xml: $(strings-xml-preqs)
+# This file depends on the locale.  It is safe to do this because when
+# we're repacking a language, we FORCE, so locale changes are always
+# recognized.  It's simpler to do this than make the intermediate file
+# name or location depend on the locale.  If it were easier to pipe
+# between py_action invocations, we could avoid this intermediate file
+# altogether.
+strings_unexpanded.xml: $(strings-xml-preqs)
 	$(call py_action,preprocessor, \
       $(DEFINES) \
       $(ACDEFINES) \
 	  -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
 	  -DBRANDPATH='$(BRANDPATH)' \
 	  -DMOZ_ANDROID_SHARED_ACCOUNT_TYPE=$(MOZ_ANDROID_SHARED_ACCOUNT_TYPE) \
 	  -DMOZ_ANDROID_SHARED_FXACCOUNT_TYPE=$(MOZ_ANDROID_SHARED_FXACCOUNT_TYPE) \
 	  -DMOZ_APP_DISPLAYNAME='@MOZ_APP_DISPLAYNAME@' \
 	  -DSTRINGSPATH='$(STRINGSPATH)' \
 	  -DSYNCSTRINGSPATH='$(SYNCSTRINGSPATH)' \
 	  -DSEARCHSTRINGSPATH='$(SEARCHSTRINGSPATH)' \
       $< \
 	  -o $@)
 
+$(dir-strings-xml)/strings.xml: strings_unexpanded.xml
+	$(call py_action,expand_xml_entities,$< -o $@)
+
 # Arg 1: Valid Make identifier, like suggestedsites.
 # Arg 2: File name, like suggestedsites.json.
 define generated_file_template
 
 # Determine the ../res/raw[-*] path.  This can be ../res/raw when no
 # locale is explicitly specified.
 $(1)-bypath = $(filter %/$(2),$(MAKECMDGOALS))
 ifeq (,$$(strip $$($(1)-bypath)))
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/action/expand_xml_entities.py
@@ -0,0 +1,27 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function
+
+import argparse
+import sys
+import xml.etree.ElementTree as ET
+
+def main(argv):
+    parser = argparse.ArgumentParser(description='Expand XML entities.')
+
+    parser.add_argument('input', help='Path to input XML file.')
+    parser.add_argument('--output', '-o', required=True, help='Output file.')
+
+    # The entities are present in the XML file, and the parser automatically
+    # expands entities, so there's no explicit step needed: parse and write.
+    args = parser.parse_args(argv)
+    tree = ET.parse(args.input)
+    tree.write(args.output)
+
+    return 0
+
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))