1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Integrates the xpcshell test runner with mach.
11 import mozpack
.path
as mozpath
13 from mozbuild
.base
import (
18 from mach
.decorators
import (
24 class JetpackRunner(MozbuildObject
):
25 """Run jetpack tests."""
26 def run_tests(self
, **kwargs
):
27 self
._run
_make
(target
='jetpack-tests')
30 class MachCommands(MachCommandBase
):
31 @Command('jetpack-test', category
='testing',
32 description
='Runs the jetpack test suite (Add-on SDK).')
33 def run_jetpack_test(self
, **params
):
34 # We should probably have a utility function to ensure the tree is
35 # ready to run tests. Until then, we just create the state dir (in
36 # case the tree wasn't built with mach).
37 self
._ensure
_state
_subdir
_exists
('.')
39 jetpack
= self
._spawn
(JetpackRunner
)
41 jetpack
.run_tests(**params
)
43 @Command('generate-addon-sdk-moz-build', category
='misc',
44 description
='Generates the moz.build file for the addon-sdk/ directory.')
45 def run_addon_sdk_moz_build(self
, **params
):
46 addon_sdk_dir
= mozpath
.join(self
.topsrcdir
, 'addon-sdk')
47 js_src_dir
= mozpath
.join(addon_sdk_dir
, 'source/lib')
50 for path
, dirs
, files
in os
.walk(js_src_dir
):
51 js_files
= [f
for f
in files
if f
.endswith(('.js', '.jsm', '.html'))]
55 relative
= mozpath
.relpath(path
, js_src_dir
)
56 dirs_to_files
[relative
] = js_files
58 moz_build
= """# AUTOMATICALLY GENERATED FROM mozbuild.template AND mach. DO NOT EDIT.
59 # This Source Code Form is subject to the terms of the Mozilla Public
60 # License, v. 2.0. If a copy of the MPL was not distributed with this
61 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
63 %(moz-build-template)s
64 if CONFIG['MOZ_WIDGET_TOOLKIT'] != "gonk":
66 %(always-on-modules)s"""
85 always_on_modules
= []
87 for d
, files
in sorted(dirs_to_files
.items()):
88 if d
in non_b2g_paths
:
89 non_b2g_modules
.append((d
, files
))
91 always_on_modules
.append((d
, files
))
93 def list_to_js_modules(l
, indent
=''):
100 # Ensure that we don't have things like:
101 # EXTRA_JS_MODULES.commonjs.sdk.private-browsing
102 # which would be a Python syntax error.
104 module_path
= ''.join('.' + p
if p
.find('-') == -1 else "['%s']" % p
for p
in path
)
106 filelist
= ["'source/lib/%s%s'" % (dir_path
, f
)
107 for f
in sorted(files
, key
=lambda x
: x
.lower())]
108 js_modules
.append("EXTRA_JS_MODULES.commonjs%s += [\n %s,\n]\n"
109 % (module_path
, ',\n '.join(filelist
)))
110 stringified
= '\n'.join(js_modules
)
111 # This isn't the same thing as |js_modules|, since |js_modules| had
113 lines
= stringified
.split('\n')
114 # Indent lines while avoiding trailing whitespace.
115 lines
= [indent
+ line
if line
else line
for line
in lines
]
116 return '\n'.join(lines
)
118 moz_build_output
= mozpath
.join(addon_sdk_dir
, 'moz.build')
119 moz_build_template
= mozpath
.join(addon_sdk_dir
, 'mozbuild.template')
120 with
open(moz_build_output
, 'w') as f
, open(moz_build_template
, 'r') as t
:
121 substs
= { 'moz-build-template': t
.read(),
122 'non-b2g-modules': list_to_js_modules(non_b2g_modules
,
124 'always-on-modules': list_to_js_modules(always_on_modules
) }
125 f
.write(moz_build
% substs
)