use of com.google.devtools.build.lib.runtime.BlazeModule in project bazel by bazelbuild.
the class DocumentationTestUtil method validateUserManual.
/**
* Validates that a user manual {@code documentationSource} contains only the flags actually
* provided by a given set of modules.
*/
public static void validateUserManual(List<Class<? extends BlazeModule>> modules, ConfiguredRuleClassProvider ruleClassProvider, String documentationSource) throws Exception {
// if there is a class missing, one can find it using
// find . -name "*.java" -exec grep -Hn "@Option(name = " {} \; | grep "xxx"
// where 'xxx' is a flag name.
List<BlazeModule> blazeModules = BlazeRuntime.createModules(modules);
Map<String, Object> optionsMap = new HashMap<>();
// collect all startup options
for (Class<? extends OptionsBase> optionsClass : BlazeCommandUtils.getStartupOptions(blazeModules)) {
optionsMap.putAll(Options.getDefaults(optionsClass).asMap());
}
// collect all command options
ServerBuilder serverBuilder = new ServerBuilder();
new BuiltinCommandModule().serverInit(null, serverBuilder);
for (BlazeModule module : blazeModules) {
module.serverInit(null, serverBuilder);
}
List<BlazeCommand> blazeCommands = serverBuilder.getCommands();
for (BlazeCommand command : blazeCommands) {
for (Class<? extends OptionsBase> optionClass : BlazeCommandUtils.getOptions(command.getClass(), blazeModules, ruleClassProvider)) {
optionsMap.putAll(Options.getDefaults(optionClass).asMap());
}
}
// check validity of option flags in manual
Matcher anchorMatcher = CODE_FLAG_PATTERN.matcher(documentationSource);
String flag;
boolean found;
while (anchorMatcher.find()) {
flag = anchorMatcher.group(1);
found = optionsMap.containsKey(flag);
if (!found && flag.startsWith("no")) {
found = optionsMap.containsKey(flag.substring(2));
}
if (!found && flag.startsWith("[no]")) {
found = optionsMap.containsKey(flag.substring(4));
}
assertWithMessage("flag '" + flag + "' is not a blaze option (anymore)").that(found).isTrue();
}
String unclosedTag = DocCheckerUtils.getFirstUnclosedTagAndPrintHelp(documentationSource);
assertWithMessage("Unclosed tag found: " + unclosedTag).that(unclosedTag).isNull();
}
use of com.google.devtools.build.lib.runtime.BlazeModule in project bazel by bazelbuild.
the class HelpCommand method emitCompletionHelp.
private void emitCompletionHelp(BlazeRuntime runtime, OutErr outErr) {
// First startup_options
Iterable<BlazeModule> blazeModules = runtime.getBlazeModules();
ConfiguredRuleClassProvider ruleClassProvider = runtime.getRuleClassProvider();
Map<String, BlazeCommand> commandsByName = getSortedCommands(runtime);
outErr.printOutLn("BAZEL_COMMAND_LIST=\"" + SPACE_JOINER.join(commandsByName.keySet()) + "\"");
outErr.printOutLn("BAZEL_INFO_KEYS=\"");
for (String name : InfoCommand.getHardwiredInfoItemNames(runtime.getProductName())) {
outErr.printOutLn(name);
}
outErr.printOutLn("\"");
outErr.printOutLn("BAZEL_STARTUP_OPTIONS=\"");
Iterable<Class<? extends OptionsBase>> options = BlazeCommandUtils.getStartupOptions(blazeModules);
outErr.printOut(OptionsParser.newOptionsParser(options).getOptionsCompletion());
outErr.printOutLn("\"");
for (Map.Entry<String, BlazeCommand> e : commandsByName.entrySet()) {
BlazeCommand command = e.getValue();
String varName = e.getKey().toUpperCase(Locale.US).replace('-', '_');
Command annotation = command.getClass().getAnnotation(Command.class);
if (!annotation.completion().isEmpty()) {
outErr.printOutLn("BAZEL_COMMAND_" + varName + "_ARGUMENT=\"" + annotation.completion() + "\"");
}
options = BlazeCommandUtils.getOptions(command.getClass(), blazeModules, ruleClassProvider);
outErr.printOutLn("BAZEL_COMMAND_" + varName + "_FLAGS=\"");
outErr.printOut(OptionsParser.newOptionsParser(options).getOptionsCompletion());
outErr.printOutLn("\"");
}
}
Aggregations