Skip to content

Commit 03add93

Browse files
comiuscopybara-github
authored andcommitted
BEGIN_PUBLIC Restructure rules_java Design doc: https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit NEW: fixed bzl_libraries END_PUBLIC Automated rollback of commit ddaf864. *** Reason for rollback *** rollforward *** Original change description *** Automated rollback of commit befbd4f. *** Reason for rollback *** postsubmit breakage: [] *** Original change description *** Restructure rules_java BEGIN_PUBLIC Restructure rules_java Design doc: https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit END_ *** PiperOrigin-RevId: 605710436 Change-Id: I4e5f2c3fe0343cf2c77dc532b97049f2686907a5
1 parent ddaf864 commit 03add93

20 files changed

Lines changed: 464 additions & 131 deletions

java/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ licenses(["notice"])
77
filegroup(
88
name = "srcs",
99
srcs = glob(["**"]) + [
10+
"//java/modules:srcs",
1011
"//java/private:srcs",
1112
"//java/proto:srcs",
13+
"//java/toolchains:srcs",
1214
],
1315
visibility = ["//:__pkg__"],
1416
)
@@ -17,6 +19,25 @@ bzl_library(
1719
name = "rules",
1820
srcs = ["defs.bzl"],
1921
visibility = ["//visibility:public"],
22+
deps = [
23+
":core_rules",
24+
"//java/modules",
25+
"//java/proto:proto_rules",
26+
"//java/toolchains:toolchain_rules",
27+
],
28+
)
29+
30+
bzl_library(
31+
name = "core_rules",
32+
srcs = [
33+
"java_binary.bzl",
34+
"java_import.bzl",
35+
"java_library.bzl",
36+
"java_plugin.bzl",
37+
"java_single_jar.bzl",
38+
"java_test.bzl",
39+
],
40+
visibility = ["//visibility:public"],
2041
deps = ["//java/private"],
2142
)
2243

java/defs.bzl

Lines changed: 30 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -13,142 +13,43 @@
1313
# limitations under the License.
1414
"""Starlark rules for building Java projects."""
1515

16-
load("//java/private:native.bzl", "NativeJavaInfo", "NativeJavaPluginInfo", "native_java_common")
16+
load("//java:java_binary.bzl", _java_binary = "java_binary")
17+
load("//java:java_import.bzl", _java_import = "java_import")
18+
load("//java:java_library.bzl", _java_library = "java_library")
19+
load("//java:java_plugin.bzl", _java_plugin = "java_plugin")
20+
load("//java:java_test.bzl", _java_test = "java_test")
21+
load("//java/modules:java_common.bzl", _java_common = "java_common")
22+
load("//java/modules:java_info.bzl", _JavaInfo = "JavaInfo")
23+
load("//java/modules:java_plugin_info.bzl", _JavaPluginInfo = "JavaPluginInfo")
24+
load("//java/proto:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library")
25+
load("//java/proto:java_proto_library.bzl", _java_proto_library = "java_proto_library")
26+
load("//java/toolchains:java_package_configuration.bzl", _java_package_configuration = "java_package_configuration")
27+
load("//java/toolchains:java_runtime.bzl", _java_runtime = "java_runtime")
28+
load("//java/toolchains:java_toolchain.bzl", _java_toolchain = "java_toolchain")
1729

18-
# Do not touch: This line marks the end of loads; needed for PR importing.
19-
20-
_MIGRATION_TAG = "__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
2130
version = "7.4.0"
2231

23-
def _add_tags(attrs):
24-
if "tags" in attrs and attrs["tags"] != None:
25-
attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
26-
else:
27-
attrs["tags"] = [_MIGRATION_TAG]
28-
return attrs
29-
30-
def java_binary(**attrs):
31-
"""Bazel java_binary rule.
32-
33-
https://docs.bazel.build/versions/master/be/java.html#java_binary
34-
35-
Args:
36-
**attrs: Rule attributes
37-
"""
38-
39-
# buildifier: disable=native-java
40-
native.java_binary(**_add_tags(attrs))
41-
42-
def java_import(**attrs):
43-
"""Bazel java_import rule.
44-
45-
https://docs.bazel.build/versions/master/be/java.html#java_import
46-
47-
Args:
48-
**attrs: Rule attributes
49-
"""
50-
51-
# buildifier: disable=native-java
52-
native.java_import(**_add_tags(attrs))
53-
54-
def java_library(**attrs):
55-
"""Bazel java_library rule.
56-
57-
https://docs.bazel.build/versions/master/be/java.html#java_library
58-
59-
Args:
60-
**attrs: Rule attributes
61-
"""
62-
63-
# buildifier: disable=native-java
64-
native.java_library(**_add_tags(attrs))
65-
66-
def java_lite_proto_library(**attrs):
67-
"""Bazel java_lite_proto_library rule.
68-
69-
https://docs.bazel.build/versions/master/be/java.html#java_lite_proto_library
70-
71-
Args:
72-
**attrs: Rule attributes
73-
"""
74-
75-
# buildifier: disable=native-java
76-
native.java_lite_proto_library(**_add_tags(attrs))
77-
78-
def java_proto_library(**attrs):
79-
"""Bazel java_proto_library rule.
80-
81-
https://docs.bazel.build/versions/master/be/java.html#java_proto_library
82-
83-
Args:
84-
**attrs: Rule attributes
85-
"""
86-
87-
# buildifier: disable=native-java
88-
native.java_proto_library(**_add_tags(attrs))
89-
90-
def java_test(**attrs):
91-
"""Bazel java_test rule.
92-
93-
https://docs.bazel.build/versions/master/be/java.html#java_test
94-
95-
Args:
96-
**attrs: Rule attributes
97-
"""
98-
99-
# buildifier: disable=native-java
100-
native.java_test(**_add_tags(attrs))
101-
102-
def java_package_configuration(**attrs):
103-
"""Bazel java_package_configuration rule.
104-
105-
https://docs.bazel.build/versions/master/be/java.html#java_package_configuration
106-
107-
Args:
108-
**attrs: Rule attributes
109-
"""
110-
111-
# buildifier: disable=native-java
112-
native.java_package_configuration(**_add_tags(attrs))
113-
114-
def java_plugin(**attrs):
115-
"""Bazel java_plugin rule.
116-
117-
https://docs.bazel.build/versions/master/be/java.html#java_plugin
118-
119-
Args:
120-
**attrs: Rule attributes
121-
"""
122-
123-
# buildifier: disable=native-java
124-
native.java_plugin(**_add_tags(attrs))
125-
126-
def java_runtime(**attrs):
127-
"""Bazel java_runtime rule.
128-
129-
https://docs.bazel.build/versions/master/be/java.html#java_runtime
130-
131-
Args:
132-
**attrs: Rule attributes
133-
"""
134-
135-
# buildifier: disable=native-java
136-
native.java_runtime(**_add_tags(attrs))
32+
# Language rules
13733

138-
def java_toolchain(**attrs):
139-
"""Bazel java_toolchain rule.
34+
java_binary = _java_binary
35+
java_test = _java_test
36+
java_library = _java_library
37+
java_plugin = _java_plugin
38+
java_import = _java_import
14039

141-
https://docs.bazel.build/versions/master/be/java.html#java_toolchain
40+
# Toolchain rules
14241

143-
Args:
144-
**attrs: Rule attributes
145-
"""
42+
java_runtime = _java_runtime
43+
java_toolchain = _java_toolchain
44+
java_package_configuration = _java_package_configuration
14645

147-
# buildifier: disable=native-java
148-
native.java_toolchain(**_add_tags(attrs))
46+
# Proto rules
14947

150-
java_common = native_java_common
48+
java_proto_library = _java_proto_library
49+
java_lite_proto_library = _java_lite_proto_library
15150

152-
JavaInfo = NativeJavaInfo
51+
# Modules and providers
15352

154-
JavaPluginInfo = NativeJavaPluginInfo
53+
JavaInfo = _JavaInfo
54+
JavaPluginInfo = _JavaPluginInfo
55+
java_common = _java_common

java/java_binary.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_binary rule"""
15+
16+
load("//java/private:add_tags.bzl", "add_tags")
17+
18+
# Do not touch: This line marks the end of loads; needed for PR importing.
19+
20+
def java_binary(**attrs):
21+
"""Bazel java_binary rule.
22+
23+
https://docs.bazel.build/versions/master/be/java.html#java_binary
24+
25+
Args:
26+
**attrs: Rule attributes
27+
"""
28+
29+
# buildifier: disable=native-java
30+
native.java_binary(**add_tags(attrs))

java/java_import.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_import rule"""
15+
16+
load("//java/private:add_tags.bzl", "add_tags")
17+
18+
def java_import(**attrs):
19+
"""Bazel java_import rule.
20+
21+
https://docs.bazel.build/versions/master/be/java.html#java_import
22+
23+
Args:
24+
**attrs: Rule attributes
25+
"""
26+
27+
# buildifier: disable=native-java
28+
native.java_import(**add_tags(attrs))

java/java_library.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_library rule"""
15+
16+
load("//java/private:add_tags.bzl", "add_tags")
17+
18+
# Do not touch: This line marks the end of loads; needed for PR importing.
19+
20+
def java_library(**attrs):
21+
"""Bazel java_library rule.
22+
23+
https://docs.bazel.build/versions/master/be/java.html#java_library
24+
25+
Args:
26+
**attrs: Rule attributes
27+
"""
28+
29+
# buildifier: disable=native-java
30+
native.java_library(**add_tags(attrs))

java/java_plugin.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_plugin rule"""
15+
16+
load("//java/private:add_tags.bzl", "add_tags")
17+
18+
def java_plugin(**attrs):
19+
"""Bazel java_plugin rule.
20+
21+
https://docs.bazel.build/versions/master/be/java.html#java_plugin
22+
23+
Args:
24+
**attrs: Rule attributes
25+
"""
26+
27+
# buildifier: disable=native-java
28+
native.java_plugin(**add_tags(attrs))

java/java_test.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_test rule"""
15+
16+
load("//java/private:add_tags.bzl", "add_tags")
17+
18+
# Do not touch: This line marks the end of loads; needed for PR importing.
19+
20+
def java_test(**attrs):
21+
"""Bazel java_test rule.
22+
23+
https://docs.bazel.build/versions/master/be/java.html#java_test
24+
25+
Args:
26+
**attrs: Rule attributes
27+
"""
28+
29+
# buildifier: disable=native-java
30+
native.java_test(**add_tags(attrs))

java/modules/BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
licenses(["notice"])
6+
7+
filegroup(
8+
name = "srcs",
9+
srcs = glob(["**"]),
10+
visibility = ["//java:__pkg__"],
11+
)
12+
13+
bzl_library(
14+
name = "modules",
15+
srcs = glob(["*.bzl"]),
16+
visibility = ["//visibility:public"],
17+
deps = ["//java/private"],
18+
)

java/modules/java_common.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""java_common module"""
15+
16+
load("//java/private:native.bzl", "native_java_common")
17+
18+
java_common = native_java_common

0 commit comments

Comments
 (0)