aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/docgen/BuildEncyclopediaProcessor.java40
-rw-r--r--src/main/java/com/google/devtools/build/docgen/DocgenConsts.java2
-rw-r--r--src/main/java/com/google/devtools/build/docgen/SourceFileReader.java76
-rw-r--r--src/main/java/com/google/devtools/build/docgen/templates/be-body.html8
4 files changed, 62 insertions, 64 deletions
diff --git a/src/main/java/com/google/devtools/build/docgen/BuildEncyclopediaProcessor.java b/src/main/java/com/google/devtools/build/docgen/BuildEncyclopediaProcessor.java
index 8a1a02d0ea..baf3399443 100644
--- a/src/main/java/com/google/devtools/build/docgen/BuildEncyclopediaProcessor.java
+++ b/src/main/java/com/google/devtools/build/docgen/BuildEncyclopediaProcessor.java
@@ -188,30 +188,31 @@ public class BuildEncyclopediaProcessor {
Set<RuleDocumentation> binaryDocs = new TreeSet<>();
Set<RuleDocumentation> libraryDocs = new TreeSet<>();
Set<RuleDocumentation> testDocs = new TreeSet<>();
- Set<RuleDocumentation> generateDocs = new TreeSet<>();
Set<RuleDocumentation> otherDocs = new TreeSet<>();
for (RuleDocumentation doc : docEntries) {
RuleClass ruleClass = ruleClassProvider.getRuleClassMap().get(doc.getRuleName());
- if (ruleClass.isDocumented()) {
- if (doc.isLanguageSpecific()) {
- switch(doc.getRuleType()) {
- case BINARY:
- binaryDocs.add(doc);
- break;
- case LIBRARY:
- libraryDocs.add(doc);
- break;
- case TEST:
- testDocs.add(doc);
- break;
- case OTHER:
- otherDocs.add(doc);
- break;
- }
- } else {
- otherDocs.add(doc);
+ if (!ruleClass.isDocumented()) {
+ continue;
+ }
+
+ if (doc.isLanguageSpecific()) {
+ switch(doc.getRuleType()) {
+ case BINARY:
+ binaryDocs.add(doc);
+ break;
+ case LIBRARY:
+ libraryDocs.add(doc);
+ break;
+ case TEST:
+ testDocs.add(doc);
+ break;
+ case OTHER:
+ otherDocs.add(doc);
+ break;
}
+ } else {
+ otherDocs.add(doc);
}
}
@@ -223,7 +224,6 @@ public class BuildEncyclopediaProcessor {
DocgenConsts.VAR_SECTION_BINARY, getRuleDocs(binaryDocs),
DocgenConsts.VAR_SECTION_LIBRARY, getRuleDocs(libraryDocs),
DocgenConsts.VAR_SECTION_TEST, getRuleDocs(testDocs),
- DocgenConsts.VAR_SECTION_GENERATE, getRuleDocs(generateDocs),
DocgenConsts.VAR_SECTION_OTHER, getRuleDocs(otherDocs));
bw.write("\n"); // for the benefit of the block-beginning comment at the top of the template
bw.write(SourceFileReader.readTemplateContents(DocgenConsts.BODY_TEMPLATE, sectionMapping));
diff --git a/src/main/java/com/google/devtools/build/docgen/DocgenConsts.java b/src/main/java/com/google/devtools/build/docgen/DocgenConsts.java
index e1edf29a6f..01bf7d60c6 100644
--- a/src/main/java/com/google/devtools/build/docgen/DocgenConsts.java
+++ b/src/main/java/com/google/devtools/build/docgen/DocgenConsts.java
@@ -39,7 +39,6 @@ public class DocgenConsts {
public static final String VAR_SECTION_BINARY = "SECTION_BINARY";
public static final String VAR_SECTION_LIBRARY = "SECTION_LIBRARY";
public static final String VAR_SECTION_TEST = "SECTION_TEST";
- public static final String VAR_SECTION_GENERATE = "SECTION_GENERATE";
public static final String VAR_SECTION_OTHER = "SECTION_OTHER";
public static final String VAR_IMPLICIT_OUTPUTS = "IMPLICIT_OUTPUTS";
@@ -133,6 +132,7 @@ public class DocgenConsts {
public static final Pattern BLAZE_RULE_ATTR_END = Pattern.compile(
"^[\\s]*\\<!\\-\\-[\\s]*#END_BLAZE_RULE\\.ATTRIBUTE[\\s]*\\-\\-\\>[\\s]*\\*/");
+ /** e.g. "[DEPRECATED]" in &lt;!-- #BLAZE_RULE(...).ATTRIBUTE(...)[DEPRECATED] --&gt; */
public static final Pattern BLAZE_RULE_FLAGS = Pattern.compile("^.*\\[(.*)\\].*$");
public static final Map<String, Integer> ATTRIBUTE_ORDERING = ImmutableMap
diff --git a/src/main/java/com/google/devtools/build/docgen/SourceFileReader.java b/src/main/java/com/google/devtools/build/docgen/SourceFileReader.java
index c17b3f611a..f3a42f320f 100644
--- a/src/main/java/com/google/devtools/build/docgen/SourceFileReader.java
+++ b/src/main/java/com/google/devtools/build/docgen/SourceFileReader.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.docgen;
+import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
@@ -141,12 +142,30 @@ public class SourceFileReader {
private void startBlazeRuleDoc(String line, Matcher matcher)
throws BuildEncyclopediaDocException {
checkDocValidity();
- // Start of a new rule
- String[] metaData = matcher.group(1).split(",");
+ // Start of a new rule.
+ // e.g.: matcher.group(1) = "NAME = cc_binary, TYPE = BINARY, FAMILY = C / C++"
+ for (String group : Splitter.on(",").split(matcher.group(1))) {
+ List<String> parts = Splitter.on("=").limit(2).splitToList(group);
+ boolean good = false;
+ if (parts.size() == 2) {
+ String key = parts.get(0).trim();
+ String value = parts.get(1).trim();
+ good = true;
+ if (DocgenConsts.META_KEY_NAME.equals(key)) {
+ ruleName = value;
+ } else if (DocgenConsts.META_KEY_TYPE.equals(key)) {
+ ruleType = value;
+ } else if (DocgenConsts.META_KEY_FAMILY.equals(key)) {
+ ruleFamily = value;
+ } else {
+ good = false;
+ }
+ }
+ if (!good) {
+ System.err.printf("WARNING: bad rule definition in line %d: '%s'", getLineCnt(), line);
+ }
+ }
- ruleName = readMetaData(metaData, DocgenConsts.META_KEY_NAME);
- ruleType = readMetaData(metaData, DocgenConsts.META_KEY_TYPE);
- ruleFamily = readMetaData(metaData, DocgenConsts.META_KEY_FAMILY);
startLineCnt = getLineCnt();
addFlags(line);
inBlazeRuleDocs = true;
@@ -224,11 +243,10 @@ public class SourceFileReader {
docMap.get(docVariable.getRuleName()).addDocVariable(
docVariable.getVariableName(), docVariable.getValue());
} else {
- throw new BuildEncyclopediaDocException(javaSourceFilePath,
- docVariable.getStartLineCnt(), String.format(
- "Malformed rule variable #BLAZE_RULE(%s).%s, "
- + "rule %s not found in file.", docVariable.getRuleName(),
- docVariable.getVariableName(), docVariable.getRuleName()));
+ throw new BuildEncyclopediaDocException(javaSourceFilePath, docVariable.getStartLineCnt(),
+ String.format("Malformed rule variable #BLAZE_RULE(%s).%s, rule %s not found in file.",
+ docVariable.getRuleName(), docVariable.getVariableName(),
+ docVariable.getRuleName()));
}
}
ruleDocEntries = docMap.values();
@@ -243,20 +261,6 @@ public class SourceFileReader {
return attributeDocEntries;
}
- private String readMetaData(String[] metaData, String metaKey) {
- for (String metaDataItem : metaData) {
- String[] metaDataItemParts = metaDataItem.split("=", 2);
- if (metaDataItemParts.length != 2) {
- return null;
- }
-
- if (metaDataItemParts[0].trim().equals(metaKey)) {
- return metaDataItemParts[1].trim();
- }
- }
- return null;
- }
-
/**
* Reads the template file without variable substitution.
*/
@@ -266,28 +270,30 @@ public class SourceFileReader {
}
/**
- * Reads the template file and expands the variables. The variables has to have
- * the following format in the template file: ${VARIABLE_NAME}. In the Map
- * input parameter the key has to be VARIABLE_NAME. Variables can be null.
+ * Reads a template file and substitutes variables of the format ${FOO}.
+ *
+ * @param variables keys are the possible variable names, e.g. "FOO", values are the substitutions
+ * (can be null)
*/
- public static String readTemplateContents(
- String templateFilePath, final Map<String, String> variables)
- throws BuildEncyclopediaDocException, IOException {
+ public static String readTemplateContents(String templateFilePath,
+ final Map<String, String> variables) throws BuildEncyclopediaDocException, IOException {
final StringBuilder sb = new StringBuilder();
readTextFile(templateFilePath, new ReadAction() {
@Override
public void readLineImpl(String line) {
- sb.append(expandVariables(line, variables) + LS);
+ sb.append(expandVariables(line, variables)).append(LS);
}
});
return sb.toString();
}
private static String expandVariables(String line, Map<String, String> variables) {
- if (variables != null) {
- for (Entry<String, String> variable : variables.entrySet()) {
- line = line.replace("${" + variable.getKey() + "}", variable.getValue());
- }
+ if (variables == null || line.indexOf("${") == -1) {
+ return line;
+ }
+
+ for (Entry<String, String> variable : variables.entrySet()) {
+ line = line.replace("${" + variable.getKey() + "}", variable.getValue());
}
return line;
}
diff --git a/src/main/java/com/google/devtools/build/docgen/templates/be-body.html b/src/main/java/com/google/devtools/build/docgen/templates/be-body.html
index 29c68285a4..dabadb80bb 100644
--- a/src/main/java/com/google/devtools/build/docgen/templates/be-body.html
+++ b/src/main/java/com/google/devtools/build/docgen/templates/be-body.html
@@ -34,14 +34,6 @@ ${SECTION_LIBRARY}
${SECTION_TEST}
<!-- ============================================
- generate code and data
- ============================================
--->
-<h2>Rules to Generate Code and Data</h2>
-
-${SECTION_GENERATE}
-
-<!-- ============================================
variables
============================================
-->