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.
--- 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:]))