mach_commands.py (2820B)
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/. 4 5 import logging 6 import os 7 8 from mach.decorators import Command, CommandArgument, CommandArgumentGroup 9 from mozbuild.base import BinaryNotFoundException 10 from mozdebug import prepend_debugger_args 11 12 13 @Command( 14 "geckodriver", 15 category="post-build", 16 description="Run the WebDriver implementation for Gecko.", 17 ) 18 @CommandArgument( 19 "--binary", type=str, help="Firefox binary (defaults to the local build)." 20 ) 21 @CommandArgument( 22 "params", nargs="...", help="Flags to be passed through to geckodriver." 23 ) 24 @CommandArgumentGroup("debugging") 25 @CommandArgument( 26 "--debug", 27 action="store_true", 28 group="debugging", 29 help="Enable the debugger. Not specifying a --debugger " 30 "option will result in the default debugger " 31 "being used.", 32 ) 33 @CommandArgument( 34 "--debugger", 35 default=None, 36 type=str, 37 group="debugging", 38 help="Name of debugger to use.", 39 ) 40 @CommandArgument( 41 "--debugger-args", 42 default=None, 43 metavar="params", 44 type=str, 45 group="debugging", 46 help="Flags to pass to the debugger itself; split as the Bourne shell would.", 47 ) 48 def run(command_context, binary, params, debug, debugger, debugger_args): 49 try: 50 binpath = command_context.get_binary_path("geckodriver") 51 except BinaryNotFoundException as e: 52 command_context.log( 53 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}" 54 ) 55 command_context.log( 56 logging.INFO, 57 "geckodriver", 58 {}, 59 "It looks like geckodriver isn't built. " 60 "Add ac_add_options --enable-geckodriver to your " 61 "mozconfig " 62 "and run |./mach build| to build it.", 63 ) 64 return 1 65 66 args = [binpath] 67 68 if params: 69 args.extend(params) 70 71 if binary is None: 72 try: 73 binary = command_context.get_binary_path("app") 74 except BinaryNotFoundException as e: 75 command_context.log( 76 logging.ERROR, "geckodriver", {"error": str(e)}, "ERROR: {error}" 77 ) 78 command_context.log( 79 logging.INFO, "geckodriver", {"help": e.help()}, "{help}" 80 ) 81 return 1 82 83 args.extend(["--binary", binary]) 84 85 if debug or debugger or debugger_args: 86 if "INSIDE_EMACS" in os.environ: 87 command_context.log_manager.terminal_handler.setLevel(logging.WARNING) 88 89 args = prepend_debugger_args(args, debugger, debugger_args) 90 if not args: 91 return 1 92 93 return command_context.run_process( 94 args=args, ensure_exit_code=False, pass_thru=True 95 )