Bug 1738926 Part 1: Check if sublayers need to be rebuilt. r=mstange
[gecko.git] / testing / geckodriver / mach_commands.py
blobe1458109a6dfad107a73a757c7b637878a24f0fe
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
7 import os
8 import logging
10 from mach.decorators import (
11 Command,
12 CommandArgument,
13 CommandArgumentGroup,
16 from mozbuild.base import BinaryNotFoundException
19 @Command(
20 "geckodriver",
21 category="post-build",
22 description="Run the WebDriver implementation for Gecko.",
24 @CommandArgument(
25 "--binary", type=str, help="Firefox binary (defaults to the local build)."
27 @CommandArgument(
28 "params", nargs="...", help="Flags to be passed through to geckodriver."
30 @CommandArgumentGroup("debugging")
31 @CommandArgument(
32 "--debug",
33 action="store_true",
34 group="debugging",
35 help="Enable the debugger. Not specifying a --debugger "
36 "option will result in the default debugger "
37 "being used.",
39 @CommandArgument(
40 "--debugger",
41 default=None,
42 type=str,
43 group="debugging",
44 help="Name of debugger to use.",
46 @CommandArgument(
47 "--debugger-args",
48 default=None,
49 metavar="params",
50 type=str,
51 group="debugging",
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):
55 try:
56 binpath = command_context.get_binary_path("geckodriver")
57 except BinaryNotFoundException as e:
58 command_context.log(
59 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}"
61 command_context.log(
62 logging.INFO,
63 "geckodriver",
64 {},
65 "It looks like geckodriver isn't built. "
66 "Add ac_add_options --enable-geckodriver to your "
67 "mozconfig "
68 "and run |./mach build| to build it.",
70 return 1
72 args = [binpath]
74 if params:
75 args.extend(params)
77 if binary is None:
78 try:
79 binary = command_context.get_binary_path("app")
80 except BinaryNotFoundException as e:
81 command_context.log(
82 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}"
84 command_context.log(
85 logging.INFO, "geckodriver", {"help": e.help()}, "{help}"
87 return 1
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)
95 import mozdebug
97 if not debugger:
98 # No debugger name was provided. Look for the default ones on
99 # current OS.
100 debugger = mozdebug.get_default_debugger_name(
101 mozdebug.DebuggerSearch.KeepLooking
104 if debugger:
105 debuggerInfo = mozdebug.get_debugger_info(debugger, debugger_args)
106 if not debuggerInfo:
107 print("Could not find a suitable debugger in your PATH.")
108 return 1
110 # Parameters come from the CLI. We need to convert them before
111 # their use.
112 if debugger_args:
113 from mozbuild import shellutil
115 try:
116 debugger_args = shellutil.split(debugger_args)
117 except shellutil.MetaCharacterException as e:
118 print(
119 "The --debugger-args you passed require a real shell to parse them."
121 print("(We can't handle the %r character.)" % e.char)
122 return 1
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