diff options
author | Michael Wachenschwanz <mwachens@google.com> | 2017-10-30 19:06:23 -0700 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-11-02 04:43:41 +0000 |
commit | 9d316c18cac26b6f00ac18236e284cd010ec6c13 (patch) | |
tree | 0291674db5330abba43a2406c18fed3d65490ab4 | |
parent | 37e2e248430976004df02588e9ff489bb2cd5ae8 (diff) | |
download | base-9d316c18cac26b6f00ac18236e284cd010ec6c13.tar.gz |
AAPT2: Allow for nested inline xmls
Add recursion to InlineXmlFormatParser::Consume for handling nested
aapt:attr
Change-Id: Iabf98945b4f5ef22a3b8fdc4ca2bac092a377629
Fixes: 64385167
Test: make aapt2_tests
(cherry picked from commit 7b6b02bd13aea90b938c3ab3b1eaa3fb5043f931)
(cherry picked from commit c8f5fc284cc635f7056307e55121e439b21ac83a)
-rw-r--r-- | tools/aapt2/compile/InlineXmlFormatParser.cpp | 4 | ||||
-rw-r--r-- | tools/aapt2/compile/InlineXmlFormatParser_test.cpp | 43 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp index 857cdd5365a0..73a90da6baf0 100644 --- a/tools/aapt2/compile/InlineXmlFormatParser.cpp +++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp @@ -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()); } } diff --git a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp index de7739ada407..a4c602c29b86 100644 --- a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp +++ b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp @@ -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 |