Skip to content

Commit 99a8186

Browse files
Wyveraldcopybara-github
authored andcommitted
Fix missing DocCategory values causing symbols to show up in wrong places
If the `category` field of the `@StarlarkBuiltin` annotation is not specified, it defaults to a "top-level module" category, which is often not correct. For example, in `attr.label(...)`, `attr` is a top-level module; but most of the things currently listed as top-level modules are not; instead, they should be listed as built-in types. This CL does just that. PiperOrigin-RevId: 487211322 Change-Id: Ide6739e96e395b0bda6cd71b07e02590b0bb488c
1 parent 5318c45 commit 99a8186

File tree

8 files changed

+21
-7
lines changed

8 files changed

+21
-7
lines changed

src/main/java/com/google/devtools/build/docgen/StarlarkDocumentationCollector.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ static synchronized ImmutableMap<String, StarlarkBuiltinDoc> getAllModules(
6060
all =
6161
collectModules(
6262
Iterables.concat(
63-
Classpath.findClasses("com/google/devtools/build"), // Bazel
64-
Classpath.findClasses("net/starlark/java")),
65-
expander); // Starlark
63+
/*Bazel*/ Classpath.findClasses("com/google/devtools/build"),
64+
/*Starlark*/ Classpath.findClasses("net/starlark/java")),
65+
expander);
6666
}
6767
return all;
6868
}

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ java_library(
4949
"TagClass.java",
5050
],
5151
deps = [
52+
"//src/main/java/com/google/devtools/build/docgen/annot",
5253
"//src/main/java/com/google/devtools/build/lib/cmdline",
5354
"//src/main/java/com/google/devtools/build/lib/events",
5455
"//src/main/java/com/google/devtools/build/lib/packages",

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtension.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.base.Preconditions;
1919
import com.google.common.collect.ImmutableMap;
20+
import com.google.devtools.build.docgen.annot.DocCategory;
2021
import com.google.devtools.build.lib.cmdline.Label;
2122
import com.google.devtools.build.lib.events.EventHandler;
2223
import com.google.devtools.build.lib.packages.StarlarkExportable;
@@ -72,7 +73,10 @@ public abstract static class Builder {
7273
* it's exported, at which point it sets the name and builds the underlying {@link
7374
* ModuleExtension}.
7475
*/
75-
@StarlarkBuiltin(name = "module_extension", doc = "A module extension.")
76+
@StarlarkBuiltin(
77+
name = "module_extension",
78+
category = DocCategory.BUILTIN,
79+
doc = "A module extension declared using the <code>module_extension</code> function.")
7680
public static class InStarlark implements StarlarkExportable {
7781
private final Builder builder;
7882
@Nullable private ModuleExtension built;

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/StarlarkBazelModule.java

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.common.collect.Maps;
21+
import com.google.devtools.build.docgen.annot.DocCategory;
2122
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
2223
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
2324
import com.google.devtools.build.lib.packages.LabelConverter;
@@ -37,6 +38,7 @@
3738
/** A Starlark object representing a Bazel module in the external dependency graph. */
3839
@StarlarkBuiltin(
3940
name = "bazel_module",
41+
category = DocCategory.BUILTIN,
4042
doc = "Represents a Bazel module in the external dependency graph.")
4143
public class StarlarkBazelModule implements StarlarkValue {
4244
private final String name;
@@ -46,6 +48,7 @@ public class StarlarkBazelModule implements StarlarkValue {
4648

4749
@StarlarkBuiltin(
4850
name = "bazel_module_tags",
51+
category = DocCategory.BUILTIN,
4952
doc =
5053
"Contains the tags in a module for the module extension currently being processed. This"
5154
+ " object has a field for each tag class of the extension, and the value of the"

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/TagClass.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.common.collect.ImmutableMap;
20+
import com.google.devtools.build.docgen.annot.DocCategory;
2021
import com.google.devtools.build.lib.packages.Attribute;
2122
import net.starlark.java.annot.StarlarkBuiltin;
2223
import net.starlark.java.eval.StarlarkValue;
@@ -25,7 +26,10 @@
2526
/**
2627
* Represents a tag class, which is a "class" of {@link Tag}s that share the same attribute schema.
2728
*/
28-
@StarlarkBuiltin(name = "tag_class", doc = "Defines a schema of attributes for a tag.")
29+
@StarlarkBuiltin(
30+
name = "tag_class",
31+
category = DocCategory.BUILTIN,
32+
doc = "Defines a schema of attributes for a tag.")
2933
@AutoValue
3034
public abstract class TagClass implements StarlarkValue {
3135
/** The list of attributes of this tag class. */

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/TypeCheckedTag.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* A {@link Tag} whose attribute values have been type-checked against the attribute schema define
3030
* in the {@link TagClass}.
3131
*/
32-
@StarlarkBuiltin(name = "bazel_module_tag", doc = "TODO")
32+
@StarlarkBuiltin(name = "bazel_module_tag", documented = false)
3333
public class TypeCheckedTag implements Structure {
3434
private final TagClass tagClass;
3535
private final Object[] attrValues;

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/TemplateDictApi.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/** Template expansion dict module. */
2828
@StarlarkBuiltin(
2929
name = "TemplateDict",
30-
category = DocCategory.TOP_LEVEL_TYPE,
30+
category = DocCategory.BUILTIN,
3131
doc =
3232
"An Args-like structure for use in ctx.actions.expand_template(), which allows for"
3333
+ " deferring evaluation of values till the execution phase.")

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/test/AnalysisTestResultInfoApi.java

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.devtools.build.lib.starlarkbuildapi.test;
1616

17+
import com.google.devtools.build.docgen.annot.DocCategory;
1718
import com.google.devtools.build.docgen.annot.StarlarkConstructor;
1819
import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
1920
import net.starlark.java.annot.Param;
@@ -26,6 +27,7 @@
2627
*/
2728
@StarlarkBuiltin(
2829
name = "AnalysisTestResultInfo",
30+
category = DocCategory.PROVIDER,
2931
doc =
3032
"Encapsulates the result of analyis-phase testing. Build targets which return an instance"
3133
+ " of this provider signal to the build system that it should generate a 'stub' test"

0 commit comments

Comments
 (0)