Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 461c8057 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

AAPT2: Fix issue where generated XML would be tagged with UNKNOWN type

CompiledFiles with UNKNOWN type are copied through, leading to protobuf
outputs in the final APK.

Test: make aapt2_tests
Change-Id: Ia0c464caa3951ff27436d1d50c2a8555bc89302b
parent 4f340a4f
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -118,10 +118,11 @@ bool InlineXmlFormatParser::Consume(IAaptContext* context, xml::XmlResource* doc

  size_t name_suffix_counter = 0;
  for (const InlineDeclaration& decl : visitor.GetInlineDeclarations()) {
    auto new_doc = util::make_unique<xml::XmlResource>();
    new_doc->file.config = doc->file.config;
    new_doc->file.source = doc->file.source.WithLine(decl.el->line_number);
    new_doc->file.name = doc->file.name;
    // Create a new XmlResource with the same ResourceFile as the base XmlResource.
    auto new_doc = util::make_unique<xml::XmlResource>(doc->file);

    // Attach the line number.
    new_doc->file.source.line = decl.el->line_number;

    // Modify the new entry name. We need to suffix the entry with a number to
    // avoid local collisions, then mangle it with the empty package, such that it won't show up
+4 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ TEST(InlineXmlFormatParserTest, ExtractOneXmlResource) {
      </View1>)");

  doc->file.name = test::ParseNameOrDie("layout/main");
  doc->file.type = ResourceFile::Type::kProtoXml;

  InlineXmlFormatParser parser;
  ASSERT_TRUE(parser.Consume(context.get(), doc.get()));
@@ -81,6 +82,9 @@ TEST(InlineXmlFormatParserTest, ExtractOneXmlResource) {
  // Make sure the generated reference is correct.
  EXPECT_THAT(extracted_doc->file.name, Eq(name_ref));

  // Make sure the ResourceFile::Type is the same.
  EXPECT_THAT(extracted_doc->file.type, Eq(ResourceFile::Type::kProtoXml));

  // Verify the structure of the extracted XML.
  el = extracted_doc->root.get();
  ASSERT_THAT(el, NotNull());