AAPT2: Introduce notion of 'product' to ResourceTable
This allows us to preserve the various product definitions during the compile
phase, and allows us to select the product in the link phase.
This allows compiled files to remain product-independent, so that they do not need
to be recompiled when switching targets.
Bug:25958912
Change-Id: Iaa7eed25c834b67a39cdc9be43613e8b5ab6cdd7
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index e01a004..2ecd5b0 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -18,9 +18,7 @@
#include "ResourceUtils.h"
#include "ResourceValues.h"
#include "ValueVisitor.h"
-
#include "link/TableMerger.h"
-#include "util/Comparators.h"
#include "util/Util.h"
#include <cassert>
@@ -197,28 +195,28 @@
ResourceNameRef resName(mMasterPackage->name, dstType->type, dstEntry->name);
- for (ResourceConfigValue& srcValue : srcEntry->values) {
- auto iter = std::lower_bound(dstEntry->values.begin(), dstEntry->values.end(),
- srcValue.config, cmp::lessThanConfig);
+ for (auto& srcValue : srcEntry->values) {
+ ResourceConfigValue* dstValue = dstEntry->findValue(srcValue->config,
+ srcValue->product);
const bool stripConfig = mOptions.filter ?
- !mOptions.filter->match(srcValue.config) : false;
+ !mOptions.filter->match(srcValue->config) : false;
- if (iter != dstEntry->values.end() && iter->config == srcValue.config) {
+ if (dstValue) {
const int collisionResult = ResourceTable::resolveValueCollision(
- iter->value.get(), srcValue.value.get());
+ dstValue->value.get(), srcValue->value.get());
if (collisionResult == 0 && !overlay) {
// Error!
ResourceNameRef resourceName(srcPackage->name,
srcType->type,
srcEntry->name);
- mContext->getDiagnostics()->error(DiagMessage(srcValue.value->getSource())
+ mContext->getDiagnostics()->error(DiagMessage(srcValue->value->getSource())
<< "resource '" << resourceName
<< "' has a conflicting value for "
<< "configuration ("
- << srcValue.config << ")");
- mContext->getDiagnostics()->note(DiagMessage(iter->value->getSource())
+ << srcValue->config << ")");
+ mContext->getDiagnostics()->note(DiagMessage(dstValue->value->getSource())
<< "originally defined here");
error = true;
continue;
@@ -227,16 +225,18 @@
continue;
}
- } else if (!stripConfig){
- // Insert a place holder value. We will fill it in below.
- iter = dstEntry->values.insert(iter, ResourceConfigValue{ srcValue.config });
}
if (stripConfig) {
continue;
}
- if (FileReference* f = valueCast<FileReference>(srcValue.value.get())) {
+ if (!dstValue) {
+ // Force create the entry if we didn't have it.
+ dstValue = dstEntry->findOrCreateValue(srcValue->config, srcValue->product);
+ }
+
+ if (FileReference* f = valueCast<FileReference>(srcValue->value.get())) {
std::unique_ptr<FileReference> newFileRef;
if (manglePackage) {
newFileRef = cloneAndMangleFile(srcPackage->name, *f);
@@ -246,15 +246,15 @@
}
if (callback) {
- if (!callback(resName, iter->config, newFileRef.get(), f)) {
+ if (!callback(resName, srcValue->config, newFileRef.get(), f)) {
error = true;
continue;
}
}
- iter->value = std::move(newFileRef);
+ dstValue->value = std::move(newFileRef);
} else {
- iter->value = std::unique_ptr<Value>(srcValue.value->clone(
+ dstValue->value = std::unique_ptr<Value>(srcValue->value->clone(
&mMasterTable->stringPool));
}
}
@@ -290,7 +290,8 @@
ResourceTablePackage* pkg = table.createPackage(fileDesc.name.package, 0x0);
pkg->findOrCreateType(fileDesc.name.type)
->findOrCreateEntry(fileDesc.name.entry)
- ->values.push_back(ResourceConfigValue{ fileDesc.config, std::move(fileRef) });
+ ->findOrCreateValue(fileDesc.config, {})
+ ->value = std::move(fileRef);
auto callback = [&](const ResourceNameRef& name, const ConfigDescription& config,
FileReference* newFile, FileReference* oldFile) -> bool {