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

Commit e59f0d80 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

AAPT2: Enable building proto artifacts

- This will allow the bundle tool to ingest the outputs of the aapt2 link
  phase.

Bug: 64143208
Test: manual
Change-Id: I1a4b3ce5c2ffbbdc4bc642c3371a9ef2e7e9ad71
parent 00451166
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -35,11 +35,11 @@ namespace aapt {

namespace {

class PrintVisitor : public DescendingValueVisitor {
class PrintVisitor : public ConstValueVisitor {
 public:
  using DescendingValueVisitor::Visit;
  using ConstValueVisitor::Visit;

  void Visit(Attribute* attr) override {
  void Visit(const Attribute* attr) override {
    std::cout << "(attr) type=";
    attr->PrintMask(&std::cout);
    static constexpr uint32_t kMask =
@@ -55,7 +55,7 @@ class PrintVisitor : public DescendingValueVisitor {
    }
  }

  void Visit(Style* style) override {
  void Visit(const Style* style) override {
    std::cout << "(style)";
    if (style->parent) {
      const Reference& parent_ref = style->parent.value();
@@ -90,15 +90,15 @@ class PrintVisitor : public DescendingValueVisitor {
    }
  }

  void Visit(Array* array) override {
  void Visit(const Array* array) override {
    array->Print(&std::cout);
  }

  void Visit(Plural* plural) override {
  void Visit(const Plural* plural) override {
    plural->Print(&std::cout);
  }

  void Visit(Styleable* styleable) override {
  void Visit(const Styleable* styleable) override {
    std::cout << "(styleable)";
    for (const auto& attr : styleable->entries) {
      std::cout << "\n        ";
@@ -116,17 +116,17 @@ class PrintVisitor : public DescendingValueVisitor {
    }
  }

  void VisitItem(Item* item) override {
  void VisitItem(const Item* item) override {
    item->Print(&std::cout);
  }
};

}  // namespace

void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) {
void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions& options) {
  PrintVisitor visitor;

  for (auto& package : table->packages) {
  for (const auto& package : table.packages) {
    std::cout << "Package name=" << package->name;
    if (package->id) {
      std::cout << " id=" << std::hex << (int)package->id.value() << std::dec;
@@ -261,11 +261,11 @@ void Debug::DumpHex(const void* data, size_t len) {

namespace {

class XmlPrinter : public xml::Visitor {
class XmlPrinter : public xml::ConstVisitor {
 public:
  using xml::Visitor::Visit;
  using xml::ConstVisitor::Visit;

  void Visit(xml::Element* el) override {
  void Visit(const xml::Element* el) override {
    const size_t previous_size = prefix_.size();

    for (const xml::NamespaceDecl& decl : el->namespace_decls) {
@@ -301,11 +301,11 @@ class XmlPrinter : public xml::Visitor {
    }

    prefix_ += "  ";
    xml::Visitor::Visit(el);
    xml::ConstVisitor::Visit(el);
    prefix_.resize(previous_size);
  }

  void Visit(xml::Text* text) override {
  void Visit(const xml::Text* text) override {
    std::cerr << prefix_ << "T: '" << text->text << "'\n";
  }

@@ -315,9 +315,9 @@ class XmlPrinter : public xml::Visitor {

}  // namespace

void Debug::DumpXml(xml::XmlResource* doc) {
void Debug::DumpXml(const xml::XmlResource& doc) {
  XmlPrinter printer;
  doc->root->Accept(&printer);
  doc.root->Accept(&printer);
}

}  // namespace aapt
+2 −4
Original line number Diff line number Diff line
@@ -31,13 +31,11 @@ struct DebugPrintTableOptions {
};

struct Debug {
  static void PrintTable(ResourceTable* table,
                         const DebugPrintTableOptions& options = {});
  static void PrintTable(const ResourceTable& table, const DebugPrintTableOptions& options = {});
  static void PrintStyleGraph(ResourceTable* table,
                              const ResourceName& target_style);
  static void DumpHex(const void* data, size_t len);
  static void DumpXml(xml::XmlResource* doc);
  static std::string ToString(xml::XmlResource* doc);
  static void DumpXml(const xml::XmlResource& doc);
};

}  // namespace aapt
+9 −2
Original line number Diff line number Diff line
@@ -704,8 +704,15 @@ std::unique_ptr<Item> ParseBinaryResValue(const ResourceType& type, const Config
      } else {
        if (type != ResourceType::kString && util::StartsWith(str, "res/")) {
          // This must be a FileReference.
          return util::make_unique<FileReference>(dst_pool->MakeRef(
          std::unique_ptr<FileReference> file_ref =
              util::make_unique<FileReference>(dst_pool->MakeRef(
                  str, StringPool::Context(StringPool::Context::kHighPriority, config)));
          if (util::EndsWith(*file_ref->path, ".xml")) {
            file_ref->type = ResourceFile::Type::kBinaryXml;
          } else if (util::EndsWith(*file_ref->path, ".png")) {
            file_ref->type = ResourceFile::Type::kPng;
          }
          return std::move(file_ref);
        }

        // There are no styles associated with this string, so treat it as a simple string.
+11 −0
Original line number Diff line number Diff line
@@ -269,8 +269,19 @@ message StyledString {

// A value that is a reference to an external entity, like an XML file or a PNG.
message FileReference {
  enum Type {
    UNKNOWN = 0;
    PNG = 1;
    BINARY_XML = 2;
    PROTO_XML = 3;
  }

  // Path to a file within the APK (typically res/type-config/entry.ext).
  string path = 1;

  // The type of file this path points to. For UAM bundle, this cannot be
  // BINARY_XML.
  Type type = 2;
}

// A value that represents a primitive data type (float, int, boolean, etc.).
+2 −11
Original line number Diff line number Diff line
@@ -41,14 +41,8 @@ message CompiledFile {
  // The configuration for which the resource is defined.
  aapt.pb.Configuration config = 2;

  enum Type {
    UNKNOWN = 0;
    PNG = 1;
    BINARY_XML = 2;
    PROTO_XML = 3;
  }

  Type type = 3;
  // The type of the file.
  aapt.pb.FileReference.Type type = 3;

  // The filesystem path to where the source file originated.
  // Mainly used to display helpful error messages.
@@ -56,7 +50,4 @@ message CompiledFile {

  // Any symbols this file auto-generates/exports (eg. @+id/foo in an XML file).
  repeated Symbol exported_symbol = 5;

  // If this is a compiled XML file, this is the root node.
  aapt.pb.XmlNode xml_root = 6;
}
Loading