Skip to content

Commit

Permalink
BEGIN_PUBLIC
Browse files Browse the repository at this point in the history
Add java toolchain type to all rules which are using java_common

END_PUBLIC

PiperOrigin-RevId: 535428309
Change-Id: I8a85dbd24a8aa5e21872ae404e09182533f8ea50
  • Loading branch information
kotlaja authored and copybara-github committed May 25, 2023
1 parent 1a6db6d commit f482fae
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation",
"//src/test/java/com/google/devtools/build/lib/actions/util",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -969,6 +970,7 @@ private void build() throws Exception {
lines.add(
"my_rule = rule(",
" implementation = _impl,",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" attrs = {",
" 'dep' : attr.label_list(),",
" 'cc_dep' : attr.label_list(),",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public void testJavaCommonCompileExposesOutputJarProvider() throws Exception {
" 'sourcepath': attr.label_list(allow_files=['.jar']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -491,6 +492,7 @@ public void javaCommonCompile_setsRuntimeDeps() throws Exception {
" 'runtime_deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -557,6 +559,7 @@ public void testJavaCommonCompileExposesAnnotationProcessingInfo() throws Except
" 'plugins': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -594,6 +597,7 @@ public void javaCommonCompile_requiresJavaPluginInfo() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -658,6 +662,7 @@ public void testJavaCommonCompileCompilationInfo() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -718,6 +723,7 @@ public void testJavaCommonCompileTransitiveSourceJars() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -786,6 +792,7 @@ public void testJavaCommonCompileSourceJarName() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -835,6 +842,7 @@ public void testJavaCommonCompileWithOnlyOneSourceJar() throws Exception {
" 'srcs': attr.label_list(allow_files=['.jar']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -884,6 +892,7 @@ public void testJavaCommonCompile_noSources() throws Exception {
" attrs = {",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -935,6 +944,7 @@ public void testJavaCommonCompileCustomSourceJar() throws Exception {
" 'srcs': attr.label_list(allow_files=['.jar']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -986,6 +996,7 @@ public void testJavaCommonCompileAdditionalInputsAndOutputs() throws Exception {
" 'additional_inputs': attr.label_list(allow_files=['.bin']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -2221,6 +2232,7 @@ public void javaCommonCompileNeverlink() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -2334,6 +2346,7 @@ public void javaCommonCompileWithNeverlink() throws Exception {
" 'srcs': attr.label_list(allow_files=['.java']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java'],",
" provides = [JavaInfo],",
")");
Expand Down Expand Up @@ -2395,6 +2408,7 @@ public void javaCommonCompile_nativeLibrariesPropagate() throws Exception {
" 'exports': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -2452,6 +2466,7 @@ public void javaCommonCompile_directNativeLibraries() throws Exception {
" 'ccdeps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -2780,6 +2795,7 @@ public void testCompileExports() throws Exception {
" 'exports': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");

Expand Down Expand Up @@ -2813,6 +2829,7 @@ public void testCompileOutputJarHasManifestProto() throws Exception {
" 'srcs': attr.label_list(allow_files=['.java']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java'],",
")");
scratch.file(
Expand Down Expand Up @@ -2851,6 +2868,7 @@ public void testCompileWithNeverlinkDeps() throws Exception {
" 'deps': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java'],",
")");
scratch.file(
Expand Down Expand Up @@ -2892,6 +2910,7 @@ public void testCompileOutputJarNotInRuntimePathWithoutAnySourcesDefined() throw
" 'exports': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java'],",
")");
scratch.file(
Expand Down Expand Up @@ -2943,6 +2962,7 @@ public void testConfiguredTargetToolchain() throws Exception {
" 'srcs': attr.label_list(allow_files=['.java']),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java'])");

reporter.removeHandler(failFastHandler);
Expand Down Expand Up @@ -3092,6 +3112,7 @@ public void testSkipAnnotationProcessing() throws Exception {
" 'plugins': attr.label_list(providers=[JavaPluginInfo]),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3164,6 +3185,7 @@ public void testCompileWithDisablingCompileJarIsPrivateApi() throws Exception {
" 'srcs': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3198,6 +3220,7 @@ public void testCompileWithClasspathResourcesIsPrivateApi() throws Exception {
" 'classpath_resources': attr.label_list(allow_files = True),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3250,6 +3273,7 @@ public void testInjectingRuleKindIsPrivateApi() throws Exception {
" 'srcs': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3282,6 +3306,7 @@ public void testEnableJSpecifyIsPrivateApi() throws Exception {
" 'srcs': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3366,6 +3391,7 @@ public void testCompileIncludeCompilationInfoIsPrivateApi() throws Exception {
" 'srcs': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3399,6 +3425,7 @@ public void testCompileWithResorceJarsIsPrivateApi() throws Exception {
" 'srcs': attr.label_list(),",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down Expand Up @@ -3451,6 +3478,7 @@ public void testRunIjarIsPrivateApi() throws Exception {
" attrs = {",
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
" },",
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
" fragments = ['java']",
")");
scratch.file(
Expand Down
9 changes: 8 additions & 1 deletion src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fi

JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain"

JAVA_TOOLCHAIN_TYPE="@bazel_tools//tools/jdk:toolchain_type"

JAVA_TOOLS_ZIP="$1"; shift
if [[ "${JAVA_TOOLS_ZIP}" != "released" ]]; then
if [[ "${JAVA_TOOLS_ZIP}" == file* ]]; then
Expand Down Expand Up @@ -319,6 +321,7 @@ java_custom_library = rule(
"resources": attr.label_list(allow_files=True),
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
},
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
fragments = ["java"]
)
EOF
Expand Down Expand Up @@ -497,6 +500,7 @@ java_custom_library = rule(
"sourcepath": attr.label_list(),
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
},
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
fragments = ["java"]
)
EOF
Expand Down Expand Up @@ -567,6 +571,7 @@ java_custom_library = rule(
"sourcepath": attr.label_list(),
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
},
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
fragments = ["java"]
)
EOF
Expand Down Expand Up @@ -1474,6 +1479,7 @@ java_custom_library = rule(
"jar": attr.label(allow_files=True),
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
},
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
fragments = ["java"]
)
EOF
Expand Down Expand Up @@ -1525,7 +1531,8 @@ my_rule = rule(
'output_source_jar' : attr.string(),
'source_jars' : attr.label_list(allow_files=['.jar']),
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:remote_toolchain")),
}
},
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
)
EOF

Expand Down
1 change: 1 addition & 0 deletions tools/android/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ run_ijar = rule(
providers = [java_common.JavaToolchainInfo],
),
},
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
)

def _run_singlejar(ctx):
Expand Down

0 comments on commit f482fae

Please sign in to comment.