Bug 870366 - Part 1: Move PREF_JS_EXPORTS to moz.build (mozbuild logic). r=gps

This commit is contained in:
Brian O'Keefe 2015-01-20 13:07:02 -05:00
parent 723f75b300
commit 96f36e3bf3
8 changed files with 84 additions and 0 deletions

View File

@ -46,6 +46,7 @@ from ..frontend.data import (
JARManifest,
JavaJarData,
JavaScriptModules,
JsPreferenceFile,
Library,
LocalInclude,
PerSourceFlag,
@ -445,6 +446,12 @@ class RecursiveMakeBackend(CommonBackend):
elif isinstance(obj, Resources):
self._process_resources(obj, obj.resources, 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)

View File

@ -648,6 +648,13 @@ VARIABLES = {
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'),
'LIBRARY_DEFINES': (OrderedDict, dict,
"""Dictionary of compiler defines to declare for the entire library.

View File

@ -244,6 +244,15 @@ class Resources(ContextDerived):
defs.update(defines)
self.defines = defs
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."""

View File

@ -47,6 +47,7 @@ from .data import (
IPDLFile,
JARManifest,
JavaScriptModules,
JsPreferenceFile,
Library,
Linkable,
LinkageWrongKindError,
@ -555,6 +556,9 @@ class TreeMetadataEmitter(LoggingMixin):
if resources:
yield Resources(context, resources, defines)
for pref in sorted(context['JS_PREFERENCE_FILES']):
yield JsPreferenceFile(context, pref)
for kind, cls in [('PROGRAM', Program), ('HOST_PROGRAM', HostProgram)]:
program = context.get(kind)
if program:

View File

@ -0,0 +1,12 @@
# -*- 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']

View File

@ -385,6 +385,24 @@ class TestRecursiveMakeBackend(BackendTester):
self.assertIn('res/tests/test.manifest', m)
self.assertIn('res/tests/extra.manifest', 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)

View File

@ -0,0 +1,11 @@
# -*- 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']

View File

@ -19,6 +19,7 @@ from mozbuild.frontend.data import (
HostSources,
IPDLFile,
JARManifest,
JsPreferenceFile,
LocalInclude,
Program,
ReaderSummary,
@ -282,6 +283,21 @@ class TestEmitterBasic(unittest.TestCase):
overwrite = resources._children['overwrite']
self.assertEqual(overwrite._strings, ['new.res'])
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)