aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-06-07 15:06:51 -0400
committerGravatar John Cater <jcater@google.com>2017-06-08 10:52:44 -0400
commit62c3105a159db52779d49f7fbd98099d71a51852 (patch)
tree8b969e46fe6d69e12cc46bb83d5d50a5640656c4 /src/main/java/com/google/devtools
parent4ed112830894161614d9b33ee26b0f9f74eb05d9 (diff)
Switch to correct runfiles directory when running python test on Windows
py_test cannot find it's data file at runtime. The reason is it's running in a wrong directory. The test directory is set to runfiles directory by test-setup.sh, but on Windows, python binary unzip itself to another temp directory which test-setup.sh doesn't know. So let the python stub template switch to the correct runfiles directory if RUN_UNDER_RUNFILES = 1 Fixed https://github.com/bazelbuild/bazel/issues/3134 Change-Id: If5dbee811330372d86484ebd871ea55d84bc29a8 PiperOrigin-RevId: 158299041
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt5
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java1
2 files changed, 6 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
index b5afddf116..218f6aeae2 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt
@@ -156,6 +156,11 @@ def Main():
try:
sys.stdout.flush()
if IsRunningFromZip():
+ # If RUN_UNDER_RUNFILES equals 1, it means we need to
+ # change directory to the right runfiles directory.
+ # (So that the data files are accessible)
+ if os.environ.get("RUN_UNDER_RUNFILES") == "1":
+ os.chdir(os.path.join(module_space, "%workspace_name%"))
retCode = subprocess.call(args)
shutil.rmtree(os.path.dirname(module_space), True)
exit(retCode)
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
index 58aed286d0..b3100c2c10 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
@@ -72,6 +72,7 @@ public class StandaloneTestStrategy extends TestStrategy {
.put("PYTHON_RUNFILES", TestPolicy.RUNFILES_DIR)
.put("RUNFILES_DIR", TestPolicy.RUNFILES_DIR)
.put("TEST_TMPDIR", TestPolicy.TEST_TMP_DIR)
+ .put("RUN_UNDER_RUNFILES", "1")
.build();
public static final TestPolicy DEFAULT_LOCAL_POLICY = new TestPolicy(ENV_VARS);