diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 5bca4df0afca..dc8b488312c7 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -57,6 +57,7 @@ from ..frontend.data import ( InstallationTarget, JARManifest, JavaJarData, + JavaScriptModules, Library, LocalInclude, PerSourceFlag, @@ -561,6 +562,9 @@ class RecursiveMakeBackend(CommonBackend): elif isinstance(obj, InstallationTarget): self._process_installation_target(obj, backend_file) + elif isinstance(obj, JavaScriptModules): + self._process_javascript_modules(obj, backend_file) + elif isinstance(obj, ContextWrapped): # Process a rich build system object from the front-end # as-is. Please follow precedent and handle CamelCaseData @@ -1023,6 +1027,18 @@ INSTALL_TARGETS += %(prefix)s if not obj.enabled: backend_file.write('NO_DIST_INSTALL := 1\n') + def _process_javascript_modules(self, obj, backend_file): + if obj.flavor != 'testing': + raise Exception('Unsupported JavaScriptModules instance: %s' % obj.flavor) + + if not self.environment.substs.get('ENABLE_TESTS', False): + return + + manifest = self._install_manifests['tests'] + + for source, dest, _ in self._walk_hierarchy(obj, obj.modules): + manifest.add_symlink(source, mozpath.join('modules', dest)) + def _handle_idl_manager(self, manager): build_files = self._install_manifests['xpidl'] diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 4d9e3ce2f8e1..06827ec2a749 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -1001,10 +1001,16 @@ VARIABLES = { """Like ``FINAL_TARGET_FILES``, with preprocessing. """, 'libs'), - 'TESTING_FILES': (HierarchicalStringList, list, - """List of files to be installed in the _tests directory. + 'TESTING_JS_MODULES': (HierarchicalStringList, list, + """JavaScript modules to install in the test-only destination. - This works similarly to FINAL_TARGET_FILES. + Some JavaScript modules (JSMs) are test-only and not distributed + with Firefox. This variable defines them. + + To install modules in a subdirectory, use properties of this + variable to control the final destination. e.g. + + ``TESTING_JS_MODULES.foo += ['module.jsm']``. """, None), 'FINAL_LIBRARY': (unicode, unicode, @@ -1968,18 +1974,6 @@ SPECIAL_VARIABLES = { ``$(FINAL_TARGET)/modules``, after preprocessing. """), - 'TESTING_JS_MODULES': (lambda context: context['TESTING_FILES'].modules, list, - """JavaScript modules to install in the test-only destination. - - Some JavaScript modules (JSMs) are test-only and not distributed - with Firefox. This variable defines them. - - To install modules in a subdirectory, use properties of this - variable to control the final destination. e.g. - - ``TESTING_JS_MODULES.foo += ['module.jsm']``. - """), - } # Deprecation hints. diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index 5ba15c607b8f..782e0f40e283 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -652,6 +652,21 @@ class JARManifest(ContextDerived): self.path = path +class JavaScriptModules(ContextDerived): + """Describes a JavaScript module.""" + + __slots__ = ( + 'modules', + 'flavor', + ) + + def __init__(self, context, modules, flavor): + super(JavaScriptModules, self).__init__(context) + + self.modules = modules + self.flavor = flavor + + class ContextWrapped(ContextDerived): """Generic context derived container object for a wrapped rich object. @@ -826,12 +841,6 @@ class FinalTargetPreprocessedFiles(ContextDerived): self.files = files -class TestingFiles(FinalTargetFiles): - @property - def install_target(self): - return '_tests' - - class GeneratedFile(ContextDerived): """Represents a generated file.""" diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index 87fabc25694f..94617f4053bc 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -53,6 +53,7 @@ from .data import ( InstallationTarget, IPDLFile, JARManifest, + JavaScriptModules, Library, Linkable, LinkageWrongKindError, @@ -66,7 +67,6 @@ from .data import ( Sources, StaticLibrary, TestHarnessFiles, - TestingFiles, TestWebIDLFile, TestManifest, UnifiedSources, @@ -629,6 +629,10 @@ class TreeMetadataEmitter(LoggingMixin): self._handle_programs(context) + test_js_modules = context.get('TESTING_JS_MODULES') + if test_js_modules: + yield JavaScriptModules(context, test_js_modules, 'testing') + simple_lists = [ ('GENERATED_EVENTS_WEBIDL_FILES', GeneratedEventWebIDLFile), ('GENERATED_WEBIDL_FILES', GeneratedWebIDLFile), @@ -655,12 +659,11 @@ class TreeMetadataEmitter(LoggingMixin): for var, cls in ( ('FINAL_TARGET_FILES', FinalTargetFiles), ('FINAL_TARGET_PP_FILES', FinalTargetPreprocessedFiles), - ('TESTING_FILES', TestingFiles), ): all_files = context.get(var) if not all_files: continue - if dist_install is False and var != 'TESTING_FILES': + if dist_install is False: raise SandboxValidationError( '%s cannot be used with DIST_INSTALL = False' % var, context)