aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2017-03-16 15:55:19 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-03-16 19:51:44 +0000
commit1fce95d0d3256253723fe87322d38f5ce63a2e88 (patch)
treeff4ff684a09c6a37b09a4de2419d2517dd82395e
parentc0fac18ed2e0407556f91317c5fdd6bcf57f5a8b (diff)
No longer crash when running "bazel help <rule>".
Fixes #2270. -- PiperOrigin-RevId: 150324978 MOS_MIGRATED_REVID=150324978
-rw-r--r--src/main/java/com/google/devtools/build/docgen/BlazeRuleHelpPrinter.java13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/docgen/BlazeRuleHelpPrinter.java b/src/main/java/com/google/devtools/build/docgen/BlazeRuleHelpPrinter.java
index e262aa4267..789554f312 100644
--- a/src/main/java/com/google/devtools/build/docgen/BlazeRuleHelpPrinter.java
+++ b/src/main/java/com/google/devtools/build/docgen/BlazeRuleHelpPrinter.java
@@ -13,10 +13,8 @@
// limitations under the License.
package com.google.devtools.build.docgen;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
-
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -50,10 +48,13 @@ public class BlazeRuleHelpPrinter {
return e.getMessage();
}
}
- // Every rule should be documented and this method should be called only
- // for existing rules (a check is performed in HelpCommand).
- Preconditions.checkState(ruleDocMap.containsKey(ruleName), String.format(
- "ERROR: Documentation of rule %s does not exist.", ruleName));
+ // TODO(fwe): generate the rule documentation when building the Bazel binary and ship
+ // the text documentation with the binary.
+ // The Bazel binary may not contain the rule sources, which means that the documentation
+ // retrieval step would fail with an exception.
+ if (!ruleDocMap.containsKey(ruleName)) {
+ return String.format("Documentation for rule %s is not part of the binary.\n", ruleName);
+ }
return "Rule " + ruleName + ":"
+ ruleDocMap.get(ruleName).getCommandLineDocumentation() + "\n";
}