Loading tools/aapt2/ResourceTable.cpp +24 −9 Original line number Diff line number Diff line Loading @@ -190,22 +190,32 @@ static constexpr const char16_t* kValidNameMangledChars = u"._-$"; bool ResourceTable::addResource(const ResourceNameRef& name, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, {}, config, std::move(value), kValidNameChars, diag); return addResourceImpl(name, {}, config, std::move(value), kValidNameChars, resolveValueCollision, diag); } bool ResourceTable::addResource(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, resId, config, std::move(value), kValidNameChars, diag); return addResourceImpl(name, resId, config, std::move(value), kValidNameChars, resolveValueCollision, diag); } bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, IDiagnostics* diag) { return addFileReference(name, config, source, path, resolveValueCollision, diag); } bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag) { std::unique_ptr<FileReference> fileRef = util::make_unique<FileReference>( stringPool.makeRef(path)); fileRef->setSource(source); return addResourceImpl(name, ResourceId{}, config, std::move(fileRef), kValidNameChars, diag); return addResourceImpl(name, ResourceId{}, config, std::move(fileRef), kValidNameChars, conflictResolver, diag); } bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, Loading @@ -213,7 +223,7 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, ResourceId{}, config, std::move(value), kValidNameMangledChars, diag); resolveValueCollision, diag); } bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, Loading @@ -221,12 +231,17 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, id, config, std::move(value), kValidNameMangledChars, diag); return addResourceImpl(name, id, config, std::move(value), kValidNameMangledChars, resolveValueCollision, diag); } bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, IDiagnostics* diag) { bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag) { assert(value && "value can't be nullptr"); assert(diag && "diagnostics can't be nullptr"); Loading Loading @@ -289,7 +304,7 @@ bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceI // This resource did not exist before, add it. entry->values.insert(iter, ResourceConfigValue{ config, std::move(value) }); } else { int collisionResult = resolveValueCollision(iter->value.get(), value.get()); int collisionResult = conflictResolver(iter->value.get(), value.get()); if (collisionResult > 0) { // Take the incoming value. iter->value = std::move(value); Loading tools/aapt2/ResourceTable.h +14 −4 Original line number Diff line number Diff line Loading @@ -163,7 +163,12 @@ public: IDiagnostics* diag); bool addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, IDiagnostics* diag); const Source& source, const StringPiece16& path, IDiagnostics* diag); bool addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag); /** * Same as addResource, but doesn't verify the validity of the name. This is used Loading Loading @@ -221,9 +226,14 @@ public: private: ResourceTablePackage* findOrCreatePackage(const StringPiece16& name); bool addResourceImpl(const ResourceNameRef& name, ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, IDiagnostics* diag); bool addResourceImpl(const ResourceNameRef& name, ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag); bool setSymbolStateImpl(const ResourceNameRef& name, ResourceId resId, const Symbol& symbol, const char16_t* validChars, IDiagnostics* diag); }; Loading tools/aapt2/link/Link.cpp +165 −107 File changed.Preview size limit exceeded, changes collapsed. Show changes tools/aapt2/link/TableMerger.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ TableMerger::TableMerger(IAaptContext* context, ResourceTable* outTable) : /** * This will merge packages with the same package name (or no package name). */ bool TableMerger::merge(const Source& src, ResourceTable* table) { bool TableMerger::merge(const Source& src, ResourceTable* table, bool overrideExisting) { const uint8_t desiredPackageId = mContext->getPackageId(); bool error = false; Loading @@ -55,7 +55,7 @@ bool TableMerger::merge(const Source& src, ResourceTable* table) { // mangled, then looked up at resolution time. // Also, when linking, we convert references with no package name to use // the compilation package name. if (!doMerge(src, table, package.get(), false)) { if (!doMerge(src, table, package.get(), false, overrideExisting)) { error = true; } } Loading @@ -79,7 +79,7 @@ bool TableMerger::mergeAndMangle(const Source& src, const StringPiece16& package bool mangle = packageName != mContext->getCompilationPackage(); mMergedPackages.insert(package->name); if (!doMerge(src, table, package.get(), mangle)) { if (!doMerge(src, table, package.get(), mangle, false)) { error = true; } } Loading @@ -87,7 +87,8 @@ bool TableMerger::mergeAndMangle(const Source& src, const StringPiece16& package } bool TableMerger::doMerge(const Source& src, ResourceTable* srcTable, ResourceTablePackage* srcPackage, const bool manglePackage) { ResourceTablePackage* srcPackage, const bool manglePackage, const bool overrideExisting) { bool error = false; for (auto& srcType : srcPackage->types) { Loading Loading @@ -149,7 +150,7 @@ bool TableMerger::doMerge(const Source& src, ResourceTable* srcTable, if (iter != dstEntry->values.end() && iter->config == srcValue.config) { const int collisionResult = ResourceTable::resolveValueCollision( iter->value.get(), srcValue.value.get()); if (collisionResult == 0) { if (collisionResult == 0 && !overrideExisting) { // Error! ResourceNameRef resourceName(srcPackage->name, srcType->type, Loading tools/aapt2/link/TableMerger.h +2 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public: /** * Merges resources from the same or empty package. This is for local sources. */ bool merge(const Source& src, ResourceTable* table); bool merge(const Source& src, ResourceTable* table, bool overrideExisting); /** * Merges resources from the given package, mangling the name. This is for static libraries. Loading @@ -79,7 +79,7 @@ private: std::queue<FileToMerge> mFilesToMerge; bool doMerge(const Source& src, ResourceTable* srcTable, ResourceTablePackage* srcPackage, const bool manglePackage); const bool manglePackage, const bool overrideExisting); std::unique_ptr<Value> cloneAndMangle(ResourceTable* table, const std::u16string& package, Value* value); Loading Loading
tools/aapt2/ResourceTable.cpp +24 −9 Original line number Diff line number Diff line Loading @@ -190,22 +190,32 @@ static constexpr const char16_t* kValidNameMangledChars = u"._-$"; bool ResourceTable::addResource(const ResourceNameRef& name, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, {}, config, std::move(value), kValidNameChars, diag); return addResourceImpl(name, {}, config, std::move(value), kValidNameChars, resolveValueCollision, diag); } bool ResourceTable::addResource(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, resId, config, std::move(value), kValidNameChars, diag); return addResourceImpl(name, resId, config, std::move(value), kValidNameChars, resolveValueCollision, diag); } bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, IDiagnostics* diag) { return addFileReference(name, config, source, path, resolveValueCollision, diag); } bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag) { std::unique_ptr<FileReference> fileRef = util::make_unique<FileReference>( stringPool.makeRef(path)); fileRef->setSource(source); return addResourceImpl(name, ResourceId{}, config, std::move(fileRef), kValidNameChars, diag); return addResourceImpl(name, ResourceId{}, config, std::move(fileRef), kValidNameChars, conflictResolver, diag); } bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, Loading @@ -213,7 +223,7 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, ResourceId{}, config, std::move(value), kValidNameMangledChars, diag); resolveValueCollision, diag); } bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, Loading @@ -221,12 +231,17 @@ bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name, const ConfigDescription& config, std::unique_ptr<Value> value, IDiagnostics* diag) { return addResourceImpl(name, id, config, std::move(value), kValidNameMangledChars, diag); return addResourceImpl(name, id, config, std::move(value), kValidNameMangledChars, resolveValueCollision, diag); } bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, IDiagnostics* diag) { bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag) { assert(value && "value can't be nullptr"); assert(diag && "diagnostics can't be nullptr"); Loading Loading @@ -289,7 +304,7 @@ bool ResourceTable::addResourceImpl(const ResourceNameRef& name, const ResourceI // This resource did not exist before, add it. entry->values.insert(iter, ResourceConfigValue{ config, std::move(value) }); } else { int collisionResult = resolveValueCollision(iter->value.get(), value.get()); int collisionResult = conflictResolver(iter->value.get(), value.get()); if (collisionResult > 0) { // Take the incoming value. iter->value = std::move(value); Loading
tools/aapt2/ResourceTable.h +14 −4 Original line number Diff line number Diff line Loading @@ -163,7 +163,12 @@ public: IDiagnostics* diag); bool addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, IDiagnostics* diag); const Source& source, const StringPiece16& path, IDiagnostics* diag); bool addFileReference(const ResourceNameRef& name, const ConfigDescription& config, const Source& source, const StringPiece16& path, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag); /** * Same as addResource, but doesn't verify the validity of the name. This is used Loading Loading @@ -221,9 +226,14 @@ public: private: ResourceTablePackage* findOrCreatePackage(const StringPiece16& name); bool addResourceImpl(const ResourceNameRef& name, ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, IDiagnostics* diag); bool addResourceImpl(const ResourceNameRef& name, ResourceId resId, const ConfigDescription& config, std::unique_ptr<Value> value, const char16_t* validChars, std::function<int(Value*,Value*)> conflictResolver, IDiagnostics* diag); bool setSymbolStateImpl(const ResourceNameRef& name, ResourceId resId, const Symbol& symbol, const char16_t* validChars, IDiagnostics* diag); }; Loading
tools/aapt2/link/Link.cpp +165 −107 File changed.Preview size limit exceeded, changes collapsed. Show changes
tools/aapt2/link/TableMerger.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ TableMerger::TableMerger(IAaptContext* context, ResourceTable* outTable) : /** * This will merge packages with the same package name (or no package name). */ bool TableMerger::merge(const Source& src, ResourceTable* table) { bool TableMerger::merge(const Source& src, ResourceTable* table, bool overrideExisting) { const uint8_t desiredPackageId = mContext->getPackageId(); bool error = false; Loading @@ -55,7 +55,7 @@ bool TableMerger::merge(const Source& src, ResourceTable* table) { // mangled, then looked up at resolution time. // Also, when linking, we convert references with no package name to use // the compilation package name. if (!doMerge(src, table, package.get(), false)) { if (!doMerge(src, table, package.get(), false, overrideExisting)) { error = true; } } Loading @@ -79,7 +79,7 @@ bool TableMerger::mergeAndMangle(const Source& src, const StringPiece16& package bool mangle = packageName != mContext->getCompilationPackage(); mMergedPackages.insert(package->name); if (!doMerge(src, table, package.get(), mangle)) { if (!doMerge(src, table, package.get(), mangle, false)) { error = true; } } Loading @@ -87,7 +87,8 @@ bool TableMerger::mergeAndMangle(const Source& src, const StringPiece16& package } bool TableMerger::doMerge(const Source& src, ResourceTable* srcTable, ResourceTablePackage* srcPackage, const bool manglePackage) { ResourceTablePackage* srcPackage, const bool manglePackage, const bool overrideExisting) { bool error = false; for (auto& srcType : srcPackage->types) { Loading Loading @@ -149,7 +150,7 @@ bool TableMerger::doMerge(const Source& src, ResourceTable* srcTable, if (iter != dstEntry->values.end() && iter->config == srcValue.config) { const int collisionResult = ResourceTable::resolveValueCollision( iter->value.get(), srcValue.value.get()); if (collisionResult == 0) { if (collisionResult == 0 && !overrideExisting) { // Error! ResourceNameRef resourceName(srcPackage->name, srcType->type, Loading
tools/aapt2/link/TableMerger.h +2 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public: /** * Merges resources from the same or empty package. This is for local sources. */ bool merge(const Source& src, ResourceTable* table); bool merge(const Source& src, ResourceTable* table, bool overrideExisting); /** * Merges resources from the given package, mangling the name. This is for static libraries. Loading @@ -79,7 +79,7 @@ private: std::queue<FileToMerge> mFilesToMerge; bool doMerge(const Source& src, ResourceTable* srcTable, ResourceTablePackage* srcPackage, const bool manglePackage); const bool manglePackage, const bool overrideExisting); std::unique_ptr<Value> cloneAndMangle(ResourceTable* table, const std::u16string& package, Value* value); Loading