Last active
October 14, 2019 14:13
-
-
Save kevingessner/e99fbc80a6fdded8b8902ca64c09b205 to your computer and use it in GitHub Desktop.
test case for https://github.com/bazelbuild/bazel/issues/10019
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java | |
index 025812d..0e7b2a3 100644 | |
--- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java | |
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java | |
@@ -130,6 +130,73 @@ public class JavaSkylarkApiTest extends BuildViewTestCase { | |
} | |
@Test | |
+ public void testJavaRuntimeProviderJavaLauncher() throws Exception { | |
+ scratch.file( | |
+ "a/BUILD", | |
+ "load(':rule.bzl', 'jrule')", | |
+ "load('" | |
+ + TestConstants.TOOLS_REPOSITORY | |
+ + "//tools/jdk:java_toolchain_alias.bzl', 'java_runtime_alias')", | |
+ "java_runtime(name='jvm', srcs=[], java_home='/foo/bar')", | |
+ "java_runtime_alias(name='alias')", | |
+ "jrule(name='r')", | |
+ "constraint_value(", | |
+ " name = 'constraint',", | |
+ " constraint_setting = '" | |
+ + TestConstants.PLATFORM_PACKAGE_ROOT | |
+ + "/java/constraints:runtime',", | |
+ ")", | |
+ "toolchain(", | |
+ " name = 'java_runtime_toolchain',", | |
+ " toolchain = ':jvm',", | |
+ " toolchain_type = '" | |
+ + TestConstants.TOOLS_REPOSITORY | |
+ + "//tools/jdk:runtime_toolchain_type',", | |
+ " target_compatible_with = [':constraint'],", | |
+ ")", | |
+ "platform(", | |
+ " name = 'platform',", | |
+ " constraint_values = [':constraint'],", | |
+ ")", | |
+ "cc_binary(", | |
+ " name = 'launcher',", | |
+ ")"); | |
+ | |
+ scratch.file( | |
+ "a/rule.bzl", | |
+ "load('//myinfo:myinfo.bzl', 'MyInfo')", | |
+ "def _impl(ctx):", | |
+ " provider = ctx.attr._java_runtime[java_common.JavaRuntimeInfo]", | |
+ " return MyInfo(", | |
+ " java_home_exec_path = provider.java_home,", | |
+ " java_executable_exec_path = provider.java_executable_exec_path,", | |
+ " java_home_runfiles_path = provider.java_home_runfiles_path,", | |
+ " java_executable_runfiles_path = provider.java_executable_runfiles_path,", | |
+ " )", | |
+ "jrule = rule(_impl, attrs = { '_java_runtime': attr.label(default=Label('//a:alias'))})"); | |
+ | |
+ useConfiguration( | |
+ "--javabase=//a:jvm", "--extra_toolchains=//a:all", "--platforms=//a:platform", "--java_launcher=//a:launcher"); | |
+ ConfiguredTarget ct = getConfiguredTarget("//a:r"); | |
+ StructImpl myInfo = getMyInfoFromTarget(ct); | |
+ @SuppressWarnings("unchecked") | |
+ PathFragment javaHomeExecPath = (PathFragment) myInfo.getValue("java_home_exec_path"); | |
+ assertThat(javaHomeExecPath.getPathString()).isEqualTo("/foo/bar"); | |
+ @SuppressWarnings("unchecked") | |
+ PathFragment javaExecutableExecPath = | |
+ (PathFragment) myInfo.getValue("java_executable_exec_path"); | |
+ assertThat(javaExecutableExecPath.getPathString()).startsWith("/foo/bar/bin/java"); | |
+ @SuppressWarnings("unchecked") | |
+ PathFragment javaHomeRunfilesPath = (PathFragment) myInfo.getValue("java_home_runfiles_path"); | |
+ // TODO should this be derived from --java_launcher? | |
+ assertThat(javaHomeRunfilesPath.getPathString()).isEqualTo("/foo/bar"); | |
+ @SuppressWarnings("unchecked") | |
+ PathFragment javaExecutableRunfiles = | |
+ (PathFragment) myInfo.getValue("java_executable_runfiles_path"); | |
+ assertThat(javaExecutableRunfiles.getPathString()).startsWith("/a/launcher"); | |
+ } | |
+ | |
+ @Test | |
public void testJavaRuntimeProviderJavaHermetic() throws Exception { | |
scratch.file( | |
"a/BUILD", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment