@@ -1091,10 +1091,10 @@ def _display_python_version():
10911091
10921092
10931093def main (args ):
1094- os .environ ["TASK_WORKDIR" ] = os .getcwd ()
1094+ task_workdir = os .environ ["TASK_WORKDIR" ] = os .getcwd ()
10951095 print_line (
10961096 b"setup" ,
1097- b"run-task started in %s\n " % os . environ [ "TASK_WORKDIR" ] .encode ("utf-8" ),
1097+ b"run-task started in %s\n " % task_workdir .encode ("utf-8" ),
10981098 )
10991099 print_line (
11001100 b"setup" ,
@@ -1313,20 +1313,27 @@ def main(args):
13131313 for repo in repositories :
13141314 vcs_checkout_from_args (repo )
13151315
1316- resource_process = None
1317-
1318- try :
1319- for k in ["MOZ_FETCHES_DIR" , "UPLOAD_DIR" ] + [
1320- "{}_PATH" .format (repository ["project" ].upper ())
1321- for repository in repositories
1322- ]:
1323- if k in os .environ :
1324- os .environ [k ] = os .path .abspath (os .environ [k ])
1316+ # Interpolate environment variables with defined substitution patterns. For
1317+ # example, the variable `CACHE_DIR={task_workdir}/.cache` will be
1318+ # interpolated with the task's working directory.
1319+ env_subs = {
1320+ "task_workdir" : task_workdir ,
1321+ }
1322+ for k , v in os .environ .items ():
1323+ for subname , subval in env_subs .items ():
1324+ # We check for an exact match rather than using a format string to
1325+ # avoid accidentally trying to interpolate environment variables
1326+ # that happen to contain brackets for some other reason.
1327+ pattern = f"{{{ subname } }}"
1328+ if pattern in v :
1329+ os .environ [k ] = v .replace (pattern , subval )
13251330 print_line (
13261331 b"setup" ,
13271332 b"%s is %s\n " % (k .encode ("utf-8" ), os .environ [k ].encode ("utf-8" )),
13281333 )
13291334
1335+ resource_process = None
1336+ try :
13301337 if "MOZ_FETCHES" in os .environ :
13311338 fetch_artifacts ()
13321339
0 commit comments