No longer crash when running "bazel help <rule>".
Fixes
MOS_MIGRATED_REVID=150324978
// 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";
}
