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 from __future__
import absolute_import
, print_function
, unicode_literals
10 from mach
.decorators
import (
16 from mozbuild
.base
import BinaryNotFoundException
21 category
="post-build",
22 description
="Run the WebDriver implementation for Gecko.",
25 "--binary", type=str, help="Firefox binary (defaults to the local build)."
28 "params", nargs
="...", help="Flags to be passed through to geckodriver."
30 @CommandArgumentGroup("debugging")
35 help="Enable the debugger. Not specifying a --debugger "
36 "option will result in the default debugger "
44 help="Name of debugger to use.",
52 help="Flags to pass to the debugger itself; split as the Bourne shell would.",
54 def run(command_context
, binary
, params
, debug
, debugger
, debugger_args
):
56 binpath
= command_context
.get_binary_path("geckodriver")
57 except BinaryNotFoundException
as e
:
59 logging
.ERROR
, "geckodriver", {"error": str(e
)}, "ERROR: {error}"
65 "It looks like geckodriver isn't built. "
66 "Add ac_add_options --enable-geckodriver to your "
68 "and run |./mach build| to build it.",
79 binary
= command_context
.get_binary_path("app")
80 except BinaryNotFoundException
as e
:
82 logging
.ERROR
, "geckodriver", {"error": str(e
)}, "ERROR: {error}"
85 logging
.INFO
, "geckodriver", {"help": e
.help()}, "{help}"
89 args
.extend(["--binary", binary
])
91 if debug
or debugger
or debugger_args
:
92 if "INSIDE_EMACS" in os
.environ
:
93 command_context
.log_manager
.terminal_handler
.setLevel(logging
.WARNING
)
98 # No debugger name was provided. Look for the default ones on
100 debugger
= mozdebug
.get_default_debugger_name(
101 mozdebug
.DebuggerSearch
.KeepLooking
105 debuggerInfo
= mozdebug
.get_debugger_info(debugger
, debugger_args
)
107 print("Could not find a suitable debugger in your PATH.")
110 # Parameters come from the CLI. We need to convert them before
113 from mozbuild
import shellutil
116 debugger_args
= shellutil
.split(debugger_args
)
117 except shellutil
.MetaCharacterException
as e
:
119 "The --debugger-args you passed require a real shell to parse them."
121 print("(We can't handle the %r character.)" % e
.char
)
124 # Prepend the debugger args.
125 args
= [debuggerInfo
.path
] + debuggerInfo
.args
+ args
127 return command_context
.run_process(
128 args
=args
, ensure_exit_code
=False, pass_thru
=True