summaryrefslogtreecommitdiffstats
path: root/comm/build/mach_initialize.py
blob: 17d2019ca6c3c66d9786b9f35385c1a7646305e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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/python/l10n/mach_commands.py",
    "comm/tools/lint/mach_commands.py",
    "comm/tools/esmify/mach_commands.py",
    "comm/mail/components/storybook/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
        False,
        os.path.join(mozilla_dir, "comm/python/sites/tb_common.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