Skip to content

Commit

Permalink
Do not attempt extract docs of unexported StarlarkExportables in star…
Browse files Browse the repository at this point in the history
…lark_doc_extract

Unexported exportables cannot be used by the user, and attempting
to extract their docs leads to NPEs.

Also, take a drive-by opportunity to convert tests to text blocks
and reformat their bzl content with buildifier.

PiperOrigin-RevId: 627782129
Change-Id: Ib24ffb1b8a25742d94e447da183118c34f2e1981
  • Loading branch information
tetromino authored and copybara-github committed Apr 24, 2024
1 parent 3ebfe24 commit ed6e895
Show file tree
Hide file tree
Showing 3 changed files with 828 additions and 521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.packages.StarlarkDefinedAspect;
import com.google.devtools.build.lib.packages.StarlarkExportable;
import com.google.devtools.build.lib.packages.StarlarkProvider;
import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier;
import com.google.devtools.build.lib.packages.Type;
Expand Down Expand Up @@ -204,6 +205,11 @@ private void maybeVisit(
String qualifiedName, Object value, boolean shouldVisitVerifiedForAncestor)
throws ExtractionException {
if (shouldVisitVerifiedForAncestor || shouldVisit(qualifiedName)) {
if (value instanceof StarlarkExportable && !((StarlarkExportable) value).isExported()) {
// Unexported StarlarkExportables are not usable and therefore do not need to have docs
// generated.
return;
}
if (value instanceof StarlarkRuleFunction) {
visitRule(qualifiedName, (StarlarkRuleFunction) value);
} else if (value instanceof MacroFunction) {
Expand Down Expand Up @@ -413,10 +419,6 @@ protected void visitRule(String qualifiedName, StarlarkRuleFunction ruleFunction
@Override
protected void visitMacroFunction(String qualifiedName, MacroFunction macroFunction)
throws ExtractionException {
if (!macroFunction.isExported()) {
// No point in documenting unexported macroFunctions - they cannot be used as macros.
return;
}
MacroInfo.Builder macroInfoBuilder = MacroInfo.newBuilder();
// Record the name under which this symbol is made accessible, which may differ from the
// symbol's exported name
Expand Down
Loading

0 comments on commit ed6e895

Please sign in to comment.