Search in sources :

Example 41 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class BinaryLinkingTargetFactory method create.

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ProtobufSupport protoSupport = new ProtobufSupport(ruleContext).registerGenerationActions().registerCompilationActions();
    Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
    Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider();
    ObjcCommon common = common(ruleContext, protosObjcProvider);
    ObjcProvider objcProvider = common.getObjcProvider();
    assertLibraryOrSources(objcProvider, ruleContext);
    XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder().addPropagatedDependencies(protosXcodeProvider.asSet());
    IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(intermediateArtifacts.strippedSingleArchitectureBinary());
    new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder);
    ruleContext.assertNoErrors();
    J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider.union(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class));
    J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder().addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build();
    CompilationSupport compilationSupport = CompilationSupport.create(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder, common).registerCompileAndArchiveActions(common).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)).registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, getExtraLinkArgs(ruleContext), ImmutableList.<Artifact>of(), DsymOutputType.APP);
    Optional<XcTestAppProvider> xcTestAppProvider;
    Optional<RunfilesSupport> maybeRunfilesSupport = Optional.absent();
    switch(hasReleaseBundlingSupport) {
        case YES:
            AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
            // TODO(bazel-team): Remove once all bundle users are migrated to ios_application.
            ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, objcProvider, LinkedBinary.LOCAL_AND_DEPENDENCIES, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getSingleArchPlatform());
            releaseBundlingSupport.registerActions(DsymOutputType.APP).addXcodeSettings(xcodeProviderBuilder).addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources().validateAttributes();
            xcTestAppProvider = Optional.of(releaseBundlingSupport.xcTestAppProvider());
            if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) == Platform.IOS_SIMULATOR) {
                Artifact runnerScript = intermediateArtifacts.runnerScript();
                Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA);
                releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile);
                maybeRunfilesSupport = Optional.of(releaseBundlingSupport.runfilesSupport(runnerScript));
            }
            break;
        case NO:
            xcTestAppProvider = Optional.absent();
            break;
        default:
            throw new AssertionError();
    }
    XcodeSupport xcodeSupport = new XcodeSupport(ruleContext).addXcodeSettings(xcodeProviderBuilder, objcProvider, productType).addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)).addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)).addNonPropagatedDependencies(xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)).addFilesToBuild(filesToBuild);
    if (productType != XcodeProductType.LIBRARY_STATIC) {
        xcodeSupport.generateCompanionLibXcodeTarget(xcodeProviderBuilder);
    }
    XcodeProvider xcodeProvider = xcodeProviderBuilder.build();
    xcodeSupport.registerActions(xcodeProvider);
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()).addProvider(XcodeProvider.class, xcodeProvider).addProvider(ObjcProvider.class, objcProvider).addProvider(InstrumentedFilesProvider.class, compilationSupport.getInstrumentedFilesProvider(common));
    if (xcTestAppProvider.isPresent()) {
        // TODO(bazel-team): Stop exporting an XcTestAppProvider once objc_binary no longer creates an
        // application bundle.
        targetBuilder.addProvider(XcTestAppProvider.class, xcTestAppProvider.get());
    }
    if (maybeRunfilesSupport.isPresent()) {
        RunfilesSupport runfilesSupport = maybeRunfilesSupport.get();
        targetBuilder.setRunfilesSupport(runfilesSupport, runfilesSupport.getExecutable());
    }
    configureTarget(targetBuilder, ruleContext);
    return targetBuilder.build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) Artifact(com.google.devtools.build.lib.actions.Artifact) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 42 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class AppleStaticLibrary method create.

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
    ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT);
    ImmutableListMultimap<BuildConfiguration, ObjcProvider> configToObjcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, ObjcProvider.class);
    ImmutableListMultimap<BuildConfiguration, CcLinkParamsProvider> configToCcAvoidDepsMap = ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT, CcLinkParamsProvider.class);
    Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);
    IntermediateArtifacts ruleIntermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
    NestedSetBuilder<Artifact> librariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(ruleIntermediateArtifacts.combinedArchitectureArchive());
    ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
    for (BuildConfiguration childConfig : childConfigurations) {
        ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig).registerGenerationActions().registerCompilationActions();
        Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
        IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig);
        ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts, nullToEmptyList(configToDepsCollectionMap.get(childConfig)), protosObjcProvider);
        ObjcProvider objcProvider = common.getObjcProvider().subtractSubtrees(configToObjcAvoidDepsMap.get(childConfig), configToCcAvoidDepsMap.get(childConfig));
        librariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureLibrary());
        CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(common).registerFullyLinkAction(objcProvider, intermediateArtifacts.strippedSingleArchitectureLibrary()).validateAttributes();
        ruleContext.assertNoErrors();
        addTransitivePropagatedKeys(objcProviderBuilder, objcProvider);
    }
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    new LipoSupport(ruleContext).registerCombineArchitecturesAction(librariesToLipo.build(), ruleIntermediateArtifacts.combinedArchitectureArchive(), appleConfiguration.getMultiArchPlatform(platformType));
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build());
    objcProviderBuilder.add(MULTI_ARCH_LINKED_ARCHIVES, ruleIntermediateArtifacts.combinedArchitectureArchive());
    targetBuilder.addProvider(ObjcProvider.class, objcProviderBuilder.build());
    return targetBuilder.build();
}
Also used : CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) PlatformType(com.google.devtools.build.lib.rules.apple.Platform.PlatformType)

Example 43 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class JavaLibrary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    JavaCommon common = new JavaCommon(ruleContext, semantics);
    RuleConfiguredTargetBuilder builder = init(ruleContext, common);
    return builder != null ? builder.build() : null;
}
Also used : RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 44 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class TestSuite method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorException {
    checkTestsAndSuites(ruleContext, "tests");
    if (ruleContext.hasErrors()) {
        return null;
    }
    //
    //  CAUTION!  Keep this logic consistent with lib.query2.TestsExpression!
    //
    List<String> tagsAttribute = new ArrayList<>(ruleContext.attributes().get("tags", Type.STRING_LIST));
    tagsAttribute.remove("manual");
    Pair<Collection<String>, Collection<String>> requiredExcluded = TestTargetUtils.sortTagsBySense(tagsAttribute);
    List<TransitiveInfoCollection> directTestsAndSuitesBuilder = new ArrayList<>();
    // Manual tests are already filtered out there. That is what $implicit_tests is about.
    for (TransitiveInfoCollection dep : Iterables.concat(getPrerequisites(ruleContext, "tests"), getPrerequisites(ruleContext, "$implicit_tests"))) {
        if (dep.getProvider(TestProvider.class) != null) {
            List<String> tags = dep.getProvider(TestProvider.class).getTestTags();
            if (!TestTargetUtils.testMatchesFilters(tags, requiredExcluded.first, requiredExcluded.second, true)) {
                // This test does not match our filter. Ignore it.
                continue;
            }
        }
        directTestsAndSuitesBuilder.add(dep);
    }
    Runfiles runfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addTargets(directTestsAndSuitesBuilder, RunfilesProvider.DATA_RUNFILES).build();
    return new RuleConfiguredTargetBuilder(ruleContext).add(RunfilesProvider.class, RunfilesProvider.withData(Runfiles.EMPTY, runfiles)).add(TransitiveTestsProvider.class, new TransitiveTestsProvider()).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Collection(java.util.Collection) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 45 with RuleConfiguredTargetBuilder

use of com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder in project bazel by bazelbuild.

the class BazelProtoLibrary method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ImmutableList<Artifact> protoSources = ruleContext.getPrerequisiteArtifacts("srcs", TARGET).list();
    NestedSet<Artifact> checkDepsProtoSources = ProtoCommon.getCheckDepsProtoSources(ruleContext, protoSources);
    ProtoCommon.checkSourceFilesAreInSamePackage(ruleContext);
    NestedSet<Artifact> transitiveImports = ProtoCommon.collectTransitiveImports(ruleContext, protoSources);
    NestedSet<Artifact> protosInDirectDeps = ProtoCommon.computeProtosInDirectDeps(ruleContext);
    final SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysTrue(), /* nonWeakDepsPredicate */
    protoSources, protosInDirectDeps, transitiveImports, !protoSources.isEmpty());
    Artifact descriptorSetOutput = ruleContext.getGenfilesArtifact(ruleContext.getLabel().getName() + "-descriptor-set.proto.bin");
    NestedSet<Artifact> dependenciesDescriptorSets = ProtoCommon.collectDependenciesDescriptorSets(ruleContext);
    NestedSet<Artifact> transitiveDescriptorSetOutput = NestedSetBuilder.fromNestedSet(dependenciesDescriptorSets).add(descriptorSetOutput).build();
    ProtoCompileActionBuilder.writeDescriptorSet(ruleContext, descriptorSetOutput.getExecPathString(), protoSources, transitiveImports, protosInDirectDeps, descriptorSetOutput, true, /* allowServices */
    dependenciesDescriptorSets);
    Runfiles dataRunfiles = ProtoCommon.createDataRunfilesProvider(transitiveImports, ruleContext).addArtifact(descriptorSetOutput).build();
    // TODO(bazel-team): this second constructor argument is superfluous and should be removed.
    ProtoSourcesProvider sourcesProvider = ProtoSourcesProvider.create(transitiveImports, transitiveImports, protoSources, checkDepsProtoSources, descriptorSetOutput, transitiveDescriptorSetOutput);
    return new RuleConfiguredTargetBuilder(ruleContext).setFilesToBuild(NestedSetBuilder.create(STABLE_ORDER, descriptorSetOutput)).addProvider(RunfilesProvider.withData(Runfiles.EMPTY, dataRunfiles)).addProvider(ProtoSourcesProvider.class, sourcesProvider).addProvider(ProtoSupportDataProvider.class, new ProtoSupportDataProvider(supportData)).addSkylarkTransitiveInfo(ProtoSourcesProvider.SKYLARK_NAME, sourcesProvider).build();
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)48 Artifact (com.google.devtools.build.lib.actions.Artifact)36 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)21 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)19 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)17 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)11 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)7 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)6 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)5 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 Label (com.google.devtools.build.lib.cmdline.Label)4 CcLinkParamsStore (com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)3 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)3 CompositeRunfilesSupplier (com.google.devtools.build.lib.actions.CompositeRunfilesSupplier)2 CommandHelper (com.google.devtools.build.lib.analysis.CommandHelper)2