AAPT2: Allow for nested inline xmls
am: c8f5fc284c
Change-Id: Ie80ba078d893d1b894d289645dae84fa2af58c40
This commit is contained in:
committed by
android-build-merger
commit
114616b27d
@@ -146,6 +146,10 @@ bool InlineXmlFormatParser::Consume(IAaptContext* context, xml::XmlResource* doc
|
||||
} else {
|
||||
new_doc->root.reset(static_cast<xml::Element*>(child.release()));
|
||||
new_doc->root->parent = nullptr;
|
||||
// Copy down the namespace declarations
|
||||
new_doc->root->namespace_decls = doc->root->namespace_decls;
|
||||
// Recurse for nested inlines
|
||||
Consume(context, new_doc.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,4 +137,47 @@ TEST(InlineXmlFormatParserTest, ExtractTwoXmlResources) {
|
||||
EXPECT_THAT(extracted_doc_drawable->root->name, StrEq("vector"));
|
||||
}
|
||||
|
||||
TEST(InlineXmlFormatParserTest, ExtractNestedXmlResources) {
|
||||
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
|
||||
std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"(
|
||||
<base_root xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt">
|
||||
<aapt:attr name="inline_xml">
|
||||
<inline_root>
|
||||
<aapt:attr name="nested_inline_xml">
|
||||
<nested_inline_root/>
|
||||
</aapt:attr>
|
||||
<aapt:attr name="another_nested_inline_xml">
|
||||
<root/>
|
||||
</aapt:attr>
|
||||
</inline_root>
|
||||
</aapt:attr>
|
||||
<aapt:attr name="turtles">
|
||||
<root1>
|
||||
<aapt:attr name="all">
|
||||
<root2>
|
||||
<aapt:attr name="the">
|
||||
<root3>
|
||||
<aapt:attr name="way">
|
||||
<root4>
|
||||
<aapt:attr name="down">
|
||||
<root5/>
|
||||
</aapt:attr>
|
||||
</root4>
|
||||
</aapt:attr>
|
||||
</root3>
|
||||
</aapt:attr>
|
||||
</root2>
|
||||
</aapt:attr>
|
||||
</root1>
|
||||
</aapt:attr>
|
||||
</base_root>)");
|
||||
|
||||
doc->file.name = test::ParseNameOrDie("layout/main");
|
||||
|
||||
InlineXmlFormatParser parser;
|
||||
ASSERT_TRUE(parser.Consume(context.get(), doc.get()));
|
||||
// Confirm that all of the nested inline xmls are parsed out.
|
||||
ASSERT_THAT(parser.GetExtractedInlineXmlDocuments(), SizeIs(8u));
|
||||
}
|
||||
} // namespace aapt
|
||||
|
||||
Reference in New Issue
Block a user