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

Commit ab7d501a authored by Adam Lesinski's avatar Adam Lesinski Committed by android-build-merger
Browse files

Merge "AAPT2: Fix <add-resource> tag for overlays" into oc-dev am: 8255ced3

am: ce1e415d

Change-Id: I13ae82041b4b94a0226aa4506b59f8bbcce971be
parents b95db872 ce1e415d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ message SymbolStatus {
	optional Visibility visibility = 1;
	optional Source source = 2;
	optional string comment = 3;
	optional bool allow_new = 4;
}

message Entry {
+6 −4
Original line number Diff line number Diff line
@@ -92,14 +92,14 @@ struct ParsedResource {
  Source source;
  ResourceId id;
  Maybe<SymbolState> symbol_state;
  bool allow_new = false;
  std::string comment;
  std::unique_ptr<Value> value;
  std::list<ParsedResource> child_resources;
};

// Recursively adds resources to the ResourceTable.
static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag,
                                ParsedResource* res) {
static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag, ParsedResource* res) {
  StringPiece trimmed_comment = util::TrimWhitespace(res->comment);
  if (trimmed_comment.size() != res->comment.size()) {
    // Only if there was a change do we re-assign.
@@ -111,6 +111,7 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag,
    symbol.state = res->symbol_state.value();
    symbol.source = res->source;
    symbol.comment = res->comment;
    symbol.allow_new = res->allow_new;
    if (!table->SetSymbolState(res->name, res->id, symbol, diag)) {
      return false;
    }
@@ -121,8 +122,8 @@ static bool AddResourcesToTable(ResourceTable* table, IDiagnostics* diag,
    res->value->SetComment(std::move(res->comment));
    res->value->SetSource(std::move(res->source));

    if (!table->AddResource(res->name, res->id, res->config, res->product,
                            std::move(res->value), diag)) {
    if (!table->AddResource(res->name, res->id, res->config, res->product, std::move(res->value),
                            diag)) {
      return false;
    }
  }
@@ -849,6 +850,7 @@ bool ResourceParser::ParseAddResource(xml::XmlPullParser* parser,
                                      ParsedResource* out_resource) {
  if (ParseSymbolImpl(parser, out_resource)) {
    out_resource->symbol_state = SymbolState::kUndefined;
    out_resource->allow_new = true;
    return true;
  }
  return false;
+2 −2
Original line number Diff line number Diff line
@@ -777,8 +777,7 @@ TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) {
  ASSERT_FALSE(TestParse(input));
}

TEST_F(ResourceParserTest,
       AddResourcesElementShouldAddEntryWithUndefinedSymbol) {
TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) {
  std::string input = R"EOF(<add-resource name="bar" type="string" />)EOF";
  ASSERT_TRUE(TestParse(input));

@@ -788,6 +787,7 @@ TEST_F(ResourceParserTest,
  const ResourceEntry* entry = result.value().entry;
  ASSERT_NE(nullptr, entry);
  EXPECT_EQ(SymbolState::kUndefined, entry->symbol_status.state);
  EXPECT_TRUE(entry->symbol_status.allow_new);
}

TEST_F(ResourceParserTest, ParseItemElementWithFormat) {
+11 −5
Original line number Diff line number Diff line
@@ -440,8 +440,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI
  return true;
}

bool ResourceTable::SetSymbolState(const ResourceNameRef& name,
                                   const ResourceId& res_id,
bool ResourceTable::SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id,
                                   const Symbol& symbol, IDiagnostics* diag) {
  return SetSymbolStateImpl(name, res_id, symbol, ValidateName, diag);
}
@@ -489,8 +488,7 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour
    diag->Error(DiagMessage(symbol.source)
                << "trying to add resource '" << name << "' with ID " << res_id
                << " but resource already has ID "
                << ResourceId(package->id.value(), type->id.value(),
                              entry->id.value()));
                << ResourceId(package->id.value(), type->id.value(), entry->id.value()));
    return false;
  }

@@ -505,6 +503,11 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour
    type->symbol_status.state = SymbolState::kPublic;
  }

  if (symbol.allow_new) {
    // This symbol can be added as a new resource when merging (if it belongs to an overlay).
    entry->symbol_status.allow_new = true;
  }

  if (symbol.state == SymbolState::kUndefined &&
      entry->symbol_status.state != SymbolState::kUndefined) {
    // We can't undefine a symbol (remove its visibility). Ignore.
@@ -517,7 +520,10 @@ bool ResourceTable::SetSymbolStateImpl(const ResourceNameRef& name, const Resour
    return true;
  }

  entry->symbol_status = std::move(symbol);
  // This symbol definition takes precedence, replace.
  entry->symbol_status.state = symbol.state;
  entry->symbol_status.source = symbol.source;
  entry->symbol_status.comment = symbol.comment;
  return true;
}

+5 −2
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ enum class SymbolState {
struct Symbol {
  SymbolState state = SymbolState::kUndefined;
  Source source;

  // Whether this entry (originating from an overlay) can be added as a new resource.
  bool allow_new = false;

  std::string comment;
};

@@ -223,8 +227,7 @@ class ResourceTable {
  bool SetSymbolState(const ResourceNameRef& name, const ResourceId& res_id,
                      const Symbol& symbol, IDiagnostics* diag);

  bool SetSymbolStateAllowMangled(const ResourceNameRef& name,
                                  const ResourceId& res_id,
  bool SetSymbolStateAllowMangled(const ResourceNameRef& name, const ResourceId& res_id,
                                  const Symbol& symbol, IDiagnostics* diag);

  struct SearchResult {
Loading