@@ -341,6 +341,9 @@ def _create_executable(
341341 output_prefix = base_executable_name ,
342342 imports = imports ,
343343 runtime_details = runtime_details ,
344+ add_runfiles_root_to_sys_path = (
345+ "1" if BootstrapImplFlag .get_value (ctx ) == BootstrapImplFlag .SYSTEM_PYTHON else "0"
346+ ),
344347 )
345348
346349 stage2_bootstrap = _create_stage2_bootstrap (
@@ -504,7 +507,7 @@ def _create_zip_main(ctx, *, stage2_bootstrap, runtime_details, venv):
504507# * https://snarky.ca/how-virtual-environments-work/
505508# * https://github.com/python/cpython/blob/main/Modules/getpath.py
506509# * https://github.com/python/cpython/blob/main/Lib/site.py
507- def _create_venv (ctx , output_prefix , imports , runtime_details ):
510+ def _create_venv (ctx , output_prefix , imports , runtime_details , add_runfiles_root_to_sys_path ):
508511 create_full_venv = BootstrapImplFlag .get_value (ctx ) == BootstrapImplFlag .SCRIPT
509512 venv = "_{}.venv" .format (output_prefix .lstrip ("_" ))
510513
@@ -592,6 +595,7 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
592595 template = runtime .site_init_template ,
593596 output = site_init ,
594597 substitutions = {
598+ "%add_runfiles_root_to_sys_path%" : add_runfiles_root_to_sys_path ,
595599 "%coverage_tool%" : _get_coverage_tool_runfiles_path (ctx , runtime ),
596600 "%import_all%" : "True" if read_possibly_native_flag (ctx , "python_import_all_repositories" ) else "False" ,
597601 "%site_init_runfiles_path%" : "{}/{}" .format (ctx .workspace_name , site_init .short_path ),
0 commit comments