From dbe19ffba09e5f31590a659f3da96fcb2bce3700 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 10 Mar 2023 09:44:01 +0100 Subject: [PATCH] Set correct runfiles variable in Python stub --- src/test/shell/testenv.sh.tmpl | 2 ++ tools/python/python_bootstrap_template.txt | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/shell/testenv.sh.tmpl b/src/test/shell/testenv.sh.tmpl index edc41b8d73f315..64d5f91106ebb8 100755 --- a/src/test/shell/testenv.sh.tmpl +++ b/src/test/shell/testenv.sh.tmpl @@ -815,11 +815,13 @@ EOF if [[ $PLATFORM =~ msys ]]; then cat > tools/python/$PYTHON3_FILENAME << EOF @ECHO I am Python 3 +SET EOF else cat > tools/python/$PYTHON3_FILENAME << EOF #!/bin/sh echo 'I am Python 3' +env EOF chmod +x tools/python/$PYTHON3_FILENAME fi diff --git a/tools/python/python_bootstrap_template.txt b/tools/python/python_bootstrap_template.txt index 19514526104b4c..92dd6b82fa0dae 100644 --- a/tools/python/python_bootstrap_template.txt +++ b/tools/python/python_bootstrap_template.txt @@ -215,7 +215,13 @@ def GetRepositoriesImports(module_space, import_all): return [os.path.join(module_space, '%workspace_name%')] def RunfilesEnvvar(module_space): - """Finds the runfiles manifest or the runfiles directory.""" + """Finds the runfiles manifest or the runfiles directory. + + Returns: + A tuple of (var_name, var_value) where var_name is either 'RUNFILES_DIR' or + 'RUNFILES_MANIFEST_FILE' and var_value is the path to that directory or + file, or (None, None) if runfiles couldn't be found. + """ # If this binary is the data-dependency of another one, the other sets # RUNFILES_MANIFEST_FILE or RUNFILES_DIR for our sake. runfiles = os.environ.get('RUNFILES_MANIFEST_FILE', None) @@ -236,9 +242,12 @@ def RunfilesEnvvar(module_space): return ('RUNFILES_MANIFEST_FILE', runfiles) # Look for the runfiles "input" manifest, argv[0] + ".runfiles/MANIFEST" + # Normally .runfiles_manifest and MANIFEST are both present, but the + # former will be missing for zip-based builds or if someone copies the + # runfiles tree elsewhere. runfiles = os.path.join(module_space, 'MANIFEST') if os.path.exists(runfiles): - return ('RUNFILES_DIR', runfiles) + return ('RUNFILES_MANIFEST_FILE', runfiles) # If running in a sandbox and no environment variables are set, then # Look for the runfiles next to the binary.