From 56f5d96de8f7cda720da9eadfa38ae1c3fdb8289 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 10 Jan 2024 05:19:38 -0800 Subject: [PATCH] Move java_lite_proto_library docs from native to bzl file PiperOrigin-RevId: 597219780 Change-Id: Iaa192ec7363f9517573a7d81da5a7cbdaf91b76e --- .../bazel/rules/BazelRuleClassProvider.java | 3 +- .../proto/BazelJavaLiteProtoLibraryRule.java | 93 ------------------- .../java/proto/java_lite_proto_library.bzl | 37 +++++++- src/main/starlark/docgen/BUILD | 5 + src/main/starlark/docgen/java.bzl | 29 ++++++ 5 files changed, 71 insertions(+), 96 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java create mode 100644 src/main/starlark/docgen/java.bzl diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index fb478eeb473ba6..6233ffec4ef566 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -50,7 +50,6 @@ import com.google.devtools.build.lib.bazel.rules.android.BazelAndroidToolsDefaultsJarRule; import com.google.devtools.build.lib.bazel.rules.android.BazelDexArchiveAspect; import com.google.devtools.build.lib.bazel.rules.android.BazelSdkToolchainRule; -import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaLiteProtoLibraryRule; import com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaProtoLibraryRule; import com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryRule; import com.google.devtools.build.lib.bazel.rules.python.BazelPyBuiltins; @@ -348,7 +347,7 @@ public ImmutableList requires() { @Override public void init(ConfiguredRuleClassProvider.Builder builder) { builder.addRuleDefinition(new BazelJavaProtoLibraryRule()); - builder.addRuleDefinition(new BazelJavaLiteProtoLibraryRule()); + builder.addRuleDefinition(new BaseRuleClasses.EmptyRule("java_lite_proto_library") {}); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java deleted file mode 100644 index 29e5f4c9cb4f1f..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoLibraryRule.java +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.bazel.rules.java.proto; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; - -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier; -import com.google.devtools.build.lib.rules.java.JavaConfiguration; -import com.google.devtools.build.lib.rules.java.JavaInfo; -import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaToolchainBaseRule; - -/** - * Declaration of the {@code java_lite_proto_library} rule. - * - *

This rule is implemented in Starlark. This class remains only for doc-gen purposes. - */ -public class BazelJavaLiteProtoLibraryRule implements RuleDefinition { - - public BazelJavaLiteProtoLibraryRule() {} - - @Override - public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { - return builder - .requiresConfigurationFragments(JavaConfiguration.class) - /* - The list of proto_library - rules to generate Java code for. - */ - .override(attr("deps", LABEL_LIST).allowedRuleClasses("proto_library").allowedFileTypes()) - .advertiseStarlarkProvider(StarlarkProviderIdentifier.forKey(JavaInfo.PROVIDER.getKey())) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("java_lite_proto_library") - .factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class) - .ancestors(BaseRuleClasses.NativeActionCreatingRule.class, JavaToolchainBaseRule.class) - .build(); - } -} - -/* - -

-java_lite_proto_library generates Java code from .proto files. -

- -

-deps must point to proto_library - rules. -

- -

-Example: -

- -
-java_library(
-    name = "lib",
-    deps = [":foo"],
-)
-
-java_lite_proto_library(
-    name = "foo",
-    deps = [":bar"],
-)
-
-proto_library(
-    name = "bar",
-)
-
- - -*/ diff --git a/src/main/starlark/builtins_bzl/common/java/proto/java_lite_proto_library.bzl b/src/main/starlark/builtins_bzl/common/java/proto/java_lite_proto_library.bzl index 38463f6d48cceb..e39f7129c0f35e 100644 --- a/src/main/starlark/builtins_bzl/common/java/proto/java_lite_proto_library.bzl +++ b/src/main/starlark/builtins_bzl/common/java/proto/java_lite_proto_library.bzl @@ -138,8 +138,43 @@ def _rule_impl(ctx): java_lite_proto_library = rule( implementation = _rule_impl, + doc = """ +

+java_lite_proto_library generates Java code from .proto files. +

+ +

+deps must point to proto_library + rules. +

+ +

+Example: +

+ +
+
+java_library(
+    name = "lib",
+    deps = [":foo"],
+)
+
+java_lite_proto_library(
+    name = "foo",
+    deps = [":bar"],
+)
+
+proto_library(
+    name = "bar",
+)
+
+
+""", attrs = { - "deps": attr.label_list(providers = [ProtoInfo], aspects = [java_lite_proto_aspect]), + "deps": attr.label_list(providers = [ProtoInfo], aspects = [java_lite_proto_aspect], doc = """ +The list of proto_library +rules to generate Java code for. +"""), } | toolchains.if_legacy_toolchain({ PROTO_TOOLCHAIN_ATTR: attr.label( default = configuration_field(fragment = "proto", name = "proto_toolchain_for_java_lite"), diff --git a/src/main/starlark/docgen/BUILD b/src/main/starlark/docgen/BUILD index 82d89e264af176..af29ffd033b8bf 100644 --- a/src/main/starlark/docgen/BUILD +++ b/src/main/starlark/docgen/BUILD @@ -8,3 +8,8 @@ starlark_doc_extract( name = "gen_be_proto_stardoc_proto", src = "proto.bzl", ) + +starlark_doc_extract( + name = "gen_be_java_stardoc_proto", + src = "java.bzl", +) diff --git a/src/main/starlark/docgen/java.bzl b/src/main/starlark/docgen/java.bzl new file mode 100644 index 00000000000000..d9120fa0abbda5 --- /dev/null +++ b/src/main/starlark/docgen/java.bzl @@ -0,0 +1,29 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Java""" +# Build Encyclopedia entry point for Java rules implemented in Starlark in Blaze's @_builtins + +binary_rules = struct( +) + +library_rules = struct( + java_lite_proto_library = native.java_lite_proto_library, +) + +test_rules = struct( +) + +other_rules = struct( +)