Skip to content

Commit f482fae

Browse files
kotlajacopybara-github
authored andcommitted
BEGIN_PUBLIC
Add java toolchain type to all rules which are using java_common END_PUBLIC PiperOrigin-RevId: 535428309 Change-Id: I8a85dbd24a8aa5e21872ae404e09182533f8ea50
1 parent 1a6db6d commit f482fae

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/test/java/com/google/devtools/build/lib/rules/java/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ java_test(
8585
"//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation",
8686
"//src/test/java/com/google/devtools/build/lib/actions/util",
8787
"//src/test/java/com/google/devtools/build/lib/analysis/util",
88+
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
8889
"//third_party:guava",
8990
"//third_party:junit4",
9091
"//third_party:truth",

src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoStarlarkApiTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.devtools.build.lib.packages.StructImpl;
2828
import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
2929
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
30+
import com.google.devtools.build.lib.testutil.TestConstants;
3031
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3132
import org.junit.Test;
3233
import org.junit.runner.RunWith;
@@ -969,6 +970,7 @@ private void build() throws Exception {
969970
lines.add(
970971
"my_rule = rule(",
971972
" implementation = _impl,",
973+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
972974
" attrs = {",
973975
" 'dep' : attr.label_list(),",
974976
" 'cc_dep' : attr.label_list(),",

src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public void testJavaCommonCompileExposesOutputJarProvider() throws Exception {
415415
" 'sourcepath': attr.label_list(allow_files=['.jar']),",
416416
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
417417
" },",
418+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
418419
" fragments = ['java']",
419420
")");
420421

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

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

@@ -594,6 +597,7 @@ public void javaCommonCompile_requiresJavaPluginInfo() throws Exception {
594597
" 'deps': attr.label_list(),",
595598
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
596599
" },",
600+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
597601
" fragments = ['java']",
598602
")");
599603
scratch.file(
@@ -658,6 +662,7 @@ public void testJavaCommonCompileCompilationInfo() throws Exception {
658662
" 'deps': attr.label_list(),",
659663
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
660664
" },",
665+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
661666
" fragments = ['java']",
662667
")");
663668

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

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

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

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

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

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

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

@@ -2334,6 +2346,7 @@ public void javaCommonCompileWithNeverlink() throws Exception {
23342346
" 'srcs': attr.label_list(allow_files=['.java']),",
23352347
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
23362348
" },",
2349+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
23372350
" fragments = ['java'],",
23382351
" provides = [JavaInfo],",
23392352
")");
@@ -2395,6 +2408,7 @@ public void javaCommonCompile_nativeLibrariesPropagate() throws Exception {
23952408
" 'exports': attr.label_list(),",
23962409
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
23972410
" },",
2411+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
23982412
" fragments = ['java']",
23992413
")");
24002414

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

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

@@ -2813,6 +2829,7 @@ public void testCompileOutputJarHasManifestProto() throws Exception {
28132829
" 'srcs': attr.label_list(allow_files=['.java']),",
28142830
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
28152831
" },",
2832+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
28162833
" fragments = ['java'],",
28172834
")");
28182835
scratch.file(
@@ -2851,6 +2868,7 @@ public void testCompileWithNeverlinkDeps() throws Exception {
28512868
" 'deps': attr.label_list(),",
28522869
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
28532870
" },",
2871+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
28542872
" fragments = ['java'],",
28552873
")");
28562874
scratch.file(
@@ -2892,6 +2910,7 @@ public void testCompileOutputJarNotInRuntimePathWithoutAnySourcesDefined() throw
28922910
" 'exports': attr.label_list(),",
28932911
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
28942912
" },",
2913+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
28952914
" fragments = ['java'],",
28962915
")");
28972916
scratch.file(
@@ -2943,6 +2962,7 @@ public void testConfiguredTargetToolchain() throws Exception {
29432962
" 'srcs': attr.label_list(allow_files=['.java']),",
29442963
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
29452964
" },",
2965+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
29462966
" fragments = ['java'])");
29472967

29482968
reporter.removeHandler(failFastHandler);
@@ -3092,6 +3112,7 @@ public void testSkipAnnotationProcessing() throws Exception {
30923112
" 'plugins': attr.label_list(providers=[JavaPluginInfo]),",
30933113
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
30943114
" },",
3115+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
30953116
" fragments = ['java']",
30963117
")");
30973118
scratch.file(
@@ -3164,6 +3185,7 @@ public void testCompileWithDisablingCompileJarIsPrivateApi() throws Exception {
31643185
" 'srcs': attr.label_list(),",
31653186
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
31663187
" },",
3188+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
31673189
" fragments = ['java']",
31683190
")");
31693191
scratch.file(
@@ -3198,6 +3220,7 @@ public void testCompileWithClasspathResourcesIsPrivateApi() throws Exception {
31983220
" 'classpath_resources': attr.label_list(allow_files = True),",
31993221
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
32003222
" },",
3223+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
32013224
" fragments = ['java']",
32023225
")");
32033226
scratch.file(
@@ -3250,6 +3273,7 @@ public void testInjectingRuleKindIsPrivateApi() throws Exception {
32503273
" 'srcs': attr.label_list(),",
32513274
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
32523275
" },",
3276+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
32533277
" fragments = ['java']",
32543278
")");
32553279
scratch.file(
@@ -3282,6 +3306,7 @@ public void testEnableJSpecifyIsPrivateApi() throws Exception {
32823306
" 'srcs': attr.label_list(),",
32833307
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
32843308
" },",
3309+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
32853310
" fragments = ['java']",
32863311
")");
32873312
scratch.file(
@@ -3366,6 +3391,7 @@ public void testCompileIncludeCompilationInfoIsPrivateApi() throws Exception {
33663391
" 'srcs': attr.label_list(),",
33673392
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
33683393
" },",
3394+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
33693395
" fragments = ['java']",
33703396
")");
33713397
scratch.file(
@@ -3399,6 +3425,7 @@ public void testCompileWithResorceJarsIsPrivateApi() throws Exception {
33993425
" 'srcs': attr.label_list(),",
34003426
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
34013427
" },",
3428+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
34023429
" fragments = ['java']",
34033430
")");
34043431
scratch.file(
@@ -3451,6 +3478,7 @@ public void testRunIjarIsPrivateApi() throws Exception {
34513478
" attrs = {",
34523479
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
34533480
" },",
3481+
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
34543482
" fragments = ['java']",
34553483
")");
34563484
scratch.file(

src/test/shell/bazel/bazel_java_test.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ fi
5757

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

60+
JAVA_TOOLCHAIN_TYPE="@bazel_tools//tools/jdk:toolchain_type"
61+
6062
JAVA_TOOLS_ZIP="$1"; shift
6163
if [[ "${JAVA_TOOLS_ZIP}" != "released" ]]; then
6264
if [[ "${JAVA_TOOLS_ZIP}" == file* ]]; then
@@ -319,6 +321,7 @@ java_custom_library = rule(
319321
"resources": attr.label_list(allow_files=True),
320322
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
321323
},
324+
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
322325
fragments = ["java"]
323326
)
324327
EOF
@@ -497,6 +500,7 @@ java_custom_library = rule(
497500
"sourcepath": attr.label_list(),
498501
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
499502
},
503+
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
500504
fragments = ["java"]
501505
)
502506
EOF
@@ -567,6 +571,7 @@ java_custom_library = rule(
567571
"sourcepath": attr.label_list(),
568572
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
569573
},
574+
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
570575
fragments = ["java"]
571576
)
572577
EOF
@@ -1474,6 +1479,7 @@ java_custom_library = rule(
14741479
"jar": attr.label(allow_files=True),
14751480
"_java_toolchain": attr.label(default = Label("${JAVA_TOOLCHAIN}")),
14761481
},
1482+
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
14771483
fragments = ["java"]
14781484
)
14791485
EOF
@@ -1525,7 +1531,8 @@ my_rule = rule(
15251531
'output_source_jar' : attr.string(),
15261532
'source_jars' : attr.label_list(allow_files=['.jar']),
15271533
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:remote_toolchain")),
1528-
}
1534+
},
1535+
toolchains = ["${JAVA_TOOLCHAIN_TYPE}"],
15291536
)
15301537
EOF
15311538

tools/android/defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ run_ijar = rule(
3232
providers = [java_common.JavaToolchainInfo],
3333
),
3434
},
35+
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
3536
)
3637

3738
def _run_singlejar(ctx):

0 commit comments

Comments
 (0)