AAPT2: Process <java-symbols> and private symbol package
Need to introduce the idea of multiple levels of visibility to support <java-symbol>.
Public, Private, Undefined.
Public means it is accessible from outside and requires an ID assigned.
Private means that we explicitly want this to be a symbol (show up in R.java), but not visible
to other packages. No ID required.
Undefined is any normal resource. When --private-symbols is specified in the link phase,
these resources will not show up in R.java.
Change-Id: Icba89221e08e685dee7683786aa7112baf28c856
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index 0d63b97..db52546 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -69,8 +69,8 @@
for (auto& srcType : srcPackage->types) {
ResourceTableType* dstType = mMasterPackage->findOrCreateType(srcType->type);
- if (srcType->publicStatus.isPublic) {
- if (dstType->publicStatus.isPublic && dstType->id && srcType->id
+ if (srcType->symbolStatus.state == SymbolState::kPublic) {
+ if (dstType->symbolStatus.state == SymbolState::kPublic && dstType->id && srcType->id
&& dstType->id.value() == srcType->id.value()) {
// Both types are public and have different IDs.
mContext->getDiagnostics()->error(DiagMessage(src)
@@ -81,7 +81,7 @@
continue;
}
- dstType->publicStatus = std::move(srcType->publicStatus);
+ dstType->symbolStatus = std::move(srcType->symbolStatus);
dstType->id = srcType->id;
}
@@ -94,20 +94,29 @@
dstEntry = dstType->findOrCreateEntry(srcEntry->name);
}
- if (srcEntry->publicStatus.isPublic) {
- if (dstEntry->publicStatus.isPublic && dstEntry->id && srcEntry->id
- && dstEntry->id.value() != srcEntry->id.value()) {
- // Both entries are public and have different IDs.
- mContext->getDiagnostics()->error(DiagMessage(src)
- << "can not merge entry '"
- << srcEntry->name
- << "': conflicting public IDs");
- error = true;
- continue;
+ if (srcEntry->symbolStatus.state != SymbolState::kUndefined) {
+ if (srcEntry->symbolStatus.state == SymbolState::kPublic) {
+ if (dstEntry->symbolStatus.state == SymbolState::kPublic &&
+ dstEntry->id && srcEntry->id &&
+ dstEntry->id.value() != srcEntry->id.value()) {
+ // Both entries are public and have different IDs.
+ mContext->getDiagnostics()->error(DiagMessage(src)
+ << "can not merge entry '"
+ << srcEntry->name
+ << "': conflicting public IDs");
+ error = true;
+ continue;
+ }
+
+ if (srcEntry->id) {
+ dstEntry->id = srcEntry->id;
+ }
}
- dstEntry->publicStatus = std::move(srcEntry->publicStatus);
- dstEntry->id = srcEntry->id;
+ if (dstEntry->symbolStatus.state != SymbolState::kPublic &&
+ dstEntry->symbolStatus.state != srcEntry->symbolStatus.state) {
+ dstEntry->symbolStatus = std::move(srcEntry->symbolStatus);
+ }
}
for (ResourceConfigValue& srcValue : srcEntry->values) {