Skip to content

Commit 1a60fad

Browse files
keertkfmeum
andauthored
fix(python): Set envvar for runfiles manifest, not runfiles dir, when using a manifest (bazelbuild#18133)
Unfortunately, we weren't able to find a way to reproduce the reported bug in a test environment, but the line of code in question is obviously wrong, so we'll just omit a test to cover this. Fixes bazelbuild#17675 Closes bazelbuild#17722. PiperOrigin-RevId: 525044539 Change-Id: I7e1eaa14eac1d4dabcdcf93d92720c41977b1fe2 Co-authored-by: Fabian Meumertzheim <[email protected]>
1 parent a0cb57f commit 1a60fad

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ def GetRepositoriesImports(module_space, import_all):
215215
return [os.path.join(module_space, '%workspace_name%')]
216216

217217
def RunfilesEnvvar(module_space):
218-
"""Finds the runfiles manifest or the runfiles directory."""
218+
"""Finds the runfiles manifest or the runfiles directory.
219+
220+
Returns:
221+
A tuple of (var_name, var_value) where var_name is either 'RUNFILES_DIR' or
222+
'RUNFILES_MANIFEST_FILE' and var_value is the path to that directory or
223+
file, or (None, None) if runfiles couldn't be found.
224+
"""
219225
# If this binary is the data-dependency of another one, the other sets
220226
# RUNFILES_MANIFEST_FILE or RUNFILES_DIR for our sake.
221227
runfiles = os.environ.get('RUNFILES_MANIFEST_FILE', None)
@@ -236,9 +242,12 @@ def RunfilesEnvvar(module_space):
236242
return ('RUNFILES_MANIFEST_FILE', runfiles)
237243

238244
# Look for the runfiles "input" manifest, argv[0] + ".runfiles/MANIFEST"
245+
# Normally .runfiles_manifest and MANIFEST are both present, but the
246+
# former will be missing for zip-based builds or if someone copies the
247+
# runfiles tree elsewhere.
239248
runfiles = os.path.join(module_space, 'MANIFEST')
240249
if os.path.exists(runfiles):
241-
return ('RUNFILES_DIR', runfiles)
250+
return ('RUNFILES_MANIFEST_FILE', runfiles)
242251

243252
# If running in a sandbox and no environment variables are set, then
244253
# Look for the runfiles next to the binary.

0 commit comments

Comments
 (0)