aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/py
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-02-15 02:59:13 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-15 03:00:36 -0800
commitbb1d0856fffd1c57ed1fd74f3b3c3287f6b66f47 (patch)
tree212abc71b053377f10c221e1695819cde19df6e3 /src/test/py
parent3edf41b70de9bb1a8702d0342beeb2ad13898d71 (diff)
runfiles library: py_binary can run java_binary
Add "JAVA_RUNFILES" (and "RUNFILES_DIR") to the dict that Runfiles.EnvVars() returns in the Python runfiles library, so Python programs that use the Python runfiles library in @bazel_tools can now run java_binary data-dependencies as subprocesses and the latter will find the runfiles. See https://github.com/bazelbuild/bazel/issues/4460 Change-Id: I0566f6d3c68631a1d99e67964fbe8019ee82324b PiperOrigin-RevId: 185812948
Diffstat (limited to 'src/test/py')
-rw-r--r--src/test/py/bazel/runfiles_test.py16
-rw-r--r--src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock1
-rw-r--r--src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py26
3 files changed, 30 insertions, 13 deletions
diff --git a/src/test/py/bazel/runfiles_test.py b/src/test/py/bazel/runfiles_test.py
index e3f697cc55..2c6a9c9d69 100644
--- a/src/test/py/bazel/runfiles_test.py
+++ b/src/test/py/bazel/runfiles_test.py
@@ -79,6 +79,8 @@ class RunfilesTest(test_base.TestBase):
("bar/BUILD.mock", "bar/BUILD"),
("bar/bar.py", "bar/bar.py"),
("bar/bar-py-data.txt", "bar/bar-py-data.txt"),
+ ("bar/Bar.java", "bar/Bar.java"),
+ ("bar/bar-java-data.txt", "bar/bar-java-data.txt"),
]:
self.CopyFile(
self.Rlocation(
@@ -101,15 +103,21 @@ class RunfilesTest(test_base.TestBase):
exit_code, stdout, stderr = self.RunProgram(
[bin_path], env_add={"TEST_SRCDIR": "__ignore_me__"})
self.AssertExitCode(exit_code, 0, stderr)
- if len(stdout) < 4:
+ if len(stdout) != 6:
self.fail("stdout: %s" % stdout)
+
self.assertEqual(stdout[0], "Hello Python Foo!")
six.assertRegex(self, stdout[1], "^rloc=.*/foo/datadep/hello.txt")
self.assertNotIn("__ignore_me__", stdout[1])
+
self.assertEqual(stdout[2], "Hello Python Bar!")
six.assertRegex(self, stdout[3], "^rloc=.*/bar/bar-py-data.txt")
self.assertNotIn("__ignore_me__", stdout[3])
+ self.assertEqual(stdout[4], "Hello Java Bar!")
+ six.assertRegex(self, stdout[5], "^rloc=.*/bar/bar-java-data.txt")
+ self.assertNotIn("__ignore_me__", stdout[5])
+
with open(stdout[1].split("=", 1)[1], "r") as f:
lines = [l.strip() for l in f.readlines()]
if len(lines) != 1:
@@ -122,6 +130,12 @@ class RunfilesTest(test_base.TestBase):
self.fail("lines: %s" % lines)
self.assertEqual(lines[0], "data for bar.py")
+ with open(stdout[5].split("=", 1)[1], "r") as f:
+ lines = [l.strip() for l in f.readlines()]
+ if len(lines) != 1:
+ self.fail("lines: %s" % lines)
+ self.assertEqual(lines[0], "data for Bar.java")
+
def testRunfilesLibrariesFindRunfilesWithoutEnvvars(self):
for s, t in [
("WORKSPACE.mock", "WORKSPACE"),
diff --git a/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock b/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
index 618ea723b9..15a3a7d467 100644
--- a/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
+++ b/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
@@ -4,6 +4,7 @@ py_binary(
data = [
"datadep/hello.txt",
"//bar:bar-py",
+ "//bar:bar-java",
],
main = "runfiles.py",
deps = ["@bazel_tools//tools/runfiles:py-runfiles"],
diff --git a/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py b/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
index 1be07c4e8f..32100447e9 100644
--- a/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
+++ b/src/test/py/bazel/testdata/runfiles_test/foo/runfiles.py
@@ -53,18 +53,20 @@ def main():
else:
env = {}
env.update(r.EnvVars())
- p = subprocess.Popen(
- [r.Rlocation(ChildBinaryName("py"))],
- env=env,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- out, err = p.communicate()
- out = SplitToLines(out)
- if len(out) >= 2:
- print(out[0]) # e.g. "Hello Python Bar!"
- print(out[1]) # e.g. "rloc=/tmp/foo_ws/bar/bar-py-data.txt"
- else:
- raise Exception("ERROR: error running bar-py: %s" % SplitToLines(err))
+ for lang in ["py", "java"]:
+ p = subprocess.Popen(
+ [r.Rlocation(ChildBinaryName(lang))],
+ env=env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ out = SplitToLines(out)
+ if len(out) >= 2:
+ print(out[0]) # e.g. "Hello Python Bar!"
+ print(out[1]) # e.g. "rloc=/tmp/foo_ws/bar/bar-py-data.txt"
+ else:
+ raise Exception("ERROR: error running bar-%s: %s" % (lang,
+ SplitToLines(err)))
if __name__ == "__main__":