Bug 1362617 - Generalize MOZ_CHROME_MULTILOCALE to work for browser as well. r?mshal,pike draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 23 Oct 2017 08:04:24 -0700
changeset 685574 8b232f0234e93b2a27eceb0d6bd6b3996d3f65d2
parent 684481 8ccbd32831c7c7e9a253aaa35834f1d7b7244672
child 737194 0bbcc09fc944b0c94dcf4a21b0ca19a765609124
push id85981
push userbmo:gandalf@aviary.pl
push dateTue, 24 Oct 2017 21:45:39 +0000
reviewersmshal, pike
bugs1362617
milestone58.0a1
Bug 1362617 - Generalize MOZ_CHROME_MULTILOCALE to work for browser as well. r?mshal,pike MozReview-Commit-ID: 80ldQPhNyi7
browser/base/content/test/static/browser_all_files_referenced.js
browser/installer/Makefile.in
browser/installer/package-manifest.in
browser/locales/Makefile.in
mobile/android/installer/Makefile.in
mobile/android/installer/package-manifest.in
mobile/android/locales/Makefile.in
toolkit/locales/Makefile.in
toolkit/mozapps/installer/l10n-repack.py
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -92,16 +92,19 @@ var whitelist = [
 
   // toolkit/components/places/ColorAnalyzer_worker.js
   {file: "resource://gre/modules/ClusterLib.js"},
   {file: "resource://gre/modules/ColorConversion.js"},
 
   // Needed by HiddenFrame.jsm, but can't be packaged test-only
   {file: "chrome://global/content/win.xul"},
 
+  // List of built-in locales. See bug 1362617 for details.
+  {file: "resource://gre/res/multilocale.json"},
+
   // The l10n build system can't package string files only for some platforms.
   {file: "resource://gre/chrome/en-US/locale/en-US/global-platform/mac/accessible.properties",
    platforms: ["linux", "win"]},
   {file: "resource://gre/chrome/en-US/locale/en-US/global-platform/mac/intl.properties",
    platforms: ["linux", "win"]},
   {file: "resource://gre/chrome/en-US/locale/en-US/global-platform/mac/platformKeys.properties",
    platforms: ["linux", "win"]},
   {file: "resource://gre/chrome/en-US/locale/en-US/global-platform/unix/accessible.properties",
--- a/browser/installer/Makefile.in
+++ b/browser/installer/Makefile.in
@@ -7,16 +7,18 @@ DIST_SUBDIR := browser
 
 include $(topsrcdir)/config/rules.mk
 
 MOZ_PKG_REMOVALS = $(srcdir)/removed-files.in
 
 MOZ_PKG_MANIFEST = $(srcdir)/package-manifest.in
 MOZ_PKG_DUPEFLAGS = -f $(srcdir)/allowed-dupes.mn
 
+DEFINES += -DPKG_LOCALE_MANIFEST=$(topobjdir)/toolkit/locales/locale-manifest.in
+
 # Some files have been already bundled with xulrunner
 ifndef MOZ_MULET
 MOZ_PKG_FATAL_WARNINGS = 1
 else
 DEFINES += -DMOZ_MULET
 endif
 
 # When packaging an artifact build not all xpt files expected by the
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -40,20 +40,16 @@
 #endif
 @APPNAME@/Contents/PkgInfo
 @RESPATH@/firefox.icns
 @RESPATH@/document.icns
 @RESPATH@/@LPROJ_ROOT@.lproj/*
 #endif
 
 [@AB_CD@]
-@RESPATH@/browser/chrome/@AB_CD@@JAREXT@
-@RESPATH@/browser/chrome/@AB_CD@.manifest
-@RESPATH@/chrome/@AB_CD@@JAREXT@
-@RESPATH@/chrome/@AB_CD@.manifest
 @RESPATH@/dictionaries/*
 #if defined(XP_WIN) || defined(XP_LINUX)
 @RESPATH@/fonts/*
 #endif
 @RESPATH@/hyphenation/*
 @RESPATH@/browser/@PREF_DIR@/firefox-l10n.js
 #ifdef HAVE_MAKENSISU
 @BINPATH@/uninstall/helper.exe
@@ -845,8 +841,12 @@ bin/libfreebl_32int64_3.so
 @RESPATH@/components/backgroundhangmonitor.xpt
 
 ; NOTE: This must match the config checks in
 ; /toolkit/components/backgroundhangmonitor/moz.build.
 #if defined(NIGHTLY_BUILD) && !defined(MOZ_DEBUG) && !defined(MOZ_TSAN)
 @RESPATH@/components/BHRTelemetryService.js
 @RESPATH@/components/BHRTelemetryService.manifest
 #endif
+
+#ifdef PKG_LOCALE_MANIFEST
+#include @PKG_LOCALE_MANIFEST@
+#endif
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -108,16 +108,23 @@ ifneq '$(or $(MOZ_DEV_EDITION),$(NIGHTLY
 	@$(MAKE) -C ../extensions/webcompat-reporter/locales AB_CD=$* XPI_NAME=locale-$*
 endif
 	@$(MAKE) -C ../../devtools/client/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) -C ../../devtools/shim/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) -B searchplugins AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=$(PREF_DIR)
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$*
 
+MOZ_CHROME_LOCALE_ENTRIES=@RESPATH@/browser/chrome/ @RESPATH@/chrome/
+
+libs::
+	@$(MAKE) -C ../../toolkit/locales multilocale MOZ_CHROME_LOCALE_ENTRIES="$(MOZ_CHROME_LOCALE_ENTRIES)"
+
+
+
 chrome-%: AB_CD=$*
 chrome-%: IS_LANGUAGE_REPACK=1
 chrome-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	@$(MAKE) -C ../../toolkit/locales chrome-$*
 	@$(MAKE) -C ../../services/sync/locales chrome AB_CD=$*
 	@$(MAKE) -C ../../extensions/spellcheck/locales chrome AB_CD=$*
 ifneq (,$(wildcard ../extensions/formautofill/locales))
--- a/mobile/android/installer/Makefile.in
+++ b/mobile/android/installer/Makefile.in
@@ -14,21 +14,17 @@ endif
 
 include $(topsrcdir)/config/rules.mk
 
 MOZ_PKG_REMOVALS = $(srcdir)/removed-files.in
 
 MOZ_PKG_MANIFEST = $(srcdir)/package-manifest.in
 MOZ_PKG_DUPEFLAGS = -f $(srcdir)/allowed-dupes.mn
 
-ifdef MOZ_CHROME_MULTILOCALE
-MOZ_PKG_MANIFEST_DEPS = locale-manifest.in
-
-DEFINES += -DPKG_LOCALE_MANIFEST=$(CURDIR)/locale-manifest.in
-endif
+DEFINES += -DPKG_LOCALE_MANIFEST=$(topobjdir)/toolkit/locales/locale-manifest.in
 
 DEFINES += \
   -DMOZ_APP_NAME=$(MOZ_APP_NAME) \
   -DPREF_DIR=$(PREF_DIR) \
   -DJAREXT= \
   -DMOZ_CHILD_PROCESS_NAME=$(MOZ_CHILD_PROCESS_NAME) \
   -DMOZ_CHILD_PROCESS_NAME_PIE=$(MOZ_CHILD_PROCESS_NAME_PIE) \
   -DANDROID_CPU_ARCH=$(ANDROID_CPU_ARCH) \
@@ -79,27 +75,8 @@ else
 # Every other platform just winds up in dist/bin
 BINPATH = bin
 endif
 DEFINES += -DBINPATH=$(BINPATH)
 
 ifdef ENABLE_MARIONETTE
 DEFINES += -DENABLE_MARIONETTE=1
 endif
-
-
-ifdef MOZ_CHROME_MULTILOCALE
-# When MOZ_CHROME_MULTILOCALE is defined, we write multilocale.json like:
-# {"locales": ["en-US", "de", "ar", ...]}
-locale-manifest.in: $(GLOBAL_DEPS) FORCE
-	printf '\n[multilocale]\n' > $@
-	printf '@BINPATH@/res/multilocale.json\n' >> $@
-	for LOCALE in en-US $(MOZ_CHROME_MULTILOCALE) ;\
-	do \
-	  printf '$(BINPATH)/chrome/'"$$LOCALE"'$(JAREXT)\n' >> $@; \
-	  printf '$(BINPATH)/chrome/'"$$LOCALE"'.manifest\n' >> $@; \
-	done
-	COMMA=,
-	echo '{"locales": [$(foreach l,$(MOZ_CHROME_MULTILOCALE),"$(l)"$(COMMA)) "en-US"]}' \
-	  > $(FINAL_TARGET)/res/multilocale.json
-
-GARBAGE += locale-manifest.in
-endif
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -10,18 +10,16 @@
 ; - in front of a file specifies it to be removed from the destination
 ; * wildcard support to recursively copy the entire directory
 ; ; file comment
 ;
 
 #filter substitution
 
 [@AB_CD@]
-@BINPATH@/chrome/@AB_CD@@JAREXT@
-@BINPATH@/chrome/@AB_CD@.manifest
 @BINPATH@/@PREF_DIR@/mobile-l10n.js
 @BINPATH@/update.locale
 #ifdef MOZ_UPDATER
 @BINPATH@/updater.ini
 #endif
 @BINPATH@/dictionaries/*
 @BINPATH@/hyphenation/*
 
--- a/mobile/android/locales/Makefile.in
+++ b/mobile/android/locales/Makefile.in
@@ -37,16 +37,21 @@ libs-%: AB_CD=$*
 libs-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	@$(MAKE) -C $(DEPTH)/mobile/locales libs-$*
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=defaults/pref
 ifeq ($(OS_TARGET),Android)
 	@$(MAKE) -C $(DEPTH)/mobile/android/base/locales AB_CD=$* XPI_NAME=locale-$*
 endif
 
+MOZ_CHROME_LOCALE_ENTRIES=@BINPATH@/chrome/
+
+libs::
+	@$(MAKE) -C $(DEPTH)/toolkit/locales multilocale MOZ_CHROME_LOCALE_ENTRIES="$(MOZ_CHROME_LOCALE_ENTRIES)"
+
 # Tailored target to just add the chrome processing for multi-locale builds
 # merge if we're not en-US, using conditional function as we need
 # the current value of AB_CD
 chrome-%: AB_CD=$*
 chrome-%: IS_LANGUAGE_REPACK=1
 chrome-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	@$(MAKE) -C $(DEPTH)/mobile/locales chrome-$*
--- a/toolkit/locales/Makefile.in
+++ b/toolkit/locales/Makefile.in
@@ -1,14 +1,16 @@
 # 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/.
 
 include $(topsrcdir)/config/rules.mk
 
+MOZ_CHROME_MULTILOCALE?=$(AB_CD)
+
 libs-%: AB_CD=$*
 libs-%:
 	@$(MAKE) -C ../../netwerk/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../dom/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../security/manager/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../devtools/shared/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$*
 
@@ -29,8 +31,54 @@ ifdef MOZ_CRASHREPORTER
 libs:: $(call MERGE_FILE,crashreporter/crashreporter.ini)
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)/crashreporter.app/Contents/Resources
 else
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)
 endif
 endif
 endif
+
+LOCALES?=$(MOZ_CHROME_MULTILOCALE)
+
+ALL_LOCALES = $(if $(filter en-US,$(LOCALES)),$(LOCALES),$(LOCALES) en-US)
+
+LOCALE_LIST = $(foreach l,$(ALL_LOCALES),"$(l)")
+
+# Firefox uses @RESPATH@.
+# Fennec uses @BINPATH@ and doesn't have the @RESPATH@ variable defined.
+ifeq ($(MOZ_BUILD_APP),mobile/android)
+BASE_PATH:=@BINPATH@
+else
+BASE_PATH:=@RESPATH@
+endif
+
+multilocale: $(GLOBAL_DEPS)
+	@$(MAKE) multilocale.json
+	@$(MAKE) locale-manifest.in
+
+locale-manifest.in: $(GLOBAL_DEPS) FORCE
+	printf '\n[multilocale]\n' > $@
+	printf '$(BASE_PATH)/res/multilocale.json\n' >> $@
+	for LOCALE in $(ALL_LOCALES) ;\
+	do \
+	  for ENTRY in $(MOZ_CHROME_LOCALE_ENTRIES) ;\
+		do \
+		  printf "$$ENTRY""$$LOCALE"'@JAREXT@\n' >> $@; \
+		  printf "$$ENTRY""$$LOCALE"'.manifest\n' >> $@; \
+	  done \
+	done
+
+# This trick allows us to replace space sign with a comma to generate
+# the list of locales.
+
+# The tricky part here is that we replace
+# LOCALE_LIST which is a space separated list into a JSON list.
+# Example:
+#
+# `ab cd ef` => `"ab", "cd", "ef"`
+#
+multilocale.json: $(GLOBAL_DEPS) FORCE
+	@$(MKDIR) -p "$(FINAL_TARGET)/res"
+	echo '{"locales": [$(subst $(SPACE),$(COMMA)$(SPACE),$(LOCALE_LIST))]}' \
+	  > $(FINAL_TARGET)/res/multilocale.json
+
+GARBAGE += locale-manifest.in
--- a/toolkit/mozapps/installer/l10n-repack.py
+++ b/toolkit/mozapps/installer/l10n-repack.py
@@ -19,16 +19,17 @@ NON_CHROME = set([
     'dictionaries',
     'defaults/profile',
     'defaults/pref*/*-l10n.js',
     'update.locale',
     'updater.ini',
     'extensions/langpack-*@*',
     'distribution/extensions/langpack-*@*',
     'chrome/**/searchplugins/*.xml',
+    '**/multilocale.json'
 ])
 
 
 def valid_extra_l10n(arg):
     if '=' not in arg:
         raise ValueError('Invalid value')
     return tuple(arg.split('=', 1))