Skip to content

Commit

Permalink
Generate docs for rules referenced in structs.
Browse files Browse the repository at this point in the history
We have rules that are directly referenced via a struct and do not have a starlark function wrapping the rule. These currently do not generate documentation, while other struct referenced fields do if they refer to a starlark function. This CL adds support for generating docs for rules which are referenced in structs.

PiperOrigin-RevId: 502977318
Change-Id: Iaf7fab8c3fc5c2685727193abbc42e5e3a13c57b
  • Loading branch information
Googler authored and pull[bot] committed Feb 20, 2024
1 parent e2f30af commit 31b8171
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ public Module eval(
if (envEntry.getValue() instanceof FakeStructApi) {
String namespaceName = envEntry.getKey();
FakeStructApi namespace = (FakeStructApi) envEntry.getValue();
putStructFields(namespaceName, namespace, userDefinedFunctionMap);
putStructFields(
namespaceName, namespace, ruleFunctions, ruleInfoMap, userDefinedFunctionMap);
}
if (aspectFunctions.containsKey(envEntry.getValue())) {
AspectInfo.Builder aspectInfoBuild =
Expand All @@ -356,16 +357,22 @@ public Module eval(
private static void putStructFields(
String namespaceName,
FakeStructApi namespace,
Map<StarlarkCallable, RuleInfoWrapper> ruleFunctions,
ImmutableMap.Builder<String, RuleInfo> ruleInfoMap,
ImmutableMap.Builder<String, StarlarkFunction> userDefinedFunctionMap)
throws EvalException {
for (String field : namespace.getFieldNames()) {
String qualifiedFieldName = namespaceName + "." + field;
if (namespace.getValue(field) instanceof StarlarkFunction) {
if (ruleFunctions.containsKey(namespace.getValue(field))) {
ruleInfoMap.put(
qualifiedFieldName, ruleFunctions.get(namespace.getValue(field)).getRuleInfo().build());
} else if (namespace.getValue(field) instanceof StarlarkFunction) {
StarlarkFunction userDefinedFunction = (StarlarkFunction) namespace.getValue(field);
userDefinedFunctionMap.put(qualifiedFieldName, userDefinedFunction);
} else if (namespace.getValue(field) instanceof FakeStructApi) {
FakeStructApi innerNamespace = (FakeStructApi) namespace.getValue(field);
putStructFields(qualifiedFieldName, innerNamespace, userDefinedFunctionMap);
putStructFields(
qualifiedFieldName, innerNamespace, ruleFunctions, ruleInfoMap, userDefinedFunctionMap);
}
}
}
Expand Down

0 comments on commit 31b8171

Please sign in to comment.