Bug 1464128 - Migrate bookmarks.html.in to LOCALIZED_GENERATED_FILES. r?ted.mielczarek draft
authorNick Alexander <nalexander@mozilla.com>
Thu, 24 May 2018 11:28:47 -0700
changeset 799462 535463ebaadced8d683d3e0f133acddec00b4b47
parent 799453 75e4196209c648e2e575553c9639ef1a608a0351
push id111066
push usernalexander@mozilla.com
push dateThu, 24 May 2018 18:29:06 +0000
reviewersted.mielczarek
bugs1464128
milestone62.0a1
Bug 1464128 - Migrate bookmarks.html.in to LOCALIZED_GENERATED_FILES. r?ted.mielczarek This one looks to be pretty straight-forward. It irritates me that the jar.mn entry doesn't explicitly say that the result is coming from the object directory, like locale/browser/bookmarks.html (!bookmarks.html) but that's for another day. MozReview-Commit-ID: Cw8E0VJhSxv
browser/locales/Makefile.in
browser/locales/generate_bookmarks.py
browser/locales/generic/profile/bookmarks.html.in
browser/locales/jar.mn
browser/locales/moz.build
config/faster/rules.mk
python/mozbuild/mozbuild/backend/tup.py
python/mozbuild/mozbuild/faster_daemon.py
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -60,18 +60,16 @@ DIST_SUBDIRS = $(DIST_SUBDIR)
 include $(topsrcdir)/config/rules.mk
 
 include $(topsrcdir)/toolkit/locales/l10n.mk
 
 $(list-json): $(call mkdir_deps,$(SEARCHPLUGINS_PATH)) $(if $(IS_LANGUAGE_REPACK),FORCE)
 	$(call py_action,generate_searchjson,$(srcdir)/search/list.json $(AB_CD) $(list-json))
 searchplugins:: $(list-json)
 
-DEFINES += -DBOOKMARKS_INCLUDE_DIR=$(dir $(call MERGE_FILE,profile/bookmarks.inc))
-
 libs-%: AB_CD=$*
 libs-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	$(NSINSTALL) -D $(DIST)/install
 	@$(MAKE) -C ../../toolkit/locales libs-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) -C ../../services/sync/locales AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../extensions/spellcheck/locales AB_CD=$* XPI_NAME=locale-$*
 ifneq (,$(wildcard ../extensions/formautofill/locales))
new file mode 100644
--- /dev/null
+++ b/browser/locales/generate_bookmarks.py
@@ -0,0 +1,38 @@
+# 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/.
+
+# Generate bookmarks.html by interpolating the included (localized)
+# `bookmarks.inc` file into the given (unlocalized) `bookmarks.html.in` input.
+
+from __future__ import absolute_import, unicode_literals, print_function
+
+import buildconfig
+import sys
+
+from mozbuild import preprocessor
+
+
+def main(output, bookmarks_html_in, bookmarks_inc, locale=None):
+    if not locale:
+        raise ValueError('locale must be specified!')
+
+    CONFIG = buildconfig.substs
+
+    # Based on
+    # https://dxr.mozilla.org/l10n-central/search?q=path%3Abookmarks.inc+%23if&redirect=true,
+    # no localized input uses the preprocessor conditional #if (really,
+    # anything but #define).
+    defines = {}
+    defines['AB_CD'] = locale
+    defines['NIGHTLY_BUILD'] = CONFIG['NIGHTLY_BUILD']
+    defines['BOOKMARKS_INCLUDE_PATH'] = bookmarks_inc
+
+    includes = preprocessor.preprocess(includes=[bookmarks_html_in],
+                                       defines=defines,
+                                       output=output)
+    return includes
+
+
+if __name__ == "__main__":
+    main(sys.argv[1:])
--- a/browser/locales/generic/profile/bookmarks.html.in
+++ b/browser/locales/generic/profile/bookmarks.html.in
@@ -1,10 +1,10 @@
 #filter substitution
-#include @BOOKMARKS_INCLUDE_DIR@/bookmarks.inc
+#include @BOOKMARKS_INCLUDE_PATH@
 #define ja_jp_mac ja-JP-mac
 #if AB_CD == ja_jp_mac
 #define AB_CD ja
 #endif
 
 #define mozilla_icon data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E %3Cpath d='M0 0h16v16H0z'/%3E %3Cpath d='M13.994 10.356H15V12h-3.171V7.741c0-1.308-.435-1.81-1.29-1.81-1.04 0-1.46.737-1.46 1.8v2.63h1.006V12H6.918V7.741c0-1.308-.435-1.81-1.291-1.81-1.039 0-1.459.737-1.459 1.8v2.63h1.441V12H1v-1.644h1.006V6.079H1V4.435h3.168v1.139a2.507 2.507 0 0 1 2.3-1.29A2.452 2.452 0 0 1 8.931 5.91 2.535 2.535 0 0 1 11.4 4.284 2.448 2.448 0 0 1 14 6.9v3.458z' fill='%23fff'/%3E %3C/svg%3E
 
 #define nightly_icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA01JREFUeNpkk01oXFUUx//vzp33ZiaTzkwnyUwmsbbNRpp0GhuVKiVgQIUiLmoX7lyIG10I6qIUrG6KGyuYZbMwiATqxipSMVhQYwWhiwSJwUxKkzbz8ZJ5H/M+7/vunUIE7Vnc1f3/zjn/c46wsCbjIOI4Rlfew+Zf6/h9+RYYYzj70hymZp7GULUCSin+H8IBwLYsfLOwiOfffndK1c2LmhO84jl+2e5ZCTN6Xer0fpp5dmq+frxy5zGAY9n49IOLuHDls8uqE3y07YV0ywwQGA6oZsJRFRT0FnK2Hpw8PTl/7tXZDw8ApF/29YUvufjqxxqLPrnLQBUiQRUI4EcQHQ+EgwbjENl8Pv3H9W/f//m7W9cOAKkXzr+J4pm5umy6S/uEkiAEOlzscWHG5jTbhcsrDJiHsN1CIScJTlc5JaSlldEna9uk8fcGHNO6tOMGqfssQjNFoHOxyAXU9xF5HiRXw2AqhuUEsLs6giCkjbXG549a+O3mMhQneLnthOh0NBiaAdozkTEdpC0Hnm2hKAKR3ESJRigNFZBHCF2zn+p7SMIwRM9kRcI/D5g2xAcd1PQeMtw8xkGuafIRGRgZKfHfCbKlIu5t3IVASYYDDtMzL85il2fLuh6qIkFkWtjrARY3zjENJLwCKgqwOjLcnW30Qh/HnpmGYTJhT1bSdPL0NBpr+6rbs8qhIiPivQtRhDDJQuCViI4BxdJRrx/jBopob25BDmIMnzgZjFTK+2R4tAo4+q8iM9Ba3wBTuxirHELeM5AxFO6FCsnSsHNnFfL9XUiFIo7ypNmB9D3eQkT665nS5Xm72Q5r3KCo04be2MIRKULOUlEkPnJpAbn8AI7XJyEUy/CBhIrJlUdT6D/rP3x1u1yQFjP5bFIbH4HdbHG2j/GJMfiqzneCwVI0oFrD8OgTiKLgl5Ubi0v/uYV3ZqcrE2ff+Do2/LlUxAi/HKQZH9eegupzpxDztL4gIfTU9d3VG+ev/nh7s6/797wiz1K3VpYuDU3MvFWunXg9ly2WTNVNDZaPgIU08V3NMNXVZfmfP68lvt187Br78d5r52hoKaUkiWspQqqHx4+OCQLhFu3KAXNbCYQWzR5SBCr5X3x/M+lrHgowAMP2wWqd+FzxAAAAAElFTkSuQmCC
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -7,17 +7,17 @@
 # override and resource entries should go to browser/base/jar.mn to avoid
 # having to create the same entry for each locale.
 
 [localization] @AB_CD@.jar:
   browser                                          (%browser/**/*.ftl)
 
 @AB_CD@.jar:
 % locale browser @AB_CD@ %locale/browser/
-*   locale/browser/bookmarks.html                  (generic/profile/bookmarks.html.in)
+    locale/browser/bookmarks.html                  (bookmarks.html)
     locale/browser/aboutDialog.dtd                 (%chrome/browser/aboutDialog.dtd)
     locale/browser/aboutPrivateBrowsing.dtd        (%chrome/browser/aboutPrivateBrowsing.dtd)
     locale/browser/aboutRobots.dtd                 (%chrome/browser/aboutRobots.dtd)
     locale/browser/accounts.properties             (%chrome/browser/accounts.properties)
     locale/browser/aboutRestartRequired.dtd        (%chrome/browser/aboutRestartRequired.dtd)
     locale/browser/aboutSearchReset.dtd            (%chrome/browser/aboutSearchReset.dtd)
     locale/browser/aboutSessionRestore.dtd         (%chrome/browser/aboutSessionRestore.dtd)
     locale/browser/aboutTabCrashed.dtd             (%chrome/browser/aboutTabCrashed.dtd)
--- a/browser/locales/moz.build
+++ b/browser/locales/moz.build
@@ -20,16 +20,26 @@ if CONFIG['MOZ_UPDATER']:
         'en-US/updater/updater.ini',
         '../installer/windows/nsis/updater_append.ini',
     ]
     # Yes, this is weird, but what can you do? This file doesn't want to be in the DIST_SUBDIR,
     # but we can't really move it to a different directory until we change how locale repacks
     # work.
     LOCALIZED_FILES['..'] += ['!updater.ini']
 
+LOCALIZED_GENERATED_FILES += ['bookmarks.html']
+bookmarks = LOCALIZED_GENERATED_FILES['bookmarks.html']
+bookmarks.script = 'generate_bookmarks.py'
+bookmarks.inputs = [
+    # This input will not be considered for localization.
+    'generic/profile/bookmarks.html.in',
+    # The `locales/en-US/` will be rewritten to the locale-specific path.
+    'en-US/profile/bookmarks.inc',
+]
+
 with Files("**"):
     BUG_COMPONENT = ("Firefox Build System", "General")
 
 with Files("all-locales"):
     BUG_COMPONENT = ("Core", "Localization")
 
 with Files("en-US/**"):
     BUG_COMPONENT = ("Core", "Localization")
--- a/config/faster/rules.mk
+++ b/config/faster/rules.mk
@@ -79,22 +79,20 @@ ACDEFINES += -DBUILD_FASTER
 # corresponding install manifests are named correspondingly, with forward
 # slashes replaced with underscores, and prefixed with `install_`. That is,
 # the install manifest for `dist/bin` would be `install_dist_bin`.
 $(addprefix install-,$(INSTALL_MANIFESTS)): install-%: $(addprefix $(TOPOBJDIR)/,buildid.h source-repo.h)
 	@# For now, force preprocessed files to be reprocessed every time.
 	@# The overhead is not that big, and this avoids waiting for proper
 	@# support for defines tracking in process_install_manifest.
 	@touch install_$(subst /,_,$*)
-	@# BOOKMARKS_INCLUDE_DIR is for bookmarks.html only.
 	$(PYTHON) -m mozbuild.action.process_install_manifest \
 		--track install_$(subst /,_,$*).track \
 		$(TOPOBJDIR)/$* \
 		-DAB_CD=en-US \
-		-DBOOKMARKS_INCLUDE_DIR=$(TOPSRCDIR)/browser/locales/en-US/profile \
 		$(ACDEFINES) \
 		install_$(subst /,_,$*)
 
 # ============================================================================
 # Below is a set of additional dependencies and variables used to build things
 # that are not supported by data in moz.build.
 
 $(TOPOBJDIR)/build/application.ini: $(TOPOBJDIR)/buildid.h $(TOPOBJDIR)/source-repo.h
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -583,20 +583,16 @@ class TupBackend(CommonBackend):
                 pass
 
         with self._write_file(mozpath.join(self.environment.topobjdir, 'Tuprules.tup')) as fh:
             acdefines_flags = ' '.join(['-D%s=%s' % (name, shell_quote(value))
                 for (name, value) in sorted(self.environment.acdefines.iteritems())])
             # TODO: AB_CD only exists in Makefiles at the moment.
             acdefines_flags += ' -DAB_CD=en-US'
 
-            # TODO: BOOKMARKS_INCLUDE_DIR is used by bookmarks.html.in, and is
-            # only defined in browser/locales/Makefile.in
-            acdefines_flags += ' -DBOOKMARKS_INCLUDE_DIR=%s/browser/locales/en-US/profile' % self.environment.topsrcdir
-
             # Use BUILD_FASTER to avoid CXXFLAGS/CPPFLAGS in
             # toolkit/content/buildconfig.html
             acdefines_flags += ' -DBUILD_FASTER=1'
 
             fh.write('MOZ_OBJ_ROOT = $(TUP_CWD)\n')
             fh.write('DIST = $(MOZ_OBJ_ROOT)/dist\n')
             fh.write('ACDEFINES = %s\n' % acdefines_flags)
             fh.write('topsrcdir = $(MOZ_OBJ_ROOT)/%s\n' % (
--- a/python/mozbuild/mozbuild/faster_daemon.py
+++ b/python/mozbuild/mozbuild/faster_daemon.py
@@ -67,26 +67,20 @@ class Daemon(object):
         self.config_environment = config_environment
         self._client = None
 
     @property
     def defines(self):
         defines = dict(self.config_environment.acdefines)
         # These additions work around warts in the build system: see
         # http://searchfox.org/mozilla-central/rev/ad093e98f42338effe2e2513e26c3a311dd96422/config/faster/rules.mk#92-93
-        # and
-        # http://searchfox.org/mozilla-central/rev/ad093e98f42338effe2e2513e26c3a311dd96422/python/mozbuild/mozbuild/backend/tup.py#244-253.
         defines.update({
             'AB_CD': 'en-US',
             'BUILD_FASTER': '1',
         })
-        defines.update({
-            'BOOKMARKS_INCLUDE_DIR': mozpath.join(self.config_environment.topsrcdir,
-                                                  'browser', 'locales', 'en-US', 'profile'),
-        })
         return defines
 
     @mozbuild.util.memoized_property
     def file_copier(self):
         # TODO: invalidate the file copier when the build system
         # itself changes, i.e., the underlying unified manifest
         # changes.
         file_copier = FileCopier()