Bug 1695312 - Selectively load only the mach command modules needed for the command about to be run r=firefox-build-system-reviewers,glandium

This makes loading almost all commands faster, since only one module
file is loaded rather than all of them. There is one main exception,
dealing with 'help'. Running `./mach help` (or -h or --help) requires
the description text for every command, so every module file is still
loaded.

We could expand this improvement here to consolidate all commands and
their parameters in this `MACH_COMMANDS` dict, but the only two benefits
are improving help, and not having two places where the commands are
specified (their file, and this dict).

There's a lot of extra work needed to do that, especially for handling
sub commands, and it did not seem worth the cost for the benefit at this
time.

Depends on D180499

Differential Revision: https://phabricator.services.mozilla.com/D180500
This commit is contained in:
ahochheiden 2023-07-25 00:24:53 +00:00
Родитель 85bd65e288
Коммит 918f331078
3 изменённых файлов: 24 добавлений и 2 удалений

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

@ -706,7 +706,25 @@ def initialize(topsrcdir, args=()):
) or os.path.exists(os.path.join(topsrcdir, "INSTALL"))
else:
missing_ok = ()
driver.load_commands_from_spec(MACH_COMMANDS, topsrcdir, missing_ok=missing_ok)
commands_that_need_all_modules_loaded = [
"mach-commands",
"mach-completion",
"mach-debug-commands",
"help",
]
if (
command_name not in MACH_COMMANDS
or command_name in commands_that_need_all_modules_loaded
):
command_modules_to_load = MACH_COMMANDS
else:
command_modules_to_load = {command_name: MACH_COMMANDS[command_name]}
driver.load_commands_from_spec(
command_modules_to_load, topsrcdir, missing_ok=missing_ok
)
return driver

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

@ -12,6 +12,10 @@ import os
import shutil
from collections import OrderedDict
# As a result of the selective module loading changes, this import has to be
# done here. It is not explicitly used, but it has an implicit side-effect
# (bringing in TASKCLUSTER_ROOT_URL) which is necessary.
import gecko_taskgraph.main # noqa: F401
import mozversioncontrol
import six
from mach.decorators import Command, CommandArgument, SubCommand

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

@ -21,7 +21,6 @@ from os import path
from pathlib import Path
import mozpack.path as mozpath
import yaml
from mach.decorators import (
Command,
CommandArgument,
@ -206,6 +205,7 @@ def cargo(
continue_on_error=False,
subcommand_args=[],
):
import yaml
from mozbuild.controller.building import BuildDriver