@@ -200,6 +200,7 @@ def get_extract_key(self):
200200 # variables (Variables): The element's Variables
201201 # environment (dict): dict of the element's environment variables
202202 # sandboxconfig (SandboxConfig): The element's SandboxConfig
203+ # buildsandbox (Sandbox): The element's configured build sandbox
203204 #
204205 def cache (
205206 self ,
@@ -213,6 +214,7 @@ def cache(
213214 variables ,
214215 environment ,
215216 sandboxconfig ,
217+ buildsandbox ,
216218 ):
217219
218220 context = self ._context
@@ -317,6 +319,19 @@ def cache(
317319 rootvdir ._import_files_internal (buildrootvdir , properties = properties , collect_result = False )
318320 artifact .buildroot .CopyFrom (rootvdir ._get_digest ())
319321
322+ if buildsandbox is not None :
323+ sandbox_env = buildsandbox ._get_configured_environment ()
324+ if sandbox_env :
325+ for key , value in sorted (sandbox_env .items ()):
326+ artifact .buildsandbox .environment .add (name = key , value = value )
327+
328+ artifact .buildsandbox .working_directory = buildsandbox ._get_work_directory ()
329+
330+ for subsandbox in buildsandbox ._get_subsandboxes ():
331+ vdir = subsandbox .get_virtual_directory ()
332+ digest = artifact .buildsandbox .subsandbox_digests .add ()
333+ digest .CopyFrom (vdir ._get_digest ())
334+
320335 os .makedirs (os .path .dirname (os .path .join (self ._artifactdir , element .get_artifact_name ())), exist_ok = True )
321336 keys = utils ._deduplicate ([self ._cache_key , self ._weak_cache_key ])
322337 for key in keys :
@@ -681,6 +696,21 @@ def pull(self, *, pull_buildtrees):
681696
682697 return True
683698
699+ def configure_sandbox (self , sandbox ):
700+ artifact = self ._get_proto ()
701+
702+ if artifact .buildsandbox and artifact .buildsandbox .environment :
703+ env = {}
704+ for env_var in artifact .buildsandbox .environment :
705+ env [env_var .name ] = env_var .value
706+ else :
707+ env = self .load_environment ()
708+
709+ sandbox .set_environment (env )
710+
711+ if artifact .buildsandbox and artifact .buildsandbox .working_directory :
712+ sandbox .set_work_directory (artifact .buildsandbox .working_directory )
713+
684714 # load_proto()
685715 #
686716 # Returns:
0 commit comments