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);
}
}
Aggregations