зеркало из https://github.com/mozilla/gecko-dev.git
Bug 808336 - Part 2: Discover mach settings providers via decorators; r=jhammel
With this patch, mach is now decoupled from the build system and is truly a generic command dispatching framework.
This commit is contained in:
Родитель
262077ed01
Коммит
fff0f2c942
1
mach
1
mach
|
@ -39,6 +39,7 @@ SEARCH_PATHS = [
|
|||
MACH_MODULES = [
|
||||
'layout/tools/reftest/mach_commands.py',
|
||||
'python/mozboot/mozboot/mach_commands.py',
|
||||
'python/mozbuild/mozbuild/config.py',
|
||||
'testing/mochitest/mach_commands.py',
|
||||
'testing/xpcshell/mach_commands.py',
|
||||
]
|
||||
|
|
|
@ -8,6 +8,7 @@ import inspect
|
|||
import types
|
||||
|
||||
from .base import MethodHandler
|
||||
from .config import ConfigProvider
|
||||
from .registrar import Registrar
|
||||
|
||||
|
||||
|
@ -111,3 +112,21 @@ class CommandArgument(object):
|
|||
func._mach_command_args = command_args
|
||||
|
||||
return func
|
||||
|
||||
def SettingsProvider(cls):
|
||||
"""Class decorator to denote that this class provides Mach settings.
|
||||
|
||||
When this decorator is encountered, the underlying class will automatically
|
||||
be registered with the Mach registrar and will (likely) be hooked up to the
|
||||
mach driver.
|
||||
|
||||
This decorator is only allowed on mach.config.ConfigProvider classes.
|
||||
"""
|
||||
if not issubclass(cls, ConfigProvider):
|
||||
raise Exception('@SettingsProvider encountered on class that does ' +
|
||||
'not derived from mach.config.ConfigProvider.')
|
||||
|
||||
Registrar.register_settings_provider(cls)
|
||||
|
||||
return cls
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ import traceback
|
|||
import uuid
|
||||
import sys
|
||||
|
||||
from mozbuild.base import BuildConfig
|
||||
|
||||
from .base import CommandContext
|
||||
|
||||
from .decorators import (
|
||||
|
@ -33,12 +31,6 @@ from .logging import LoggingManager
|
|||
from .registrar import Registrar
|
||||
|
||||
|
||||
# Classes inheriting from ConfigProvider that provide settings.
|
||||
# TODO this should come from auto-discovery somehow.
|
||||
SETTINGS_PROVIDERS = [
|
||||
BuildConfig,
|
||||
]
|
||||
|
||||
# Settings for argument parser that don't get proxied to sub-module. i.e. these
|
||||
# are things consumed by the driver itself.
|
||||
CONSUMED_ARGUMENTS = [
|
||||
|
@ -412,7 +404,7 @@ To see more help for a specific command, run:
|
|||
self.settings = None
|
||||
return False
|
||||
|
||||
for provider in SETTINGS_PROVIDERS:
|
||||
for provider in Registrar.settings_providers:
|
||||
provider.register_settings()
|
||||
self.settings.register_provider(provider)
|
||||
|
||||
|
|
|
@ -12,12 +12,16 @@ class MachRegistrar(object):
|
|||
|
||||
def __init__(self):
|
||||
self.command_handlers = {}
|
||||
self.settings_providers = set()
|
||||
|
||||
def register_command_handler(self, handler):
|
||||
name = handler.parser_args[0][0]
|
||||
|
||||
self.command_handlers[name] = handler
|
||||
|
||||
def register_settings_provider(self, cls):
|
||||
self.settings_providers.add(cls)
|
||||
|
||||
def populate_argument_parser(self, parser):
|
||||
for command in sorted(self.command_handlers.keys()):
|
||||
handler = self.command_handlers[command]
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import pymake.parser
|
||||
import subprocess
|
||||
|
@ -14,14 +13,11 @@ import which
|
|||
|
||||
from pymake.data import Makefile
|
||||
|
||||
from mach.config import (
|
||||
ConfigProvider,
|
||||
PositiveIntegerType,
|
||||
)
|
||||
|
||||
from mach.mixin.logging import LoggingMixin
|
||||
from mach.mixin.process import ProcessExecutionMixin
|
||||
|
||||
from .config import BuildConfig
|
||||
|
||||
|
||||
class MozbuildObject(ProcessExecutionMixin):
|
||||
"""Base class providing basic functionality useful to many modules.
|
||||
|
@ -282,22 +278,6 @@ class MozbuildObject(ProcessExecutionMixin):
|
|||
topobjdir=self.topobjdir)
|
||||
|
||||
|
||||
class BuildConfig(ConfigProvider):
|
||||
"""The configuration for mozbuild."""
|
||||
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
|
||||
@classmethod
|
||||
def _register_settings(cls):
|
||||
def register(section, option, type_cls, **kwargs):
|
||||
cls.register_setting(section, option, type_cls, domain='mozbuild',
|
||||
**kwargs)
|
||||
|
||||
register('build', 'threads', PositiveIntegerType,
|
||||
default=multiprocessing.cpu_count())
|
||||
|
||||
|
||||
class MachCommandBase(MozbuildObject):
|
||||
"""Base class for mach command providers that wish to be MozbuildObjects.
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# 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 __future__ import unicode_literals
|
||||
|
||||
import multiprocessing
|
||||
|
||||
from mach.config import (
|
||||
ConfigProvider,
|
||||
PositiveIntegerType,
|
||||
)
|
||||
|
||||
from mach.decorators import SettingsProvider
|
||||
|
||||
|
||||
@SettingsProvider
|
||||
class BuildConfig(ConfigProvider):
|
||||
"""The configuration for mozbuild."""
|
||||
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
|
||||
@classmethod
|
||||
def _register_settings(cls):
|
||||
def register(section, option, type_cls, **kwargs):
|
||||
cls.register_setting(section, option, type_cls, domain='mozbuild',
|
||||
**kwargs)
|
||||
|
||||
register('build', 'threads', PositiveIntegerType,
|
||||
default=multiprocessing.cpu_count())
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче