Search in sources :

Example 6 with RuleClass

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)));
}
Also used : ImplicitOutputsFunction(com.google.devtools.build.lib.packages.ImplicitOutputsFunction) RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 7 with RuleClass

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());
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 8 with RuleClass

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;
}
Also used : OutErr(com.google.devtools.build.lib.util.io.OutErr) BlazeCommand(com.google.devtools.build.lib.runtime.BlazeCommand) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) NoBuildEvent(com.google.devtools.build.lib.analysis.NoBuildEvent) RuleClass(com.google.devtools.build.lib.packages.RuleClass) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Example 9 with RuleClass

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();
}
Also used : BuiltinFunction(com.google.devtools.build.lib.syntax.BuiltinFunction) Attribute(com.google.devtools.build.lib.packages.Attribute) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 10 with RuleClass

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);
        }
    }
}
Also used : FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) RuleClass(com.google.devtools.build.lib.packages.RuleClass) ConfigurationFragmentFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Aggregations

RuleClass (com.google.devtools.build.lib.packages.RuleClass)23 RuleFunction (com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction)9 Test (org.junit.Test)9 Attribute (com.google.devtools.build.lib.packages.Attribute)6 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)2 Rule (com.google.devtools.build.lib.packages.Rule)2 ArrayList (java.util.ArrayList)2 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)1 ConfigurationFragmentFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory)1 FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)1 Label (com.google.devtools.build.lib.cmdline.Label)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 AdvertisedProviderSet (com.google.devtools.build.lib.packages.AdvertisedProviderSet)1 Aspect (com.google.devtools.build.lib.packages.Aspect)1 FileTarget (com.google.devtools.build.lib.packages.FileTarget)1 ImplicitOutputsFunction (com.google.devtools.build.lib.packages.ImplicitOutputsFunction)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)1 RuleClassProvider (com.google.devtools.build.lib.packages.RuleClassProvider)1 AllowedRuleClassInfo (com.google.devtools.build.lib.query2.proto.proto2api.Build.AllowedRuleClassInfo)1