use of com.android.bundle.Targeting.NativeDirectoryTargeting in project bundletool by google.
the class AbiNativeLibrariesSplitter method split.
/**
* Generates {@link ModuleSplit} objects dividing the native libraries by ABI.
*/
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
if (!moduleSplit.getNativeConfig().isPresent()) {
return ImmutableList.of(moduleSplit);
}
ImmutableList.Builder<ModuleSplit> splits = new ImmutableList.Builder<>();
// Flatten all targeted directories.
List<TargetedNativeDirectory> allTargetedDirectories = moduleSplit.getNativeConfig().get().getDirectoryList();
// Currently we only support targeting via ABI, so grouping it by Targeting.equals() should be
// enough.
ImmutableMultimap<NativeDirectoryTargeting, TargetedNativeDirectory> targetingMap = Multimaps.index(allTargetedDirectories, TargetedNativeDirectory::getTargeting);
// We need to know the exact set of ABIs that we will generate, to set alternatives correctly.
ImmutableSet<Abi> abisToGenerate = targetingMap.keySet().stream().map(NativeDirectoryTargeting::getAbi).collect(toImmutableSet());
// Any entries not claimed by the ABI splits will be returned in a separate split using the
// original targeting.
HashSet<ModuleEntry> leftOverEntries = new HashSet<>(moduleSplit.getEntries());
for (NativeDirectoryTargeting targeting : targetingMap.keySet()) {
ImmutableList<ModuleEntry> entriesList = targetingMap.get(targeting).stream().flatMap(directory -> moduleSplit.findEntriesUnderPath(directory.getPath())).collect(toImmutableList());
ModuleSplit.Builder splitBuilder = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setAbiTargeting(AbiTargeting.newBuilder().addValue(targeting.getAbi()).addAllAlternatives(Sets.difference(abisToGenerate, ImmutableSet.of(targeting.getAbi())))).build()).setMasterSplit(false).addMasterManifestMutator(withSplitsRequired(true)).setEntries(entriesList);
splits.add(splitBuilder.build());
leftOverEntries.removeAll(entriesList);
}
if (!leftOverEntries.isEmpty()) {
splits.add(moduleSplit.toBuilder().setEntries(ImmutableList.copyOf(leftOverEntries)).build());
}
return splits.build();
}
use of com.android.bundle.Targeting.NativeDirectoryTargeting in project bundletool by google.
the class NativeTargetingValidator method validateTargeting.
private static void validateTargeting(BundleModule module, NativeLibraries nativeLibraries) {
for (TargetedNativeDirectory targetedDirectory : nativeLibraries.getDirectoryList()) {
ZipPath path = ZipPath.create(targetedDirectory.getPath());
NativeDirectoryTargeting targeting = targetedDirectory.getTargeting();
if (!targeting.hasAbi()) {
throw InvalidBundleException.builder().withUserMessage("Targeted native directory '%s' does not have the ABI dimension set.", targetedDirectory.getPath()).build();
}
if (!path.startsWith(LIB_DIRECTORY) || path.getNameCount() != 2) {
throw InvalidBundleException.builder().withUserMessage("Path of targeted native directory must be in format 'lib/<directory>' but " + "found '%s'.", path).build();
}
if (BundleValidationUtils.directoryContainsNoFiles(module, path)) {
throw InvalidBundleException.builder().withUserMessage("Targeted directory '%s' is empty.", path).build();
}
}
SetView<String> libDirsWithoutTargeting = Sets.difference(module.findEntriesUnderPath(LIB_DIRECTORY).map(libFile -> libFile.getPath().subpath(0, 2).toString()).collect(toImmutableSet()), nativeLibraries.getDirectoryList().stream().map(TargetedNativeDirectory::getPath).collect(toImmutableSet()));
if (!libDirsWithoutTargeting.isEmpty()) {
throw InvalidBundleException.builder().withUserMessage("Following native directories are not targeted: %s", libDirsWithoutTargeting).build();
}
}
Aggregations