diff --git a/build/valgrind/mach_commands.py b/build/valgrind/mach_commands.py index 408c0be28c14..9e209f24c61c 100644 --- a/build/valgrind/mach_commands.py +++ b/build/valgrind/mach_commands.py @@ -48,7 +48,7 @@ class MachCommands(MachCommandBase): "--suppression multiple times to specify multiple suppression " "files.", ) - def valgrind_test(self, suppressions): + def valgrind_test(self, command_context, suppressions): from mozfile import TemporaryDirectory from mozhttpd import MozHttpd diff --git a/devtools/shared/css/generated/mach_commands.py b/devtools/shared/css/generated/mach_commands.py index feeac78b1ae5..0a72e7043f25 100644 --- a/devtools/shared/css/generated/mach_commands.py +++ b/devtools/shared/css/generated/mach_commands.py @@ -45,7 +45,7 @@ class MachCommands(MachCommandBase): category="post-build", description="Rebuild the devtool's static css properties database.", ) - def generate_css_db(self): + def generate_css_db(self, command_context): """Generate the static css properties database for devtools and write it to file.""" print("Re-generating the css properties database...") diff --git a/dom/bindings/mach_commands.py b/dom/bindings/mach_commands.py index 28d278015691..596c4a28546c 100644 --- a/dom/bindings/mach_commands.py +++ b/dom/bindings/mach_commands.py @@ -33,7 +33,7 @@ class WebIDLProvider(MachCommandBase): @CommandArgument( "interface", nargs="+", help="Interface(s) whose examples to generate." ) - def webidl_example(self, interface): + def webidl_example(self, command_context, interface): from mozwebidlcodegen import BuildSystemWebIDL manager = self._spawn(BuildSystemWebIDL).manager @@ -46,7 +46,7 @@ class WebIDLProvider(MachCommandBase): parser=get_test_parser, description="Run WebIDL tests (Interface Browser parser).", ) - def webidl_test(self, **kwargs): + def webidl_test(self, command_context, **kwargs): sys.path.insert(0, os.path.join(self.topsrcdir, "other-licenses", "ply")) # Ensure the topobjdir exists. On a Taskcluster test run there won't be diff --git a/js/src/devtools/rootAnalysis/mach_commands.py b/js/src/devtools/rootAnalysis/mach_commands.py index de38df738816..b4a4b58219dc 100644 --- a/js/src/devtools/rootAnalysis/mach_commands.py +++ b/js/src/devtools/rootAnalysis/mach_commands.py @@ -111,7 +111,7 @@ class MachCommands(MachCommandBase): order="declaration", description="Commands for running the static analysis for GC rooting hazards", ) - def hazards(self): + def hazards(self, command_context): """Commands related to performing the GC rooting hazard analysis""" print("See `mach hazards --help` for a list of subcommands") @@ -121,7 +121,7 @@ class MachCommands(MachCommandBase): "bootstrap", description="Install prerequisites for the hazard analysis", ) - def bootstrap(self, **kwargs): + def bootstrap(self, command_context, **kwargs): orig_dir = os.getcwd() os.chdir(self.ensure_dir_exists(self.tools_dir)) try: @@ -142,7 +142,7 @@ class MachCommands(MachCommandBase): metavar="FILENAME", help="Build with the given mozconfig.", ) - def build_shell(self, **kwargs): + def build_shell(self, command_context, **kwargs): """Build a JS shell to use to run the rooting hazard analysis.""" # The JS shell requires some specific configuration settings to execute # the hazard analysis code, and configuration is done via mozconfig. @@ -215,7 +215,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell` @CommandArgument( "--work-dir", default=None, help="Directory for output and working files." ) - def gather_hazard_data(self, **kwargs): + def gather_hazard_data(self, command_context, **kwargs): """Gather analysis information by compiling the tree""" application = kwargs["application"] objdir = kwargs["haz_objdir"] @@ -279,7 +279,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell` default=os.environ.get("HAZ_OBJDIR"), help="Write object files to this directory.", ) - def inner_compile(self, **kwargs): + def inner_compile(self, command_context, **kwargs): """Build a source tree and gather analysis information while running under the influence of the analysis collection server.""" @@ -346,7 +346,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell` @CommandArgument( "--work-dir", default=None, help="Directory for output and working files." ) - def analyze(self, application, shell_objdir, work_dir): + def analyze(self, command_context, application, shell_objdir, work_dir): """Analyzed gathered data for rooting hazards""" shell = self.ensure_shell(shell_objdir) @@ -374,7 +374,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell` default=None, help="objdir containing the optimized JS shell for running the analysis.", ) - def self_test(self, shell_objdir): + def self_test(self, command_context, shell_objdir): """Analyzed gathered data for rooting hazards""" shell = self.ensure_shell(shell_objdir) args = [ diff --git a/layout/tools/reftest/mach_commands.py b/layout/tools/reftest/mach_commands.py index e1ff5fbc709d..f2b160fb5663 100644 --- a/layout/tools/reftest/mach_commands.py +++ b/layout/tools/reftest/mach_commands.py @@ -236,7 +236,7 @@ class MachCommands(MachCommandBase): description="Run reftests (layout and graphics correctness).", parser=get_parser, ) - def run_reftest(self, **kwargs): + def run_reftest(self, command_context, **kwargs): kwargs["suite"] = "reftest" return self._run_reftest(**kwargs) @@ -246,7 +246,7 @@ class MachCommands(MachCommandBase): description="Run js/src/tests in the browser.", parser=get_parser, ) - def run_jstestbrowser(self, **kwargs): + def run_jstestbrowser(self, command_context, **kwargs): if "--enable-js-shell" not in self.mozconfig["configure_args"]: raise Exception( "jstestbrowser requires --enable-js-shell be specified in mozconfig." @@ -263,7 +263,7 @@ class MachCommands(MachCommandBase): description="Run crashtests (Check if crashes on a page).", parser=get_parser, ) - def run_crashtest(self, **kwargs): + def run_crashtest(self, command_context, **kwargs): kwargs["suite"] = "crashtest" return self._run_reftest(**kwargs) diff --git a/layout/tools/reftest/mach_test_package_commands.py b/layout/tools/reftest/mach_test_package_commands.py index a671d555cc0d..0ee2053b381c 100644 --- a/layout/tools/reftest/mach_test_package_commands.py +++ b/layout/tools/reftest/mach_test_package_commands.py @@ -115,7 +115,7 @@ class ReftestCommands(MachCommandBase): description="Run the reftest harness.", parser=setup_argument_parser, ) - def reftest(self, **kwargs): + def reftest(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() kwargs["suite"] = "reftest" return run_reftest(self._mach_context, **kwargs) diff --git a/mobile/android/mach_commands.py b/mobile/android/mach_commands.py index 691977425475..4308b38010de 100644 --- a/mobile/android/mach_commands.py +++ b/mobile/android/mach_commands.py @@ -57,7 +57,7 @@ class MachCommands(MachCommandBase): description="Run Android-specific commands.", conditions=[conditions.is_android], ) - def android(self): + def android(self, command_context): pass @SubCommand( @@ -67,8 +67,9 @@ class MachCommands(MachCommandBase): See http://firefox-source-docs.mozilla.org/build/buildsystem/toolchains.html#firefox-for-android-with-gradle""", # NOQA: E501 ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_assemble_app(self, args): + def android_assemble_app(self, command_context, args): ret = self.gradle( + command_context, self.substs["GRADLE_ANDROID_APP_TASKS"] + ["-x", "lint"] + args, verbose=True, ) @@ -86,7 +87,7 @@ class MachCommands(MachCommandBase): help="config files, " "like [/path/to/ClassName-classes.txt]+", ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_generate_sdk_bindings(self, inputs, args): + def android_generate_sdk_bindings(self, command_context, inputs, args): import itertools def stem(input): @@ -101,6 +102,7 @@ class MachCommands(MachCommandBase): ) ret = self.gradle( + command_context, self.substs["GRADLE_ANDROID_GENERATE_SDK_BINDINGS_TASKS"] + [bindings_args] + args, @@ -115,8 +117,9 @@ class MachCommands(MachCommandBase): """Generate GeckoView JNI wrappers used when building GeckoView.""", ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_generate_generated_jni_wrappers(self, args): + def android_generate_generated_jni_wrappers(self, command_context, args): ret = self.gradle( + command_context, self.substs["GRADLE_ANDROID_GENERATE_GENERATED_JNI_WRAPPERS_TASKS"] + args, verbose=True, ) @@ -129,7 +132,7 @@ class MachCommands(MachCommandBase): """Run Android api-lint. REMOVED/DEPRECATED: Use 'mach lint --linter android-api-lint'.""", ) - def android_apilint_REMOVED(self): + def android_apilint_REMOVED(self, command_context): print(LINT_DEPRECATION_MESSAGE) return 1 @@ -139,7 +142,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-api-lint'.""", """Run Android test. REMOVED/DEPRECATED: Use 'mach lint --linter android-test'.""", ) - def android_test_REMOVED(self): + def android_test_REMOVED(self, command_context): print(LINT_DEPRECATION_MESSAGE) return 1 @@ -149,7 +152,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-test'.""", """Run Android lint. REMOVED/DEPRECATED: Use 'mach lint --linter android-lint'.""", ) - def android_lint_REMOVED(self): + def android_lint_REMOVED(self, command_context): print(LINT_DEPRECATION_MESSAGE) return 1 @@ -159,7 +162,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-lint'.""", """Run Android checkstyle. REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", ) - def android_checkstyle_REMOVED(self): + def android_checkstyle_REMOVED(self, command_context): print(LINT_DEPRECATION_MESSAGE) return 1 @@ -170,11 +173,12 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", See http://firefox-source-docs.mozilla.org/build/buildsystem/toolchains.html#firefox-for-android-with-gradle""", # NOQA: E501 ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_gradle_dependencies(self, args): + def android_gradle_dependencies(self, command_context, args): # We don't want to gate producing dependency archives on clean # lint or checkstyle, particularly because toolchain versions # can change the outputs for those processes. self.gradle( + command_context, self.substs["GRADLE_ANDROID_DEPENDENCIES_TASKS"] + ["--continue"] + args, verbose=True, ) @@ -188,17 +192,20 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", See http://firefox-source-docs.mozilla.org/build/buildsystem/toolchains.html#firefox-for-android-with-gradle""", # NOQA: E501 ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_archive_geckoview(self, args): + def android_archive_geckoview(self, command_context, args): ret = self.gradle( - self.substs["GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS"] + args, verbose=True + command_context, + self.substs["GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS"] + args, + verbose=True, ) return ret @SubCommand("android", "build-geckoview_example", """Build geckoview_example """) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_build_geckoview_example(self, args): + def android_build_geckoview_example(self, command_context, args): self.gradle( + command_context, self.substs["GRADLE_ANDROID_BUILD_GECKOVIEW_EXAMPLE_TASKS"] + args, verbose=True, ) @@ -214,8 +221,9 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", "android", "install-geckoview_example", """Install geckoview_example """ ) @CommandArgument("args", nargs=argparse.REMAINDER) - def android_install_geckoview_example(self, args): + def android_install_geckoview_example(self, command_context, args): self.gradle( + command_context, self.substs["GRADLE_ANDROID_INSTALL_GECKOVIEW_EXAMPLE_TASKS"] + args, verbose=True, ) @@ -260,7 +268,13 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", help="Use the specified message for commits.", ) def android_geckoview_docs( - self, archive, upload, upload_branch, javadoc_path, upload_message + self, + command_context, + archive, + upload, + upload_branch, + javadoc_path, + upload_message, ): tasks = ( @@ -269,7 +283,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", else self.substs["GRADLE_ANDROID_GECKOVIEW_DOCS_TASKS"] ) - ret = self.gradle(tasks, verbose=True) + ret = self.gradle(command_context, tasks, verbose=True) if ret or not upload: return ret @@ -383,7 +397,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", help="Verbose output for what commands the build is running.", ) @CommandArgument("args", nargs=argparse.REMAINDER) - def gradle(self, args, verbose=False): + def gradle(self, command_context, args, verbose=False): if not verbose: # Avoid logging the command self.log_manager.terminal_handler.setLevel(logging.CRITICAL) @@ -442,7 +456,7 @@ REMOVED/DEPRECATED: Use 'mach lint --linter android-checkstyle'.""", ) @Command("gradle-install", category="devenv", conditions=[REMOVED]) - def gradle_install_REMOVED(self): + def gradle_install_REMOVED(self, command_context): pass @@ -486,7 +500,13 @@ class AndroidEmulatorCommands(MachCommandBase): "--verbose", action="store_true", help="Log informative status messages." ) def emulator( - self, version, wait=False, force_update=False, gpu=None, verbose=False + self, + command_context, + version, + wait=False, + force_update=False, + gpu=None, + verbose=False, ): from mozrunner.devices.android_device import AndroidEmulator diff --git a/python/mach/docs/commands.rst b/python/mach/docs/commands.rst index 2d014af9f744..70dbcb3d7077 100644 --- a/python/mach/docs/commands.rst +++ b/python/mach/docs/commands.rst @@ -17,7 +17,11 @@ The important decorators are as follows: A method decorator that denotes that the method should be called when the specified command is requested. The decorator takes a command name as its first argument and a number of additional arguments to - configure the behavior of the command. + configure the behavior of the command. The decorated method must take a + ``command_context`` argument as its first (after ``self``). + ``command_context`` is a properly configured instance of a ``MozbuildObject`` + subclass, meaning it can be used for accessing things like the current config + and running processes. :py:func:`CommandArgument ` A method decorator that defines an argument to the command. Its @@ -51,7 +55,7 @@ Here is a complete example: @Command('doit', help='Do ALL OF THE THINGS.') @CommandArgument('--force', '-f', action='store_true', help='Force doing it.') - def doit(self, force=False): + def doit(self, command_context, force=False): # Do stuff here. When the module is loaded, the decorators tell mach about all handlers. @@ -101,7 +105,7 @@ Here is an example: self.build_path = ... @Command('run_tests', conditions=[build_available]) - def run_tests(self): + def run_tests(self, command_context): # Do stuff here. It is important to make sure that any state needed by the condition is diff --git a/python/mach/mach/commands/commandinfo.py b/python/mach/mach/commands/commandinfo.py index 93eb52e9249c..3c9510dc8cd1 100644 --- a/python/mach/mach/commands/commandinfo.py +++ b/python/mach/mach/commands/commandinfo.py @@ -128,7 +128,7 @@ class BuiltinCommands(MachCommandBase): return commands_info @Command("mach-commands", category="misc", description="List all mach commands.") - def run_commands(self): + def run_commands(self, command_context): print("\n".join(self.commands)) @Command( @@ -143,7 +143,7 @@ class BuiltinCommands(MachCommandBase): nargs="?", help="Only display commands containing given substring.", ) - def run_debug_commands(self, match=None): + def run_debug_commands(self, command_context, match=None): import inspect for command, handler in self.command_handlers.items(): @@ -169,7 +169,7 @@ class BuiltinCommands(MachCommandBase): @CommandArgument( "args", default=None, nargs=argparse.REMAINDER, help="Command to complete." ) - def run_completion(self, args): + def run_completion(self, command_context, args): if not args: print("\n".join(self.commands)) return @@ -231,7 +231,7 @@ class BuiltinCommands(MachCommandBase): default=None, help="File path to save completion script.", ) - def completion_bash(self, outfile): + def completion_bash(self, command_context, outfile): commands_subcommands = [] case_options = [] case_subcommands = [] @@ -325,7 +325,7 @@ class BuiltinCommands(MachCommandBase): default=None, help="File path to save completion script.", ) - def completion_zsh(self, outfile): + def completion_zsh(self, command_context, outfile): commands_descriptions = [] commands_subcommands = [] case_options = [] @@ -420,7 +420,7 @@ class BuiltinCommands(MachCommandBase): default=None, help="File path to save completion script.", ) - def completion_fish(self, outfile): + def completion_fish(self, command_context, outfile): def _append_opt_strs(comp, opt_strs): for opt in opt_strs: if opt.startswith("--"): diff --git a/python/mach/mach/commands/settings.py b/python/mach/mach/commands/settings.py index 22e8ba9c4298..812bfd939c35 100644 --- a/python/mach/mach/commands/settings.py +++ b/python/mach/mach/commands/settings.py @@ -38,7 +38,7 @@ class Settings(MachCommandBase): action="store_true", help="Show settings in a concise list", ) - def run_settings(self, short=None): + def run_settings(self, command_context, short=None): """List available settings.""" types = {v: k for k, v in TYPE_CLASSES.items()} wrapper = TextWrapper(initial_indent="# ", subsequent_indent="# ") diff --git a/python/mach/mach/registrar.py b/python/mach/mach/registrar.py index ef1886992145..6db52957a8fb 100644 --- a/python/mach/mach/registrar.py +++ b/python/mach/mach/registrar.py @@ -102,9 +102,9 @@ class MachRegistrar(object): if debug_command: import pdb - result = pdb.runcall(fn, **kwargs) + result = pdb.runcall(fn, instance, **kwargs) else: - result = fn(**kwargs) + result = fn(instance, **kwargs) end_time = time.time() diff --git a/python/mach/mach/test/providers/commands.py b/python/mach/mach/test/providers/commands.py index 9463c6b4039f..00cda7775bb3 100644 --- a/python/mach/mach/test/providers/commands.py +++ b/python/mach/mach/test/providers/commands.py @@ -31,15 +31,15 @@ class MachCommands(MachCommandBase): @Command("cmd_foo", category="testing") @CommandArgument("--arg", default=None, help="Argument help.") - def run_foo(self): + def run_foo(self, command_context): pass @Command("cmd_bar", category="testing", conditions=[partial(is_bar, False)]) - def run_bar(self): + def run_bar(self, command_context): pass @Command( "cmd_foobar", category="testing", conditions=[is_foo, partial(is_bar, True)] ) - def run_foobar(self): + def run_foobar(self, command_context): pass diff --git a/python/mach/mach/test/providers/conditions.py b/python/mach/mach/test/providers/conditions.py index 2ca619fa4d8e..9801bd1fc33c 100644 --- a/python/mach/mach/test/providers/conditions.py +++ b/python/mach/mach/test/providers/conditions.py @@ -28,15 +28,15 @@ class ConditionsProvider(MachCommandBase): bar = False @Command("cmd_foo", category="testing", conditions=[is_foo]) - def run_foo(self): + def run_foo(self, command_context): pass @Command("cmd_bar", category="testing", conditions=[is_bar]) - def run_bar(self): + def run_bar(self, command_context): pass @Command("cmd_foobar", category="testing", conditions=[is_foo, is_bar]) - def run_foobar(self): + def run_foobar(self, command_context): pass @@ -48,13 +48,13 @@ class ConditionsContextProvider(MachCommandBase): self.bar = self._mach_context.bar @Command("cmd_foo_ctx", category="testing", conditions=[is_foo]) - def run_foo(self): + def run_foo(self, command_context): pass @Command("cmd_bar_ctx", category="testing", conditions=[is_bar]) - def run_bar(self): + def run_bar(self, command_context): pass @Command("cmd_foobar_ctx", category="testing", conditions=[is_foo, is_bar]) - def run_foobar(self): + def run_foobar(self, command_context): pass diff --git a/python/mach/mach/test/providers/throw.py b/python/mach/mach/test/providers/throw.py index b562ee1566e5..392f444bb749 100644 --- a/python/mach/mach/test/providers/throw.py +++ b/python/mach/mach/test/providers/throw.py @@ -18,10 +18,10 @@ from mozbuild.base import MachCommandBase class TestCommandProvider(MachCommandBase): @Command("throw", category="testing") @CommandArgument("--message", "-m", default="General Error") - def throw(self, message): + def throw(self, command_context, message): raise Exception(message) @Command("throw_deep", category="testing") @CommandArgument("--message", "-m", default="General Error") - def throw_deep(self, message): + def throw_deep(self, command_context, message): throw2.throw_deep(message) diff --git a/python/mach/mach/test/test_decorators.py b/python/mach/mach/test/test_decorators.py index 93215c0fb8c1..f4a82d126042 100644 --- a/python/mach/mach/test/test_decorators.py +++ b/python/mach/mach/test/test_decorators.py @@ -37,7 +37,7 @@ def test_register_command_with_argument(registrar): class CommandFoo(MachCommandBase): @Command("cmd_foo", category="testing") @CommandArgument("--arg", default=None, help="Argument help.") - def run_foo(self, arg): + def run_foo(self, command_context, arg): inner_function(arg) registrar.dispatch("cmd_foo", context, arg="argument") @@ -56,12 +56,14 @@ def test_register_command_with_metrics_path(registrar): @CommandProvider class CommandFoo(MachCommandBase): @Command("cmd_foo", category="testing", metrics_path=metrics_path) - def run_foo(self): + def run_foo(self, command_context): assert self.metrics == metrics_mock + assert command_context.metrics == metrics_mock @SubCommand("cmd_foo", "sub_foo", metrics_path=metrics_path + "2") - def run_subfoo(self): + def run_subfoo(self, command_context): assert self.metrics == metrics_mock + assert command_context.metrics == metrics_mock registrar.dispatch("cmd_foo", context) @@ -83,17 +85,25 @@ def test_register_command_sets_up_class_at_runtime(registrar): @CommandProvider class CommandFoo(MachCommandBase): @Command("cmd_foo", category="testing", virtualenv_name="env_foo") - def run_foo(self): + def run_foo(self, command_context): assert ( os.path.basename(self.virtualenv_manager.virtualenv_root) == "env_foo" ) + assert ( + os.path.basename(command_context.virtualenv_manager.virtualenv_root) + == "env_foo" + ) inner_function("foo") @Command("cmd_bar", category="testing", virtualenv_name="env_bar") - def run_bar(self): + def run_bar(self, command_context): assert ( os.path.basename(self.virtualenv_manager.virtualenv_root) == "env_bar" ) + assert ( + os.path.basename(command_context.virtualenv_manager.virtualenv_root) + == "env_bar" + ) inner_function("bar") registrar.dispatch("cmd_foo", context) @@ -108,7 +118,7 @@ def test_cannot_create_command_nonexisting_category(registrar): @CommandProvider class CommandFoo(MachCommandBase): @Command("cmd_foo", category="bar") - def run_foo(self): + def run_foo(self, command_context): pass @@ -118,7 +128,7 @@ def test_subcommand_requires_parent_to_exist(registrar): @CommandProvider class CommandFoo(MachCommandBase): @SubCommand("sub_foo", "foo") - def run_foo(self): + def run_foo(self, command_context): pass diff --git a/python/mach_commands.py b/python/mach_commands.py index 7e1ce9bf43bc..74abe042ae0e 100644 --- a/python/mach_commands.py +++ b/python/mach_commands.py @@ -61,7 +61,14 @@ class MachCommands(MachCommandBase): ) @CommandArgument("args", nargs=argparse.REMAINDER) def python( - self, no_virtualenv, no_activate, exec_file, ipython, requirements, args + self, + command_context, + no_virtualenv, + no_activate, + exec_file, + ipython, + requirements, + args, ): # Avoid logging the command self.log_manager.terminal_handler.setLevel(logging.CRITICAL) @@ -165,7 +172,7 @@ class MachCommands(MachCommandBase): "passed as it is to pytest" ), ) - def python_test(self, *args, **kwargs): + def python_test(self, command_context, *args, **kwargs): try: tempdir = str(tempfile.mkdtemp(suffix="-python-test")) if six.PY2: diff --git a/python/mozboot/mozboot/mach_commands.py b/python/mozboot/mozboot/mach_commands.py index 8b8040e59684..a9f7f1e03721 100644 --- a/python/mozboot/mozboot/mach_commands.py +++ b/python/mozboot/mozboot/mach_commands.py @@ -38,7 +38,12 @@ class Bootstrap(MachCommandBase): action="store_true", help="Only execute actions that leave the system " "configuration alone.", ) - def bootstrap(self, application_choice=None, no_system_changes=False): + def bootstrap( + self, + command_context, + application_choice=None, + no_system_changes=False, + ): from mozboot.bootstrap import Bootstrapper bootstrapper = Bootstrapper( @@ -63,7 +68,7 @@ class VersionControlCommands(MachCommandBase): action="store_true", help="Only update recommended extensions, don't run the wizard.", ) - def vcs_setup(self, update_only=False): + def vcs_setup(self, command_context, update_only=False): """Ensure a Version Control System (Mercurial or Git) is optimally configured. diff --git a/python/mozbuild/mozbuild/artifact_commands.py b/python/mozbuild/mozbuild/artifact_commands.py index 6e9c892230c7..fea86658cb1e 100644 --- a/python/mozbuild/mozbuild/artifact_commands.py +++ b/python/mozbuild/mozbuild/artifact_commands.py @@ -72,7 +72,7 @@ class PackageFrontend(MachCommandBase): category="post-build", description="Use pre-built artifacts to build Firefox.", ) - def artifact(self): + def artifact(self, command_context): """Download, cache, and install pre-built binary artifacts to build Firefox. Use |mach build| as normal to freshen your installed binary libraries: @@ -176,6 +176,7 @@ class PackageFrontend(MachCommandBase): ) def artifact_install( self, + command_context, source=None, skip_cache=False, tree=None, @@ -207,7 +208,7 @@ class PackageFrontend(MachCommandBase): "clear-cache", "Delete local artifacts and reset local artifact cache.", ) - def artifact_clear_cache(self, tree=None, job=None, verbose=False): + def artifact_clear_cache(self, command_context, tree=None, job=None, verbose=False): self._set_log_level(verbose) artifacts = self._make_artifacts(tree=tree, job=job) artifacts.clear_cache() @@ -259,6 +260,7 @@ class PackageFrontend(MachCommandBase): ) def artifact_toolchain( self, + command_context, verbose=False, cache_dir=None, skip_cache=False, diff --git a/python/mozbuild/mozbuild/backend/mach_commands.py b/python/mozbuild/mozbuild/backend/mach_commands.py index d2f0af2d62ca..da93474b1410 100644 --- a/python/mozbuild/mozbuild/backend/mach_commands.py +++ b/python/mozbuild/mozbuild/backend/mach_commands.py @@ -29,7 +29,7 @@ class MachCommands(MachCommandBase): ) @CommandArgument("ide", choices=["eclipse", "visualstudio", "vscode"]) @CommandArgument("args", nargs=argparse.REMAINDER) - def run(self, ide, args): + def run(self, command_context, ide, args): if ide == "eclipse": backend = "CppEclipse" elif ide == "visualstudio": diff --git a/python/mozbuild/mozbuild/build_commands.py b/python/mozbuild/mozbuild/build_commands.py index 11a6a69aa4ac..a0d9f1f0eb59 100644 --- a/python/mozbuild/mozbuild/build_commands.py +++ b/python/mozbuild/mozbuild/build_commands.py @@ -64,7 +64,15 @@ class Build(MachCommandBase): action="store_true", help="Keep building after an error has occurred", ) - def build(self, what=None, jobs=0, directory=None, verbose=False, keep_going=False): + def build( + self, + context_context, + what=None, + jobs=0, + directory=None, + verbose=False, + keep_going=False, + ): """Build the source tree. With no arguments, this will perform a full build. @@ -168,7 +176,13 @@ class Build(MachCommandBase): @CommandArgument( "options", default=None, nargs=argparse.REMAINDER, help="Configure options" ) - def configure(self, options=None, buildstatus_messages=False, line_handler=None): + def configure( + self, + command_context, + options=None, + buildstatus_messages=False, + line_handler=None, + ): from mozbuild.controller.building import BuildDriver self.log_manager.enable_all_structured_loggers() @@ -203,7 +217,9 @@ class Build(MachCommandBase): help="Web browser to automatically open. See webbrowser Python module.", ) @CommandArgument("--url", help="URL of JSON document to display") - def resource_usage(self, address=None, port=None, browser=None, url=None): + def resource_usage( + self, command_context, address=None, port=None, browser=None, url=None + ): import webbrowser from mozbuild.html_build_viewer import BuildViewerServer @@ -258,7 +274,9 @@ class Build(MachCommandBase): action="store_true", help="Do everything except writing files out.", ) - def build_backend(self, backend, diff=False, verbose=False, dry_run=False): + def build_backend( + self, command_context, backend, diff=False, verbose=False, dry_run=False + ): python = self.virtualenv_manager.python_path config_status = os.path.join(self.topobjdir, "config.status") diff --git a/python/mozbuild/mozbuild/code_analysis/mach_commands.py b/python/mozbuild/mozbuild/code_analysis/mach_commands.py index f8975f25c81d..a600c48d3fb0 100644 --- a/python/mozbuild/mozbuild/code_analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code_analysis/mach_commands.py @@ -203,7 +203,7 @@ class StaticAnalysis(MachCommandBase): category="testing", description="Run C++ static analysis checks", ) - def static_analysis(self): + def static_analysis(self, command_context): # If no arguments are provided, just print a help message. """Detailed documentation: https://firefox-source-docs.mozilla.org/code-quality/static-analysis.html @@ -289,6 +289,7 @@ class StaticAnalysis(MachCommandBase): ) def check( self, + command_context, source=None, jobs=2, strip=1, @@ -453,6 +454,7 @@ class StaticAnalysis(MachCommandBase): ) def check_coverity( self, + command_context, source=[], output=None, coverity_output_path=None, @@ -1049,6 +1051,7 @@ class StaticAnalysis(MachCommandBase): @CommandArgument("--output", default=None, help="Write infer json output in a file") def check_java( self, + command_context, source=["mobile"], jobs=2, strip=1, @@ -1424,7 +1427,12 @@ class StaticAnalysis(MachCommandBase): help="Checkers that are going to be auto-tested.", ) def autotest( - self, verbose=False, dump_results=False, intree_tool=False, checker_names=[] + self, + command_context, + verbose=False, + dump_results=False, + intree_tool=False, + checker_names=[], ): # If 'dump_results' is True than we just want to generate the issues files for each # checker in particulat and thus 'force_download' becomes 'False' since we want to @@ -1983,6 +1991,7 @@ class StaticAnalysis(MachCommandBase): ) def install( self, + command_context, source=None, skip_cache=False, force=False, @@ -2004,7 +2013,7 @@ class StaticAnalysis(MachCommandBase): "clear-cache", "Delete local helpers and reset static analysis helper tool cache", ) - def clear_cache(self, verbose=False): + def clear_cache(self, command_context, verbose=False): self._set_log_level(verbose) rc = self._get_clang_tools( force=True, download_if_needed=True, skip_cache=True, verbose=verbose @@ -2028,7 +2037,7 @@ class StaticAnalysis(MachCommandBase): "print-checks", "Print a list of the static analysis checks performed by default", ) - def print_checks(self, verbose=False): + def print_checks(self, command_context, verbose=False): self._set_log_level(verbose) rc = self._get_clang_tools(verbose=verbose) @@ -2080,7 +2089,7 @@ class StaticAnalysis(MachCommandBase): "When reading from stdin, Prettier assumes this " "filename to decide which style and parser to use.", ) - def prettier_format(self, path, assume_filename): + def prettier_format(self, command_context, path, assume_filename): # With assume_filename we want to have stdout clean since the result of the # format will be redirected to stdout. @@ -2115,7 +2124,7 @@ class StaticAnalysis(MachCommandBase): @CommandArgument( "source", nargs="*", help="Source files to be compiled checked (regex on path)." ) - def check_syntax(self, source, verbose=False): + def check_syntax(self, command_context, source, verbose=False): self._set_log_level(verbose) self.log_manager.enable_unstructured() @@ -2276,6 +2285,7 @@ class StaticAnalysis(MachCommandBase): ) def clang_format( self, + command_context, assume_filename, path, commit, @@ -2492,7 +2502,7 @@ class StaticAnalysis(MachCommandBase): return (1, None, None) os.environ["AUTOCLOBBER"] = "1" - rc = builder.configure() + rc = builder.configure(self) if rc != 0: return (rc, config, ran_configure) ran_configure = True @@ -2530,7 +2540,9 @@ class StaticAnalysis(MachCommandBase): "created yet, creating it now..." ) builder = Build(self._mach_context, None) - rc = builder.build_backend(["StaticAnalysis"], verbose=verbose) + rc = builder.build_backend( + self._mach_context, ["StaticAnalysis"], verbose=verbose + ) if rc != 0: return rc assert os.path.exists(self._compile_db) diff --git a/python/mozbuild/mozbuild/compilation/codecomplete.py b/python/mozbuild/mozbuild/compilation/codecomplete.py index cf82612a138e..f2e9c35fd254 100644 --- a/python/mozbuild/mozbuild/compilation/codecomplete.py +++ b/python/mozbuild/mozbuild/compilation/codecomplete.py @@ -31,7 +31,7 @@ class Introspection(MachCommandBase): @CommandArgument( "what", default=None, help="Source file to display compilation flags for" ) - def compileflags(self, what): + def compileflags(self, command_context, what): from mozbuild.util import resolve_target_to_make from mozbuild.compilation import util diff --git a/python/mozbuild/mozbuild/frontend/mach_commands.py b/python/mozbuild/mozbuild/frontend/mach_commands.py index 385151595f75..a06199c318a3 100644 --- a/python/mozbuild/mozbuild/frontend/mach_commands.py +++ b/python/mozbuild/mozbuild/frontend/mach_commands.py @@ -46,7 +46,7 @@ class MozbuildFileCommands(MachCommandBase): action="store_true", help="Print symbol names only.", ) - def reference(self, symbol, name_only=False): + def reference(self, command_context, symbol, name_only=False): # mozbuild.sphinx imports some Sphinx modules, so we need to be sure # the optional Sphinx package is installed. self.activate_virtualenv() @@ -101,7 +101,7 @@ class MozbuildFileCommands(MachCommandBase): @Command( "file-info", category="build-dev", description="Query for metadata about files." ) - def file_info(self): + def file_info(self, command_context): """Show files metadata derived from moz.build files. moz.build files contain "Files" sub-contexts for declaring metadata @@ -124,7 +124,7 @@ class MozbuildFileCommands(MachCommandBase): dest="fmt", ) @CommandArgument("paths", nargs="+", help="Paths whose data to query") - def file_info_bugzilla(self, paths, rev=None, fmt=None): + def file_info_bugzilla(self, command_context, paths, rev=None, fmt=None): """Show Bugzilla component for a set of files. Given a requested set of files (which can be specified using @@ -180,7 +180,7 @@ class MozbuildFileCommands(MachCommandBase): help="Output format", ) @CommandArgument("paths", nargs="+", help="Paths whose data to query") - def file_info_missing_bugzilla(self, paths, rev=None, fmt=None): + def file_info_missing_bugzilla(self, command_context, paths, rev=None, fmt=None): missing = set() try: @@ -207,7 +207,7 @@ class MozbuildFileCommands(MachCommandBase): "Perform Bugzilla metadata analysis as required for automation", ) @CommandArgument("out_dir", help="Where to write files") - def bugzilla_automation(self, out_dir): + def bugzilla_automation(self, command_context, out_dir): """Analyze and validate Bugzilla metadata as required by automation. This will write out JSON and gzipped JSON files for Bugzilla metadata. @@ -337,7 +337,7 @@ class MozbuildFileCommands(MachCommandBase): "file-info", "schedules", "Show the combined SCHEDULES for the files listed." ) @CommandArgument("paths", nargs="+", help="Paths whose data to query") - def file_info_schedules(self, paths): + def file_info_schedules(self, command_context, paths): """Show what is scheduled by the given files. Given a requested set of files (which can be specified using diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index d9432eff6842..aa34444b9b32 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -83,9 +83,8 @@ class Watch(MachCommandBase): action="store_true", help="Verbose output for what commands the watcher is running.", ) - def watch(self, verbose=False): + def watch(self, command_context, verbose=False): """Watch and re-build (parts of) the source tree.""" - if not conditions.is_artifact_build(self): print( "WARNING: mach watch only rebuilds the `mach build faster` parts of the tree!" @@ -124,7 +123,7 @@ class CargoProvider(MachCommandBase): """Invoke cargo in useful ways.""" @Command("cargo", category="build", description="Invoke cargo in useful ways.") - def cargo(self): + def cargo(self, command_context): self._sub_mach(["help", "cargo"]) return 1 @@ -152,7 +151,9 @@ class CargoProvider(MachCommandBase): help="Run the tests in parallel using multiple processes.", ) @CommandArgument("-v", "--verbose", action="store_true", help="Verbose output.") - def check(self, all_crates=None, crates=None, jobs=0, verbose=False): + def check( + self, command_context, all_crates=None, crates=None, jobs=0, verbose=False + ): # XXX duplication with `mach vendor rust` crates_and_roots = { "gkrust": "toolkit/library/rust", @@ -208,7 +209,7 @@ class Doctor(MachCommandBase): action="store_true", help="Attempt to fix found problems.", ) - def doctor(self, fix=None): + def doctor(self, command_context, fix=None): self.activate_virtualenv() from mozbuild.doctor import Doctor @@ -234,7 +235,7 @@ class Clobber(MachCommandBase): "objdir and python).".format(", ".join(CLOBBER_CHOICES)), ) @CommandArgument("--full", action="store_true", help="Perform a full clobber") - def clobber(self, what, full=False): + def clobber(self, command_context, what, full=False): """Clean up the source and object directories. Performing builds and running various commands generate various files. @@ -357,7 +358,7 @@ class Logs(MachCommandBase): help="Filename to read log data from. Defaults to the log of the last " "mach command.", ) - def show_log(self, log_file=None): + def show_log(self, command_context, log_file=None): if not log_file: path = self._get_state_filename("last_log.json") log_file = open(path, "rb") @@ -446,7 +447,7 @@ class Warnings(MachCommandBase): help="Warnings report to display. If not defined, show the most " "recent report.", ) - def summary(self, directory=None, report=None): + def summary(self, command_context, directory=None, report=None): database = self.database if directory: @@ -487,7 +488,7 @@ class Warnings(MachCommandBase): help="Warnings report to display. If not defined, show the most " "recent report.", ) - def list(self, directory=None, flags=None, report=None): + def list(self, command_context, directory=None, flags=None, report=None): database = self.database by_name = sorted(database.warnings) @@ -645,6 +646,7 @@ class GTestCommands(MachCommandBase): ) def gtest( self, + command_context, shuffle, jobs, gtest_filter, @@ -876,7 +878,7 @@ class Package(MachCommandBase): action="store_true", help="Verbose output for what commands the packaging process is running.", ) - def package(self, verbose=False): + def package(self, command_context, verbose=False): ret = self._run_make( directory=".", target="package", silent=not verbose, ensure_exit_code=False ) @@ -919,7 +921,7 @@ class Install(MachCommandBase): parser=setup_install_parser, description="Install the package on the machine (or device in the case of Android).", ) - def install(self, **kwargs): + def install(self, command_context, **kwargs): if conditions.is_android(self): from mozrunner.devices.android_device import ( verify_android_device, @@ -1228,7 +1230,7 @@ class RunProgram(MachCommandBase): parser=setup_run_parser, description="Run the compiled program, possibly under a debugger or DMD.", ) - def run(self, **kwargs): + def run(self, command_context, **kwargs): if conditions.is_android(self): return self._run_android(**kwargs) if conditions.is_jsshell(self): @@ -1838,7 +1840,7 @@ class Buildsymbols(MachCommandBase): category="post-build", description="Produce a package of Breakpad-format symbols.", ) - def buildsymbols(self): + def buildsymbols(self, command_context): return self._run_make( directory=".", target="buildsymbols", ensure_exit_code=False ) @@ -1861,7 +1863,7 @@ class MachDebug(MachCommandBase): @CommandArgument( "--verbose", "-v", action="store_true", help="Print verbose output." ) - def environment(self, format, output=None, verbose=False): + def environment(self, command_context, format, output=None, verbose=False): func = getattr(self, "_environment_%s" % format.replace(".", "_")) if output: @@ -1968,7 +1970,7 @@ class Repackage(MachCommandBase): ) @CommandArgument("--input", "-i", type=str, required=True, help="Input filename") @CommandArgument("--output", "-o", type=str, required=True, help="Output filename") - def repackage_dmg(self, input, output): + def repackage_dmg(self, command_context, input, output): if not os.path.exists(input): print("Input file does not exist: %s" % input) return 1 @@ -2022,7 +2024,15 @@ class Repackage(MachCommandBase): help="Run UPX on the self-extraction stub.", ) def repackage_installer( - self, tag, setupexe, package, output, package_name, sfx_stub, use_upx + self, + command_context, + tag, + setupexe, + package, + output, + package_name, + sfx_stub, + use_upx, ): from mozbuild.repackaging.installer import repackage_installer @@ -2065,7 +2075,16 @@ class Repackage(MachCommandBase): ) @CommandArgument("--output", "-o", type=str, required=True, help="Output filename") def repackage_msi( - self, wsx, version, locale, arch, setupexe, candle, light, output + self, + command_context, + wsx, + version, + locale, + arch, + setupexe, + candle, + light, + output, ): from mozbuild.repackaging.msi import repackage_msi @@ -2089,7 +2108,7 @@ class Repackage(MachCommandBase): "--arch", type=str, required=True, help="The archtecture you are building." ) @CommandArgument("--mar-channel-id", type=str, help="Mar channel id") - def repackage_mar(self, input, mar, output, arch, mar_channel_id): + def repackage_mar(self, command_context, input, mar, output, arch, mar_channel_id): from mozbuild.repackaging.mar import repackage_mar repackage_mar( @@ -2120,7 +2139,7 @@ class L10NCommands(MachCommandBase): @CommandArgument( "--verbose", action="store_true", help="Log informative status messages." ) - def package_l10n(self, verbose=False, locales=[]): + def package_l10n(self, command_context, verbose=False, locales=[]): if "RecursiveMake" not in self.substs["BUILD_BACKENDS"]: print( "Artifact builds do not support localization. " @@ -2258,7 +2277,7 @@ class CreateMachEnvironment(MachCommandBase): action="store_true", help=("Force re-creating the virtualenv even if it is already " "up-to-date."), ) - def create_mach_environment(self, force=False): + def create_mach_environment(self, command_context, force=False): from mozboot.util import get_mach_virtualenv_root from mozbuild.virtualenv import VirtualenvManager diff --git a/python/mozbuild/mozbuild/vendor/mach_commands.py b/python/mozbuild/mozbuild/vendor/mach_commands.py index 0818ba5af40f..67bff6e5717c 100644 --- a/python/mozbuild/mozbuild/vendor/mach_commands.py +++ b/python/mozbuild/mozbuild/vendor/mach_commands.py @@ -51,6 +51,7 @@ class Vendor(MachCommandBase): ) def vendor( self, + command_context, library, revision, ignore_modified=False, @@ -138,7 +139,7 @@ Please commit or stash these changes before vendoring, or re-run with `--ignore- ), default=False, ) - def vendor_rust(self, **kwargs): + def vendor_rust(self, command_context, **kwargs): from mozbuild.vendor.vendor_rust import VendorRust vendor_command = self._spawn(VendorRust) @@ -167,7 +168,7 @@ Please commit or stash these changes before vendoring, or re-run with `--ignore- "then Pipfile.lock will be regenerated. Note that transient dependencies " "may be updated when running this command.", ) - def vendor_python(self, **kwargs): + def vendor_python(self, command_context, **kwargs): from mozbuild.vendor.vendor_python import VendorPython vendor_command = self._spawn(VendorPython) diff --git a/python/mozperftest/mozperftest/mach_commands.py b/python/mozperftest/mozperftest/mach_commands.py index 4651e02c5b9f..b0a93739a2de 100644 --- a/python/mozperftest/mozperftest/mach_commands.py +++ b/python/mozperftest/mozperftest/mach_commands.py @@ -42,7 +42,7 @@ class Perftest(MachCommandBase): description="Run any flavor of perftest", parser=get_perftest_parser, ) - def run_perftest(self, **kwargs): + def run_perftest(self, command_context, **kwargs): # original parser that brought us there original_parser = self.get_parser() @@ -185,7 +185,7 @@ class PerftestTests(MachCommandBase): default=False, help="Verbose mode", ) - def run_tests(self, **kwargs): + def run_tests(self, command_context, **kwargs): MachCommandBase.activate_virtualenv(self) from pathlib import Path diff --git a/python/mozperftest/mozperftest/tests/test_mach_commands.py b/python/mozperftest/mozperftest/tests/test_mach_commands.py index 2975b47a9bdf..cb5de9e9e30d 100644 --- a/python/mozperftest/mozperftest/tests/test_mach_commands.py +++ b/python/mozperftest/mozperftest/tests/test_mach_commands.py @@ -61,9 +61,9 @@ def _get_command(klass=Perftest): # used to make arguments passed by the test as # being set by the user. def _run_perftest(func): - def _run(**kwargs): + def _run(command_context, **kwargs): parser.set_by_user = list(kwargs.keys()) - return func(**kwargs) + return func(command_context, **kwargs) return _run @@ -84,7 +84,7 @@ def _get_command(klass=Perftest): @mock.patch("mozperftest.mach_commands.MachCommandBase.activate_virtualenv") def test_command(mocked_func): with _get_command() as test, silence(test): - test.run_perftest(tests=[EXAMPLE_TEST], flavor="desktop-browser") + test.run_perftest(test, tests=[EXAMPLE_TEST], flavor="desktop-browser") @mock.patch("mozperftest.MachEnvironment") @@ -96,7 +96,7 @@ def test_command_iterations(venv, env): "flavor": "desktop-browser", } with _get_command() as test, silence(test): - test.run_perftest(**kwargs) + test.run_perftest(test, **kwargs) # the hook changes the iteration value to 5. # each iteration generates 5 calls, so we want to see 25 assert len(env.mock_calls) == 25 @@ -111,7 +111,7 @@ def test_hooks_state(venv, env): "flavor": "desktop-browser", } with _get_command() as test, silence(test): - test.run_perftest(**kwargs) + test.run_perftest(test, **kwargs) @mock.patch("mozperftest.MachEnvironment", new=_TestMachEnvironment) @@ -120,6 +120,7 @@ def test_hooks_state(venv, env): def test_push_command(push_to_try, venv): with _get_command() as test, silence(test): test.run_perftest( + test, tests=[EXAMPLE_TEST], flavor="desktop-browser", push_to_try=True, @@ -136,6 +137,7 @@ def test_push_command_unknown_platforms(push_to_try, venv): # full stop when a platform is unknown with _get_command() as test, pytest.raises(NotImplementedError): test.run_perftest( + test, tests=[EXAMPLE_TEST], flavor="desktop-browser", push_to_try=True, @@ -149,6 +151,7 @@ def test_push_command_unknown_platforms(push_to_try, venv): def test_push_command_several_platforms(push_to_try, venv): with running_on_try(False), _get_command() as test: # , silence(test): test.run_perftest( + test, tests=[EXAMPLE_TEST], flavor="desktop-browser", push_to_try=True, @@ -165,7 +168,7 @@ def test_push_command_several_platforms(push_to_try, venv): @mock.patch("mozperftest.mach_commands.MachCommandBase.activate_virtualenv") def test_doc_flavor(mocked_func): with _get_command() as test, silence(test): - test.run_perftest(tests=[EXAMPLE_TEST], flavor="doc") + test.run_perftest(test, tests=[EXAMPLE_TEST], flavor="doc") @mock.patch("mozperftest.MachEnvironment", new=_TestMachEnvironment) @@ -173,7 +176,7 @@ def test_doc_flavor(mocked_func): @mock.patch("mozperftest.utils.run_script") def test_test_runner(*mocked): with running_on_try(False), _get_command(PerftestTests) as test: - test.run_tests(tests=[EXAMPLE_TEST], verbose=True) + test.run_tests(test, tests=[EXAMPLE_TEST], verbose=True) @mock.patch("mozperftest.MachEnvironment", new=_TestMachEnvironment) @@ -182,7 +185,7 @@ def test_test_runner(*mocked): def test_test_runner_on_try(*mocked): # simulating on try to run the paths parser with running_on_try(), _get_command(PerftestTests) as test: - test.run_tests(tests=[EXAMPLE_TEST]) + test.run_tests(test, tests=[EXAMPLE_TEST]) @mock.patch("mozperftest.MachEnvironment", new=_TestMachEnvironment) @@ -194,7 +197,7 @@ def test_test_runner_coverage(*mocked): old = list(sys.meta_path) sys.meta_path = [] try: - test.run_tests(tests=[EXAMPLE_TEST]) + test.run_tests(test, tests=[EXAMPLE_TEST]) finally: sys.meta_path = old @@ -225,7 +228,7 @@ def resolve_tests(tests=None): @mock.patch("moztest.resolve.TestResolver.resolve_tests", new=resolve_tests()) def test_fzf_flavor(*mocked): with running_on_try(False), _get_command() as test: # , silence(): - test.run_perftest(flavor="desktop-browser") + test.run_perftest(test, flavor="desktop-browser") @mock.patch("mozperftest.MachEnvironment", new=_TestMachEnvironment) @@ -234,7 +237,7 @@ def test_fzf_flavor(*mocked): @mock.patch("moztest.resolve.TestResolver.resolve_tests", new=resolve_tests([])) def test_fzf_nothing_selected(*mocked): with running_on_try(False), _get_command() as test, silence(): - test.run_perftest(flavor="desktop-browser") + test.run_perftest(test, flavor="desktop-browser") if __name__ == "__main__": diff --git a/python/mozrelease/mozrelease/mach_commands.py b/python/mozrelease/mozrelease/mach_commands.py index 14bda59489dd..de3320b66400 100644 --- a/python/mozrelease/mozrelease/mach_commands.py +++ b/python/mozrelease/mozrelease/mach_commands.py @@ -28,7 +28,7 @@ class MachCommands(MachCommandBase): category="release", description="Task that are part of the release process.", ) - def release(self): + def release(self, command_context): """ The release subcommands all relate to the release process. """ @@ -47,7 +47,7 @@ class MachCommands(MachCommandBase): @CommandArgument("--product", required=True, help="The product being built.") @CommandArgument("--repo", help="The repo being built.") @CommandArgument("--revision", required=True, help="The revision being built.") - def buglist(self, version, product, revision, repo): + def buglist(self, command_context, version, product, revision, repo): self.setup_logging() from mozrelease.buglist_creator import create_bugs_url @@ -84,7 +84,7 @@ class MachCommands(MachCommandBase): @CommandArgument("--revision", required=True, help="The revision being built.") @CommandArgument("--build-number", required=True, help="The build number") @CommandArgument("--task-group-id", help="The task group of the build.") - def buglist_email(self, **options): + def buglist_email(self, command_context, **options): self.setup_logging() from mozrelease.buglist_creator import email_release_drivers @@ -115,7 +115,9 @@ class MachCommands(MachCommandBase): required=False, help="Taskcluster secret with ssh-key to use for hg.mozilla.org", ) - def push_scriptworker_canary(self, scriptworkers, addresses, ssh_key_secret): + def push_scriptworker_canary( + self, command_context, scriptworkers, addresses, ssh_key_secret + ): self.setup_logging() from mozrelease.scriptworker_canary import push_canary diff --git a/remote/mach_commands.py b/remote/mach_commands.py index 64a79217002c..b5a0bb4d530c 100644 --- a/remote/mach_commands.py +++ b/remote/mach_commands.py @@ -61,7 +61,7 @@ class RemoteCommands(MachCommandBase): @Command( "remote", category="misc", description="Remote protocol related operations." ) - def remote(self): + def remote(self, command_context): """The remote subcommands all relate to the remote protocol.""" self._sub_mach(["help", "remote"]) return 1 @@ -88,7 +88,7 @@ class RemoteCommands(MachCommandBase): default=True, help="Do not install the just-pulled Puppeteer package,", ) - def vendor_puppeteer(self, repository, commitish, install): + def vendor_puppeteer(self, command_context, repository, commitish, install): puppeteer_dir = os.path.join(self.remotedir, "test", "puppeteer") # Preserve our custom mocha reporter @@ -587,6 +587,7 @@ class PuppeteerTest(MachCommandBase): ) def puppeteer_test( self, + command_context, binary=None, ci=False, enable_fission=False, diff --git a/taskcluster/mach_commands.py b/taskcluster/mach_commands.py index e62c0151f1a3..aaf084b80692 100644 --- a/taskcluster/mach_commands.py +++ b/taskcluster/mach_commands.py @@ -339,7 +339,7 @@ class MachCommands(MachCommandBase): default=argparse.SUPPRESS, help="Kinds that should not be re-used from the on-push graph.", ) - def taskgraph_decision(self, **options): + def taskgraph_decision(self, command_context, **options): """Run the decision task: generate a task graph and submit to TaskCluster. This is only meant to be called within decision tasks, and requires a great many arguments. Commands like `mach taskgraph @@ -380,7 +380,7 @@ class MachCommands(MachCommandBase): "cron", description="Provide a pointer to the new `.cron.yml` handler.", ) - def taskgraph_cron(self, **options): + def taskgraph_cron(self, command_context, **options): print( 'Handling of ".cron.yml" files has move to ' "https://hg.mozilla.org/ci/ci-admin/file/default/build-decision." @@ -398,7 +398,7 @@ class MachCommands(MachCommandBase): default="taskcluster/ci", help="root of the taskgraph definition relative to topsrcdir", ) - def action_callback(self, **options): + def action_callback(self, command_context, **options): from taskgraph.actions import trigger_action_callback from taskgraph.actions.util import get_parameters @@ -456,7 +456,7 @@ class MachCommands(MachCommandBase): @CommandArgument( "callback", default=None, help="Action callback name (Python function name)" ) - def test_action_callback(self, **options): + def test_action_callback(self, command_context, **options): import taskgraph.actions import taskgraph.parameters from taskgraph.util import yaml @@ -714,7 +714,7 @@ class TaskClusterImagesProvider(MachCommandBase): "contents of the tree (as built for mozilla-central " "or mozilla-inbound)", ) - def load_image(self, image_name, task_id, tag): + def load_image(self, command_context, image_name, task_id, tag): from taskgraph.docker import load_image_by_name, load_image_by_task_id if not image_name and not task_id: @@ -744,7 +744,7 @@ class TaskClusterImagesProvider(MachCommandBase): "with this option it will only build the context.tar.", metavar="context.tar", ) - def build_image(self, image_name, tag, context_only): + def build_image(self, command_context, image_name, tag, context_only): from taskgraph.docker import build_context, build_image try: @@ -773,7 +773,7 @@ class TaskClusterPartialsData(MachCommandBase): @CommandArgument( "--product", default="Firefox", help="The product identifier, such as 'Firefox'" ) - def generate_partials_builds(self, product, branch): + def generate_partials_builds(self, command_context, product, branch): from taskgraph.util.partials import populate_release_history try: diff --git a/testing/awsy/mach_commands.py b/testing/awsy/mach_commands.py index 1ca974bb0acc..ae9bd46c52bf 100644 --- a/testing/awsy/mach_commands.py +++ b/testing/awsy/mach_commands.py @@ -307,7 +307,7 @@ class MachCommands(MachCommandBase): default=False, help="Use the tp6 pageset during testing.", ) - def run_awsy_test(self, tests, **kwargs): + def run_awsy_test(self, command_context, tests, **kwargs): """mach awsy-test runs the in-tree version of the Are We Slim Yet (AWSY) tests. diff --git a/testing/condprofile/mach_commands.py b/testing/condprofile/mach_commands.py index df70f1005fae..39fc17ff54e4 100644 --- a/testing/condprofile/mach_commands.py +++ b/testing/condprofile/mach_commands.py @@ -36,6 +36,7 @@ class CondprofileCommandProvider(MachCommandBase): ) def fetch( self, + command_context, target_dir, platform, scenario, @@ -88,7 +89,7 @@ class CondprofileCommandProvider(MachCommandBase): default=sys.platform.startswith("win") and "geckodriver.exe" or "geckodriver", ) @CommandArgument("--device-name", help="Name of the device", type=str, default=None) - def run(self, **kw): + def run(self, command_context, **kw): os.environ["MANUAL_MACH_RUN"] = "1" self._init() diff --git a/testing/firefox-ui/mach_commands.py b/testing/firefox-ui/mach_commands.py index 56edef080eef..5b38d4127da3 100644 --- a/testing/firefox-ui/mach_commands.py +++ b/testing/firefox-ui/mach_commands.py @@ -98,7 +98,7 @@ class MachCommands(MachCommandBase): description="Run the functional test suite of Firefox UI tests.", parser=setup_argument_parser_functional, ) - def run_firefox_ui_functional(self, **kwargs): + def run_firefox_ui_functional(self, command_context, **kwargs): try: kwargs["binary"] = kwargs["binary"] or self.get_binary_path("app") except BinaryNotFoundException as e: diff --git a/testing/geckodriver/mach_commands.py b/testing/geckodriver/mach_commands.py index bf5fe594e33d..ee55e61893f4 100644 --- a/testing/geckodriver/mach_commands.py +++ b/testing/geckodriver/mach_commands.py @@ -55,7 +55,7 @@ class GeckoDriver(MachCommandBase): help="Flags to pass to the debugger itself; " "split as the Bourne shell would.", ) - def run(self, binary, params, debug, debugger, debugger_args): + def run(self, command_context, binary, params, debug, debugger, debugger_args): try: binpath = self.get_binary_path("geckodriver") except BinaryNotFoundException as e: diff --git a/testing/gtest/mach_test_package_commands.py b/testing/gtest/mach_test_package_commands.py index a837f070b644..d9ff70c2a261 100644 --- a/testing/gtest/mach_test_package_commands.py +++ b/testing/gtest/mach_test_package_commands.py @@ -127,7 +127,7 @@ class GtestCommands(MachCommandBase): description="Run the gtest harness.", parser=setup_argument_parser, ) - def gtest(self, **kwargs): + def gtest(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() result = run_gtest(self._mach_context, **kwargs) return 0 if result else 1 diff --git a/testing/mach_commands.py b/testing/mach_commands.py index da226e41e3ff..983f6f85f00b 100644 --- a/testing/mach_commands.py +++ b/testing/mach_commands.py @@ -170,6 +170,7 @@ class AddTest(MachCommandBase): ) def addtest( self, + command_context, suite=None, test=None, doc=None, @@ -351,7 +352,7 @@ class Test(MachCommandBase): description="Run tests (detects the kind of test and runs it).", parser=get_test_parser, ) - def test(self, what, extra_args, **log_args): + def test(self, command_context, what, extra_args, **log_args): """Run tests from names or paths. mach test accepts arguments specifying which tests to run. Each argument @@ -724,7 +725,9 @@ class CramTest(MachCommandBase): help="Extra arguments to pass down to the cram binary. See " "'./mach python -m cram -- -h' for a list of available options.", ) - def cramtest(self, cram_args=None, test_paths=None, test_objects=None): + def cramtest( + self, command_context, cram_args=None, test_paths=None, test_objects=None + ): self.activate_virtualenv() import mozinfo from manifestparser import TestManifest diff --git a/testing/marionette/mach_commands.py b/testing/marionette/mach_commands.py index 8f3c009ff59b..7e9f57bd9488 100644 --- a/testing/marionette/mach_commands.py +++ b/testing/marionette/mach_commands.py @@ -72,7 +72,7 @@ class MarionetteTest(MachCommandBase): conditions=[functools.partial(conditions.is_buildapp_in, apps=SUPPORTED_APPS)], parser=create_parser_tests, ) - def marionette_test(self, tests, **kwargs): + def marionette_test(self, command_context, tests, **kwargs): if "test_objects" in kwargs: tests = [] for obj in kwargs["test_objects"]: diff --git a/testing/marionette/mach_test_package_commands.py b/testing/marionette/mach_test_package_commands.py index ad0328b2abda..0a13a1c2c8dc 100644 --- a/testing/marionette/mach_test_package_commands.py +++ b/testing/marionette/mach_test_package_commands.py @@ -70,6 +70,6 @@ class MachCommands(MachCommandBase): "using marionette).", parser=setup_marionette_argument_parser, ) - def run_marionette_test(self, **kwargs): + def run_marionette_test(self, command_context, **kwargs): self.context.activate_mozharness_venv() return run_marionette(self.context, **kwargs) diff --git a/testing/mochitest/mach_commands.py b/testing/mochitest/mach_commands.py index 41458c179413..6f69128c8803 100644 --- a/testing/mochitest/mach_commands.py +++ b/testing/mochitest/mach_commands.py @@ -307,7 +307,12 @@ class MachCommands(MachCommandBase): parser=setup_argument_parser, ) def run_mochitest_general( - self, flavor=None, test_objects=None, resolve_tests=True, **kwargs + self, + command_context, + flavor=None, + test_objects=None, + resolve_tests=True, + **kwargs ): from mochitest_options import ALL_FLAVORS from mozlog.commandline import setup_logging @@ -531,7 +536,7 @@ class GeckoviewJunitCommands(MachCommandBase): action="store_true", default=False, ) - def run_junit(self, no_install, **kwargs): + def run_junit(self, command_context, no_install, **kwargs): self._ensure_state_subdir_exists(".") from mozrunner.devices.android_device import ( diff --git a/testing/mochitest/mach_test_package_commands.py b/testing/mochitest/mach_test_package_commands.py index 7ded92247d7e..20228cc20f09 100644 --- a/testing/mochitest/mach_test_package_commands.py +++ b/testing/mochitest/mach_test_package_commands.py @@ -201,7 +201,7 @@ class MochitestCommands(MachCommandBase): description="Run the mochitest harness.", parser=setup_mochitest_argument_parser, ) - def mochitest(self, **kwargs): + def mochitest(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() return run_test(self._mach_context, False, **kwargs) @@ -211,6 +211,6 @@ class MochitestCommands(MachCommandBase): description="Run the geckoview-junit harness.", parser=setup_junit_argument_parser, ) - def geckoview_junit(self, **kwargs): + def geckoview_junit(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() return run_test(self._mach_context, True, **kwargs) diff --git a/testing/mozharness/mach_commands.py b/testing/mozharness/mach_commands.py index 5f1c0994a415..c1938cbbfa10 100644 --- a/testing/mozharness/mach_commands.py +++ b/testing/mozharness/mach_commands.py @@ -216,6 +216,6 @@ class MozharnessCommands(MachCommandBase): conditions=[conditions.is_firefox_or_android], parser=get_parser, ) - def mozharness(self, **kwargs): + def mozharness(self, command_context, **kwargs): runner = self._spawn(MozharnessRunner) return runner.run_suite(kwargs.pop("suite_name")[0], **kwargs) diff --git a/testing/raptor/mach_commands.py b/testing/raptor/mach_commands.py index d2b63cdac35f..d94c0459bfb3 100644 --- a/testing/raptor/mach_commands.py +++ b/testing/raptor/mach_commands.py @@ -305,7 +305,7 @@ class MachRaptor(MachCommandBase): description="Run Raptor performance tests.", parser=create_parser, ) - def run_raptor(self, **kwargs): + def run_raptor(self, command_context, **kwargs): # Defers this import so that a transitive dependency doesn't # stop |mach bootstrap| from running from raptor.power import enable_charging, disable_charging @@ -381,5 +381,5 @@ class MachRaptor(MachCommandBase): description="Run Raptor performance tests.", parser=create_parser, ) - def run_raptor_test(self, **kwargs): + def run_raptor_test(self, command_context, **kwargs): return self.run_raptor(**kwargs) diff --git a/testing/talos/mach_commands.py b/testing/talos/mach_commands.py index 3ac68f11f863..bd0b19673f98 100644 --- a/testing/talos/mach_commands.py +++ b/testing/talos/mach_commands.py @@ -131,7 +131,7 @@ class MachCommands(MachCommandBase): description="Run talos tests (performance testing).", parser=create_parser, ) - def run_talos_test(self, **kwargs): + def run_talos_test(self, command_context, **kwargs): talos = self._spawn(TalosRunner) try: diff --git a/testing/tps/mach_commands.py b/testing/tps/mach_commands.py index d389cac4623a..4e25696aecef 100644 --- a/testing/tps/mach_commands.py +++ b/testing/tps/mach_commands.py @@ -17,7 +17,7 @@ class MachCommands(MachCommandBase): @Command("tps-build", category="testing", description="Build TPS add-on.") @CommandArgument("--dest", default=None, help="Where to write add-on.") - def build(self, dest): + def build(self, command_context, dest): src = os.path.join( self.topsrcdir, "services", "sync", "tps", "extensions", "tps" ) diff --git a/testing/web-platform/mach_commands.py b/testing/web-platform/mach_commands.py index 333425c16bf9..478f1352fa9e 100644 --- a/testing/web-platform/mach_commands.py +++ b/testing/web-platform/mach_commands.py @@ -480,7 +480,7 @@ class MachCommands(MachCommandBase): description="Run web-platform-tests.", parser=create_parser_wpt, ) - def run_web_platform_tests(self, **params): + def run_web_platform_tests(self, command_context, **params): self.setup() if params["product"] is None: if conditions.is_android(self): @@ -523,7 +523,7 @@ class MachCommands(MachCommandBase): description="Run web-platform-tests.", parser=create_parser_wpt, ) - def run_wpt(self, **params): + def run_wpt(self, command_context, **params): return self.run_web_platform_tests(**params) @Command( @@ -532,7 +532,7 @@ class MachCommands(MachCommandBase): description="Update web-platform-test metadata.", parser=create_parser_update, ) - def update_web_platform_tests(self, **params): + def update_web_platform_tests(self, command_context, **params): self.setup() self.virtualenv_manager.install_pip_package("html5lib==1.0.1") self.virtualenv_manager.install_pip_package("ujson") @@ -548,7 +548,7 @@ class MachCommands(MachCommandBase): description="Update web-platform-test metadata.", parser=create_parser_update, ) - def update_wpt(self, **params): + def update_wpt(self, command_context, **params): return self.update_web_platform_tests(**params) @Command( @@ -557,7 +557,7 @@ class MachCommands(MachCommandBase): description="Update web-platform-test manifests.", parser=create_parser_manifest_update, ) - def wpt_manifest_update(self, **params): + def wpt_manifest_update(self, command_context, **params): self.setup() wpt_setup = self._spawn(WebPlatformTestsRunnerSetup) wpt_runner = WebPlatformTestsRunner(wpt_setup) @@ -574,7 +574,7 @@ class MachCommands(MachCommandBase): description="Run the wpt server", parser=create_parser_serve, ) - def wpt_serve(self, **params): + def wpt_serve(self, command_context, **params): self.setup() import logging @@ -589,7 +589,7 @@ class MachCommands(MachCommandBase): description="Create a json summary of the wpt metadata", parser=create_parser_metadata_summary, ) - def wpt_summary(self, **params): + def wpt_summary(self, command_context, **params): import metasummary wpt_setup = self._spawn(WebPlatformTestsRunnerSetup) @@ -598,7 +598,7 @@ class MachCommands(MachCommandBase): @Command( "wpt-metadata-merge", category="testing", parser=create_parser_metadata_merge ) - def wpt_meta_merge(self, **params): + def wpt_meta_merge(self, command_context, **params): import metamerge if params["dest"] is None: @@ -611,7 +611,7 @@ class MachCommands(MachCommandBase): description="Run the wpt tools and wptrunner unit tests", parser=create_parser_unittest, ) - def wpt_unittest(self, **params): + def wpt_unittest(self, command_context, **params): self.setup() self.virtualenv_manager.install_pip_package("tox") runner = self._spawn(WebPlatformTestsUnittestRunner) @@ -623,7 +623,7 @@ class MachCommands(MachCommandBase): description="Get a mapping from test ids to files", parser=create_parser_testpaths, ) - def wpt_test_paths(self, **params): + def wpt_test_paths(self, command_context, **params): runner = self._spawn(WebPlatformTestsTestPathsRunner) runner.run(**params) return 0 @@ -634,7 +634,7 @@ class MachCommands(MachCommandBase): description="Dump a list of fission-specific regressions", parser=create_parser_fission_regressions, ) - def wpt_fission_regressions(self, **params): + def wpt_fission_regressions(self, command_context, **params): runner = self._spawn(WebPlatformTestsFissionRegressionsRunner) runner.run(**params) return 0 diff --git a/testing/web-platform/mach_test_package_commands.py b/testing/web-platform/mach_test_package_commands.py index e64bc3b0a86b..d6b3815a279d 100644 --- a/testing/web-platform/mach_test_package_commands.py +++ b/testing/web-platform/mach_test_package_commands.py @@ -75,12 +75,12 @@ class WebPlatformTestsRunnerSetup(object): @CommandProvider class MachCommands(MachCommandBase): @Command("web-platform-tests", category="testing", parser=create_parser_wpt) - def run_web_platform_tests(self, **kwargs): + def run_web_platform_tests(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() return WebPlatformTestsRunner( WebPlatformTestsRunnerSetup(self._mach_context) ).run(**kwargs) @Command("wpt", category="testing", parser=create_parser_wpt) - def run_wpt(self, **params): + def run_wpt(self, command_context, **params): return self.run_web_platform_tests(**params) diff --git a/testing/xpcshell/mach_commands.py b/testing/xpcshell/mach_commands.py index b7ec9c2e8561..60b2f3e9980e 100644 --- a/testing/xpcshell/mach_commands.py +++ b/testing/xpcshell/mach_commands.py @@ -228,7 +228,7 @@ class MachCommands(MachCommandBase): conditions=[lambda *args: True], parser=get_parser, ) - def run_xpcshell_test(self, test_objects=None, **params): + def run_xpcshell_test(self, command_context, test_objects=None, **params): from mozbuild.controller.building import BuildDriver if test_objects is not None: diff --git a/testing/xpcshell/mach_test_package_commands.py b/testing/xpcshell/mach_test_package_commands.py index ba11d8160e22..f96219f37db9 100644 --- a/testing/xpcshell/mach_test_package_commands.py +++ b/testing/xpcshell/mach_test_package_commands.py @@ -60,6 +60,6 @@ class MochitestCommands(MachCommandBase): description="Run the xpcshell harness.", parser=parser_desktop, ) - def xpcshell(self, **kwargs): + def xpcshell(self, command_context, **kwargs): self._mach_context.activate_mozharness_venv() return run_xpcshell(self._mach_context, **kwargs) diff --git a/toolkit/components/telemetry/tests/marionette/mach_commands.py b/toolkit/components/telemetry/tests/marionette/mach_commands.py index bc0129c180d1..90d3675f42c4 100644 --- a/toolkit/components/telemetry/tests/marionette/mach_commands.py +++ b/toolkit/components/telemetry/tests/marionette/mach_commands.py @@ -74,7 +74,7 @@ class TelemetryTest(MachCommandBase): conditions=[conditions.is_firefox_or_android], parser=create_parser_tests, ) - def telemetry_test(self, tests, **kwargs): + def telemetry_test(self, command_context, tests, **kwargs): if "test_objects" in kwargs: tests = [] for obj in kwargs["test_objects"]: diff --git a/tools/browsertime/mach_commands.py b/tools/browsertime/mach_commands.py index 489d87c13bc4..fdbae945238a 100644 --- a/tools/browsertime/mach_commands.py +++ b/tools/browsertime/mach_commands.py @@ -608,6 +608,7 @@ class MachBrowsertime(MachCommandBase): @CommandArgument("args", nargs=argparse.REMAINDER) def browsertime( self, + command_context, args, verbose=False, update_upstream_url="", diff --git a/tools/compare-locales/mach_commands.py b/tools/compare-locales/mach_commands.py index a8c1c901548a..f796e3ec5ce8 100644 --- a/tools/compare-locales/mach_commands.py +++ b/tools/compare-locales/mach_commands.py @@ -75,7 +75,7 @@ the output file, pass "-" to serialize to stdout and hide the default output. @CommandArgument( "--return-zero", action="store_true", help="Return 0 regardless of l10n status" ) - def compare(self, **kwargs): + def compare(self, command_context, **kwargs): from compare_locales.commands import CompareLocales class ErrorHelper(object): diff --git a/tools/lint/mach_commands.py b/tools/lint/mach_commands.py index 4d48866b38a9..f5800b1c1e5e 100644 --- a/tools/lint/mach_commands.py +++ b/tools/lint/mach_commands.py @@ -69,7 +69,7 @@ class MachCommands(MachCommandBase): description="Run linters.", parser=setup_argument_parser, ) - def lint(self, *runargs, **lintargs): + def lint(self, command_context, *runargs, **lintargs): """Run linters.""" self.activate_virtualenv() from mozlint import cli, parser @@ -124,7 +124,7 @@ class MachCommands(MachCommandBase): nargs=argparse.REMAINDER, help="Extra args that will be forwarded to eslint.", ) - def eslint(self, paths, extra_args=[], **kwargs): + def eslint(self, command_context, paths, extra_args=[], **kwargs): self._mach_context.commands.dispatch( "lint", self._mach_context, diff --git a/tools/mach_commands.py b/tools/mach_commands.py index 3b340bf891fd..f3b47bf5f56f 100644 --- a/tools/mach_commands.py +++ b/tools/mach_commands.py @@ -38,7 +38,7 @@ class BustedProvider(MachCommandBase): category="misc", description="Query known bugs in our tooling, and file new ones.", ) - def busted_default(self): + def busted_default(self, command_context): unresolved = _get_busted_bugs({"resolution": "---"}) creation_time = datetime.now() - timedelta(days=15) creation_time = creation_time.strftime("%Y-%m-%dT%H-%M-%SZ") @@ -72,7 +72,7 @@ class BustedProvider(MachCommandBase): "can also run `mach busted file general`." ), ) - def busted_file(self, against): + def busted_file(self, command_context, against): import webbrowser if ( @@ -262,7 +262,9 @@ class PastebinProvider(MachCommandBase): default=None, help="Path to file for upload to paste.mozilla.org", ) - def pastebin(self, list_highlighters, highlighter, expires, verbose, path): + def pastebin( + self, command_context, list_highlighters, highlighter, expires, verbose, path + ): import requests def verbose_print(*args, **kwargs): @@ -436,7 +438,7 @@ class MozregressionCommand(MachCommandBase): description=("Regression range finder for nightly" " and inbound builds."), parser=mozregression_create_parser, ) - def run(self, **options): + def run(self, command_context, **options): self.activate_virtualenv() mozregression = PypiBasedTool("mozregression") mozregression.run(**options) @@ -450,7 +452,7 @@ class NodeCommands(MachCommandBase): description="Run the NodeJS interpreter used for building.", ) @CommandArgument("args", nargs=argparse.REMAINDER) - def node(self, args): + def node(self, command_context, args): from mozbuild.nodeutil import find_node_executable # Avoid logging the command @@ -470,7 +472,7 @@ class NodeCommands(MachCommandBase): description="Run the npm executable from the NodeJS used for building.", ) @CommandArgument("args", nargs=argparse.REMAINDER) - def npm(self, args): + def npm(self, command_context, args): from mozbuild.nodeutil import find_npm_executable # Avoid logging the command @@ -503,7 +505,7 @@ class LogspamCommand(MachCommandBase): category="misc", description=("Warning categorizer for treeherder test runs."), ) - def logspam(self): + def logspam(self, command_context): pass @SubCommand("logspam", "report", parser=partial(logspam_create_parser, "report")) diff --git a/tools/moztreedocs/mach_commands.py b/tools/moztreedocs/mach_commands.py index a8597690179d..406feff996c0 100644 --- a/tools/moztreedocs/mach_commands.py +++ b/tools/moztreedocs/mach_commands.py @@ -107,6 +107,7 @@ class Documentation(MachCommandBase): ) def build_docs( self, + command_context, path=None, fmt="html", outdir=None, @@ -390,7 +391,7 @@ class Documentation(MachCommandBase): "mach-telemetry", description="Generate documentation from Glean metrics.yaml files", ) - def generate_telemetry_docs(self): + def generate_telemetry_docs(self, command_context): args = [ sys.executable, "-m" "glean_parser", diff --git a/tools/phabricator/mach_commands.py b/tools/phabricator/mach_commands.py index 532a6f4a0dcb..58c64122993f 100644 --- a/tools/phabricator/mach_commands.py +++ b/tools/phabricator/mach_commands.py @@ -22,7 +22,7 @@ class PhabricatorCommandProvider(MachCommandBase): action="store_true", help="Force installation even if already installed.", ) - def install_moz_phab(self, force=False): + def install_moz_phab(self, command_context, force=False): import logging import os import re diff --git a/tools/power/mach_commands.py b/tools/power/mach_commands.py index 19e27874be41..bce8ea5b3bf6 100644 --- a/tools/power/mach_commands.py +++ b/tools/power/mach_commands.py @@ -42,7 +42,7 @@ class MachCommands(MachCommandBase): default=30000, help="The sample period, measured in milliseconds. Defaults to 30000.", ) - def power(self, interval): + def power(self, command_context, interval): import os import re import subprocess diff --git a/tools/tryselect/mach_commands.py b/tools/tryselect/mach_commands.py index 1f5ed1547d7b..85b0f690be39 100644 --- a/tools/tryselect/mach_commands.py +++ b/tools/tryselect/mach_commands.py @@ -202,7 +202,7 @@ class TrySelect(MachCommandBase): description="Push selected tasks to the try server", parser=generic_parser, ) - def try_default(self, argv=None, **kwargs): + def try_default(self, command_context, argv=None, **kwargs): """Push selected tests to the try server. The |mach try| command is a frontend for scheduling tasks to @@ -234,7 +234,7 @@ class TrySelect(MachCommandBase): description="Select tasks on try using a fuzzy finder", parser=get_parser("fuzzy"), ) - def try_fuzzy(self, **kwargs): + def try_fuzzy(self, command_context, **kwargs): """Select which tasks to run with a fuzzy finding interface (fzf). When entering the fzf interface you'll be confronted by two panes. The @@ -337,7 +337,7 @@ class TrySelect(MachCommandBase): description="Schedule tasks by selecting them from a web " "interface.", parser=get_parser("chooser"), ) - def try_chooser(self, **kwargs): + def try_chooser(self, command_context, **kwargs): """Push tasks selected from a web interface to try. This selector will build the taskgraph and spin up a dynamically @@ -361,7 +361,7 @@ class TrySelect(MachCommandBase): "selector is EXPERIMENTAL.", parser=get_parser("auto"), ) - def try_auto(self, **kwargs): + def try_auto(self, command_context, **kwargs): return self.run(**kwargs) @SubCommand( @@ -370,7 +370,7 @@ class TrySelect(MachCommandBase): description="Schedule a previously generated (non try syntax) " "push again.", parser=get_parser("again"), ) - def try_again(self, **kwargs): + def try_again(self, command_context, **kwargs): return self.run(**kwargs) @SubCommand( @@ -379,7 +379,7 @@ class TrySelect(MachCommandBase): description="Push to try without scheduling any tasks.", parser=get_parser("empty"), ) - def try_empty(self, **kwargs): + def try_empty(self, command_context, **kwargs): """Push to try, running no builds or tests This selector does not prompt you to run anything, it just pushes @@ -396,7 +396,7 @@ class TrySelect(MachCommandBase): description="Select tasks on try using try syntax", parser=get_parser("syntax"), ) - def try_syntax(self, **kwargs): + def try_syntax(self, command_context, **kwargs): """Push the current tree to try, with the specified syntax. Build options, platforms and regression tests may be selected @@ -456,7 +456,7 @@ class TrySelect(MachCommandBase): description="Select tasks on try using coverage data", parser=get_parser("coverage"), ) - def try_coverage(self, **kwargs): + def try_coverage(self, command_context, **kwargs): """Select which tasks to use using coverage data.""" return self.run(**kwargs) @@ -466,7 +466,7 @@ class TrySelect(MachCommandBase): description="Push the current tree to try, configured for a staging release.", parser=get_parser("release"), ) - def try_release(self, **kwargs): + def try_release(self, command_context, **kwargs): """Push the current tree to try, configured for a staging release.""" return self.run(**kwargs) @@ -476,7 +476,7 @@ class TrySelect(MachCommandBase): description="Run scriptworker tasks against a recent release.", parser=get_parser("scriptworker"), ) - def try_scriptworker(self, **kwargs): + def try_scriptworker(self, command_context, **kwargs): """Run scriptworker tasks against a recent release. Requires VPN and shipit access. diff --git a/tools/vcs/mach_commands.py b/tools/vcs/mach_commands.py index 0208399b857b..fb7bf111beb2 100644 --- a/tools/vcs/mach_commands.py +++ b/tools/vcs/mach_commands.py @@ -71,7 +71,12 @@ class PullRequestImporter(MachCommandBase): "https://github.com/servo/webrender/pull/3665).", ) def import_pr( - self, pull_request, bug_number=None, bugzilla_token=None, reviewer=None + self, + command_context, + pull_request, + bug_number=None, + bugzilla_token=None, + reviewer=None, ): import requests