Search in sources :

Example 1 with CcLinkParams

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

the class NativeLibs method fromLinkedNativeDeps.

public static NativeLibs fromLinkedNativeDeps(RuleContext ruleContext, String nativeDepsFileName, Multimap<String, TransitiveInfoCollection> depsByArchitecture, Map<String, CcToolchainProvider> toolchainMap, Map<String, BuildConfiguration> configurationMap) throws InterruptedException {
    Map<String, Iterable<Artifact>> result = new LinkedHashMap<>();
    String nativeDepsLibraryBasename = null;
    for (Map.Entry<String, Collection<TransitiveInfoCollection>> entry : depsByArchitecture.asMap().entrySet()) {
        CcLinkParams linkParams = AndroidCommon.getCcLinkParamsStore(entry.getValue(), ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName())).get(/* linkingStatically */
        true, /* linkShared */
        true);
        Artifact nativeDepsLibrary = NativeDepsHelper.linkAndroidNativeDepsIfPresent(ruleContext, linkParams, configurationMap.get(entry.getKey()), toolchainMap.get(entry.getKey()));
        ImmutableList.Builder<Artifact> librariesBuilder = ImmutableList.builder();
        if (nativeDepsLibrary != null) {
            librariesBuilder.add(nativeDepsLibrary);
            nativeDepsLibraryBasename = nativeDepsLibrary.getExecPath().getBaseName();
        }
        librariesBuilder.addAll(filterUniqueSharedLibraries(ruleContext, nativeDepsLibrary, linkParams.getLibraries()));
        ImmutableList<Artifact> libraries = librariesBuilder.build();
        if (!libraries.isEmpty()) {
            result.put(entry.getKey(), libraries);
        }
    }
    if (result.isEmpty()) {
        return NativeLibs.EMPTY;
    } else if (nativeDepsLibraryBasename == null) {
        return new NativeLibs(ImmutableMap.copyOf(result), null);
    } else {
        // The native deps name file must be the only file in its directory because ApkBuilder does
        // not have an option to add a particular file to the .apk, only one to add every file in a
        // particular directory.
        Artifact nativeDepsName = ruleContext.getUniqueDirectoryArtifact("nativedeps_filename", nativeDepsFileName, ruleContext.getBinOrGenfilesDirectory());
        ruleContext.registerAction(FileWriteAction.create(ruleContext, nativeDepsName, nativeDepsLibraryBasename, false));
        return new NativeLibs(ImmutableMap.copyOf(result), nativeDepsName);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Artifact(com.google.devtools.build.lib.actions.Artifact) LinkedHashMap(java.util.LinkedHashMap) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Collection(java.util.Collection) CcLinkParams(com.google.devtools.build.lib.rules.cpp.CcLinkParams) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 CcLinkParams (com.google.devtools.build.lib.rules.cpp.CcLinkParams)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1