From 214d2d15ca6ec77977483b38e0393ea2e8eb4403 Mon Sep 17 00:00:00 2001 From: Rob Lemley Date: Tue, 30 Nov 2021 21:37:52 +0200 Subject: [PATCH] Bug 1731160 - mach initialization for Thunderbird mach commands. r=darktrojan Creating mach commands in comm-central. The initialize function calls the mozilla-central mach initialize first, then modifies the returned mach.driver. This implementation allows for new command categories and new mach command modules. Mach settings providers can also be added in the mach_commands files. "mach commlint" is implemented, it just calls "mach lint", but with the Thunderbird lint configurations in comm/tools/lint. Requires bug 1731158 in mozilla-central. Differential Revision: https://phabricator.services.mozilla.com/D125984 --HG-- extra : amend_source : 2699448d31d7e5ec062f6daddb12394301417fb7 --- build/mach_initialize.py | 61 ++++++++++++++++++++++++++++++ build/mach_virtualenv_packages.txt | 2 + build/virtualenv_packages.txt | 1 + tools/lint/mach_commands.py | 24 ++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 build/mach_initialize.py create mode 100644 build/mach_virtualenv_packages.txt create mode 100644 tools/lint/mach_commands.py diff --git a/build/mach_initialize.py b/build/mach_initialize.py new file mode 100644 index 0000000000..5984cc9911 --- /dev/null +++ b/build/mach_initialize.py @@ -0,0 +1,61 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +""" +mach_initialize.py + +This file contains initialization code for mach commands that are outside of +the Firefox source repository. +""" + +import os +import sys + +from build import mach_initialize as mach_init + +# Individual files that provide mach commands +MACH_MODULES = [ + "comm/tools/lint/mach_commands.py", +] + +CATEGORIES = { + "thunderbird": { + "short": "Thunderbird Development", + "long": "Mach commands that aid Thunderbird Development", + "priority": 65, + }, +} + + +def mach_sys_path(mozilla_dir): + from mach.requirements import MachEnvRequirements + + requirements = MachEnvRequirements.from_requirements_definition( + mozilla_dir, + True, # is_thunderbird + True, + os.path.join(mozilla_dir, "comm/build/mach_virtualenv_packages.txt"), + ) + return sorted( + [ + os.path.normcase(os.path.join(mozilla_dir, pth.path)) + for pth in requirements.pth_requirements + ] + ) + + +def initialize(topsrcdir): + driver = mach_init.initialize(topsrcdir) + + # Add comm Python module paths + sys.path.extend(mach_sys_path(topsrcdir)) + + # Define Thunderbird mach command categories + for category, meta in CATEGORIES.items(): + driver.define_category(category, meta["short"], meta["long"], meta["priority"]) + + for path in MACH_MODULES: + driver.load_commands_from_file(os.path.join(topsrcdir, path)) + + return driver diff --git a/build/mach_virtualenv_packages.txt b/build/mach_virtualenv_packages.txt new file mode 100644 index 0000000000..c52e8b2642 --- /dev/null +++ b/build/mach_virtualenv_packages.txt @@ -0,0 +1,2 @@ +packages.txt:build/mach_virtualenv_packages.txt +packages.txt:comm/build/virtualenv_packages.txt diff --git a/build/virtualenv_packages.txt b/build/virtualenv_packages.txt index 0a7406e72f..a900c41b68 100644 --- a/build/virtualenv_packages.txt +++ b/build/virtualenv_packages.txt @@ -1,4 +1,5 @@ pth:comm/testing/marionette pth:comm/python/l10n +pth:comm/python/mach pth:comm/taskcluster pth:comm/python/thirdroc diff --git a/tools/lint/mach_commands.py b/tools/lint/mach_commands.py new file mode 100644 index 0000000000..ae52f55496 --- /dev/null +++ b/tools/lint/mach_commands.py @@ -0,0 +1,24 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from mach.decorators import Command + + +def setup_argument_parser(): + from mozlint import cli + + return cli.MozlintParser() + + +@Command( + "commlint", + category="thunderbird", + description="Run linters with Thunderbird configurations.", + parser=setup_argument_parser, +) +def commlint(command_context, paths, extra_args=[], **kwargs): + kwargs["config_paths"].insert(0, "comm/tools/lint") + command_context._mach_context.commands.dispatch( + "lint", command_context._mach_context, paths=paths, argv=extra_args, **kwargs + )