зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1562287: Allow setting other try_task_config settings than `templates`; r=ahal
Templates invoke the `morph` logic, which is somewhat confusing and inflexible. Update the machinery to support setting other `try_task_config` values. Differential Revision: https://phabricator.services.mozilla.com/D36364 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
225b100443
Коммит
770166e1f5
|
@ -18,6 +18,7 @@ from mach.decorators import (
|
|||
from mozboot.util import get_state_dir
|
||||
from mozbuild.base import BuildEnvironmentNotFoundException, MachCommandBase
|
||||
|
||||
|
||||
CONFIG_ENVIRONMENT_NOT_FOUND = '''
|
||||
No config environment detected. This means we are unable to properly
|
||||
detect test files in the specified paths or tags. Please run:
|
||||
|
@ -157,12 +158,13 @@ class TrySelect(MachCommandBase):
|
|||
|
||||
return kwargs
|
||||
|
||||
def handle_templates(self, **kwargs):
|
||||
kwargs.setdefault('templates', {})
|
||||
def handle_try_config(self, **kwargs):
|
||||
from tryselect.util.dicttools import merge
|
||||
kwargs.setdefault('try_config', {})
|
||||
for cls in self.parser.templates.itervalues():
|
||||
context = cls.context(**kwargs)
|
||||
if context is not None:
|
||||
kwargs['templates'].update(context)
|
||||
try_config = cls.try_config(**kwargs)
|
||||
if try_config is not None:
|
||||
kwargs['try_config'] = merge(kwargs['try_config'], try_config)
|
||||
|
||||
for name in cls.dests:
|
||||
del kwargs[name]
|
||||
|
@ -174,7 +176,7 @@ class TrySelect(MachCommandBase):
|
|||
kwargs = self.handle_presets(**kwargs)
|
||||
|
||||
if self.parser.templates:
|
||||
kwargs = self.handle_templates(**kwargs)
|
||||
kwargs = self.handle_try_config(**kwargs)
|
||||
|
||||
mod = importlib.import_module('tryselect.selectors.{}'.format(self.subcommand))
|
||||
return mod.run(**kwargs)
|
||||
|
|
|
@ -79,16 +79,16 @@ def check_working_directory(push=True):
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def generate_try_task_config(method, labels, templates=None):
|
||||
if templates is not None:
|
||||
templates.setdefault('env', {}).update({'TRY_SELECTOR': method})
|
||||
def generate_try_task_config(method, labels, try_config=None):
|
||||
try_task_config = try_config or {}
|
||||
|
||||
try_task_config = {
|
||||
templates = try_task_config.setdefault('templates', {})
|
||||
templates.setdefault('env', {}).update({'TRY_SELECTOR': method})
|
||||
|
||||
try_task_config.update({
|
||||
'version': 1,
|
||||
'tasks': sorted(labels),
|
||||
}
|
||||
if templates:
|
||||
try_task_config['templates'] = templates
|
||||
})
|
||||
|
||||
return try_task_config
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class ChooserParser(BaseTryParser):
|
|||
templates = ['artifact', 'env', 'rebuild', 'chemspill-prio', 'gecko-profile']
|
||||
|
||||
|
||||
def run(update=False, query=None, templates=None, full=False, parameters=None,
|
||||
def run(update=False, query=None, try_config=None, full=False, parameters=None,
|
||||
save=False, preset=None, mod_presets=False, push=True, message='{msg}',
|
||||
closed_tree=False):
|
||||
from .app import create_application
|
||||
|
@ -49,5 +49,5 @@ def run(update=False, query=None, templates=None, full=False, parameters=None,
|
|||
|
||||
msg = "Try Chooser Enhanced ({} tasks selected)".format(len(selected))
|
||||
return push_to_try('chooser', message.format(msg=msg),
|
||||
try_task_config=generate_try_task_config('chooser', selected, templates),
|
||||
try_task_config=generate_try_task_config('chooser', selected, try_config),
|
||||
push=push, closed_tree=closed_tree)
|
||||
|
|
|
@ -343,7 +343,7 @@ def is_opt_task(task):
|
|||
return any(platform in task for platform in OPT_TASK_PATTERNS)
|
||||
|
||||
|
||||
def run(templates={}, full=False, parameters=None, push=True, message='{msg}', closed_tree=False):
|
||||
def run(try_config={}, full=False, parameters=None, push=True, message='{msg}', closed_tree=False):
|
||||
download_coverage_mapping(vcs.base_ref)
|
||||
|
||||
changed_sources = vcs.get_outgoing_files()
|
||||
|
@ -374,10 +374,10 @@ def run(templates={}, full=False, parameters=None, push=True, message='{msg}', c
|
|||
|
||||
# Set the test paths to be run by setting MOZHARNESS_TEST_PATHS.
|
||||
path_env = {'MOZHARNESS_TEST_PATHS': json.dumps(resolve_tests_by_suite(test_files))}
|
||||
templates.setdefault('env', {}).update(path_env)
|
||||
try_config.setdefault('templates', {}).setdefault('env', {}).update(path_env)
|
||||
|
||||
# Build commit message.
|
||||
msg = 'try coverage - ' + test_count_message
|
||||
return push_to_try('coverage', message.format(msg=msg),
|
||||
try_task_config=generate_try_task_config('coverage', tasks, templates),
|
||||
try_task_config=generate_try_task_config('coverage', tasks, try_config),
|
||||
push=push, closed_tree=closed_tree)
|
||||
|
|
|
@ -219,7 +219,7 @@ def filter_target_task(task):
|
|||
return not any(re.search(pattern, task) for pattern in TARGET_TASK_FILTERS)
|
||||
|
||||
|
||||
def run(update=False, query=None, intersect_query=None, templates=None, full=False,
|
||||
def run(update=False, query=None, intersect_query=None, try_config=None, full=False,
|
||||
parameters=None, save_query=False, push=True, message='{msg}',
|
||||
test_paths=None, exact=False, closed_tree=False):
|
||||
fzf = fzf_bootstrap(update)
|
||||
|
@ -296,5 +296,5 @@ def run(update=False, query=None, intersect_query=None, templates=None, full=Fal
|
|||
if args:
|
||||
msg = "{} {}".format(msg, '&'.join(args))
|
||||
return push_to_try('fuzzy', message.format(msg=msg),
|
||||
try_task_config=generate_try_task_config('fuzzy', selected, templates),
|
||||
try_task_config=generate_try_task_config('fuzzy', selected, try_config),
|
||||
push=push, closed_tree=closed_tree)
|
||||
|
|
|
@ -23,7 +23,7 @@ here = os.path.abspath(os.path.dirname(__file__))
|
|||
build = MozbuildObject.from_environment(cwd=here)
|
||||
|
||||
|
||||
class Template(object):
|
||||
class TryConfig(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self):
|
||||
|
@ -38,6 +38,17 @@ class Template(object):
|
|||
def arguments(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def try_config(self, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class Template(TryConfig):
|
||||
def try_config(self, **kwargs):
|
||||
context = self.context(**kwargs)
|
||||
if context:
|
||||
return {'templates': context}
|
||||
|
||||
@abstractmethod
|
||||
def context(self, **kwargs):
|
||||
pass
|
||||
|
|
|
@ -15,7 +15,7 @@ from tryselect.selectors import again
|
|||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_history_path(tmpdir, monkeypatch):
|
||||
monkeypatch.setattr(push, 'history_path', tmpdir.join('history.json').strpath)
|
||||
monkeypatch.setattr(push, "history_path", tmpdir.join("history.json").strpath)
|
||||
reload(again)
|
||||
|
||||
|
||||
|
@ -24,33 +24,33 @@ def test_try_again(monkeypatch):
|
|||
"fuzzy",
|
||||
"Fuzzy message",
|
||||
try_task_config=push.generate_try_task_config(
|
||||
"fuzzy", ["foo", "bar"], {"artifact": True},
|
||||
"fuzzy", ["foo", "bar"], {"templates": {"artifact": True}},
|
||||
),
|
||||
)
|
||||
|
||||
assert os.path.isfile(push.history_path)
|
||||
with open(push.history_path, 'r') as fh:
|
||||
with open(push.history_path, "r") as fh:
|
||||
assert len(fh.readlines()) == 1
|
||||
|
||||
def fake_push_to_try(*args, **kwargs):
|
||||
return args, kwargs
|
||||
|
||||
monkeypatch.setattr(push, 'push_to_try', fake_push_to_try)
|
||||
monkeypatch.setattr(push, "push_to_try", fake_push_to_try)
|
||||
reload(again)
|
||||
|
||||
args, kwargs = again.run()
|
||||
|
||||
assert args[0] == 'again'
|
||||
assert args[1] == 'Fuzzy message'
|
||||
assert args[0] == "again"
|
||||
assert args[1] == "Fuzzy message"
|
||||
|
||||
try_task_config = kwargs.pop('try_task_config')
|
||||
assert sorted(try_task_config.get('tasks')) == sorted(['foo', 'bar'])
|
||||
assert try_task_config.get('templates') == {
|
||||
'artifact': True,
|
||||
'env': {'TRY_SELECTOR': 'fuzzy'},
|
||||
try_task_config = kwargs.pop("try_task_config")
|
||||
assert sorted(try_task_config.get("tasks")) == sorted(["foo", "bar"])
|
||||
assert try_task_config.get("templates") == {
|
||||
"artifact": True,
|
||||
"env": {"TRY_SELECTOR": "fuzzy"},
|
||||
}
|
||||
|
||||
with open(push.history_path, 'r') as fh:
|
||||
with open(push.history_path, "r") as fh:
|
||||
assert len(fh.readlines()) == 1
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ def test_no_push_does_not_generate_history(tmpdir):
|
|||
"fuzzy",
|
||||
"Fuzzy",
|
||||
try_task_config=push.generate_try_task_config(
|
||||
"fuzzy", ["foo", "bar"], {"artifact": True},
|
||||
"fuzzy", ["foo", "bar"], {"templates": {"artifact": True}},
|
||||
),
|
||||
push=False,
|
||||
)
|
||||
|
@ -69,5 +69,5 @@ def test_no_push_does_not_generate_history(tmpdir):
|
|||
assert again.run() == 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
mozunit.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче