Move StringPool to libandroidfw
Test: verified affected tests pass
Bug: 232940948
Change-Id: I22089893d7e5013f759c39ce190bec07fa6435db
diff --git a/tools/aapt2/link/Linkers.h b/tools/aapt2/link/Linkers.h
index be6c930..44cd276 100644
--- a/tools/aapt2/link/Linkers.h
+++ b/tools/aapt2/link/Linkers.h
@@ -101,9 +101,10 @@
explicit ProductFilter(std::unordered_set<std::string> products) : products_(products) {
}
- ResourceConfigValueIter SelectProductToKeep(
- const ResourceNameRef& name, const ResourceConfigValueIter begin,
- const ResourceConfigValueIter end, IDiagnostics* diag);
+ ResourceConfigValueIter SelectProductToKeep(const ResourceNameRef& name,
+ const ResourceConfigValueIter begin,
+ const ResourceConfigValueIter end,
+ android::IDiagnostics* diag);
bool Consume(IAaptContext* context, ResourceTable* table) override;
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index d432341..cbf920ac 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -30,16 +30,16 @@
namespace aapt {
-static bool RequiredNameIsNotEmpty(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool RequiredNameIsNotEmpty(xml::Element* el, android::SourcePathDiagnostics* diag) {
xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "name");
if (attr == nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> is missing attribute 'android:name'");
return false;
}
if (attr->value.empty()) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "attribute 'android:name' in <" << el->name << "> tag must not be empty");
return false;
}
@@ -48,7 +48,7 @@
// This is how PackageManager builds class names from AndroidManifest.xml entries.
static bool NameIsJavaClassName(xml::Element* el, xml::Attribute* attr,
- SourcePathDiagnostics* diag) {
+ android::SourcePathDiagnostics* diag) {
// We allow unqualified class names (ie: .HelloActivity)
// Since we don't know the package name, we can just make a fake one here and
// the test will be identical as long as the real package name is valid too.
@@ -60,51 +60,50 @@
: attr->value;
if (!util::IsJavaClassName(qualified_class_name)) {
- diag->Error(DiagMessage(el->line_number)
- << "attribute 'android:name' in <" << el->name
- << "> tag must be a valid Java class name");
+ diag->Error(android::DiagMessage(el->line_number) << "attribute 'android:name' in <" << el->name
+ << "> tag must be a valid Java class name");
return false;
}
return true;
}
-static bool OptionalNameIsJavaClassName(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool OptionalNameIsJavaClassName(xml::Element* el, android::SourcePathDiagnostics* diag) {
if (xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "name")) {
return NameIsJavaClassName(el, attr, diag);
}
return true;
}
-static bool RequiredNameIsJavaClassName(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool RequiredNameIsJavaClassName(xml::Element* el, android::SourcePathDiagnostics* diag) {
xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "name");
if (attr == nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> is missing attribute 'android:name'");
return false;
}
return NameIsJavaClassName(el, attr, diag);
}
-static bool RequiredNameIsJavaPackage(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool RequiredNameIsJavaPackage(xml::Element* el, android::SourcePathDiagnostics* diag) {
xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "name");
if (attr == nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> is missing attribute 'android:name'");
return false;
}
if (!util::IsJavaPackageName(attr->value)) {
- diag->Error(DiagMessage(el->line_number) << "attribute 'android:name' in <" << el->name
- << "> tag must be a valid Java package name");
+ diag->Error(android::DiagMessage(el->line_number) << "attribute 'android:name' in <" << el->name
+ << "> tag must be a valid Java package name");
return false;
}
return true;
}
static xml::XmlNodeAction::ActionFuncWithDiag RequiredAndroidAttribute(const std::string& attr) {
- return [=](xml::Element* el, SourcePathDiagnostics* diag) -> bool {
+ return [=](xml::Element* el, android::SourcePathDiagnostics* diag) -> bool {
if (el->FindAttribute(xml::kSchemaAndroid, attr) == nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> is missing required attribute 'android:" << attr << "'");
return false;
}
@@ -114,17 +113,17 @@
static xml::XmlNodeAction::ActionFuncWithDiag RequiredOneAndroidAttribute(
const std::string& attrName1, const std::string& attrName2) {
- return [=](xml::Element* el, SourcePathDiagnostics* diag) -> bool {
+ return [=](xml::Element* el, android::SourcePathDiagnostics* diag) -> bool {
xml::Attribute* attr1 = el->FindAttribute(xml::kSchemaAndroid, attrName1);
xml::Attribute* attr2 = el->FindAttribute(xml::kSchemaAndroid, attrName2);
if (attr1 == nullptr && attr2 == nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> is missing required attribute 'android:" << attrName1
<< "' or 'android:" << attrName2 << "'");
return false;
}
if (attr1 != nullptr && attr2 != nullptr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<" << el->name << "> can only specify one of attribute 'android:" << attrName1
<< "' or 'android:" << attrName2 << "'");
return false;
@@ -133,7 +132,7 @@
};
}
-static bool AutoGenerateIsFeatureSplit(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool AutoGenerateIsFeatureSplit(xml::Element* el, android::SourcePathDiagnostics* diag) {
constexpr const char* kFeatureSplit = "featureSplit";
constexpr const char* kIsFeatureSplit = "isFeatureSplit";
@@ -149,7 +148,7 @@
if (!ResourceUtils::ParseBool(attr->value).value_or(false)) {
// The isFeatureSplit attribute is false, which conflicts with the use
// of "featureSplit".
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "attribute 'featureSplit' used in <manifest> but 'android:isFeatureSplit' "
"is not 'true'");
return false;
@@ -163,7 +162,7 @@
return true;
}
-static bool AutoGenerateIsSplitRequired(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool AutoGenerateIsSplitRequired(xml::Element* el, android::SourcePathDiagnostics* diag) {
constexpr const char* kRequiredSplitTypes = "requiredSplitTypes";
constexpr const char* kIsSplitRequired = "isSplitRequired";
@@ -175,7 +174,7 @@
if (!ResourceUtils::ParseBool(attr->value).value_or(false)) {
// The isFeatureSplit attribute is false, which conflicts with the use
// of "featureSplit".
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "attribute 'requiredSplitTypes' used in <manifest> but "
"'android:isSplitRequired' is not 'true'");
return false;
@@ -189,18 +188,18 @@
}
static bool VerifyManifest(xml::Element* el, xml::XmlActionExecutorPolicy policy,
- SourcePathDiagnostics* diag) {
+ android::SourcePathDiagnostics* diag) {
xml::Attribute* attr = el->FindAttribute({}, "package");
if (!attr) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<manifest> tag is missing 'package' attribute");
return false;
} else if (ResourceUtils::IsReference(attr->value)) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "attribute 'package' in <manifest> tag must not be a reference");
return false;
} else if (!util::IsAndroidPackageName(attr->value)) {
- DiagMessage error_msg(el->line_number);
+ android::DiagMessage error_msg(el->line_number);
error_msg << "attribute 'package' in <manifest> tag is not a valid Android package name: '"
<< attr->value << "'";
if (policy == xml::XmlActionExecutorPolicy::kAllowListWarning) {
@@ -215,8 +214,9 @@
attr = el->FindAttribute({}, "split");
if (attr) {
if (!util::IsJavaPackageName(attr->value)) {
- diag->Error(DiagMessage(el->line_number) << "attribute 'split' in <manifest> tag is not a "
- "valid split name");
+ diag->Error(android::DiagMessage(el->line_number)
+ << "attribute 'split' in <manifest> tag is not a "
+ "valid split name");
return false;
}
}
@@ -225,11 +225,11 @@
// The coreApp attribute in <manifest> is not a regular AAPT attribute, so type
// checking on it is manual.
-static bool FixCoreAppAttribute(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool FixCoreAppAttribute(xml::Element* el, android::SourcePathDiagnostics* diag) {
if (xml::Attribute* attr = el->FindAttribute("", "coreApp")) {
std::unique_ptr<BinaryPrimitive> result = ResourceUtils::TryParseBool(attr->value);
if (!result) {
- diag->Error(DiagMessage(el->line_number) << "attribute coreApp must be a boolean");
+ diag->Error(android::DiagMessage(el->line_number) << "attribute coreApp must be a boolean");
return false;
}
attr->compiled_value = std::move(result);
@@ -238,11 +238,11 @@
}
// Checks that <uses-feature> has android:glEsVersion or android:name, not both (or neither).
-static bool VerifyUsesFeature(xml::Element* el, SourcePathDiagnostics* diag) {
+static bool VerifyUsesFeature(xml::Element* el, android::SourcePathDiagnostics* diag) {
bool has_name = false;
if (xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "name")) {
if (attr->value.empty()) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "android:name in <uses-feature> must not be empty");
return false;
}
@@ -252,7 +252,7 @@
bool has_gl_es_version = false;
if (xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, "glEsVersion")) {
if (has_name) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "cannot define both android:name and android:glEsVersion in <uses-feature>");
return false;
}
@@ -260,7 +260,7 @@
}
if (!has_name && !has_gl_es_version) {
- diag->Error(DiagMessage(el->line_number)
+ diag->Error(android::DiagMessage(el->line_number)
<< "<uses-feature> must have either android:name or android:glEsVersion attribute");
return false;
}
@@ -294,34 +294,29 @@
}
}
-bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
- IDiagnostics* diag) {
+bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor, android::IDiagnostics* diag) {
// First verify some options.
if (options_.rename_manifest_package) {
if (!util::IsJavaPackageName(options_.rename_manifest_package.value())) {
- diag->Error(DiagMessage() << "invalid manifest package override '"
- << options_.rename_manifest_package.value()
- << "'");
+ diag->Error(android::DiagMessage() << "invalid manifest package override '"
+ << options_.rename_manifest_package.value() << "'");
return false;
}
}
if (options_.rename_instrumentation_target_package) {
if (!util::IsJavaPackageName(options_.rename_instrumentation_target_package.value())) {
- diag->Error(DiagMessage()
+ diag->Error(android::DiagMessage()
<< "invalid instrumentation target package override '"
- << options_.rename_instrumentation_target_package.value()
- << "'");
+ << options_.rename_instrumentation_target_package.value() << "'");
return false;
}
}
if (options_.rename_overlay_target_package) {
if (!util::IsJavaPackageName(options_.rename_overlay_target_package.value())) {
- diag->Error(DiagMessage()
- << "invalid overlay target package override '"
- << options_.rename_overlay_target_package.value()
- << "'");
+ diag->Error(android::DiagMessage() << "invalid overlay target package override '"
+ << options_.rename_overlay_target_package.value() << "'");
return false;
}
}
@@ -614,7 +609,7 @@
TRACE_CALL();
xml::Element* root = xml::FindRootElement(doc->root.get());
if (!root || !root->namespace_uri.empty() || root->name != "manifest") {
- context->GetDiagnostics()->Error(DiagMessage(doc->file.source)
+ context->GetDiagnostics()->Error(android::DiagMessage(doc->file.source)
<< "root tag must be <manifest>");
return false;
}
diff --git a/tools/aapt2/link/ManifestFixer.h b/tools/aapt2/link/ManifestFixer.h
index d5d1d17..5b04cad 100644
--- a/tools/aapt2/link/ManifestFixer.h
+++ b/tools/aapt2/link/ManifestFixer.h
@@ -96,7 +96,7 @@
private:
DISALLOW_COPY_AND_ASSIGN(ManifestFixer);
- bool BuildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag);
+ bool BuildRules(xml::XmlActionExecutor* executor, android::IDiagnostics* diag);
ManifestFixerOptions options_;
};
diff --git a/tools/aapt2/link/NoDefaultResourceRemover.cpp b/tools/aapt2/link/NoDefaultResourceRemover.cpp
index ab3c04e..2a5163f 100644
--- a/tools/aapt2/link/NoDefaultResourceRemover.cpp
+++ b/tools/aapt2/link/NoDefaultResourceRemover.cpp
@@ -77,14 +77,14 @@
for (auto iter = remove_iter; iter != end_iter; ++iter) {
const ResourceName name(pkg->name, type->named_type, (*iter)->name);
- IDiagnostics* diag = context->GetDiagnostics();
- diag->Warn(DiagMessage() << "removing resource " << name
- << " without required default value");
+ android::IDiagnostics* diag = context->GetDiagnostics();
+ diag->Warn(android::DiagMessage()
+ << "removing resource " << name << " without required default value");
if (context->IsVerbose()) {
- diag->Note(DiagMessage() << " did you forget to remove all definitions?");
+ diag->Note(android::DiagMessage() << " did you forget to remove all definitions?");
for (const auto& config_value : (*iter)->values) {
if (config_value->value != nullptr) {
- diag->Note(DiagMessage(config_value->value->GetSource()) << "defined here");
+ diag->Note(android::DiagMessage(config_value->value->GetSource()) << "defined here");
}
}
}
diff --git a/tools/aapt2/link/ProductFilter.cpp b/tools/aapt2/link/ProductFilter.cpp
index 0c54a73..9544986 100644
--- a/tools/aapt2/link/ProductFilter.cpp
+++ b/tools/aapt2/link/ProductFilter.cpp
@@ -23,7 +23,7 @@
ProductFilter::ResourceConfigValueIter ProductFilter::SelectProductToKeep(
const ResourceNameRef& name, const ResourceConfigValueIter begin,
- const ResourceConfigValueIter end, IDiagnostics* diag) {
+ const ResourceConfigValueIter end, android::IDiagnostics* diag) {
ResourceConfigValueIter default_product_iter = end;
ResourceConfigValueIter selected_product_iter = end;
@@ -32,16 +32,15 @@
if (products_.find(config_value->product) != products_.end()) {
if (selected_product_iter != end) {
// We have two possible values for this product!
- diag->Error(DiagMessage(config_value->value->GetSource())
- << "selection of product '" << config_value->product
- << "' for resource " << name << " is ambiguous");
+ diag->Error(android::DiagMessage(config_value->value->GetSource())
+ << "selection of product '" << config_value->product << "' for resource "
+ << name << " is ambiguous");
ResourceConfigValue* previously_selected_config_value =
selected_product_iter->get();
- diag->Note(
- DiagMessage(previously_selected_config_value->value->GetSource())
- << "product '" << previously_selected_config_value->product
- << "' is also a candidate");
+ diag->Note(android::DiagMessage(previously_selected_config_value->value->GetSource())
+ << "product '" << previously_selected_config_value->product
+ << "' is also a candidate");
return end;
}
@@ -52,15 +51,13 @@
if (config_value->product.empty() || config_value->product == "default") {
if (default_product_iter != end) {
// We have two possible default values.
- diag->Error(DiagMessage(config_value->value->GetSource())
- << "multiple default products defined for resource "
- << name);
+ diag->Error(android::DiagMessage(config_value->value->GetSource())
+ << "multiple default products defined for resource " << name);
ResourceConfigValue* previously_default_config_value =
default_product_iter->get();
- diag->Note(
- DiagMessage(previously_default_config_value->value->GetSource())
- << "default product also defined here");
+ diag->Note(android::DiagMessage(previously_default_config_value->value->GetSource())
+ << "default product also defined here");
return end;
}
@@ -70,8 +67,7 @@
}
if (default_product_iter == end) {
- diag->Error(DiagMessage() << "no default product defined for resource "
- << name);
+ diag->Error(android::DiagMessage() << "no default product defined for resource " << name);
return end;
}
diff --git a/tools/aapt2/link/ProductFilter_test.cpp b/tools/aapt2/link/ProductFilter_test.cpp
index 4f78bbc..2cb9afa 100644
--- a/tools/aapt2/link/ProductFilter_test.cpp
+++ b/tools/aapt2/link/ProductFilter_test.cpp
@@ -31,27 +31,29 @@
ResourceTable table;
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("land/default.xml")).Build(), land)
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("land/default.xml")).Build(),
+ land)
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("land/tablet.xml")).Build(), land,
- "tablet")
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("land/tablet.xml")).Build(),
+ land, "tablet")
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("port/default.xml")).Build(), port)
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("port/default.xml")).Build(),
+ port)
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("port/tablet.xml")).Build(), port,
- "tablet")
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("port/tablet.xml")).Build(),
+ port, "tablet")
.Build(),
context->GetDiagnostics()));
@@ -74,13 +76,14 @@
ResourceTable table;
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("default.xml")).Build())
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("default.xml")).Build())
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("tablet.xml")).Build(), {}, "tablet")
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("tablet.xml")).Build(), {},
+ "tablet")
.Build(),
context->GetDiagnostics()));
;
@@ -102,20 +105,21 @@
ResourceTable table;
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("default.xml")).Build())
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("default.xml")).Build())
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("tablet.xml")).Build(), {}, "tablet")
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("tablet.xml")).Build(), {},
+ "tablet")
.Build(),
context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("no-sdcard.xml")).Build(), {},
- "no-sdcard")
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("no-sdcard.xml")).Build(),
+ {}, "no-sdcard")
.Build(),
context->GetDiagnostics()));
@@ -127,15 +131,15 @@
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
ResourceTable table;
- ASSERT_TRUE(
- table.AddResource(NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source(".xml")).Build())
- .Build(),
- context->GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(
+ NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source(".xml")).Build())
+ .Build(),
+ context->GetDiagnostics()));
ASSERT_TRUE(table.AddResource(
NewResourceBuilder(test::ParseNameOrDie("android:string/one"))
- .SetValue(test::ValueBuilder<Id>().SetSource(Source("default.xml")).Build(), {},
+ .SetValue(test::ValueBuilder<Id>().SetSource(android::Source("default.xml")).Build(), {},
"default")
.Build(),
context->GetDiagnostics()));
diff --git a/tools/aapt2/link/ReferenceLinker.cpp b/tools/aapt2/link/ReferenceLinker.cpp
index d1fbffa..f2a93a8 100644
--- a/tools/aapt2/link/ReferenceLinker.cpp
+++ b/tools/aapt2/link/ReferenceLinker.cpp
@@ -16,16 +16,15 @@
#include "link/ReferenceLinker.h"
-#include "android-base/logging.h"
-#include "android-base/stringprintf.h"
-#include "androidfw/ResourceTypes.h"
-
-#include "Diagnostics.h"
#include "ResourceParser.h"
#include "ResourceTable.h"
#include "ResourceUtils.h"
#include "ResourceValues.h"
#include "ValueVisitor.h"
+#include "android-base/logging.h"
+#include "android-base/stringprintf.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/ResourceTypes.h"
#include "link/Linkers.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
@@ -82,7 +81,7 @@
if (auto ref = ValueCast<Reference>(linked_item_ptr)) {
return std::unique_ptr<Reference>(ref);
}
- context_->GetDiagnostics()->Error(DiagMessage(value->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(value->GetSource())
<< "value of '"
<< LoggingResourceName(*value, callsite_, package_decls_)
<< "' must be a resource reference");
@@ -130,7 +129,7 @@
// check is fast and we avoid creating a DiagMessage when the match is successful.
if (!symbol->attribute->Matches(*entry.value, nullptr)) {
// The actual type of this item is incompatible with the attribute.
- DiagMessage msg(entry.key.GetSource());
+ android::DiagMessage msg(entry.key.GetSource());
// Call the matches method again, this time with a DiagMessage so we fill in the actual
// error message.
@@ -139,7 +138,7 @@
error_ = true;
}
} else {
- context_->GetDiagnostics()->Error(DiagMessage(entry.key.GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(entry.key.GetSource())
<< "style attribute '"
<< LoggingResourceName(entry.key, callsite_, package_decls_)
<< "' " << err_str);
@@ -344,7 +343,7 @@
void ReferenceLinker::WriteAttributeName(const Reference& ref, const CallSite& callsite,
const xml::IPackageDeclStack* decls,
- DiagMessage* out_msg) {
+ android::DiagMessage* out_msg) {
CHECK(out_msg != nullptr);
if (!ref.name) {
*out_msg << ref.id.value();
@@ -393,7 +392,7 @@
auto result = table->FindResource(transformed_reference.name.value());
if (!result || result.value().entry->values.empty()) {
context->GetDiagnostics()->Error(
- DiagMessage(reference.GetSource())
+ android::DiagMessage(reference.GetSource())
<< "failed to find definition for "
<< LoggingResourceName(transformed_reference, callsite, decls));
return {};
@@ -424,7 +423,7 @@
macro_values[0]->config, *context->GetDiagnostics());
if (new_value == nullptr) {
context->GetDiagnostics()->Error(
- DiagMessage(reference.GetSource())
+ android::DiagMessage(reference.GetSource())
<< "failed to substitute macro "
<< LoggingResourceName(transformed_reference, callsite, decls)
<< ": failed to parse contents as one of type(s) " << Attribute::MaskString(type_flags));
@@ -450,7 +449,7 @@
return std::move(new_ref);
}
- context->GetDiagnostics()->Error(DiagMessage(reference.GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(reference.GetSource())
<< "resource "
<< LoggingResourceName(transformed_reference, callsite, decls)
<< " " << err_str);
@@ -473,17 +472,16 @@
// Symbol state information may be lost if there is no value for the resource.
if (entry->visibility.level != Visibility::Level::kUndefined && entry->values.empty()) {
- context->GetDiagnostics()->Error(DiagMessage(entry->visibility.source)
- << "no definition for declared symbol '" << name
- << "'");
+ context->GetDiagnostics()->Error(android::DiagMessage(entry->visibility.source)
+ << "no definition for declared symbol '" << name << "'");
error = true;
}
// Ensure that definitions for values declared as overlayable exist
if (entry->overlayable_item && entry->values.empty()) {
- context->GetDiagnostics()->Error(DiagMessage(entry->overlayable_item.value().source)
- << "no definition for overlayable symbol '"
- << name << "'");
+ context->GetDiagnostics()->Error(
+ android::DiagMessage(entry->overlayable_item.value().source)
+ << "no definition for overlayable symbol '" << name << "'");
error = true;
}
diff --git a/tools/aapt2/link/ReferenceLinker.h b/tools/aapt2/link/ReferenceLinker.h
index b460853..9fb25e1 100644
--- a/tools/aapt2/link/ReferenceLinker.h
+++ b/tools/aapt2/link/ReferenceLinker.h
@@ -32,7 +32,7 @@
class ReferenceLinkerTransformer : public CloningValueTransformer {
public:
ReferenceLinkerTransformer(const CallSite& callsite, IAaptContext* context, SymbolTable* symbols,
- StringPool* string_pool, ResourceTable* table,
+ android::StringPool* string_pool, ResourceTable* table,
xml::IPackageDeclStack* decl)
: CloningValueTransformer(string_pool),
callsite_(callsite),
@@ -110,7 +110,8 @@
// Same as WriteResourceName but omits the 'attr' part.
static void WriteAttributeName(const Reference& ref, const CallSite& callsite,
- const xml::IPackageDeclStack* decls, DiagMessage* out_msg);
+ const xml::IPackageDeclStack* decls,
+ android::DiagMessage* out_msg);
// Returns a fully linked version a resource reference.
//
diff --git a/tools/aapt2/link/ResourceExcluder.cpp b/tools/aapt2/link/ResourceExcluder.cpp
index b3b9dc4..59393cb 100644
--- a/tools/aapt2/link/ResourceExcluder.cpp
+++ b/tools/aapt2/link/ResourceExcluder.cpp
@@ -50,12 +50,9 @@
if (masked_diff == 0) {
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(
- DiagMessage(value->value->GetSource())
- << "excluded resource \""
- << entry->name
- << "\" with config "
- << config.toString());
+ context->GetDiagnostics()->Note(android::DiagMessage(value->value->GetSource())
+ << "excluded resource \"" << entry->name
+ << "\" with config " << config.toString());
}
value->value = {};
return;
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index caaaba6..c9f0964 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -37,7 +37,7 @@
CHECK(main_package_ != nullptr) << "package name or ID already taken";
}
-bool TableMerger::Merge(const Source& src, ResourceTable* table, bool overlay) {
+bool TableMerger::Merge(const android::Source& src, ResourceTable* table, bool overlay) {
TRACE_CALL();
// We allow adding new resources if this is not an overlay, or if the options allow overlays
// to add new resources.
@@ -45,7 +45,8 @@
}
// This will merge packages with the same package name (or no package name).
-bool TableMerger::MergeImpl(const Source& src, ResourceTable* table, bool overlay, bool allow_new) {
+bool TableMerger::MergeImpl(const android::Source& src, ResourceTable* table, bool overlay,
+ bool allow_new) {
bool error = false;
for (auto& package : table->packages) {
// Only merge an empty package or the package we're building.
@@ -65,13 +66,14 @@
// This will merge and mangle resources from a static library. It is assumed that all FileReferences
// have correctly set their io::IFile*.
-bool TableMerger::MergeAndMangle(const Source& src, const StringPiece& package_name,
+bool TableMerger::MergeAndMangle(const android::Source& src, const StringPiece& package_name,
ResourceTable* table) {
bool error = false;
for (auto& package : table->packages) {
// Warn of packages with an unrelated ID.
if (package_name != package->name) {
- context_->GetDiagnostics()->Warn(DiagMessage(src) << "ignoring package " << package->name);
+ context_->GetDiagnostics()->Warn(android::DiagMessage(src)
+ << "ignoring package " << package->name);
continue;
}
@@ -82,8 +84,8 @@
return !error;
}
-static bool MergeType(IAaptContext* context, const Source& src, ResourceTableType* dst_type,
- ResourceTableType* src_type) {
+static bool MergeType(IAaptContext* context, const android::Source& src,
+ ResourceTableType* dst_type, ResourceTableType* src_type) {
if (src_type->visibility_level >= dst_type->visibility_level) {
// The incoming type's visibility is stronger, so we should override the visibility.
dst_type->visibility_level = src_type->visibility_level;
@@ -91,15 +93,15 @@
return true;
}
-static bool MergeEntry(IAaptContext* context, const Source& src,
- ResourceEntry* dst_entry, ResourceEntry* src_entry,
- bool strict_visibility) {
+static bool MergeEntry(IAaptContext* context, const android::Source& src, ResourceEntry* dst_entry,
+ ResourceEntry* src_entry, bool strict_visibility) {
if (strict_visibility
&& dst_entry->visibility.level != Visibility::Level::kUndefined
&& src_entry->visibility.level != dst_entry->visibility.level) {
- context->GetDiagnostics()->Error(
- DiagMessage(src) << "cannot merge resource '" << dst_entry->name << "' with conflicting visibilities: "
- << "public and private");
+ context->GetDiagnostics()->Error(android::DiagMessage(src)
+ << "cannot merge resource '" << dst_entry->name
+ << "' with conflicting visibilities: "
+ << "public and private");
return false;
}
@@ -114,8 +116,9 @@
dst_entry->visibility.level == Visibility::Level::kPublic && dst_entry->id &&
src_entry->id && src_entry->id != dst_entry->id) {
// Both entries are public and have different IDs.
- context->GetDiagnostics()->Error(DiagMessage(src) << "cannot merge entry '" << src_entry->name
- << "': conflicting public IDs");
+ context->GetDiagnostics()->Error(android::DiagMessage(src)
+ << "cannot merge entry '" << src_entry->name
+ << "': conflicting public IDs");
return false;
}
@@ -139,11 +142,12 @@
// Do not allow a resource with an overlayable declaration to have that overlayable
// declaration redefined.
- context->GetDiagnostics()->Error(DiagMessage(src_entry->overlayable_item.value().source)
- << "duplicate overlayable declaration for resource '"
- << src_entry->name << "'");
- context->GetDiagnostics()->Error(DiagMessage(dst_entry->overlayable_item.value().source)
- << "previous declaration here");
+ context->GetDiagnostics()->Error(
+ android::DiagMessage(src_entry->overlayable_item.value().source)
+ << "duplicate overlayable declaration for resource '" << src_entry->name << "'");
+ context->GetDiagnostics()->Error(
+ android::DiagMessage(dst_entry->overlayable_item.value().source)
+ << "previous declaration here");
return false;
}
}
@@ -154,10 +158,10 @@
if (src_entry->staged_id) {
if (dst_entry->staged_id &&
dst_entry->staged_id.value().id != src_entry->staged_id.value().id) {
- context->GetDiagnostics()->Error(DiagMessage(src_entry->staged_id.value().source)
+ context->GetDiagnostics()->Error(android::DiagMessage(src_entry->staged_id.value().source)
<< "conflicting staged id declaration for resource '"
<< src_entry->name << "'");
- context->GetDiagnostics()->Error(DiagMessage(dst_entry->staged_id.value().source)
+ context->GetDiagnostics()->Error(android::DiagMessage(dst_entry->staged_id.value().source)
<< "previous declaration here");
}
dst_entry->staged_id = std::move(src_entry->staged_id);
@@ -174,7 +178,7 @@
// If both values are Styleables/Styles, we just merge them into the existing value.
static ResourceTable::CollisionResult ResolveMergeCollision(
bool override_styles_instead_of_overlaying, Value* existing, Value* incoming,
- StringPool* pool) {
+ android::StringPool* pool) {
if (Styleable* existing_styleable = ValueCast<Styleable>(existing)) {
if (Styleable* incoming_styleable = ValueCast<Styleable>(incoming)) {
// Styleables get merged.
@@ -194,13 +198,10 @@
return ResourceTable::ResolveValueCollision(existing, incoming);
}
-static ResourceTable::CollisionResult MergeConfigValue(IAaptContext* context,
- const ResourceNameRef& res_name,
- bool overlay,
- bool override_styles_instead_of_overlaying,
- ResourceConfigValue* dst_config_value,
- ResourceConfigValue* src_config_value,
- StringPool* pool) {
+static ResourceTable::CollisionResult MergeConfigValue(
+ IAaptContext* context, const ResourceNameRef& res_name, bool overlay,
+ bool override_styles_instead_of_overlaying, ResourceConfigValue* dst_config_value,
+ ResourceConfigValue* src_config_value, android::StringPool* pool) {
using CollisionResult = ResourceTable::CollisionResult;
Value* dst_value = dst_config_value->value.get();
@@ -220,18 +221,18 @@
}
// Error!
- context->GetDiagnostics()->Error(DiagMessage(src_value->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(src_value->GetSource())
<< "resource '" << res_name << "' has a conflicting value for "
<< "configuration (" << src_config_value->config << ")");
- context->GetDiagnostics()->Note(DiagMessage(dst_value->GetSource())
+ context->GetDiagnostics()->Note(android::DiagMessage(dst_value->GetSource())
<< "originally defined here");
return CollisionResult::kConflict;
}
return collision_result;
}
-bool TableMerger::DoMerge(const Source& src, ResourceTablePackage* src_package, bool mangle_package,
- bool overlay, bool allow_new_resources) {
+bool TableMerger::DoMerge(const android::Source& src, ResourceTablePackage* src_package,
+ bool mangle_package, bool overlay, bool allow_new_resources) {
bool error = false;
for (auto& src_type : src_package->types) {
@@ -257,11 +258,12 @@
const ResourceNameRef res_name(src_package->name, src_type->named_type, src_entry->name);
if (!dst_entry) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "resource " << res_name
<< " does not override an existing resource");
- context_->GetDiagnostics()->Note(DiagMessage(src) << "define an <add-resource> tag or use "
- << "--auto-add-overlay");
+ context_->GetDiagnostics()->Note(android::DiagMessage(src)
+ << "define an <add-resource> tag or use "
+ << "--auto-add-overlay");
error = true;
continue;
}
diff --git a/tools/aapt2/link/TableMerger.h b/tools/aapt2/link/TableMerger.h
index e01a0c1..2ba2123 100644
--- a/tools/aapt2/link/TableMerger.h
+++ b/tools/aapt2/link/TableMerger.h
@@ -67,11 +67,12 @@
// Merges resources from the same or empty package. This is for local sources.
// If overlay is true, the resources are treated as overlays.
- bool Merge(const Source& src, ResourceTable* table, bool overlay);
+ bool Merge(const android::Source& src, ResourceTable* table, bool overlay);
// Merges resources from the given package, mangling the name. This is for static libraries.
// All FileReference values must have their io::IFile set.
- bool MergeAndMangle(const Source& src, const android::StringPiece& package, ResourceTable* table);
+ bool MergeAndMangle(const android::Source& src, const android::StringPiece& package,
+ ResourceTable* table);
// Merges a compiled file that belongs to this same or empty package.
bool MergeFile(const ResourceFile& fileDesc, bool overlay, io::IFile* file);
@@ -85,9 +86,10 @@
ResourceTablePackage* main_package_;
std::set<std::string> merged_packages_;
- bool MergeImpl(const Source& src, ResourceTable* src_table, bool overlay, bool allow_new);
+ bool MergeImpl(const android::Source& src, ResourceTable* src_table, bool overlay,
+ bool allow_new);
- bool DoMerge(const Source& src, ResourceTablePackage* src_package, bool mangle_package,
+ bool DoMerge(const android::Source& src, ResourceTablePackage* src_package, bool mangle_package,
bool overlay, bool allow_new_resources);
std::unique_ptr<FileReference> CloneAndMangleFile(const std::string& package,
diff --git a/tools/aapt2/link/TableMerger_test.cpp b/tools/aapt2/link/TableMerger_test.cpp
index 4cbf2d3..56a7c3b 100644
--- a/tools/aapt2/link/TableMerger_test.cpp
+++ b/tools/aapt2/link/TableMerger_test.cpp
@@ -94,7 +94,7 @@
ResourceFile file_desc;
file_desc.config = test::ParseConfigOrDie("hdpi-v4");
file_desc.name = test::ParseNameOrDie("layout/main");
- file_desc.source = Source("res/layout-hdpi/main.xml");
+ file_desc.source = android::Source("res/layout-hdpi/main.xml");
test::TestFile test_file("path/to/res/layout-hdpi/main.xml.flat");
ASSERT_TRUE(merger.MergeFile(file_desc, false /*overlay*/, &test_file));
diff --git a/tools/aapt2/link/XmlCompatVersioner.cpp b/tools/aapt2/link/XmlCompatVersioner.cpp
index 957b64c..482c227 100644
--- a/tools/aapt2/link/XmlCompatVersioner.cpp
+++ b/tools/aapt2/link/XmlCompatVersioner.cpp
@@ -22,7 +22,7 @@
namespace aapt {
-static xml::Attribute CopyAttr(const xml::Attribute& src, StringPool* out_string_pool) {
+static xml::Attribute CopyAttr(const xml::Attribute& src, android::StringPool* out_string_pool) {
CloningValueTransformer cloner(out_string_pool);
xml::Attribute dst{src.namespace_uri, src.name, src.value, src.compiled_attribute};
if (src.compiled_value != nullptr) {
@@ -34,7 +34,7 @@
// Returns false if the attribute is not copied because an existing attribute takes precedence
// (came from a rule).
static bool CopyAttribute(const xml::Attribute& src_attr, bool generated, xml::Element* dst_el,
- StringPool* out_string_pool) {
+ android::StringPool* out_string_pool) {
CloningValueTransformer cloner(out_string_pool);
xml::Attribute* dst_attr = dst_el->FindAttribute(src_attr.namespace_uri, src_attr.name);
if (dst_attr != nullptr) {
@@ -58,7 +58,7 @@
const util::Range<ApiVersion>& api_range, bool generated,
xml::Element* dst_el,
std::set<ApiVersion>* out_apis_referenced,
- StringPool* out_string_pool) {
+ android::StringPool* out_string_pool) {
if (src_attr_version <= api_range.start) {
// The API is compatible, so don't check the rule and just copy.
if (!CopyAttribute(src_attr, generated, dst_el, out_string_pool)) {
@@ -156,7 +156,7 @@
}
static inline std::unique_ptr<Item> CloneIfNotNull(const std::unique_ptr<Item>& src,
- StringPool* out_string_pool) {
+ android::StringPool* out_string_pool) {
if (src == nullptr) {
return {};
}
@@ -166,7 +166,7 @@
std::vector<DegradeResult> DegradeToManyRule::Degrade(const xml::Element& src_el,
const xml::Attribute& src_attr,
- StringPool* out_string_pool) const {
+ android::StringPool* out_string_pool) const {
std::vector<DegradeResult> result;
result.reserve(attrs_.size());
for (const ReplacementAttr& attr : attrs_) {
diff --git a/tools/aapt2/link/XmlCompatVersioner.h b/tools/aapt2/link/XmlCompatVersioner.h
index 9980618..22f9828 100644
--- a/tools/aapt2/link/XmlCompatVersioner.h
+++ b/tools/aapt2/link/XmlCompatVersioner.h
@@ -45,7 +45,7 @@
virtual std::vector<DegradeResult> Degrade(const xml::Element& src_el,
const xml::Attribute& src_attr,
- StringPool* out_string_pool) const = 0;
+ android::StringPool* out_string_pool) const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(IDegradeRule);
@@ -70,7 +70,7 @@
void ProcessRule(const xml::Element& src_el, const xml::Attribute& src_attr,
const ApiVersion& src_attr_version, const IDegradeRule* rule,
const util::Range<ApiVersion>& api_range, bool generated, xml::Element* dst_el,
- std::set<ApiVersion>* out_apis_referenced, StringPool* out_string_pool);
+ std::set<ApiVersion>* out_apis_referenced, android::StringPool* out_string_pool);
const Rules* rules_;
};
@@ -87,7 +87,7 @@
virtual ~DegradeToManyRule() = default;
std::vector<DegradeResult> Degrade(const xml::Element& src_el, const xml::Attribute& src_attr,
- StringPool* out_string_pool) const override;
+ android::StringPool* out_string_pool) const override;
private:
DISALLOW_COPY_AND_ASSIGN(DegradeToManyRule);
diff --git a/tools/aapt2/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index 1f8548b..d2e9bd7 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -14,14 +14,12 @@
* limitations under the License.
*/
-#include "link/Linkers.h"
-
-#include "androidfw/ResourceTypes.h"
-
-#include "Diagnostics.h"
#include "ResourceUtils.h"
#include "SdkConstants.h"
#include "ValueVisitor.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/ResourceTypes.h"
+#include "link/Linkers.h"
#include "link/ReferenceLinker.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
@@ -38,7 +36,7 @@
public:
using xml::PackageAwareVisitor::Visit;
- XmlVisitor(const Source& source, StringPool* pool, const CallSite& callsite,
+ XmlVisitor(const android::Source& source, android::StringPool* pool, const CallSite& callsite,
IAaptContext* context, ResourceTable* table, SymbolTable* symbols)
: source_(source),
callsite_(callsite),
@@ -61,7 +59,7 @@
}
}
- const Source source = source_.WithLine(el->line_number);
+ const android::Source source = source_.WithLine(el->line_number);
for (xml::Attribute& attr : el->attributes) {
// If the attribute has no namespace, interpret values as if
// they were assigned to the default Attribute.
@@ -80,7 +78,7 @@
ReferenceLinker::CompileXmlAttribute(attr_ref, callsite_, context_, symbols_, &err_str);
if (!attr.compiled_attribute) {
- DiagMessage error_msg(source);
+ android::DiagMessage error_msg(source);
error_msg << "attribute ";
ReferenceLinker::WriteAttributeName(attr_ref, callsite_, this, &error_msg);
error_msg << " " << err_str;
@@ -99,7 +97,7 @@
attr.compiled_value = attr.compiled_value->Transform(reference_transformer_);
} else if ((attribute->type_mask & android::ResTable_map::TYPE_STRING) == 0) {
// We won't be able to encode this as a string.
- DiagMessage msg(source);
+ android::DiagMessage msg(source);
msg << "'" << attr.value << "' is incompatible with attribute " << attr.name << " "
<< *attribute;
context_->GetDiagnostics()->Error(msg);
@@ -118,7 +116,7 @@
private:
DISALLOW_COPY_AND_ASSIGN(XmlVisitor);
- Source source_;
+ android::Source source_;
const CallSite& callsite_;
IAaptContext* context_;
SymbolTable* symbols_;