AAPT2: Improve diff command
Change-Id: Ia1e2f8482c7192ef50126b61bed7975297332767
diff --git a/tools/aapt2/diff/Diff.cpp b/tools/aapt2/diff/Diff.cpp
index 67333a2..1ff6ef6 100644
--- a/tools/aapt2/diff/Diff.cpp
+++ b/tools/aapt2/diff/Diff.cpp
@@ -16,6 +16,7 @@
#include "Flags.h"
#include "ResourceTable.h"
+#include "ValueVisitor.h"
#include "io/ZipArchive.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
@@ -385,6 +386,24 @@
return diff;
}
+class ZeroingReferenceVisitor : public ValueVisitor {
+public:
+ using ValueVisitor::visit;
+
+ void visit(Reference* ref) override {
+ if (ref->name && ref->id) {
+ if (ref->id.value().packageId() == 0x7f) {
+ ref->id = {};
+ }
+ }
+ }
+};
+
+static void zeroOutAppReferences(ResourceTable* table) {
+ ZeroingReferenceVisitor visitor;
+ visitAllValuesInTable(table, &visitor);
+}
+
int diff(const std::vector<StringPiece>& args) {
DiffContext context;
@@ -405,6 +424,10 @@
return 1;
}
+ // Zero out Application IDs in references.
+ zeroOutAppReferences(apkA->getResourceTable());
+ zeroOutAppReferences(apkB->getResourceTable());
+
if (emitResourceTableDiff(&context, apkA.get(), apkB.get())) {
// We emitted a diff, so return 1 (failure).
return 1;