Skip to content

Commit fc3bdbf

Browse files
authored
feat: support fully configured fetches for toolchain and fetch upstreams (#545)
This allows for toolchains for things such as Python wheels to be fetched without being extracted in the wake of #541
1 parent ed62115 commit fc3bdbf

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/taskgraph/transforms/run/__init__.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import json
1515
import logging
1616

17-
from voluptuous import Any, Exclusive, Extra, Optional, Required
17+
from voluptuous import Exclusive, Extra, Optional, Required
1818

1919
from taskgraph.transforms.base import TransformSequence
2020
from taskgraph.transforms.cached_tasks import order_tasks
@@ -85,7 +85,6 @@
8585
},
8686
# A list of artifacts to install from 'fetch' tasks.
8787
Optional("fetches"): {
88-
Any("toolchain", "fetch"): [str],
8988
str: [
9089
str,
9190
fetches_schema,
@@ -252,7 +251,15 @@ def use_fetches(config, tasks):
252251
for kind in sorted(fetches):
253252
artifacts = fetches[kind]
254253
if kind in ("fetch", "toolchain"):
255-
for fetch_name in sorted(artifacts):
254+
for artifact in sorted(artifacts):
255+
# Convert name only fetch entries to full fledged ones for
256+
# easier processing.
257+
if isinstance(artifact, str):
258+
artifact = {
259+
"artifact": artifact,
260+
}
261+
262+
fetch_name = artifact["artifact"]
256263
label = f"{kind}-{fetch_name}"
257264
label = aliases.get(label, label)
258265
if label not in artifact_names:
@@ -263,15 +270,21 @@ def use_fetches(config, tasks):
263270
env.update(extra_env[label])
264271

265272
path = artifact_names[label]
273+
dest = artifact.get("dest", None)
274+
extract = artifact.get("extract", True)
275+
verify_hash = artifact.get("verify-hash", False)
266276

267277
dependencies[label] = label
268-
task_fetches.append(
269-
{
270-
"artifact": path,
271-
"task": f"<{label}>",
272-
"extract": True,
273-
}
274-
)
278+
fetch = {
279+
"artifact": path,
280+
"task": f"<{label}>",
281+
"extract": extract,
282+
}
283+
if dest is not None:
284+
fetch["dest"] = dest
285+
if verify_hash:
286+
fetch["verify-hash"] = verify_hash
287+
task_fetches.append(fetch)
275288
else:
276289
if kind not in dependencies:
277290
raise Exception(

test/test_transforms_run.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Tests for the 'run' transform subsystem.
77
"""
88

9+
import json
910
import os
1011
from copy import deepcopy
1112
from pprint import pprint
@@ -89,6 +90,12 @@ def assert_use_fetches_toolchain_env(task):
8990
assert task["worker"]["env"]["FOO"] == "1"
9091

9192

93+
def assert_use_fetches_toolchain_extract_false(task):
94+
fetches = json.loads(task["worker"]["env"]["MOZ_FETCHES"]["task-reference"])
95+
assert len(fetches) == 1
96+
assert fetches[0]["extract"] is False
97+
98+
9299
@pytest.mark.parametrize(
93100
"task,kind_dependencies_tasks",
94101
(
@@ -107,6 +114,20 @@ def assert_use_fetches_toolchain_env(task):
107114
],
108115
id="toolchain_env",
109116
),
117+
pytest.param(
118+
{"fetches": {"toolchain": [{"artifact": "foo", "extract": False}]}},
119+
[
120+
Task(
121+
kind="toolchain",
122+
label="toolchain-foo",
123+
attributes={
124+
"toolchain-artifact": "target.whl",
125+
},
126+
task={},
127+
)
128+
],
129+
id="toolchain_extract_false",
130+
),
110131
),
111132
)
112133
def test_use_fetches(

0 commit comments

Comments
 (0)