Bug 1731160 - mach initialization for Thunderbird mach commands. r=darktrojan
authorRob Lemley <rob@thunderbird.net>
Mon, 29 Nov 2021 18:49:17 +0000
changeset 34418 86650caf004480a503bf44eafd3615675dc55c85
parent 34417 c3d468fc8947be91dbdd1585375d4c22fe6bcd9b
child 34419 7c3baedab88f0ab1fcd7a2b6c945995a01ff4077
push id19419
push userthunderbird@calypsoblue.org
push dateMon, 29 Nov 2021 18:51:23 +0000
treeherdercomm-central@86650caf0044 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan
bugs1731160, 1731158
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
build/mach_initialize.py
build/mach_virtualenv_packages.txt
build/virtualenv_packages.txt
tools/lint/mach_commands.py
new file mode 100644
--- /dev/null
+++ b/build/mach_initialize.py
@@ -0,0 +1,60 @@
+# 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,
+        "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
new file mode 100644
--- /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
--- 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
new file mode 100644
--- /dev/null
+++ b/tools/lint/mach_commands.py
@@ -0,0 +1,28 @@
+# 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
+    )