Bug 1229241 - Use FINAL_TARGET{,_PP}_FILES for JS_PREFERENCE{,_PP}_FILES. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 28 Nov 2015 10:21:19 +0900
changeset 308996 48d86aacdfc526c919826cf5248a7cbc9e931bb9
parent 308995 839564f83b4966f7732d4cf4e24edb70361064c9
child 308997 192e590b1a63cad3fc36b768e3e3b7e3ef73fd1c
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1229241
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1229241 - Use FINAL_TARGET{,_PP}_FILES for JS_PREFERENCE{,_PP}_FILES. r=gps
config/rules.mk
python/mozbuild/mozbuild/backend/fastermake.py
python/mozbuild/mozbuild/backend/recursivemake.py
python/mozbuild/mozbuild/frontend/context.py
python/mozbuild/mozbuild/frontend/data.py
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/test/backend/data/js_preference_files/moz.build
python/mozbuild/mozbuild/test/backend/test_recursivemake.py
python/mozbuild/mozbuild/test/frontend/data/js_preference_files/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -1133,38 +1133,27 @@ endif
 ifneq ($(XPI_NAME),)
 $(FINAL_TARGET):
 	$(NSINSTALL) -D $@
 
 export:: $(FINAL_TARGET)
 endif
 
 ################################################################################
-# Copy each element of PREF_JS_EXPORTS
-
-# The default location for PREF_JS_EXPORTS is the gre prefs directory.
+# The default location for prefs is the gre prefs directory.
+# PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
 PREF_DIR = defaults/pref
 
 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
 # different and that we are building app related resources. Hence,
 # PREF_DIR should point to the app prefs location.
 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
 PREF_DIR = defaults/preferences
 endif
 
-ifneq ($(PREF_JS_EXPORTS),)
-ifndef NO_DIST_INSTALL
-PREF_JS_EXPORTS_PATH := $(FINAL_TARGET)/$(PREF_DIR)
-# We preprocess these, but they don't necessarily have preprocessor directives,
-# so tell them preprocessor to not complain about that.
-PREF_JS_EXPORTS_FLAGS := $(PREF_PPFLAGS) --silence-missing-directive-warnings
-PP_TARGETS += PREF_JS_EXPORTS
-endif
-endif
-
 ################################################################################
 # Copy each element of AUTOCFG_JS_EXPORTS to $(FINAL_TARGET)/defaults/autoconfig
 
 ifneq ($(AUTOCFG_JS_EXPORTS),)
 ifndef NO_DIST_INSTALL
 AUTOCFG_JS_EXPORTS_FILES := $(AUTOCFG_JS_EXPORTS)
 AUTOCFG_JS_EXPORTS_DEST := $(FINAL_TARGET)/defaults/autoconfig
 AUTOCFG_JS_EXPORTS_TARGET := export
--- a/python/mozbuild/mozbuild/backend/fastermake.py
+++ b/python/mozbuild/mozbuild/backend/fastermake.py
@@ -8,17 +8,16 @@ from mozbuild.backend.common import Comm
 from mozbuild.frontend.data import (
     ChromeManifestEntry,
     ContextDerived,
     Defines,
     FinalTargetPreprocessedFiles,
     FinalTargetFiles,
     JARManifest,
     JavaScriptModules,
-    JsPreferenceFile,
     Resources,
     XPIDLFile,
 )
 from mozbuild.jar import JarManifestParser
 from mozbuild.makeutil import Makefile
 from mozbuild.preprocessor import Preprocessor
 from mozbuild.util import OrderedDefaultDict
 from mozpack.manifests import InstallManifest
@@ -85,39 +84,16 @@ class FasterMakeBackend(CommonBackend):
                     if obj.flavor == 'extra':
                         self._install_manifests[obj.install_target].add_symlink(
                             mozpath.join(obj.srcdir, f),
                             mozpath.join(base, mozpath.basename(f))
                         )
                     elif obj.flavor == 'extra_pp':
                         self._add_preprocess(obj, f, base, defines=defines)
 
-        elif isinstance(obj, JsPreferenceFile) and \
-                obj.install_target.startswith('dist/bin'):
-            # The condition for the directory value in config/rules.mk is:
-            # ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
-            # - when XPI_NAME is set, obj.install_target will start with
-            # dist/xpi-stage
-            # - when DIST_SUBDIR is set, obj.install_target will start with
-            # dist/bin/$(DIST_SUBDIR)
-            # So an equivalent condition that is not cumbersome for us and that
-            # is enough at least for now is checking if obj.install_target is
-            # different from dist/bin.
-            if obj.install_target == 'dist/bin':
-                pref_dir = 'defaults/pref'
-            else:
-                pref_dir = 'defaults/preferences'
-
-            dest = mozpath.join(obj.install_target, pref_dir,
-                                mozpath.basename(obj.path))
-            # We preprocess these, but they don't necessarily have preprocessor
-            # directives, so tell the preprocessor to not complain about that.
-            self._add_preprocess(obj, obj.path, pref_dir, defines=defines,
-                                 silence_missing_directive_warnings=True)
-
         elif isinstance(obj, Resources) and \
                 obj.install_target.startswith('dist/bin'):
             for path, strings in obj.resources.walk():
                 base = mozpath.join('res', path)
                 for f in strings:
                     self._install_manifests[obj.install_target].add_symlink(
                         mozpath.join(obj.srcdir, f),
                         mozpath.join(base, mozpath.basename(f))
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -53,17 +53,16 @@ from ..frontend.data import (
     HostLibrary,
     HostProgram,
     HostSimpleProgram,
     HostSources,
     InstallationTarget,
     JARManifest,
     JavaJarData,
     JavaScriptModules,
-    JsPreferenceFile,
     Library,
     LocalInclude,
     PerSourceFlag,
     Program,
     Resources,
     SharedLibrary,
     SimpleProgram,
     Sources,
@@ -534,22 +533,16 @@ class RecursiveMakeBackend(CommonBackend
             self._process_test_harness_files(obj, backend_file)
 
         elif isinstance(obj, Resources):
             self._process_resources(obj, obj.resources, backend_file)
 
         elif isinstance(obj, BrandingFiles):
             self._process_branding_files(obj, obj.files, backend_file)
 
-        elif isinstance(obj, JsPreferenceFile):
-            if obj.path.startswith('/'):
-                backend_file.write('PREF_JS_EXPORTS += $(topsrcdir)%s\n' % obj.path)
-            else:
-                backend_file.write('PREF_JS_EXPORTS += $(srcdir)/%s\n' % obj.path)
-
         elif isinstance(obj, JARManifest):
             backend_file.write('JAR_MANIFEST := %s\n' % obj.path)
 
         elif isinstance(obj, Program):
             self._process_program(obj.program, backend_file)
             self._process_linked_libraries(obj, backend_file)
 
         elif isinstance(obj, HostProgram):
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -1084,27 +1084,16 @@ VARIABLES = {
 
     'JAVA_JAR_TARGETS': (dict, dict,
         """Defines Java JAR targets to be built.
 
         This variable should not be populated directly. Instead, it should
         populated by calling add_java_jar().
         """, 'libs'),
 
-    'JS_PREFERENCE_FILES': (StrictOrderingOnAppendList, list,
-        """Exported javascript files.
-
-        A list of files copied into the dist directory for packaging and installation.
-        Path will be defined for gre or application prefs dir based on what is building.
-        """, 'libs'),
-
-    'JS_PREFERENCE_PP_FILES': (StrictOrderingOnAppendList, list,
-        """Like JS_PREFERENCE_FILES, preprocessed..
-        """, 'libs'),
-
     'LIBRARY_DEFINES': (OrderedDict, dict,
         """Dictionary of compiler defines to declare for the entire library.
 
         This variable works like DEFINES, except that declarations apply to all
         libraries that link into this library via FINAL_LIBRARY.
         """, None),
 
     'LIBRARY_NAME': (unicode, unicode,
@@ -1969,16 +1958,27 @@ SPECIAL_VARIABLES = {
 
     'EXTRA_PP_COMPONENTS': (lambda context: context['FINAL_TARGET_PP_FILES'].components._strings, list,
         """Javascript XPCOM files.
 
        This variable contains a list of files to preprocess.  Generated
        files will be installed in the ``/components`` directory of the distribution.
         """),
 
+    'JS_PREFERENCE_FILES': (lambda context: context['FINAL_TARGET_FILES'].defaults.pref._strings, list,
+        """Exported javascript files.
+
+        A list of files copied into the dist directory for packaging and installation.
+        Path will be defined for gre or application prefs dir based on what is building.
+        """),
+
+    'JS_PREFERENCE_PP_FILES': (lambda context: context['FINAL_TARGET_PP_FILES'].defaults.pref._strings, list,
+        """Like JS_PREFERENCE_FILES, preprocessed..
+        """),
+
 }
 
 # Deprecation hints.
 DEPRECATION_HINTS = {
     'CPP_UNIT_TESTS': '''
         Please use'
 
             CppUnitTests(['foo', 'bar'])
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -244,26 +244,16 @@ class BrandingFiles(ContextDerived):
     HierarchicalStringList, which is created when parsing BRANDING_FILES.
     """
     __slots__ = ('files')
 
     def __init__(self, sandbox, files):
         ContextDerived.__init__(self, sandbox)
         self.files = files
 
-class JsPreferenceFile(ContextDerived):
-    """Context derived container object for a Javascript preference file.
-
-    Paths are assumed to be relative to the srcdir."""
-    __slots__ = ('path')
-
-    def __init__(self, context, path):
-        ContextDerived.__init__(self, context)
-        self.path = path
-
 class IPDLFile(ContextDerived):
     """Describes an individual .ipdl source file."""
 
     __slots__ = (
         'basename',
     )
 
     def __init__(self, context, path):
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -49,17 +49,16 @@ from .data import (
     HostLibrary,
     HostProgram,
     HostSimpleProgram,
     HostSources,
     InstallationTarget,
     IPDLFile,
     JARManifest,
     JavaScriptModules,
-    JsPreferenceFile,
     Library,
     Linkable,
     LinkageWrongKindError,
     LocalInclude,
     PerSourceFlag,
     PreprocessedTestWebIDLFile,
     PreprocessedWebIDLFile,
     Program,
@@ -632,20 +631,16 @@ class TreeMetadataEmitter(LoggingMixin):
         resources = context.get('RESOURCE_FILES')
         if resources:
             if context.get('DIST_SUBDIR') or context.get('XPI_NAME'):
                 raise SandboxValidationError(
                     'RESOURCES_FILES cannot be used with DIST_SUBDIR or '
                     'XPI_NAME.', context)
             yield Resources(context, resources)
 
-        for pref in sorted(context['JS_PREFERENCE_FILES'] +
-                           context['JS_PREFERENCE_PP_FILES']):
-            yield JsPreferenceFile(context, pref)
-
         self._handle_programs(context)
 
         extra_js_modules = context.get('EXTRA_JS_MODULES')
         if extra_js_modules:
             yield JavaScriptModules(context, extra_js_modules, 'extra')
 
         extra_pp_js_modules = context.get('EXTRA_PP_JS_MODULES')
         if extra_pp_js_modules:
@@ -684,26 +679,39 @@ class TreeMetadataEmitter(LoggingMixin):
         ):
             all_files = context.get(var)
             if not all_files:
                 continue
             if dist_install is False:
                 raise SandboxValidationError(
                     '%s cannot be used with DIST_INSTALL = False' % var,
                     context)
+            has_prefs = False
             for base, files in all_files.walk():
                 if base == 'components':
                     components.extend(files)
+                if base == 'defaults/pref':
+                    has_prefs = True
                 for f in files:
                     path = os.path.join(context.srcdir, f)
                     if not os.path.exists(path):
                         raise SandboxValidationError(
                             'File listed in %s does not exist: %s'
                             % (var, f), context)
 
+            # Addons (when XPI_NAME is defined) and Applications (when
+            # DIST_SUBDIR is defined) use a different preferences directory
+            # (default/preferences) from the one the GRE uses (defaults/pref).
+            # Hence, we move the files from the latter to the former in that
+            # case.
+            if has_prefs and (context.get('XPI_NAME') or
+                              context.get('DIST_SUBDIR')):
+                all_files.defaults.preferences += all_files.defaults.pref
+                del all_files.defaults._children['pref']
+
             yield cls(context, all_files, context['FINAL_TARGET'])
 
         # Check for manifest declarations in EXTRA_{PP_,}COMPONENTS.
         if any(e.endswith('.js') for e in components) and \
                 not any(e.endswith('.manifest') for e in components) and \
                 not context.get('NO_JS_MANIFEST', False):
             raise SandboxValidationError('A .js component was specified in EXTRA_COMPONENTS '
                                          'or EXTRA_PP_COMPONENTS without a matching '
deleted file mode 100644
--- a/python/mozbuild/mozbuild/test/backend/data/js_preference_files/moz.build
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
-# Any copyright is dedicated to the Public Domain.
-# http://creativecommons.org/publicdomain/zero/1.0/
-
-JS_PREFERENCE_FILES  = ['aa/aa.js', 'bb/bb.js']
-JS_PREFERENCE_FILES += ['cc/cc.js', 'dd/dd.js']
-JS_PREFERENCE_FILES += ['/ee/ee.js', '/ff/ff.js']
-
-if CONFIG['_INVALID_CONFIG_VALUE']:
-    JS_PREFERENCE_FILES += ['invalid_val/prefs.js']
-else:
-    JS_PREFERENCE_FILES += ['valid_val/prefs.js']
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -417,34 +417,16 @@ class TestRecursiveMakeBackend(BackendTe
         m = InstallManifest(path=os.path.join(env.topobjdir,
             '_build_manifests', 'install', 'dist_branding'))
         self.assertEqual(len(m), 4)
         self.assertIn('app.ico', m)
         self.assertIn('bar.ico', m)
         self.assertIn('quux.png', m)
         self.assertIn('icons/foo.ico', m)
 
-    def test_js_preference_files(self):
-        """Ensure PREF_JS_EXPORTS is written out correctly."""
-        env = self._consume('js_preference_files', RecursiveMakeBackend)
-
-        backend_path = os.path.join(env.topobjdir, 'backend.mk')
-        lines = [l.strip() for l in open(backend_path, 'rt').readlines()]
-
-        # Avoid positional parameter and async related breakage
-        var = 'PREF_JS_EXPORTS'
-        found = [val for val in lines if val.startswith(var)]
-
-        # Assignment[aa], append[cc], conditional[valid]
-        expected = ('aa/aa.js', 'bb/bb.js', 'cc/cc.js', 'dd/dd.js', 'valid_val/prefs.js')
-        expected_top = ('ee/ee.js', 'ff/ff.js')
-        self.assertEqual(found,
-            ['PREF_JS_EXPORTS += $(topsrcdir)/%s' % val for val in expected_top] +
-            ['PREF_JS_EXPORTS += $(srcdir)/%s' % val for val in expected])
-
     def test_test_manifests_files_written(self):
         """Ensure test manifests get turned into files."""
         env = self._consume('test-manifests-written', RecursiveMakeBackend)
 
         tests_dir = mozpath.join(env.topobjdir, '_tests')
         m_master = mozpath.join(tests_dir, 'testing', 'mochitest', 'tests', 'mochitest.ini')
         x_master = mozpath.join(tests_dir, 'xpcshell', 'xpcshell.ini')
         self.assertTrue(os.path.exists(m_master))
deleted file mode 100644
--- a/python/mozbuild/mozbuild/test/frontend/data/js_preference_files/moz.build
+++ /dev/null
@@ -1,11 +0,0 @@
-# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
-# Any copyright is dedicated to the Public Domain.
-# http://creativecommons.org/publicdomain/zero/1.0/
-
-JS_PREFERENCE_FILES  = ['ww/ww.js', 'xx/xx.js']
-JS_PREFERENCE_FILES += ['yy/yy.js']
-
-if CONFIG['_INVALID_CONFIG_VALUE']:
-    JS_PREFERENCE_FILES += ['invalid_val/prefs.js']
-else:
-    JS_PREFERENCE_FILES += ['valid_val/prefs.js']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -19,17 +19,16 @@ from mozbuild.frontend.data import (
     Exports,
     FinalTargetPreprocessedFiles,
     GeneratedFile,
     GeneratedSources,
     HostDefines,
     HostSources,
     IPDLFile,
     JARManifest,
-    JsPreferenceFile,
     LocalInclude,
     Program,
     Resources,
     SharedLibrary,
     SimpleProgram,
     Sources,
     StaticLibrary,
     TestHarnessFiles,
@@ -335,31 +334,16 @@ class TestEmitterBasic(unittest.TestCase
         self.assertEqual(files._strings, ['app.ico', 'bar.ico', 'baz.png', 'foo.xpm'])
         self.assertEqual(files['app.ico'].source, 'test/bar.ico')
 
         self.assertIn('icons', files._children)
         icons = files._children['icons']
 
         self.assertEqual(icons._strings, ['quux.icns'])
 
-    def test_preferences_js(self):
-        reader = self.reader('js_preference_files')
-        objs = self.read_topsrcdir(reader)
-
-        prefs = [o.path for o in objs if isinstance(o, JsPreferenceFile)]
-
-        prefsByDir = [
-            'valid_val/prefs.js',
-            'ww/ww.js',
-            'xx/xx.js',
-            'yy/yy.js',
-            ]
-
-        self.assertEqual(sorted(prefs), prefsByDir)
-
     def test_program(self):
         reader = self.reader('program')
         objs = self.read_topsrcdir(reader)
 
         self.assertEqual(len(objs), 3)
         self.assertIsInstance(objs[0], Program)
         self.assertIsInstance(objs[1], SimpleProgram)
         self.assertIsInstance(objs[2], SimpleProgram)