use of com.android.bundle.Targeting.Sanitizer in project bundletool by google.
the class SanitizerNativeLibrariesSplitter method split.
/**
* Generates {@link ModuleSplit} objects dividing the native libraries by sanitizer.
*/
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
if (!moduleSplit.getNativeConfig().isPresent()) {
return ImmutableList.of(moduleSplit);
}
Set<ZipPath> hwasanDirs = new HashSet<>();
for (TargetedNativeDirectory dir : moduleSplit.getNativeConfig().get().getDirectoryList()) {
if (!dir.getTargeting().hasSanitizer()) {
continue;
}
if (dir.getTargeting().getSanitizer().getAlias().equals(SanitizerAlias.HWADDRESS)) {
hwasanDirs.add(ZipPath.create(dir.getPath()));
}
}
List<ModuleEntry> hwasanEntries = moduleSplit.getEntries().stream().filter(entry -> hwasanDirs.contains(entry.getPath().subpath(0, 2))).collect(toImmutableList());
if (hwasanEntries.isEmpty()) {
return ImmutableList.of(moduleSplit);
}
List<ModuleEntry> nonHwasanEntries = moduleSplit.getEntries().stream().filter(entry -> !hwasanDirs.contains(entry.getPath().subpath(0, 2))).collect(toImmutableList());
ModuleSplit hwasanSplit = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setSanitizerTargeting(SanitizerTargeting.newBuilder().addValue(Sanitizer.newBuilder().setAlias(SanitizerAlias.HWADDRESS))).build()).setMasterSplit(false).setEntries(hwasanEntries).build();
ModuleSplit nonHwasanSplit = moduleSplit.toBuilder().setEntries(nonHwasanEntries).build();
return ImmutableList.of(hwasanSplit, nonHwasanSplit);
}
use of com.android.bundle.Targeting.Sanitizer in project bundletool by google.
the class ModuleSplit method getSuffix.
/**
* Returns the split suffix base name based on the targeting.
*
* <p>The split suffix cannot contain dashes as they are not allowed by the Android Framework. We
* replace them with underscores instead.
*/
public String getSuffix() {
if (isMasterSplit()) {
return "";
}
StringJoiner suffixJoiner = new StringJoiner("_");
// The dimensions below should be ordered by their priority.
AbiTargeting abiTargeting = getApkTargeting().getAbiTargeting();
if (!abiTargeting.getValueList().isEmpty()) {
abiTargeting.getValueList().forEach(value -> suffixJoiner.add(formatAbi(value)));
} else if (!abiTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_abis");
}
MultiAbiTargeting multiAbiTargeting = getApkTargeting().getMultiAbiTargeting();
for (MultiAbi value : multiAbiTargeting.getValueList()) {
suffixJoiner.add(MULTI_ABI_SUFFIX_JOINER.join(value.getAbiList().stream().map(ModuleSplit::formatAbi).collect(toImmutableList())));
}
// Alternatives without values are not supported for MultiAbiTargeting.
SanitizerTargeting sanitizerTargeting = getApkTargeting().getSanitizerTargeting();
for (Sanitizer sanitizer : sanitizerTargeting.getValueList()) {
if (sanitizer.getAlias().equals(SanitizerAlias.HWADDRESS)) {
suffixJoiner.add("hwasan");
} else {
throw new IllegalArgumentException("Unknown sanitizer");
}
}
LanguageTargeting languageTargeting = getApkTargeting().getLanguageTargeting();
if (!languageTargeting.getValueList().isEmpty()) {
languageTargeting.getValueList().forEach(suffixJoiner::add);
} else if (!languageTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_lang");
}
getApkTargeting().getScreenDensityTargeting().getValueList().forEach(value -> suffixJoiner.add(SCREEN_DENSITY_TO_PROTO_VALUE_MAP.inverse().get(value.getDensityAlias()).replace('-', '_')));
TextureCompressionFormatTargeting textureFormatTargeting = getApkTargeting().getTextureCompressionFormatTargeting();
if (!textureFormatTargeting.getValueList().isEmpty()) {
textureFormatTargeting.getValueList().forEach(value -> suffixJoiner.add(Ascii.toLowerCase(value.getAlias().name())));
} else if (!textureFormatTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_tcf");
}
getApkTargeting().getDeviceTierTargeting().getValueList().forEach(value -> suffixJoiner.add("tier_" + value.getValue()));
return suffixJoiner.toString();
}
Aggregations