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/.
8 from mach
.decorators
import Command
, CommandArgument
, CommandArgumentGroup
9 from mozbuild
.base
import BinaryNotFoundException
14 category
="post-build",
15 description
="Run the WebDriver implementation for Gecko.",
18 "--binary", type=str, help="Firefox binary (defaults to the local build)."
21 "params", nargs
="...", help="Flags to be passed through to geckodriver."
23 @CommandArgumentGroup("debugging")
28 help="Enable the debugger. Not specifying a --debugger "
29 "option will result in the default debugger "
37 help="Name of debugger to use.",
45 help="Flags to pass to the debugger itself; split as the Bourne shell would.",
47 def run(command_context
, binary
, params
, debug
, debugger
, debugger_args
):
49 binpath
= command_context
.get_binary_path("geckodriver")
50 except BinaryNotFoundException
as e
:
52 logging
.ERROR
, "geckodriver", {"error": str(e
)}, "ERROR: {error}"
58 "It looks like geckodriver isn't built. "
59 "Add ac_add_options --enable-geckodriver to your "
61 "and run |./mach build| to build it.",
72 binary
= command_context
.get_binary_path("app")
73 except BinaryNotFoundException
as e
:
75 logging
.ERROR
, "geckodriver", {"error": str(e
)}, "ERROR: {error}"
78 logging
.INFO
, "geckodriver", {"help": e
.help()}, "{help}"
82 args
.extend(["--binary", binary
])
84 if debug
or debugger
or debugger_args
:
85 if "INSIDE_EMACS" in os
.environ
:
86 command_context
.log_manager
.terminal_handler
.setLevel(logging
.WARNING
)
91 # No debugger name was provided. Look for the default ones on
93 debugger
= mozdebug
.get_default_debugger_name(
94 mozdebug
.DebuggerSearch
.KeepLooking
98 debuggerInfo
= mozdebug
.get_debugger_info(debugger
, debugger_args
)
100 print("Could not find a suitable debugger in your PATH.")
103 # Parameters come from the CLI. We need to convert them before
106 from mozbuild
import shellutil
109 debugger_args
= shellutil
.split(debugger_args
)
110 except shellutil
.MetaCharacterException
as e
:
112 "The --debugger-args you passed require a real shell to parse them."
114 print("(We can't handle the %r character.)" % e
.char
)
117 # Prepend the debugger args.
118 args
= [debuggerInfo
.path
] + debuggerInfo
.args
+ args
120 return command_context
.run_process(
121 args
=args
, ensure_exit_code
=False, pass_thru
=True