77consistency.
88"""
99
10- import hashlib
1110import json
1211from typing import Any , Dict , List , Union
1312
1413from taskgraph .transforms .base import TransformConfig
1514from taskgraph .util import path
15+ from taskgraph .util .caches import CACHES , get_checkout_dir
1616from taskgraph .util .taskcluster import get_artifact_prefix
1717
1818
@@ -23,54 +23,6 @@ def get_vcsdir_name(os):
2323 return "vcs"
2424
2525
26- def get_checkout_dir (task : Dict [str , Any ]) -> str :
27- worker = task ["worker" ]
28- if worker ["os" ] == "windows" :
29- return "build"
30- elif worker ["implementation" ] == "docker-worker" :
31- return f"{ task ['run' ]['workdir' ]} /checkouts"
32- else :
33- return "checkouts"
34-
35-
36- def get_checkout_cache_name (config : TransformConfig , task : Dict [str , Any ]) -> str :
37- repo_configs = config .repo_configs
38- cache_name = "checkouts"
39-
40- # Robust checkout does not clean up subrepositories, so ensure that tasks
41- # that checkout different sets of paths have separate caches.
42- # See https://bugzilla.mozilla.org/show_bug.cgi?id=1631610
43- if len (repo_configs ) > 1 :
44- checkout_paths = {
45- "\t " .join ([repo_config .path , repo_config .prefix ])
46- for repo_config in sorted (
47- repo_configs .values (), key = lambda repo_config : repo_config .path
48- )
49- }
50- checkout_paths_str = "\n " .join (checkout_paths ).encode ("utf-8" )
51- digest = hashlib .sha256 (checkout_paths_str ).hexdigest ()
52- cache_name += f"-repos-{ digest } "
53-
54- # Sparse checkouts need their own cache because they can interfere
55- # with clients that aren't sparse aware.
56- if task ["run" ]["sparse-profile" ]:
57- cache_name += "-sparse"
58-
59- return cache_name
60-
61-
62- CACHES = {
63- "cargo" : {"env" : "CARGO_HOME" },
64- "checkout" : {
65- "cache_dir" : get_checkout_dir ,
66- "cache_name" : get_checkout_cache_name ,
67- },
68- "npm" : {"env" : "npm_config_cache" },
69- "pip" : {"env" : "PIP_CACHE_DIR" },
70- "uv" : {"env" : "UV_CACHE_DIR" },
71- }
72-
73-
7426def add_cache (task , taskdesc , name , mount_point , skip_untrusted = False ):
7527 """Adds a cache based on the worker's implementation.
7628
@@ -216,8 +168,15 @@ def support_caches(
216168 workdir = workdir or "/builds/worker"
217169 base_cache_dir = path .join (workdir , base_cache_dir )
218170
219- # Default to checkout cache if no selection is specified.
220- use_caches = run .get ("use-caches" , ["checkout" ])
171+ use_caches = run .get ("use-caches" )
172+ if use_caches is None :
173+ # Use project default values for filtering caches, default to
174+ # checkout cache if no selection is specified.
175+ use_caches = (
176+ config .graph_config .get ("taskgraph" , {})
177+ .get ("run" , {})
178+ .get ("use-caches" , ["checkout" ])
179+ )
221180
222181 for name , cache_cfg in CACHES .items ():
223182 if not should_use_cache (name , use_caches , run ["checkout" ]):
0 commit comments