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

Commit 09ef94e9 authored by Adam Koski's avatar Adam Koski
Browse files

Change conditional keep rule syntax

Google's ProGuard fork is migrating to a new syntax that upstream
ProGuard 6.0 will also support.

Test: unit tests
Bug: 69162105
Change-Id: I3b6d7e82eb99c2e2af6c4d851a4f97ec3e471b55
parent 5d815009
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -345,15 +345,14 @@ bool WriteKeepSet(std::ostream* out, const KeepSet& keep_set) {
      *out << "# Referenced at " << location.source << "\n";
    }
    if (keep_set.conditional_keep_rules_ && can_be_conditional) {
      *out << "-keep class " << entry.first << " {\n  ifused class **.R$layout {\n";
      *out << "-if class **.R$layout {\n";
      for (const UsageLocation& location : locations) {
        auto transformed_name = JavaClassGenerator::TransformToFieldName(location.name.entry);
        *out << "  int " << transformed_name << ";\n";
      }
      *out << "  };\n  <init>(...);\n}\n" << std::endl;
    } else {
      *out << "-keep class " << entry.first << " { <init>(...); }\n" << std::endl;
      *out << "}\n";
    }
    *out << "-keep class " << entry.first << " { <init>(...); }\n" << std::endl;
  }

  for (const auto& entry : keep_set.method_set_) {
+3 −3
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ TEST(ProguardRulesTest, IncludedLayoutRulesAreConditional) {
  ASSERT_TRUE(proguard::WriteKeepSet(&out, set));

  std::string actual = out.str();
  EXPECT_THAT(actual, HasSubstr("ifused class **.R$layout"));
  EXPECT_THAT(actual, HasSubstr("-if class **.R$layout"));
  EXPECT_THAT(actual, HasSubstr("int foo"));
  EXPECT_THAT(actual, HasSubstr("int bar"));
  EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
@@ -152,7 +152,7 @@ TEST(ProguardRulesTest, AliasedLayoutRulesAreConditional) {
  ASSERT_TRUE(proguard::WriteKeepSet(&out, set));

  std::string actual = out.str();
  EXPECT_THAT(actual, HasSubstr("ifused class **.R$layout"));
  EXPECT_THAT(actual, HasSubstr("-if class **.R$layout"));
  EXPECT_THAT(actual, HasSubstr("int foo"));
  EXPECT_THAT(actual, HasSubstr("int bar"));
  EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
@@ -174,7 +174,7 @@ TEST(ProguardRulesTest, NonLayoutReferencesAreUnconditional) {
  ASSERT_TRUE(proguard::WriteKeepSet(&out, set));

  std::string actual = out.str();
  EXPECT_THAT(actual, Not(HasSubstr("ifused")));
  EXPECT_THAT(actual, Not(HasSubstr("-if")));
}

TEST(ProguardRulesTest, ViewOnClickRuleIsEmitted) {