Search in sources :

Example 1 with CcLinkParamsProvider

use of com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider in project bazel by bazelbuild.

the class ObjcProvider method subtractSubtrees.

/**
   * Subtracts dependency subtrees from this provider and returns the result (subtraction does not
   * mutate this provider). Note that not all provider keys are subtracted; generally only keys
   * which correspond with compiled libraries will be subtracted.
   * 
   * <p>This is an expensive operation, as it requires flattening of all nested sets contained
   * in each provider.
   *
   * @param avoidObjcProviders objc providers which contain the dependency subtrees to subtract
   * @param avoidCcProviders cc providers which contain the dependency subtrees to subtract
   */
// TODO(b/19795062): Investigate subtraction generalized to NestedSet.
public ObjcProvider subtractSubtrees(Iterable<ObjcProvider> avoidObjcProviders, Iterable<CcLinkParamsProvider> avoidCcProviders) {
    // LIBRARY and CC_LIBRARY need to be special cased for objc-cc interop.
    // A library which is a dependency of a cc_library may be present in all or any of 
    // three possible locations (and may be duplicated!):
    // 1. ObjcProvider.LIBRARY
    // 2. ObjcProvider.CC_LIBRARY
    // 3. CcLinkParamsProvider->LibraryToLink->getArtifact()
    // TODO(cpeyser): Clean up objc-cc interop.
    HashSet<Artifact> avoidLibrariesSet = new HashSet<>();
    for (CcLinkParamsProvider linkProvider : avoidCcProviders) {
        NestedSet<LibraryToLink> librariesToLink = linkProvider.getCcLinkParams(true, false).getLibraries();
        for (LibraryToLink libraryToLink : librariesToLink.toList()) {
            avoidLibrariesSet.add(libraryToLink.getArtifact());
        }
    }
    for (ObjcProvider avoidProvider : avoidObjcProviders) {
        avoidLibrariesSet.addAll(avoidProvider.getCcLibraries());
        for (Artifact libraryToAvoid : avoidProvider.getPropagable(LIBRARY)) {
            avoidLibrariesSet.add(libraryToAvoid);
        }
    }
    ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
    for (Key<?> key : getValuedKeys()) {
        if (key == CC_LIBRARY) {
            addTransitiveAndFilter(objcProviderBuilder, CC_LIBRARY, ccLibraryNotYetLinked(avoidLibrariesSet));
        } else if (key == LIBRARY) {
            addTransitiveAndFilter(objcProviderBuilder, LIBRARY, notContainedIn(avoidLibrariesSet));
        } else if (NON_SUBTRACTABLE_KEYS.contains(key)) {
            addTransitiveAndAvoid(objcProviderBuilder, key, ImmutableList.<ObjcProvider>of());
        } else {
            addTransitiveAndAvoid(objcProviderBuilder, key, avoidObjcProviders);
        }
    }
    return objcProviderBuilder.build();
}
Also used : LibraryToLink(com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink) CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) HashSet(java.util.HashSet)

Example 2 with CcLinkParamsProvider

use of com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider in project bazel by bazelbuild.

the class JavaImport method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    ImmutableList<Artifact> srcJars = ImmutableList.of();
    ImmutableList<Artifact> jars = collectJars(ruleContext);
    Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar", Mode.TARGET);
    if (ruleContext.hasErrors()) {
        return null;
    }
    ImmutableList<TransitiveInfoCollection> targets = ImmutableList.<TransitiveInfoCollection>builder().addAll(ruleContext.getPrerequisites("deps", Mode.TARGET)).addAll(ruleContext.getPrerequisites("exports", Mode.TARGET)).build();
    final JavaCommon common = new JavaCommon(ruleContext, semantics, /*srcs=*/
    ImmutableList.<Artifact>of(), targets, targets, targets);
    semantics.checkRule(ruleContext, common);
    // No need for javac options - no compilation happening here.
    ImmutableBiMap.Builder<Artifact, Artifact> compilationToRuntimeJarMapBuilder = ImmutableBiMap.builder();
    ImmutableList<Artifact> interfaceJars = processWithIjar(jars, ruleContext, compilationToRuntimeJarMapBuilder);
    JavaCompilationArtifacts javaArtifacts = collectJavaArtifacts(jars, interfaceJars);
    common.setJavaCompilationArtifacts(javaArtifacts);
    CppCompilationContext transitiveCppDeps = common.collectTransitiveCppDeps();
    NestedSet<LinkerInput> transitiveJavaNativeLibraries = common.collectTransitiveJavaNativeLibraries();
    boolean neverLink = JavaCommon.isNeverLink(ruleContext);
    JavaCompilationArgs javaCompilationArgs = common.collectJavaCompilationArgs(false, neverLink, false);
    JavaCompilationArgs recursiveJavaCompilationArgs = common.collectJavaCompilationArgs(true, neverLink, false);
    NestedSet<Artifact> transitiveJavaSourceJars = collectTransitiveJavaSourceJars(ruleContext, srcJar);
    if (srcJar != null) {
        srcJars = ImmutableList.of(srcJar);
    }
    // The "neverlink" attribute is transitive, so if it is enabled, we don't add any
    // runfiles from this target or its dependencies.
    Runfiles runfiles = neverLink ? Runfiles.EMPTY : new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).addArtifacts(javaArtifacts.getRuntimeJars()).addTargets(targets, RunfilesProvider.DEFAULT_RUNFILES).addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES).addTargets(targets, JavaRunfilesProvider.TO_RUNFILES).add(ruleContext, JavaRunfilesProvider.TO_RUNFILES).build();
    CcLinkParamsStore ccLinkParamsStore = new CcLinkParamsStore() {

        @Override
        protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
            builder.addTransitiveTargets(common.targetsTreatedAsDeps(ClasspathType.BOTH), JavaCcLinkParamsProvider.TO_LINK_PARAMS, CcLinkParamsProvider.TO_LINK_PARAMS);
        }
    };
    RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
    NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.stableOrder();
    filesBuilder.addAll(jars);
    ImmutableBiMap<Artifact, Artifact> compilationToRuntimeJarMap = compilationToRuntimeJarMapBuilder.build();
    semantics.addProviders(ruleContext, common, ImmutableList.<String>of(), null, /* classJar */
    srcJar, /* srcJar */
    null, /* genJar */
    null, /* gensrcJar */
    compilationToRuntimeJarMap, filesBuilder, ruleBuilder);
    NestedSet<Artifact> filesToBuild = filesBuilder.build();
    JavaSourceInfoProvider javaSourceInfoProvider = new JavaSourceInfoProvider.Builder().setJarFiles(jars).setSourceJarsForJarFiles(srcJars).build();
    JavaRuleOutputJarsProvider.Builder ruleOutputJarsProviderBuilder = JavaRuleOutputJarsProvider.builder();
    for (Artifact jar : jars) {
        ruleOutputJarsProviderBuilder.addOutputJar(jar, compilationToRuntimeJarMap.inverse().get(jar), srcJars);
    }
    NestedSet<Artifact> proguardSpecs = new ProguardLibrary(ruleContext).collectProguardSpecs();
    JavaRuleOutputJarsProvider ruleOutputJarsProvider = ruleOutputJarsProviderBuilder.build();
    JavaSourceJarsProvider sourceJarsProvider = JavaSourceJarsProvider.create(transitiveJavaSourceJars, srcJars);
    JavaCompilationArgsProvider compilationArgsProvider = JavaCompilationArgsProvider.create(javaCompilationArgs, recursiveJavaCompilationArgs);
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(compilationArgsProvider);
    common.addTransitiveInfoProviders(ruleBuilder, skylarkApiProvider, filesToBuild, null);
    return ruleBuilder.setFilesToBuild(filesToBuild).addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).add(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).add(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(javaArtifacts.getRuntimeJars())).add(JavaNeverlinkInfoProvider.class, new JavaNeverlinkInfoProvider(neverLink)).add(RunfilesProvider.class, RunfilesProvider.simple(runfiles)).add(CcLinkParamsProvider.class, new CcLinkParamsProvider(ccLinkParamsStore)).add(JavaCompilationArgsProvider.class, compilationArgsProvider).add(JavaNativeLibraryProvider.class, new JavaNativeLibraryProvider(transitiveJavaNativeLibraries)).add(CppCompilationContext.class, transitiveCppDeps).add(JavaSourceInfoProvider.class, javaSourceInfoProvider).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(ProguardSpecProvider.class, new ProguardSpecProvider(proguardSpecs)).addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveJavaSourceJars).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, proguardSpecs).build();
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) LinkerInput(com.google.devtools.build.lib.rules.cpp.LinkerInput) CcLinkParamsStore(com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) CppCompilationContext(com.google.devtools.build.lib.rules.cpp.CppCompilationContext) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 3 with CcLinkParamsProvider

use of com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider in project bazel by bazelbuild.

the class JavaLibrary method init.

public RuleConfiguredTargetBuilder init(RuleContext ruleContext, final JavaCommon common) throws InterruptedException {
    JavaTargetAttributes.Builder attributesBuilder = common.initCommon();
    // Collect the transitive dependencies.
    JavaCompilationHelper helper = new JavaCompilationHelper(ruleContext, semantics, common.getJavacOpts(), attributesBuilder);
    helper.addLibrariesToAttributes(common.targetsTreatedAsDeps(ClasspathType.COMPILE_ONLY));
    if (ruleContext.hasErrors()) {
        return null;
    }
    semantics.checkRule(ruleContext, common);
    JavaCompilationArtifacts.Builder javaArtifactsBuilder = new JavaCompilationArtifacts.Builder();
    if (ruleContext.hasErrors()) {
        common.setJavaCompilationArtifacts(JavaCompilationArtifacts.EMPTY);
        return null;
    }
    JavaConfiguration javaConfig = ruleContext.getFragment(JavaConfiguration.class);
    NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.stableOrder();
    JavaTargetAttributes attributes = helper.getAttributes();
    if (attributes.hasMessages()) {
        helper.setTranslations(semantics.translate(ruleContext, javaConfig, attributes.getMessages()));
    }
    ruleContext.checkSrcsSamePackage(true);
    Artifact jar = null;
    Artifact srcJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_LIBRARY_SOURCE_JAR);
    Artifact classJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_LIBRARY_CLASS_JAR);
    if (attributes.hasSourceFiles() || attributes.hasSourceJars() || attributes.hasResources() || attributes.hasMessages()) {
        // We only want to add a jar to the classpath of a dependent rule if it has content.
        javaArtifactsBuilder.addRuntimeJar(classJar);
        jar = classJar;
    }
    filesBuilder.add(classJar);
    Artifact manifestProtoOutput = helper.createManifestProtoOutput(classJar);
    // The gensrc jar is created only if the target uses annotation processing.
    // Otherwise, it is null, and the source jar action will not depend on the compile action.
    Artifact genSourceJar = null;
    Artifact genClassJar = null;
    if (helper.usesAnnotationProcessing()) {
        genClassJar = helper.createGenJar(classJar);
        genSourceJar = helper.createGensrcJar(classJar);
        helper.createGenJarAction(classJar, manifestProtoOutput, genClassJar);
    }
    Artifact outputDepsProto = helper.createOutputDepsProtoArtifact(classJar, javaArtifactsBuilder);
    helper.createCompileActionWithInstrumentation(classJar, manifestProtoOutput, genSourceJar, outputDepsProto, javaArtifactsBuilder);
    helper.createSourceJarAction(srcJar, genSourceJar);
    Artifact iJar = null;
    if ((attributes.hasSourceFiles() || attributes.hasSourceJars()) && jar != null) {
        iJar = helper.createCompileTimeJarAction(jar, javaArtifactsBuilder);
    }
    boolean neverLink = JavaCommon.isNeverLink(ruleContext);
    JavaCompilationArtifacts javaArtifacts = javaArtifactsBuilder.build();
    common.setJavaCompilationArtifacts(javaArtifacts);
    common.setClassPathFragment(new ClasspathConfiguredFragment(javaArtifacts, attributes, neverLink, helper.getBootclasspathOrDefault()));
    CppCompilationContext transitiveCppDeps = common.collectTransitiveCppDeps();
    NestedSet<Artifact> transitiveSourceJars = common.collectTransitiveSourceJars(srcJar);
    // If sources are empty, treat this library as a forwarding node for dependencies.
    JavaCompilationArgs javaCompilationArgs = common.collectJavaCompilationArgs(false, neverLink, false);
    JavaCompilationArgs recursiveJavaCompilationArgs = common.collectJavaCompilationArgs(true, neverLink, false);
    NestedSet<Artifact> compileTimeJavaDepArtifacts = common.collectCompileTimeDependencyArtifacts(javaArtifacts.getCompileTimeDependencyArtifact());
    NestedSet<Artifact> runTimeJavaDepArtifacts = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
    NestedSet<LinkerInput> transitiveJavaNativeLibraries = common.collectTransitiveJavaNativeLibraries();
    CcLinkParamsStore ccLinkParamsStore = new CcLinkParamsStore() {

        @Override
        protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
            builder.addTransitiveTargets(common.targetsTreatedAsDeps(ClasspathType.BOTH), JavaCcLinkParamsProvider.TO_LINK_PARAMS, CcLinkParamsProvider.TO_LINK_PARAMS);
        }
    };
    ProtoJavaApiInfoAspectProvider.Builder protoAspectBuilder = ProtoJavaApiInfoAspectProvider.builder();
    for (TransitiveInfoCollection dep : common.getDependencies()) {
        ProtoJavaApiInfoAspectProvider protoProvider = JavaProvider.getProvider(ProtoJavaApiInfoAspectProvider.class, dep);
        if (protoProvider != null) {
            protoAspectBuilder.addTransitive(protoProvider);
        }
    }
    RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
    semantics.addProviders(ruleContext, common, ImmutableList.<String>of(), classJar, srcJar, genClassJar, genSourceJar, ImmutableMap.<Artifact, Artifact>of(), filesBuilder, builder);
    JavaRuleOutputJarsProvider ruleOutputJarsProvider = JavaRuleOutputJarsProvider.builder().addOutputJar(classJar, iJar, ImmutableList.of(srcJar)).setJdeps(outputDepsProto).build();
    JavaCompilationArgsProvider compilationArgsProvider = JavaCompilationArgsProvider.create(javaCompilationArgs, recursiveJavaCompilationArgs, compileTimeJavaDepArtifacts, runTimeJavaDepArtifacts);
    JavaSourceJarsProvider sourceJarsProvider = JavaSourceJarsProvider.create(transitiveSourceJars, ImmutableList.of(srcJar));
    JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(ruleOutputJarsProvider).setSourceJarsProvider(sourceJarsProvider).setCompilationArgsProvider(compilationArgsProvider);
    NestedSet<Artifact> filesToBuild = filesBuilder.build();
    common.addTransitiveInfoProviders(builder, skylarkApiProvider, filesToBuild, classJar);
    common.addGenJarsProvider(builder, skylarkApiProvider, genClassJar, genSourceJar);
    NestedSet<Artifact> proguardSpecs = new ProguardLibrary(ruleContext).collectProguardSpecs();
    CcLinkParamsProvider ccLinkParamsProvider = new CcLinkParamsProvider(ccLinkParamsStore);
    JavaProvider javaProvider = JavaProvider.Builder.create().addProvider(JavaCompilationArgsProvider.class, compilationArgsProvider).addProvider(JavaSourceJarsProvider.class, sourceJarsProvider).addProvider(ProtoJavaApiInfoAspectProvider.class, protoAspectBuilder.build()).build();
    builder.addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()).add(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider).add(JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(javaArtifacts.getRuntimeJars())).add(RunfilesProvider.class, RunfilesProvider.simple(JavaCommon.getRunfiles(ruleContext, semantics, javaArtifacts, neverLink))).setFilesToBuild(filesToBuild).add(JavaNeverlinkInfoProvider.class, new JavaNeverlinkInfoProvider(neverLink)).add(CppCompilationContext.class, transitiveCppDeps).add(JavaCompilationArgsProvider.class, compilationArgsProvider).add(JavaProvider.class, javaProvider).add(CcLinkParamsProvider.class, ccLinkParamsProvider).addNativeDeclaredProvider(ccLinkParamsProvider).addNativeDeclaredProvider(javaProvider).add(JavaNativeLibraryProvider.class, new JavaNativeLibraryProvider(transitiveJavaNativeLibraries)).add(JavaSourceInfoProvider.class, JavaSourceInfoProvider.fromJavaTargetAttributes(attributes, semantics)).add(JavaSourceJarsProvider.class, sourceJarsProvider).add(JavaPluginInfoProvider.class, JavaCommon.getTransitivePlugins(ruleContext)).add(ProguardSpecProvider.class, new ProguardSpecProvider(proguardSpecs)).addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveSourceJars).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, proguardSpecs);
    if (ruleContext.hasErrors()) {
        return null;
    }
    return builder;
}
Also used : NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) LinkerInput(com.google.devtools.build.lib.rules.cpp.LinkerInput) CcLinkParamsStore(com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) CppCompilationContext(com.google.devtools.build.lib.rules.cpp.CppCompilationContext) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 4 with CcLinkParamsProvider

use of com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider in project bazel by bazelbuild.

the class PyBinary method init.

static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics, PyCommon common) throws InterruptedException {
    CcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext);
    List<Artifact> srcs = common.validateSrcs();
    List<Artifact> allOutputs = new ArrayList<>(semantics.precompiledPythonFiles(ruleContext, srcs, common));
    if (ruleContext.hasErrors()) {
        return null;
    }
    common.initBinary(allOutputs);
    semantics.validate(ruleContext, common);
    if (ruleContext.hasErrors()) {
        return null;
    }
    NestedSet<PathFragment> imports = common.collectImports(ruleContext, semantics);
    if (ruleContext.hasErrors()) {
        return null;
    }
    semantics.createExecutable(ruleContext, common, ccLinkParamsStore, imports);
    Runfiles commonRunfiles = collectCommonRunfiles(ruleContext, common, semantics);
    Runfiles.Builder defaultRunfilesBuilder = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles);
    semantics.collectDefaultRunfilesForBinary(ruleContext, defaultRunfilesBuilder);
    Runfiles defaultRunfiles = defaultRunfilesBuilder.build();
    RunfilesSupport runfilesSupport = RunfilesSupport.withExecutable(ruleContext, defaultRunfiles, common.getExecutable(), ruleContext.shouldCreateRunfilesSymlinks());
    if (ruleContext.hasErrors()) {
        return null;
    }
    // Only include common runfiles and middleman. Default runfiles added by semantics are
    // excluded. The middleman is necessary to ensure the runfiles trees are generated for all
    // dependency binaries.
    Runfiles dataRunfiles = new Runfiles.Builder(ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles()).merge(commonRunfiles).addArtifact(runfilesSupport.getRunfilesMiddleman()).build();
    RunfilesProvider runfilesProvider = RunfilesProvider.withData(defaultRunfiles, dataRunfiles);
    RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
    common.addCommonTransitiveInfoProviders(builder, semantics, common.getFilesToBuild());
    semantics.postInitBinary(ruleContext, runfilesSupport, common);
    return builder.setFilesToBuild(common.getFilesToBuild()).add(RunfilesProvider.class, runfilesProvider).setRunfilesSupport(runfilesSupport, common.getExecutable()).add(CcLinkParamsProvider.class, new CcLinkParamsProvider(ccLinkParamsStore)).add(PythonImportsProvider.class, new PythonImportsProvider(imports));
}
Also used : CcLinkParamsProvider(com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider) CcLinkParamsStore(com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) Runfiles(com.google.devtools.build.lib.analysis.Runfiles) RunfilesSupport(com.google.devtools.build.lib.analysis.RunfilesSupport) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 5 with CcLinkParamsProvider

use of com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider 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)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)6 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)6 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)5 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)5 CcLinkParamsStore (com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore)4 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)3 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)3 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)3 CppCompilationContext (com.google.devtools.build.lib.rules.cpp.CppCompilationContext)2 LinkerInput (com.google.devtools.build.lib.rules.cpp.LinkerInput)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 ArrayList (java.util.ArrayList)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)1 PlatformType (com.google.devtools.build.lib.rules.apple.Platform.PlatformType)1 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)1 HashSet (java.util.HashSet)1