Centralize registration of commands
Categories
(Firefox Build System :: Mach Core, enhancement)
Tracking
(firefox98 fixed)
Tracking | Status | |
---|---|---|
firefox98 | --- | fixed |
People
(Reporter: ahal, Assigned: alex.lopez.zorzano)
References
Details
Attachments
(4 files)
Comment 1•8 years ago
|
||
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Reporter | ||
Comment 5•8 years ago
|
||
mozreview-review |
Reporter | ||
Comment 6•8 years ago
|
||
mozreview-review |
Comment 7•8 years ago
|
||
mozreview-review |
Comment 8•8 years ago
|
||
Updated•8 years ago
|
Updated•7 years ago
|
Reporter | ||
Comment 9•7 years ago
|
||
Reporter | ||
Comment 10•7 years ago
|
||
Re-reading the cache patches, I think I'd prefer a single static place to register commands. Instead of a tuple, maybe it can be a yml/toml/json file where each command is keyed by its top-level name and contains some metadata. For example, 'path', 'description', 'conditions', etc. Just the bare minimum we need to show |mach help| and dispatch. After dispatch, things can keep working the way they do now. If we really wanted to avoid centralization, we could register this information in moz.build I guess, but that adds its own overhead.
We also don't need to overthink settings. Settings that should be loaded globally, need to be defined somewhere globally (e.g in mach itself). Settings that only affect a specific command, get defined next to that command. I think the only corner case is if a command depends on settings that were originally defined somewhere else for another purpose. I don't think a case like this exists, but if it does maybe we can get that second command to re-define the settings.
We will need to adjust the mach-commands
, mach-debug-commands
and mach-completion
commands though.
Comment 11•6 years ago
|
||
FWIW I wrote a very simple implementation of this idea for wpt [1]. Commands are defined in json files, there's a central list of places to search for the json files, and we don't execute any code except that required to run the actual command. In theory this model could be extended to do things like install additional components before even accessing the argument parser, but that's not a requirement for wpt (it has been suggested that there are use cases for gecko to have commands where all the code lives in an external library).
[1] https://github.com/web-platform-tests/wpt/blob/master/tools/wpt/wpt.py
Updated•4 years ago
|
Comment 12•4 years ago
|
||
I'd like to tweak this bug to focus more on the central registration and less on the performance/lazy-load factor (that has been relegated to 1695312).
I imagine that this central registration is very similar to what :ahal has recommended above: rather than centrally defining a block of python scripts to import together, we should centrally define a list of Mach commands.
So, I'm guessing it would look like this:
(
builder
.register_command(<command name>, <command description>, <function reference>)
.register_command("try", "Push selected tasks to the try server", tools.tryselect.try_default)
.register_command("build", "Build the tree", mozbuild.mozbuild.build_commands.build)
...
)
A couple notes and requirements:
- As previously brought up, there's concerns around
conditions
. They either need to be ported, or maybe they're unused enough that they can be removed. - I'd prefer to have this registration function with parameters as opposed to individual tuples so that each parameter is associated with a name (and, arguably, a type).
- I feel strongly that this is better than a cached command -> file mapping, because it has lower complexity and there's no extra cache state to manage.
Comment 13•4 years ago
|
||
Adding "top-level function commands" as a dependent, because that makes referencing commands in this centralized list easier, since we don't need to manage the instantiation of the specific MachCommandBase
object.
Updated•4 years ago
|
Reporter | ||
Updated•4 years ago
|
Assignee | ||
Comment 14•4 years ago
|
||
This reduces some code duplication and paves the way for modifying how
Mach loads modules.
The plan is to follow this up by making this function take a more fleshed out 'spec'
that maps command names to the files they're defined at and possibly more metadata.
Since this may affect how Mach works internally (e.g. with lazy loading in the roadmap),
it makes sense to move this logic inside the Mach class.
Updated•4 years ago
|
Assignee | ||
Comment 15•4 years ago
|
||
This starts a centralized place to keep track of mach commands with some essential
metadata.
Depends on D136789
Updated•4 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
Comment 16•4 years ago
|
||
Comment 17•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/9bcccaed059c
https://hg.mozilla.org/mozilla-central/rev/6123fcc09630
Description
•