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
This commit is contained in:
Rob Lemley 2021-11-30 21:37:52 +02:00
Родитель e875e53981
Коммит 214d2d15ca
4 изменённых файлов: 88 добавлений и 0 удалений

61
build/mach_initialize.py Normal file
Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,2 @@
packages.txt:build/mach_virtualenv_packages.txt
packages.txt:comm/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

Просмотреть файл

@ -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
)