2016-05-17 01:53:22 +03:00
|
|
|
# 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 absolute_import, print_function, unicode_literals
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import yaml
|
2017-02-02 14:34:43 +03:00
|
|
|
import copy
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-11-18 02:53:30 +03:00
|
|
|
from . import filter_tasks
|
2016-05-17 01:53:22 +03:00
|
|
|
from .graph import Graph
|
2016-06-20 22:11:52 +03:00
|
|
|
from .taskgraph import TaskGraph
|
2017-03-10 00:40:33 +03:00
|
|
|
from .task.base import Task
|
2016-06-05 22:49:41 +03:00
|
|
|
from .optimize import optimize_task_graph
|
2016-06-30 01:12:09 +03:00
|
|
|
from .util.python_path import find_object
|
2017-03-10 00:40:33 +03:00
|
|
|
from .transforms.base import TransformSequence, TransformConfig
|
2016-12-21 11:04:04 +03:00
|
|
|
from .util.verify import (
|
|
|
|
verify_docs,
|
|
|
|
verify_task_graph_symbol,
|
|
|
|
verify_gecko_v2_routes,
|
|
|
|
)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-05-18 21:02:51 +03:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-06-21 04:06:55 +03:00
|
|
|
|
2016-06-28 01:31:06 +03:00
|
|
|
class Kind(object):
|
|
|
|
|
|
|
|
def __init__(self, name, path, config):
|
|
|
|
self.name = name
|
|
|
|
self.path = path
|
|
|
|
self.config = config
|
|
|
|
|
2017-03-10 07:14:40 +03:00
|
|
|
def _get_loader(self):
|
2016-06-28 01:31:06 +03:00
|
|
|
try:
|
2017-03-10 07:14:40 +03:00
|
|
|
loader = self.config['loader']
|
2016-06-28 01:31:06 +03:00
|
|
|
except KeyError:
|
2017-03-10 07:14:40 +03:00
|
|
|
raise KeyError("{!r} does not define `loader`".format(self.path))
|
|
|
|
return find_object(loader)
|
2016-06-28 01:31:06 +03:00
|
|
|
|
|
|
|
def load_tasks(self, parameters, loaded_tasks):
|
2017-03-10 07:14:40 +03:00
|
|
|
loader = self._get_loader()
|
2017-02-02 14:34:43 +03:00
|
|
|
config = copy.deepcopy(self.config)
|
|
|
|
|
|
|
|
if 'parse-commit' in self.config:
|
|
|
|
parse_commit = find_object(config['parse-commit'])
|
|
|
|
config['args'] = parse_commit(parameters['message'])
|
|
|
|
else:
|
|
|
|
config['args'] = None
|
|
|
|
|
2017-03-10 00:40:33 +03:00
|
|
|
inputs = loader(self.name, self.path, config, parameters, loaded_tasks)
|
|
|
|
|
|
|
|
transforms = TransformSequence()
|
|
|
|
for xform_path in config['transforms']:
|
|
|
|
transform = find_object(xform_path)
|
|
|
|
transforms.add(transform)
|
|
|
|
|
|
|
|
# perform the transformations on the loaded inputs
|
|
|
|
trans_config = TransformConfig(self.name, self.path, config, parameters)
|
|
|
|
tasks = [Task(self.name,
|
|
|
|
label=task_dict['label'],
|
|
|
|
attributes=task_dict['attributes'],
|
|
|
|
task=task_dict['task'],
|
|
|
|
optimizations=task_dict.get('optimizations'),
|
|
|
|
dependencies=task_dict.get('dependencies'))
|
|
|
|
for task_dict in transforms(trans_config, inputs)]
|
|
|
|
return tasks
|
2016-06-28 01:31:06 +03:00
|
|
|
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
class TaskGraphGenerator(object):
|
|
|
|
"""
|
|
|
|
The central controller for taskgraph. This handles all phases of graph
|
|
|
|
generation. The task is generated from all of the kinds defined in
|
|
|
|
subdirectories of the generator's root directory.
|
|
|
|
|
|
|
|
Access to the results of this generation, as well as intermediate values at
|
|
|
|
various phases of generation, is available via properties. This encourages
|
|
|
|
the provision of all generation inputs at instance construction time.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Task-graph generation is implemented as a Python generator that yields
|
|
|
|
# each "phase" of generation. This allows some mach subcommands to short-
|
|
|
|
# circuit generation of the entire graph by never completing the generator.
|
|
|
|
|
2016-11-18 03:29:51 +03:00
|
|
|
def __init__(self, root_dir, parameters):
|
2016-05-17 01:53:22 +03:00
|
|
|
"""
|
|
|
|
@param root_dir: root directory, with subdirectories for each kind
|
|
|
|
@param parameters: parameters for this task-graph generation
|
|
|
|
@type parameters: dict
|
|
|
|
"""
|
|
|
|
self.root_dir = root_dir
|
|
|
|
self.parameters = parameters
|
2016-11-18 03:29:51 +03:00
|
|
|
|
2016-12-06 09:33:36 +03:00
|
|
|
self.verify_parameters(self.parameters)
|
|
|
|
|
2016-11-18 02:53:30 +03:00
|
|
|
filters = parameters.get('filters', [])
|
|
|
|
|
|
|
|
# Always add legacy target tasks method until we deprecate that API.
|
|
|
|
if 'target_tasks_method' not in filters:
|
|
|
|
filters.insert(0, 'target_tasks_method')
|
|
|
|
|
|
|
|
self.filters = [filter_tasks.filter_task_functions[f] for f in filters]
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# this can be set up until the time the target task set is generated;
|
|
|
|
# it defaults to parameters['target_tasks']
|
|
|
|
self._target_tasks = parameters.get('target_tasks')
|
|
|
|
|
|
|
|
# start the generator
|
|
|
|
self._run = self._run()
|
|
|
|
self._run_results = {}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def full_task_set(self):
|
|
|
|
"""
|
|
|
|
The full task set: all tasks defined by any kind (a graph without edges)
|
|
|
|
|
|
|
|
@type: TaskGraph
|
|
|
|
"""
|
|
|
|
return self._run_until('full_task_set')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def full_task_graph(self):
|
|
|
|
"""
|
|
|
|
The full task graph: the full task set, with edges representing
|
|
|
|
dependencies.
|
|
|
|
|
|
|
|
@type: TaskGraph
|
|
|
|
"""
|
|
|
|
return self._run_until('full_task_graph')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_task_set(self):
|
|
|
|
"""
|
|
|
|
The set of targetted tasks (a graph without edges)
|
|
|
|
|
|
|
|
@type: TaskGraph
|
|
|
|
"""
|
|
|
|
return self._run_until('target_task_set')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_task_graph(self):
|
|
|
|
"""
|
|
|
|
The set of targetted tasks and all of their dependencies
|
|
|
|
|
|
|
|
@type: TaskGraph
|
|
|
|
"""
|
|
|
|
return self._run_until('target_task_graph')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def optimized_task_graph(self):
|
|
|
|
"""
|
|
|
|
The set of targetted tasks and all of their dependencies; tasks that
|
|
|
|
have been optimized out are either omitted or replaced with a Task
|
|
|
|
instance containing only a task_id.
|
|
|
|
|
|
|
|
@type: TaskGraph
|
|
|
|
"""
|
|
|
|
return self._run_until('optimized_task_graph')
|
|
|
|
|
2016-06-05 22:49:41 +03:00
|
|
|
@property
|
|
|
|
def label_to_taskid(self):
|
|
|
|
"""
|
|
|
|
A dictionary mapping task label to assigned taskId. This property helps
|
|
|
|
in interpreting `optimized_task_graph`.
|
|
|
|
|
|
|
|
@type: dictionary
|
|
|
|
"""
|
|
|
|
return self._run_until('label_to_taskid')
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
def _load_kinds(self):
|
|
|
|
for path in os.listdir(self.root_dir):
|
|
|
|
path = os.path.join(self.root_dir, path)
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
continue
|
2016-06-28 01:57:44 +03:00
|
|
|
kind_name = os.path.basename(path)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
kind_yml = os.path.join(path, 'kind.yml')
|
2016-08-18 23:08:22 +03:00
|
|
|
if not os.path.exists(kind_yml):
|
|
|
|
continue
|
|
|
|
|
|
|
|
logger.debug("loading kind `{}` from `{}`".format(kind_name, path))
|
2016-08-18 20:21:26 +03:00
|
|
|
with open(kind_yml) as f:
|
2016-05-17 01:53:22 +03:00
|
|
|
config = yaml.load(f)
|
|
|
|
|
2016-06-28 01:31:06 +03:00
|
|
|
yield Kind(kind_name, path, config)
|
2016-06-28 01:45:44 +03:00
|
|
|
|
|
|
|
def _run(self):
|
2016-06-28 01:31:06 +03:00
|
|
|
logger.info("Loading kinds")
|
|
|
|
# put the kinds into a graph and sort topologically so that kinds are loaded
|
|
|
|
# in post-order
|
|
|
|
kinds = {kind.name: kind for kind in self._load_kinds()}
|
2016-11-25 22:52:46 +03:00
|
|
|
self.verify_kinds(kinds)
|
|
|
|
|
2016-06-28 01:31:06 +03:00
|
|
|
edges = set()
|
|
|
|
for kind in kinds.itervalues():
|
|
|
|
for dep in kind.config.get('kind-dependencies', []):
|
|
|
|
edges.add((kind.name, dep, 'kind-dependency'))
|
|
|
|
kind_graph = Graph(set(kinds), edges)
|
|
|
|
|
2016-05-18 18:54:30 +03:00
|
|
|
logger.info("Generating full task set")
|
2016-05-17 01:53:22 +03:00
|
|
|
all_tasks = {}
|
2016-06-28 01:31:06 +03:00
|
|
|
for kind_name in kind_graph.visit_postorder():
|
|
|
|
logger.debug("Loading tasks for kind {}".format(kind_name))
|
|
|
|
kind = kinds[kind_name]
|
Bug 1281004: Specify test tasks more flexibly; r=gps; r=gbrown
This introduces a completely new way of specifying test task in-tree,
completely replacing the old spider-web of YAML files.
The high-level view is this:
- some configuration files are used to determine which test suites to run
for each test platform, and against which build platforms
- each test suite is then represented by a dictionary, and modified by a
sequence of transforms, duplicating as necessary (e.g., chunks), until
it becomes a task definition
The transforms allow sufficient generality to support just about any desired
configuration, with the advantage that common configurations are "easy" while
unusual configurations are supported but notable for their oddness (they
require a custom transform).
As of this commit, this system produces the same set of test graphs as the
existing YAML, modulo:
- extra.treeherder.groupName -- this was not consistent in the YAML
- extra.treeherder.build -- this is ignored by taskcluster-treeherder anyway
- mozharness command argument order
- boolean True values for environment variables are now the string "true"
- metadata -- this is now much more consistent, with task name being the label
Testing of this commit demonstrates that it produces the same set of test tasks for
the following projects (those which had special cases defined in the YAML):
- autoland
- ash (*)
- willow
- mozilla-inbound
- mozilla-central
- try:
-b do -p all -t all -u all
-b d -p linux64,linux64-asan -u reftest -t none
-b d -p linux64,linux64-asan -u reftest[x64] -t none[x64]
(*) this patch omits the linux64/debug tc-M-e10s(dt) test, which is enabled on
ash; ash will require a small changeset to re-enable this test.
IGNORE BAD COMMIT MESSAGES (because the hook flags try syntax!)
MozReview-Commit-ID: G34dg9f17Hq
--HG--
rename : taskcluster/taskgraph/kind/base.py => taskcluster/taskgraph/task/base.py
rename : taskcluster/taskgraph/kind/docker_image.py => taskcluster/taskgraph/task/docker_image.py
rename : taskcluster/taskgraph/kind/legacy.py => taskcluster/taskgraph/task/legacy.py
extra : rebase_source : 03e70902c2d3a297eb9e3ce852f8737c2550d5a6
extra : histedit_source : d4d9f4b192605af21f41d83495fc3c923759c3cb
2016-07-12 02:27:14 +03:00
|
|
|
new_tasks = kind.load_tasks(self.parameters, list(all_tasks.values()))
|
|
|
|
for task in new_tasks:
|
2016-06-28 01:31:06 +03:00
|
|
|
if task.label in all_tasks:
|
|
|
|
raise Exception("duplicate tasks with label " + task.label)
|
|
|
|
all_tasks[task.label] = task
|
Bug 1281004: Specify test tasks more flexibly; r=gps; r=gbrown
This introduces a completely new way of specifying test task in-tree,
completely replacing the old spider-web of YAML files.
The high-level view is this:
- some configuration files are used to determine which test suites to run
for each test platform, and against which build platforms
- each test suite is then represented by a dictionary, and modified by a
sequence of transforms, duplicating as necessary (e.g., chunks), until
it becomes a task definition
The transforms allow sufficient generality to support just about any desired
configuration, with the advantage that common configurations are "easy" while
unusual configurations are supported but notable for their oddness (they
require a custom transform).
As of this commit, this system produces the same set of test graphs as the
existing YAML, modulo:
- extra.treeherder.groupName -- this was not consistent in the YAML
- extra.treeherder.build -- this is ignored by taskcluster-treeherder anyway
- mozharness command argument order
- boolean True values for environment variables are now the string "true"
- metadata -- this is now much more consistent, with task name being the label
Testing of this commit demonstrates that it produces the same set of test tasks for
the following projects (those which had special cases defined in the YAML):
- autoland
- ash (*)
- willow
- mozilla-inbound
- mozilla-central
- try:
-b do -p all -t all -u all
-b d -p linux64,linux64-asan -u reftest -t none
-b d -p linux64,linux64-asan -u reftest[x64] -t none[x64]
(*) this patch omits the linux64/debug tc-M-e10s(dt) test, which is enabled on
ash; ash will require a small changeset to re-enable this test.
IGNORE BAD COMMIT MESSAGES (because the hook flags try syntax!)
MozReview-Commit-ID: G34dg9f17Hq
--HG--
rename : taskcluster/taskgraph/kind/base.py => taskcluster/taskgraph/task/base.py
rename : taskcluster/taskgraph/kind/docker_image.py => taskcluster/taskgraph/task/docker_image.py
rename : taskcluster/taskgraph/kind/legacy.py => taskcluster/taskgraph/task/legacy.py
extra : rebase_source : 03e70902c2d3a297eb9e3ce852f8737c2550d5a6
extra : histedit_source : d4d9f4b192605af21f41d83495fc3c923759c3cb
2016-07-12 02:27:14 +03:00
|
|
|
logger.info("Generated {} tasks for kind {}".format(len(new_tasks), kind_name))
|
2016-05-17 01:53:22 +03:00
|
|
|
full_task_set = TaskGraph(all_tasks, Graph(set(all_tasks), set()))
|
2016-11-25 22:52:46 +03:00
|
|
|
self.verify_attributes(all_tasks)
|
|
|
|
self.verify_run_using()
|
2016-05-17 01:53:22 +03:00
|
|
|
yield 'full_task_set', full_task_set
|
|
|
|
|
2016-05-18 18:54:30 +03:00
|
|
|
logger.info("Generating full task graph")
|
2016-05-17 01:53:22 +03:00
|
|
|
edges = set()
|
|
|
|
for t in full_task_set:
|
2017-03-09 00:22:31 +03:00
|
|
|
for depname, dep in t.dependencies.iteritems():
|
2016-05-17 01:53:22 +03:00
|
|
|
edges.add((t.label, dep, depname))
|
|
|
|
|
|
|
|
full_task_graph = TaskGraph(all_tasks,
|
|
|
|
Graph(full_task_set.graph.nodes, edges))
|
2016-12-22 19:45:10 +03:00
|
|
|
full_task_graph.for_each_task(verify_task_graph_symbol, scratch_pad={})
|
2017-01-02 17:09:30 +03:00
|
|
|
full_task_graph.for_each_task(verify_gecko_v2_routes, scratch_pad={})
|
2016-11-18 02:53:30 +03:00
|
|
|
logger.info("Full task graph contains %d tasks and %d dependencies" % (
|
|
|
|
len(full_task_set.graph.nodes), len(edges)))
|
2016-05-17 01:53:22 +03:00
|
|
|
yield 'full_task_graph', full_task_graph
|
|
|
|
|
2016-05-18 18:54:30 +03:00
|
|
|
logger.info("Generating target task set")
|
2016-11-18 02:53:30 +03:00
|
|
|
target_task_set = TaskGraph(dict(all_tasks),
|
|
|
|
Graph(set(all_tasks.keys()), set()))
|
|
|
|
for fltr in self.filters:
|
|
|
|
old_len = len(target_task_set.graph.nodes)
|
|
|
|
target_tasks = set(fltr(target_task_set, self.parameters))
|
|
|
|
target_task_set = TaskGraph(
|
|
|
|
{l: all_tasks[l] for l in target_tasks},
|
|
|
|
Graph(target_tasks, set()))
|
|
|
|
logger.info('Filter %s pruned %d tasks (%d remain)' % (
|
|
|
|
fltr.__name__,
|
|
|
|
old_len - len(target_tasks),
|
|
|
|
len(target_tasks)))
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
yield 'target_task_set', target_task_set
|
|
|
|
|
2016-05-18 18:54:30 +03:00
|
|
|
logger.info("Generating target task graph")
|
2016-05-17 01:53:22 +03:00
|
|
|
target_graph = full_task_graph.graph.transitive_closure(target_tasks)
|
|
|
|
target_task_graph = TaskGraph(
|
|
|
|
{l: all_tasks[l] for l in target_graph.nodes},
|
|
|
|
target_graph)
|
|
|
|
yield 'target_task_graph', target_task_graph
|
|
|
|
|
2016-05-18 18:54:30 +03:00
|
|
|
logger.info("Generating optimized task graph")
|
2016-06-05 22:49:41 +03:00
|
|
|
do_not_optimize = set()
|
2016-11-25 22:52:46 +03:00
|
|
|
|
2016-06-05 22:49:41 +03:00
|
|
|
if not self.parameters.get('optimize_target_tasks', True):
|
|
|
|
do_not_optimize = target_task_set.graph.nodes
|
2016-06-21 04:06:55 +03:00
|
|
|
optimized_task_graph, label_to_taskid = optimize_task_graph(target_task_graph,
|
2016-09-12 21:40:12 +03:00
|
|
|
self.parameters,
|
2016-06-21 04:06:55 +03:00
|
|
|
do_not_optimize)
|
2016-06-05 22:49:41 +03:00
|
|
|
yield 'label_to_taskid', label_to_taskid
|
|
|
|
yield 'optimized_task_graph', optimized_task_graph
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
def _run_until(self, name):
|
|
|
|
while name not in self._run_results:
|
|
|
|
try:
|
|
|
|
k, v = self._run.next()
|
|
|
|
except StopIteration:
|
|
|
|
raise AttributeError("No such run result {}".format(name))
|
|
|
|
self._run_results[k] = v
|
|
|
|
return self._run_results[name]
|
2016-11-25 22:52:46 +03:00
|
|
|
|
2016-12-06 09:33:36 +03:00
|
|
|
def verify_parameters(self, parameters):
|
|
|
|
parameters_dict = dict(**parameters)
|
|
|
|
verify_docs(
|
|
|
|
filename="parameters.rst",
|
|
|
|
identifiers=parameters_dict.keys(),
|
|
|
|
appearing_as="inline-literal"
|
|
|
|
)
|
|
|
|
|
2016-11-25 22:52:46 +03:00
|
|
|
def verify_kinds(self, kinds):
|
|
|
|
verify_docs(
|
|
|
|
filename="kinds.rst",
|
|
|
|
identifiers=kinds.keys(),
|
|
|
|
appearing_as="heading"
|
|
|
|
)
|
|
|
|
|
|
|
|
def verify_attributes(self, all_tasks):
|
|
|
|
attribute_set = set()
|
|
|
|
for label, task in all_tasks.iteritems():
|
|
|
|
attribute_set.update(task.attributes.keys())
|
|
|
|
verify_docs(
|
|
|
|
filename="attributes.rst",
|
|
|
|
identifiers=list(attribute_set),
|
|
|
|
appearing_as="heading"
|
|
|
|
)
|
|
|
|
|
|
|
|
def verify_run_using(self):
|
|
|
|
from .transforms.job import registry
|
|
|
|
verify_docs(
|
|
|
|
filename="transforms.rst",
|
|
|
|
identifiers=registry.keys(),
|
|
|
|
appearing_as="inline-literal"
|
|
|
|
)
|