aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Austin Schuh <austin.linux@gmail.com>2017-12-04 06:00:23 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-04 06:02:25 -0800
commit8bd3c97d61e6992cc5fd32a50f63a02839fae205 (patch)
tree1ca82325c0572b191e74e46b3189bcbf19663701 /src/main/java/com/google
parent2c63af5c886b7e328f3996ae1ef7d0bcb07b2b54 (diff)
py_binary can now be used as data with custom python.
The stub template now looks for the python binary relative to the modules if a relative path was provided. This correctly finds it inside the runfiles folder both when the py_binary is the output, and when the py_binary is called by another binary (ie is data for it). We also now add the binary and dependencies to the runfiles when it is used as data so python is accesible. Change-Id: I3bf6ff17265e72d964614ad66af22933c89f853d PiperOrigin-RevId: 177803641
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt8
2 files changed, 9 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
index 52d839c4d9..701a29327d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
@@ -74,6 +74,7 @@ public class BazelPythonSemantics implements PythonSemantics {
@Override
public void collectDefaultRunfilesForBinary(RuleContext ruleContext, Builder builder) {
+ addRuntime(ruleContext, builder);
}
@Override
@@ -348,7 +349,10 @@ public class BazelPythonSemantics implements PythonSemantics {
pythonBinary = provider.interpreterPath();
} else {
// checked in Python interpreter in py_runtime
- pythonBinary = provider.interpreter().getExecPathString();
+ PathFragment workspaceName =
+ PathFragment.create(ruleContext.getRule().getPackage().getWorkspaceName());
+ pythonBinary =
+ workspaceName.getRelative(provider.interpreter().getRunfilesPath()).getPathString();
}
} else {
// make use of the Python interpreter in an absolute path
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
index 6adf21f01d..84dd571afa 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
@@ -50,7 +50,7 @@ def IsRunningFromZip():
return %is_zipfile%
# Find the real Python binary if it's not a normal absolute path
-def FindPythonBinary():
+def FindPythonBinary(module_space):
if PYTHON_BINARY.startswith('//'):
# Case 1: Path is a label. Not supported yet.
raise AssertionError(
@@ -59,8 +59,8 @@ def FindPythonBinary():
# Case 2: Absolute path.
return PYTHON_BINARY
elif '/' in PYTHON_BINARY:
- # Case 3: Path is relative to current working directory.
- return os.path.join(os.getcwd(), PYTHON_BINARY)
+ # Case 3: Path is relative to the repo root.
+ return os.path.join(module_space, PYTHON_BINARY)
else:
# Case 4: Path has to be looked up in the search path.
return SearchPath(PYTHON_BINARY)
@@ -140,7 +140,7 @@ def Main():
assert os.access(main_filename, os.R_OK), \
'Cannot exec() %r: file not readable.' % main_filename
- program = python_program = FindPythonBinary()
+ program = python_program = FindPythonBinary(module_space)
if python_program is None:
raise AssertionError('Could not find python binary: ' + PYTHON_BINARY)
args = [python_program, main_filename] + args