@@ -323,7 +323,7 @@ def _create_executable(
323323
324324def  _create_zip_main (ctx , * , stage2_bootstrap , runtime_details , venv ):
325325    python_binary  =  _runfiles_root_path (ctx , venv .interpreter .short_path )
326-     python_binary_actual  =  _runfiles_root_path ( ctx ,  venv .interpreter_actual_path ) 
326+     python_binary_actual  =  venv .interpreter_actual_path 
327327
328328    # The location of this file doesn't really matter. It's added to 
329329    # the zip file as the top-level __main__.py file and not included 
@@ -344,7 +344,6 @@ def _create_zip_main(ctx, *, stage2_bootstrap, runtime_details, venv):
344344    )
345345    return  output 
346346
347- 
348347# Return a relative path from one path to another, where both paths are each 
349348# relative paths from a common root. 
350349def  relative_path (from_ , to ):
@@ -366,8 +365,7 @@ def relative_path(from_, to):
366365        fail ("cannot compute relative path from '%s' to '%s'" , from_ , to )
367366
368367    parts  =  ([".." ] *  len (from_parts )) +  to_parts 
369-     return  "/" .join (parts )
370- 
368+     return  paths .join (* parts )
371369
372370# Create a venv the executable can use. 
373371# For venv details and the venv startup process, see: 
@@ -393,9 +391,15 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
393391        # in runfiles is always a symlink. An RBE implementation, for example, 
394392        # may choose to write what symlink() points to instead. 
395393        interpreter  =  ctx .actions .declare_symlink ("{}/bin/{}" .format (venv , py_exe_basename ))
396-         interpreter_actual_path  =  runtime .interpreter .short_path 
397-         venv_bin_dir  =  paths .dirname (interpreter .short_path )
398-         rel_path  =  relative_path (from_ = venv_bin_dir , to = interpreter_actual_path )
394+ 
395+         interpreter_actual_path  =  _runfiles_root_path (ctx , runtime .interpreter .short_path )
396+         rel_path  =  relative_path (
397+             # dirname is necessary because a relative symlink is relative to 
398+             # the directory the symlink resides within. 
399+             from_  =  paths .dirname (_runfiles_root_path (ctx , interpreter .short_path )),
400+             to  =  interpreter_actual_path ,
401+         )
402+ 
399403        ctx .actions .symlink (output  =  interpreter , target_path  =  rel_path )
400404    else :
401405        py_exe_basename  =  paths .basename (runtime .interpreter_path )
@@ -437,7 +441,7 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
437441
438442    return  struct (
439443        interpreter  =  interpreter ,
440-         # Runfiles- relative path or absolute path 
444+         # Runfiles root  relative path or absolute path 
441445        interpreter_actual_path  =  interpreter_actual_path ,
442446        files_without_interpreter  =  [pyvenv_cfg , pth , site_init ],
443447    )
@@ -487,12 +491,22 @@ def _create_stage2_bootstrap(
487491    )
488492    return  output 
489493
490- def  _runfiles_root_path (ctx , path ):
491-     # The ../ comes from short_path for files in other repos. 
492-     if  path .startswith ("../" ):
493-         return  path [3 :]
494+ def  _runfiles_root_path (ctx , short_path ):
495+     """Compute a runfiles-root relative path from `File.short_path` 
496+ 
497+     Args: 
498+         ctx: current target ctx 
499+         short_path: str, a main-repo relative path from `File.short_path` 
500+ 
501+     Returns: 
502+         {type}`str`, a runflies-root relative path 
503+     """ 
504+ 
505+     # The ../ comes from short_path is for files in other repos. 
506+     if  short_path .startswith ("../" ):
507+         return  short_path [3 :]
494508    else :
495-         return  "{}/{}" .format (ctx .workspace_name , path )
509+         return  "{}/{}" .format (ctx .workspace_name , short_path )
496510
497511def  _create_stage1_bootstrap (
498512        ctx ,
@@ -512,7 +526,7 @@ def _create_stage1_bootstrap(
512526        python_binary_path  =  runtime_details .executable_interpreter_path 
513527
514528    if  is_for_zip  and  venv :
515-         python_binary_actual  =  _runfiles_root_path ( ctx ,  venv .interpreter_actual_path ) 
529+         python_binary_actual  =  venv .interpreter_actual_path 
516530    else :
517531        python_binary_actual  =  "" 
518532
0 commit comments