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

Commit 558a6305 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "AAPT2: Support CtsContentTestCases build"

parents a07efe52 86d67df8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ namespace aapt {
static const char* sMajorVersion = "2";

// Update minor version whenever a feature or flag is added.
static const char* sMinorVersion = "5";
static const char* sMinorVersion = "6";

int PrintVersion() {
  std::cerr << "Android Asset Packaging Tool (aapt) " << sMajorVersion << "."
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ StringPiece ToString(ResourceType type) {
      return "bool";
    case ResourceType::kColor:
      return "color";
    case ResourceType::kConfigVarying:
      return "configVarying";
    case ResourceType::kDimen:
      return "dimen";
    case ResourceType::kDrawable:
@@ -85,6 +87,7 @@ static const std::map<StringPiece, ResourceType> sResourceTypeMap{
    {"^attr-private", ResourceType::kAttrPrivate},
    {"bool", ResourceType::kBool},
    {"color", ResourceType::kColor},
    {"configVarying", ResourceType::kConfigVarying},
    {"dimen", ResourceType::kDimen},
    {"drawable", ResourceType::kDrawable},
    {"font", ResourceType::kFont},
+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ enum class ResourceType {
  kAttrPrivate,
  kBool,
  kColor,

  // Not really a type, but it shows up in some CTS tests and
  // we need to continue respecting it.
  kConfigVarying,

  kDimen,
  kDrawable,
  kFont,
+107 −92
Original line number Diff line number Diff line
@@ -338,41 +338,39 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
  using BagParseFunc = std::function<bool(ResourceParser*, xml::XmlPullParser*,
                                          ParsedResource*)>;

  static const auto elToItemMap =
      ImmutableMap<std::string, ItemTypeFormat>::CreatePreSorted({
  static const auto elToItemMap = ImmutableMap<std::string, ItemTypeFormat>::CreatePreSorted({
      {"bool", {ResourceType::kBool, android::ResTable_map::TYPE_BOOLEAN}},
      {"color", {ResourceType::kColor, android::ResTable_map::TYPE_COLOR}},
      {"configVarying", {ResourceType::kConfigVarying, android::ResTable_map::TYPE_ANY}},
      {"dimen",
           {ResourceType::kDimen, android::ResTable_map::TYPE_FLOAT |
                                      android::ResTable_map::TYPE_FRACTION |
       {ResourceType::kDimen,
        android::ResTable_map::TYPE_FLOAT | android::ResTable_map::TYPE_FRACTION |
            android::ResTable_map::TYPE_DIMENSION}},
          {"drawable",
           {ResourceType::kDrawable, android::ResTable_map::TYPE_COLOR}},
      {"drawable", {ResourceType::kDrawable, android::ResTable_map::TYPE_COLOR}},
      {"fraction",
       {ResourceType::kFraction,
            android::ResTable_map::TYPE_FLOAT |
                android::ResTable_map::TYPE_FRACTION |
        android::ResTable_map::TYPE_FLOAT | android::ResTable_map::TYPE_FRACTION |
            android::ResTable_map::TYPE_DIMENSION}},
          {"integer",
           {ResourceType::kInteger, android::ResTable_map::TYPE_INTEGER}},
          {"string",
           {ResourceType::kString, android::ResTable_map::TYPE_STRING}},
      {"integer", {ResourceType::kInteger, android::ResTable_map::TYPE_INTEGER}},
      {"string", {ResourceType::kString, android::ResTable_map::TYPE_STRING}},
  });

  static const auto elToBagMap =
      ImmutableMap<std::string, BagParseFunc>::CreatePreSorted({
  static const auto elToBagMap = ImmutableMap<std::string, BagParseFunc>::CreatePreSorted({
      {"add-resource", std::mem_fn(&ResourceParser::ParseAddResource)},
      {"array", std::mem_fn(&ResourceParser::ParseArray)},
      {"attr", std::mem_fn(&ResourceParser::ParseAttr)},
          {"declare-styleable",
           std::mem_fn(&ResourceParser::ParseDeclareStyleable)},
      {"configVarying",
       std::bind(&ResourceParser::ParseStyle, std::placeholders::_1, ResourceType::kConfigVarying,
                 std::placeholders::_2, std::placeholders::_3)},
      {"declare-styleable", std::mem_fn(&ResourceParser::ParseDeclareStyleable)},
      {"integer-array", std::mem_fn(&ResourceParser::ParseIntegerArray)},
      {"java-symbol", std::mem_fn(&ResourceParser::ParseSymbol)},
      {"plurals", std::mem_fn(&ResourceParser::ParsePlural)},
      {"public", std::mem_fn(&ResourceParser::ParsePublic)},
      {"public-group", std::mem_fn(&ResourceParser::ParsePublicGroup)},
      {"string-array", std::mem_fn(&ResourceParser::ParseStringArray)},
          {"style", std::mem_fn(&ResourceParser::ParseStyle)},
      {"style", std::bind(&ResourceParser::ParseStyle, std::placeholders::_1, ResourceType::kStyle,
                          std::placeholders::_2, std::placeholders::_3)},
      {"symbol", std::mem_fn(&ResourceParser::ParseSymbol)},
  });

@@ -381,7 +379,11 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
  // The value format accepted for this resource.
  uint32_t resource_format = 0u;

  bool can_be_item = true;
  bool can_be_bag = true;
  if (resource_type == "item") {
    can_be_bag = false;

    // Items have their type encoded in the type attribute.
    if (Maybe<StringPiece> maybe_type =
            xml::FindNonEmptyAttribute(parser, "type")) {
@@ -406,6 +408,17 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
        return false;
      }
    }
  } else if (resource_type == "bag") {
    can_be_item = false;

    // Bags have their type encoded in the type attribute.
    if (Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
      resource_type = maybe_type.value().to_string();
    } else {
      diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
                   << "<bag> must have a 'type' attribute");
      return false;
    }
  }

  // Get the name of the resource. This will be checked later, because not all
@@ -426,14 +439,14 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
    return true;
  }

  if (can_be_item) {
    const auto item_iter = elToItemMap.find(resource_type);
    if (item_iter != elToItemMap.end()) {
      // This is an item, record its type and format and start parsing.

      if (!maybe_name) {
        diag_->Error(DiagMessage(out_resource->source)
                   << "<" << parser->element_name()
                   << "> missing 'name' attribute");
                     << "<" << parser->element_name() << "> missing 'name' attribute");
        return false;
      }

@@ -450,16 +463,17 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
      }
      return true;
    }
  }

  // This might be a bag or something.
  if (can_be_bag) {
    const auto bag_iter = elToBagMap.find(resource_type);
    if (bag_iter != elToBagMap.end()) {
      // Ensure we have a name (unless this is a <public-group>).
      if (resource_type != "public-group") {
        if (!maybe_name) {
          diag_->Error(DiagMessage(out_resource->source)
                     << "<" << parser->element_name()
                     << "> missing 'name' attribute");
                       << "<" << parser->element_name() << "> missing 'name' attribute");
          return false;
        }

@@ -473,7 +487,9 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
      }
      return true;
    }
  }

  if (can_be_item) {
    // Try parsing the elementName (or type) as a resource. These shall only be
    // resources like 'layout' or 'xml' and they can only be references.
    const ResourceType* parsed_type = ParseResourceType(resource_type);
@@ -487,16 +503,15 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,

      out_resource->name.type = *parsed_type;
      out_resource->name.entry = maybe_name.value().to_string();
    out_resource->value =
        ParseXml(parser, android::ResTable_map::TYPE_REFERENCE, kNoRawString);
      out_resource->value = ParseXml(parser, android::ResTable_map::TYPE_REFERENCE, kNoRawString);
      if (!out_resource->value) {
        diag_->Error(DiagMessage(out_resource->source)
                   << "invalid value for type '" << *parsed_type
                   << "'. Expected a reference");
                     << "invalid value for type '" << *parsed_type << "'. Expected a reference");
        return false;
      }
      return true;
    }
  }

  diag_->Warn(DiagMessage(out_resource->source)
              << "unknown resource type '" << parser->element_name() << "'");
@@ -1048,9 +1063,9 @@ bool ResourceParser::ParseStyleItem(xml::XmlPullParser* parser, Style* style) {
  return true;
}

bool ResourceParser::ParseStyle(xml::XmlPullParser* parser,
bool ResourceParser::ParseStyle(const ResourceType type, xml::XmlPullParser* parser,
                                ParsedResource* out_resource) {
  out_resource->name.type = ResourceType::kStyle;
  out_resource->name.type = type;

  std::unique_ptr<Style> style = util::make_unique<Style>();

+2 −1
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ class ResourceParser {
                     bool weak);
  Maybe<Attribute::Symbol> ParseEnumOrFlagItem(xml::XmlPullParser* parser,
                                               const android::StringPiece& tag);
  bool ParseStyle(xml::XmlPullParser* parser, ParsedResource* out_resource);
  bool ParseStyle(const ResourceType type, xml::XmlPullParser* parser,
                  ParsedResource* out_resource);
  bool ParseStyleItem(xml::XmlPullParser* parser, Style* style);
  bool ParseDeclareStyleable(xml::XmlPullParser* parser,
                             ParsedResource* out_resource);
Loading