use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class SkylarkRuleClassFunctionsTest method testRuleOutputs.
@Test
public void testRuleOutputs() throws Exception {
evalAndExport("def impl(ctx): return None", "r1 = rule(impl, outputs = {'a': 'a.txt'})");
RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
ImplicitOutputsFunction function = c.getDefaultImplicitOutputsFunction();
assertEquals("a.txt", Iterables.getOnlyElement(function.getImplicitOutputs(null)));
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class SkylarkRuleClassFunctionsTest method testRuleImplementation.
@Test
public void testRuleImplementation() throws Exception {
evalAndExport("def impl(ctx): return None", "rule1 = rule(impl)");
RuleClass c = ((RuleFunction) lookup("rule1")).getRuleClass();
assertEquals("impl", c.getConfiguredTargetFunction().getName());
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class HelpCommand method exec.
@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
env.getEventBus().post(new NoBuildEvent());
BlazeRuntime runtime = env.getRuntime();
OutErr outErr = env.getReporter().getOutErr();
Options helpOptions = options.getOptions(Options.class);
if (options.getResidue().isEmpty()) {
emitBlazeVersionInfo(outErr, runtime.getProductName());
emitGenericHelp(outErr, runtime);
return ExitCode.SUCCESS;
}
if (options.getResidue().size() != 1) {
env.getReporter().handle(Event.error("You must specify exactly one command"));
return ExitCode.COMMAND_LINE_ERROR;
}
String helpSubject = options.getResidue().get(0);
if (helpSubject.equals("startup_options")) {
emitBlazeVersionInfo(outErr, runtime.getProductName());
emitStartupOptions(outErr, helpOptions.helpVerbosity, runtime, getOptionCategories(runtime));
return ExitCode.SUCCESS;
} else if (helpSubject.equals("target-syntax")) {
emitBlazeVersionInfo(outErr, runtime.getProductName());
emitTargetSyntaxHelp(outErr, getOptionCategories(runtime), runtime.getProductName());
return ExitCode.SUCCESS;
} else if (helpSubject.equals("info-keys")) {
emitInfoKeysHelp(env, outErr);
return ExitCode.SUCCESS;
} else if (helpSubject.equals("completion")) {
emitCompletionHelp(runtime, outErr);
return ExitCode.SUCCESS;
} else if (helpSubject.equals("everything-as-html")) {
new HtmlEmitter(runtime).emit(outErr);
return ExitCode.SUCCESS;
}
BlazeCommand command = runtime.getCommandMap().get(helpSubject);
if (command == null) {
ConfiguredRuleClassProvider provider = runtime.getRuleClassProvider();
RuleClass ruleClass = provider.getRuleClassMap().get(helpSubject);
if (ruleClass != null && ruleClass.isDocumented()) {
// There is a rule with a corresponding name
outErr.printOut(BlazeRuleHelpPrinter.getRuleDoc(helpSubject, provider));
return ExitCode.SUCCESS;
} else {
env.getReporter().handle(Event.error(null, "'" + helpSubject + "' is neither a command nor a build rule"));
return ExitCode.COMMAND_LINE_ERROR;
}
}
emitBlazeVersionInfo(outErr, runtime.getProductName());
outErr.printOut(BlazeCommandUtils.getUsage(command.getClass(), getOptionCategories(runtime), helpOptions.helpVerbosity, runtime.getBlazeModules(), runtime.getRuleClassProvider(), runtime.getProductName()));
return ExitCode.SUCCESS;
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class SkylarkRepositoryContextTest method buildRuleClass.
protected static RuleClass buildRuleClass(Attribute... attributes) {
RuleClass.Builder ruleClassBuilder = new RuleClass.Builder("test", RuleClassType.WORKSPACE, true);
for (Attribute attr : attributes) {
ruleClassBuilder.addOrOverrideAttribute(attr);
}
ruleClassBuilder.setWorkspaceOnly();
ruleClassBuilder.setConfiguredTargetFunction(new BuiltinFunction("test") {
});
return ruleClassBuilder.build();
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class BazelRuleClassProviderTest method checkConfigConsistency.
private void checkConfigConsistency(ConfiguredRuleClassProvider provider) {
// Check that every fragment required by a rule is present.
Set<Class<? extends BuildConfiguration.Fragment>> configurationFragments = provider.getAllFragments();
for (RuleClass ruleClass : provider.getRuleClassMap().values()) {
for (Class<?> fragment : ruleClass.getConfigurationFragmentPolicy().getRequiredConfigurationFragments()) {
assertWithMessage(ruleClass.toString()).that(configurationFragments).contains(fragment);
}
}
List<Class<? extends FragmentOptions>> configOptions = provider.getConfigurationOptions();
for (ConfigurationFragmentFactory fragmentFactory : provider.getConfigurationFragments()) {
// Check that every created fragment is present.
assertThat(configurationFragments).contains(fragmentFactory.creates());
// Check that every options class required for fragment creation is provided.
for (Class<? extends FragmentOptions> options : fragmentFactory.requiredOptions()) {
assertThat(configOptions).contains(options);
}
}
}
Aggregations