Search in sources :

Example 1 with SupportData

use of com.google.devtools.build.lib.rules.proto.SupportData in project bazel by bazelbuild.

the class J2ObjcAspect method createJ2ObjcProtoCompileActions.

private J2ObjcMappingFileProvider createJ2ObjcProtoCompileActions(ConfiguredTarget base, RuleContext ruleContext, Iterable<Artifact> filteredProtoSources, J2ObjcSource j2ObjcSource) {
    Iterable<Artifact> outputHeaderMappingFiles = ProtoCommon.getGeneratedOutputs(ruleContext, ImmutableList.copyOf(filteredProtoSources), ".j2objc.mapping");
    Iterable<Artifact> outputClassMappingFiles = ProtoCommon.getGeneratedOutputs(ruleContext, ImmutableList.copyOf(filteredProtoSources), ".clsmap.properties");
    ImmutableList<Artifact> outputs = ImmutableList.<Artifact>builder().addAll(j2ObjcSource.getObjcSrcs()).addAll(j2ObjcSource.getObjcHdrs()).addAll(outputHeaderMappingFiles).addAll(outputClassMappingFiles).build();
    String langPluginParameter = String.format("%s:%s", Joiner.on(',').join(J2OBJC_PLUGIN_PARAMS), ruleContext.getConfiguration().getGenfilesFragment().getPathString());
    SupportData supportData = base.getProvider(ProtoSupportDataProvider.class).getSupportData();
    ProtoCompileActionBuilder actionBuilder = new ProtoCompileActionBuilder(ruleContext, supportData, "J2ObjC", "j2objc", outputs).setLangPluginName("$j2objc_plugin").setLangPluginParameter(langPluginParameter).allowServices(shouldAllowProtoServices(ruleContext));
    ruleContext.registerAction(actionBuilder.build());
    return new J2ObjcMappingFileProvider(NestedSetBuilder.<Artifact>stableOrder().addAll(outputHeaderMappingFiles).build(), NestedSetBuilder.<Artifact>stableOrder().addAll(outputClassMappingFiles).build(), NestedSetBuilder.<Artifact>stableOrder().build(), NestedSetBuilder.<Artifact>stableOrder().build());
}
Also used : SupportData(com.google.devtools.build.lib.rules.proto.SupportData) ProtoSupportDataProvider(com.google.devtools.build.lib.rules.proto.ProtoSupportDataProvider) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 2 with SupportData

use of com.google.devtools.build.lib.rules.proto.SupportData in project bazel by bazelbuild.

the class JavaLiteProtoAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    ConfiguredAspect.Builder aspect = new ConfiguredAspect.Builder(this, parameters, ruleContext);
    // Get SupportData, which is provided by the proto_library rule we attach to.
    SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData();
    Impl impl = new Impl(ruleContext, supportData, javaSemantics);
    impl.addProviders(aspect);
    return aspect.build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) SupportData(com.google.devtools.build.lib.rules.proto.SupportData) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)

Example 3 with SupportData

use of com.google.devtools.build.lib.rules.proto.SupportData in project bazel by bazelbuild.

the class CcProtoAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    // Get SupportData, which is provided by the proto_library rule we attach to.
    SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData();
    try {
        ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(this, parameters, ruleContext);
        new Impl(ruleContext, supportData, cppSemantics).addProviders(result);
        return result.build();
    } catch (RuleErrorException e) {
        ruleContext.ruleError(e.getMessage());
        return null;
    }
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) RuleErrorException(com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException) SupportData(com.google.devtools.build.lib.rules.proto.SupportData) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)

Example 4 with SupportData

use of com.google.devtools.build.lib.rules.proto.SupportData in project bazel by bazelbuild.

the class JavaProtoAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    ConfiguredAspect.Builder aspect = new ConfiguredAspect.Builder(this, parameters, ruleContext);
    if (!rpcSupport.checkAttributes(ruleContext, parameters)) {
        return aspect.build();
    }
    // Get SupportData, which is provided by the proto_library rule we attach to.
    SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData();
    Impl impl = new Impl(ruleContext, supportData, javaSemantics, rpcSupport);
    if (impl.shouldGenerateCode() && ActionReuser.reuseExistingActions(base, ruleContext, aspect)) {
        return aspect.build();
    }
    impl.addProviders(aspect);
    return aspect.build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) SupportData(com.google.devtools.build.lib.rules.proto.SupportData) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder)

Example 5 with SupportData

use of com.google.devtools.build.lib.rules.proto.SupportData in project bazel by bazelbuild.

the class JavaProtoSkylarkCommon method createProtoCompileAction.

@SkylarkCallable(name = "create_java_lite_proto_compile_action", // This function is experimental for now.
documented = false, // There's 2 mandatory positional arguments, the Skylark context and the ConfiguredTarget.
mandatoryPositionals = 2, parameters = { @Param(name = "src_jar", positional = false, named = true, type = Artifact.class), @Param(name = "proto_toolchain_attr", positional = false, named = true, type = String.class), @Param(name = "flavour", positional = false, named = true, type = String.class, defaultValue = "java") })
public static void createProtoCompileAction(SkylarkRuleContext skylarkRuleContext, ConfiguredTarget target, Artifact sourceJar, String protoToolchainAttr, String flavour) {
    SupportData supportData = checkNotNull(target.getProvider(ProtoSupportDataProvider.class).getSupportData());
    ProtoCompileActionBuilder.registerActions(skylarkRuleContext.getRuleContext(), ImmutableList.of(new ProtoCompileActionBuilder.ToolchainInvocation(flavour, getProtoToolchainProvider(skylarkRuleContext, protoToolchainAttr), sourceJar.getExecPathString())), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), skylarkRuleContext.getLabel().getCanonicalForm(), ImmutableList.of(sourceJar), "JavaLite", true);
}
Also used : SupportData(com.google.devtools.build.lib.rules.proto.SupportData) SkylarkCallable(com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)

Aggregations

SupportData (com.google.devtools.build.lib.rules.proto.SupportData)5 ProtoCompileActionBuilder (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder)4 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)3 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)3 Artifact (com.google.devtools.build.lib.actions.Artifact)1 RuleErrorException (com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException)1 ProtoSupportDataProvider (com.google.devtools.build.lib.rules.proto.ProtoSupportDataProvider)1 SkylarkCallable (com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)1