Backed out changeset 85b802206e37 (bug 1883618) for causing bustage on nsHTTPCompress...
[gecko.git] / testing / geckodriver / mach_commands.py
blobcb56d3acf2ad82c273e33fce0c878f1340669bbe
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 import logging
6 import os
8 from mach.decorators import Command, CommandArgument, CommandArgumentGroup
9 from mozbuild.base import BinaryNotFoundException
12 @Command(
13 "geckodriver",
14 category="post-build",
15 description="Run the WebDriver implementation for Gecko.",
17 @CommandArgument(
18 "--binary", type=str, help="Firefox binary (defaults to the local build)."
20 @CommandArgument(
21 "params", nargs="...", help="Flags to be passed through to geckodriver."
23 @CommandArgumentGroup("debugging")
24 @CommandArgument(
25 "--debug",
26 action="store_true",
27 group="debugging",
28 help="Enable the debugger. Not specifying a --debugger "
29 "option will result in the default debugger "
30 "being used.",
32 @CommandArgument(
33 "--debugger",
34 default=None,
35 type=str,
36 group="debugging",
37 help="Name of debugger to use.",
39 @CommandArgument(
40 "--debugger-args",
41 default=None,
42 metavar="params",
43 type=str,
44 group="debugging",
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):
48 try:
49 binpath = command_context.get_binary_path("geckodriver")
50 except BinaryNotFoundException as e:
51 command_context.log(
52 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}"
54 command_context.log(
55 logging.INFO,
56 "geckodriver",
57 {},
58 "It looks like geckodriver isn't built. "
59 "Add ac_add_options --enable-geckodriver to your "
60 "mozconfig "
61 "and run |./mach build| to build it.",
63 return 1
65 args = [binpath]
67 if params:
68 args.extend(params)
70 if binary is None:
71 try:
72 binary = command_context.get_binary_path("app")
73 except BinaryNotFoundException as e:
74 command_context.log(
75 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}"
77 command_context.log(
78 logging.INFO, "geckodriver", {"help": e.help()}, "{help}"
80 return 1
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)
88 import mozdebug
90 if not debugger:
91 # No debugger name was provided. Look for the default ones on
92 # current OS.
93 debugger = mozdebug.get_default_debugger_name(
94 mozdebug.DebuggerSearch.KeepLooking
97 if debugger:
98 debuggerInfo = mozdebug.get_debugger_info(debugger, debugger_args)
99 if not debuggerInfo:
100 print("Could not find a suitable debugger in your PATH.")
101 return 1
103 # Parameters come from the CLI. We need to convert them before
104 # their use.
105 if debugger_args:
106 from mozbuild import shellutil
108 try:
109 debugger_args = shellutil.split(debugger_args)
110 except shellutil.MetaCharacterException as e:
111 print(
112 "The --debugger-args you passed require a real shell to parse them."
114 print("(We can't handle the %r character.)" % e.char)
115 return 1
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