2016-05-17 01:53:22 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# 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 os
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from .generator import TaskGraphGenerator
|
|
|
|
from .create import create_tasks
|
2016-05-18 00:27:11 +03:00
|
|
|
from .parameters import Parameters
|
2016-05-17 01:53:22 +03:00
|
|
|
from .target_tasks import get_method
|
|
|
|
|
2016-07-11 20:13:58 +03:00
|
|
|
from taskgraph.util.templates import Templates
|
|
|
|
from taskgraph.util.time import (
|
|
|
|
json_time_from_now,
|
|
|
|
current_json_time,
|
|
|
|
)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-07-11 20:13:58 +03:00
|
|
|
ARTIFACTS_DIR = 'artifacts'
|
|
|
|
GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..'))
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
# For each project, this gives a set of parameters specific to the project.
|
|
|
|
# See `taskcluster/docs/parameters.rst` for information on parameters.
|
|
|
|
PER_PROJECT_PARAMETERS = {
|
|
|
|
'try': {
|
|
|
|
'target_tasks_method': 'try_option_syntax',
|
2016-09-12 21:41:58 +03:00
|
|
|
# Always perform optimization. This makes it difficult to use try
|
|
|
|
# pushes to run a task that would otherwise be optimized, but is a
|
|
|
|
# compromise to avoid essentially disabling optimization in try.
|
|
|
|
'optimize_target_tasks': True,
|
2016-05-18 00:27:11 +03:00
|
|
|
},
|
|
|
|
|
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
|
|
|
'ash': {
|
|
|
|
'target_tasks_method': 'ash_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
},
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
# the default parameters are used for projects that do not match above.
|
|
|
|
'default': {
|
2016-09-12 21:41:58 +03:00
|
|
|
'target_tasks_method': 'default',
|
2016-06-05 22:49:41 +03:00
|
|
|
'optimize_target_tasks': True,
|
2016-05-18 00:27:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-05-18 21:02:51 +03:00
|
|
|
def taskgraph_decision(options):
|
2016-05-17 01:53:22 +03:00
|
|
|
"""
|
|
|
|
Run the decision task. This function implements `mach taskgraph decision`,
|
|
|
|
and is responsible for
|
|
|
|
|
|
|
|
* processing decision task command-line options into parameters
|
|
|
|
* running task-graph generation exactly the same way the other `mach
|
|
|
|
taskgraph` commands do
|
|
|
|
* generating a set of artifacts to memorialize the graph
|
|
|
|
* calling TaskCluster APIs to create the graph
|
|
|
|
"""
|
|
|
|
|
|
|
|
parameters = get_decision_parameters(options)
|
|
|
|
|
|
|
|
# create a TaskGraphGenerator instance
|
|
|
|
target_tasks_method = parameters.get('target_tasks_method', 'all_tasks')
|
|
|
|
target_tasks_method = get_method(target_tasks_method)
|
|
|
|
tgg = TaskGraphGenerator(
|
|
|
|
root_dir=options['root'],
|
|
|
|
parameters=parameters,
|
|
|
|
target_tasks_method=target_tasks_method)
|
|
|
|
|
|
|
|
# write out the parameters used to generate this graph
|
2016-05-18 21:02:51 +03:00
|
|
|
write_artifact('parameters.yml', dict(**parameters))
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-07-11 20:13:58 +03:00
|
|
|
# write out the yml file for action tasks
|
|
|
|
write_artifact('action.yml', get_action_yml(parameters))
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
# write out the full graph for reference
|
2016-06-07 06:09:48 +03:00
|
|
|
write_artifact('full-task-graph.json', tgg.full_task_graph.to_json())
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# write out the target task set to allow reproducing this as input
|
2016-06-07 06:09:48 +03:00
|
|
|
write_artifact('target-tasks.json', tgg.target_task_set.tasks.keys())
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-06-05 22:49:41 +03:00
|
|
|
# write out the optimized task graph to describe what will actually happen,
|
|
|
|
# and the map of labels to taskids
|
2016-06-07 06:09:48 +03:00
|
|
|
write_artifact('task-graph.json', tgg.optimized_task_graph.to_json())
|
2016-06-05 22:49:41 +03:00
|
|
|
write_artifact('label-to-taskid.json', tgg.label_to_taskid)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# actually create the graph
|
2016-06-05 22:49:41 +03:00
|
|
|
create_tasks(tgg.optimized_task_graph, tgg.label_to_taskid)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
def get_decision_parameters(options):
|
|
|
|
"""
|
|
|
|
Load parameters from the command-line options for 'taskgraph decision'.
|
|
|
|
This also applies per-project parameters, based on the given project.
|
|
|
|
|
|
|
|
"""
|
|
|
|
parameters = {n: options[n] for n in [
|
|
|
|
'base_repository',
|
|
|
|
'head_repository',
|
|
|
|
'head_rev',
|
|
|
|
'head_ref',
|
|
|
|
'message',
|
|
|
|
'project',
|
|
|
|
'pushlog_id',
|
2016-07-13 21:50:50 +03:00
|
|
|
'pushdate',
|
2016-05-18 00:27:11 +03:00
|
|
|
'owner',
|
|
|
|
'level',
|
2016-09-02 20:29:07 +03:00
|
|
|
'triggered_by',
|
2016-05-18 00:27:11 +03:00
|
|
|
'target_tasks_method',
|
|
|
|
] if n in options}
|
|
|
|
|
|
|
|
project = parameters['project']
|
|
|
|
try:
|
|
|
|
parameters.update(PER_PROJECT_PARAMETERS[project])
|
|
|
|
except KeyError:
|
|
|
|
logger.warning("using default project parameters; add {} to "
|
2016-06-21 04:06:55 +03:00
|
|
|
"PER_PROJECT_PARAMETERS in {} to customize behavior "
|
|
|
|
"for this project".format(project, __file__))
|
2016-05-18 00:27:11 +03:00
|
|
|
parameters.update(PER_PROJECT_PARAMETERS['default'])
|
|
|
|
|
2016-09-02 20:29:07 +03:00
|
|
|
# `target_tasks_method` has higher precedence than `project` parameters
|
|
|
|
if options.get('target_tasks_method'):
|
|
|
|
parameters['target_tasks_method'] = options['target_tasks_method']
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
return Parameters(parameters)
|
|
|
|
|
|
|
|
|
2016-05-18 21:02:51 +03:00
|
|
|
def write_artifact(filename, data):
|
|
|
|
logger.info('writing artifact file `{}`'.format(filename))
|
2016-05-17 01:53:22 +03:00
|
|
|
if not os.path.isdir(ARTIFACTS_DIR):
|
|
|
|
os.mkdir(ARTIFACTS_DIR)
|
|
|
|
path = os.path.join(ARTIFACTS_DIR, filename)
|
|
|
|
if filename.endswith('.yml'):
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
yaml.safe_dump(data, f, allow_unicode=True, default_flow_style=False)
|
|
|
|
elif filename.endswith('.json'):
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
json.dump(data, f, sort_keys=True, indent=2, separators=(',', ': '))
|
|
|
|
else:
|
|
|
|
raise TypeError("Don't know how to write to {}".format(filename))
|
2016-07-11 20:13:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
def get_action_yml(parameters):
|
|
|
|
templates = Templates(os.path.join(GECKO, "taskcluster/taskgraph"))
|
|
|
|
action_parameters = parameters.copy()
|
|
|
|
action_parameters.update({
|
|
|
|
"decision_task_id": "{{decision_task_id}}",
|
|
|
|
"task_labels": "{{task_labels}}",
|
|
|
|
"from_now": json_time_from_now,
|
|
|
|
"now": current_json_time()
|
|
|
|
})
|
|
|
|
return templates.load('action.yml', action_parameters)
|