Bug 1373216 - Add mach command for starting geckodriver, r=ato
authorJames Graham <james@hoppipolla.co.uk>
Thu, 15 Jun 2017 12:47:20 +0100
changeset 364087 c8497caddebb58fa8db7816b578c629987b82c07
parent 364086 20831c1fdba37021ab6a8ceb22be73ea5663a95b
child 364088 bc85129e5c3ea2e54fa9d201638f90765ca4fb11
push id32032
push userarchaeopteryx@coole-files.de
push dateThu, 15 Jun 2017 18:04:52 +0000
treeherdermozilla-central@00f228ced57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1373216
milestone56.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 1373216 - Add mach command for starting geckodriver, r=ato MozReview-Commit-ID: 8hNAjT5db44
build/mach_bootstrap.py
testing/geckodriver/mach_commands.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -47,16 +47,17 @@ MACH_MODULES = [
     'python/mozbuild/mozbuild/mach_commands.py',
     'python/mozbuild/mozbuild/backend/mach_commands.py',
     'python/mozbuild/mozbuild/compilation/codecomplete.py',
     'python/mozbuild/mozbuild/frontend/mach_commands.py',
     'services/common/tests/mach_commands.py',
     'taskcluster/mach_commands.py',
     'testing/awsy/mach_commands.py',
     'testing/firefox-ui/mach_commands.py',
+    'testing/geckodriver/mach_commands.py',
     'testing/mach_commands.py',
     'testing/marionette/mach_commands.py',
     'testing/mochitest/mach_commands.py',
     'testing/mozharness/mach_commands.py',
     'testing/talos/mach_commands.py',
     'testing/web-platform/mach_commands.py',
     'testing/xpcshell/mach_commands.py',
     'tools/compare-locales/mach_commands.py',
new file mode 100644
--- /dev/null
+++ b/testing/geckodriver/mach_commands.py
@@ -0,0 +1,86 @@
+import argparse
+import os
+
+from mozbuild.base import (
+    MachCommandBase
+)
+
+from mach.decorators import (
+    CommandArgument,
+    CommandArgumentGroup,
+    CommandProvider,
+    Command,
+)
+
+
+@CommandProvider
+class RunGeckodriver(MachCommandBase):
+    """Run the compiled program."""
+
+    @Command('geckodriver', category='post-build',
+        description='Run the geckodriver WebDriver implementation')
+    @CommandArgument('--binary', type=str,
+        help='Firefox binary (defaults to the local build).')
+    @CommandArgument('params', nargs='...',
+        help='Command-line arguments to be passed through to the program.')
+
+    @CommandArgumentGroup('debugging')
+    @CommandArgument('--debug', action='store_true', group='debugging',
+        help='Enable the debugger. Not specifying a --debugger option will result in the default debugger being used.')
+    @CommandArgument('--debugger', default=None, type=str, group='debugging',
+        help='Name of debugger to use.')
+    @CommandArgument('--debugger-args', default=None, metavar='params', type=str,
+        group='debugging',
+        help='Command-line arguments to pass to the debugger itself; split as the Bourne shell would.')
+    def run(self, binary, params, debug, debugger, debugger_args):
+        try:
+            binpath = self.get_binary_path('geckodriver')
+        except Exception as e:
+                print("It looks like geckodriver isn't built. "
+                      "Add ac_add_options --enable-geckodrver to your mozconfig ",
+                      "and run |mach build| to build it.")
+                print(e)
+                return 1
+
+        args = [binpath]
+
+        if params:
+            args.extend(params)
+
+        if binary is None:
+            binary = self.get_binary_path('app')
+
+        args.extend(["--binary", binary])
+
+        if debug or debugger or debugger_args:
+            if 'INSIDE_EMACS' in os.environ:
+                self.log_manager.terminal_handler.setLevel(logging.WARNING)
+
+            import mozdebug
+            if not debugger:
+                # No debugger name was provided. Look for the default ones on
+                # current OS.
+                debugger = mozdebug.get_default_debugger_name(mozdebug.DebuggerSearch.KeepLooking)
+
+            if debugger:
+                self.debuggerInfo = mozdebug.get_debugger_info(debugger, debugger_args)
+                if not self.debuggerInfo:
+                    print("Could not find a suitable debugger in your PATH.")
+                    return 1
+
+            # Parameters come from the CLI. We need to convert them before
+            # their use.
+            if debugger_args:
+                from mozbuild import shellutil
+                try:
+                    debugger_args = shellutil.split(debugger_args)
+                except shellutil.MetaCharacterException as e:
+                    print("The --debugger-args you passed require a real shell to parse them.")
+                    print("(We can't handle the %r character.)" % e.char)
+                    return 1
+
+            # Prepend the debugger args.
+            args = [self.debuggerInfo.path] + self.debuggerInfo.args + args
+
+        return self.run_process(args=args, ensure_exit_code=False,
+            pass_thru=True)