Mark -keepkotlinmetadata proguard rule as used

When we synthesize a keep class kotlin.Metadata we will report the rule as unused if the class is not present or is on classpath.

Fixes: b/243480702
Change-Id: I57064e778aada631e41223c2fd40f2d6b5f9a886
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
index cf357ed..773903d 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
@@ -288,7 +288,7 @@
           || parseUnsupportedOptionAndErr(optionStart)) {
         // Intentionally left empty.
       } else if (acceptString("keepkotlinmetadata")) {
-        configurationBuilder.addRule(
+        ProguardKeepRule keepKotlinMetadata =
             ProguardKeepRule.builder()
                 .setType(ProguardKeepRuleType.KEEP)
                 .setClassType(ProguardClassType.CLASS)
@@ -301,7 +301,11 @@
                         .build())
                 .setMemberRules(Collections.singletonList(ProguardMemberRule.defaultKeepAllRule()))
                 .setSource("-keepkotlinmetadata")
-                .build());
+                .build();
+        // Mark the rule as used to ensure we do not report any information messages if the class
+        // is not present.
+        keepKotlinMetadata.markAsUsed();
+        configurationBuilder.addRule(keepKotlinMetadata);
         configurationBuilder.addKeepAttributePatterns(
             Collections.singletonList(RUNTIME_VISIBLE_ANNOTATIONS));
       } else if (acceptString("renamesourcefileattribute")) {
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRewriteInMultifileClassTest.java b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRewriteInMultifileClassTest.java
index dfc31a7..5a3960e 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRewriteInMultifileClassTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRewriteInMultifileClassTest.java
@@ -18,7 +18,6 @@
 import com.android.tools.r8.KotlinTestParameters;
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.ToolHelper.ProcessResult;
-import com.android.tools.r8.shaking.ProguardKeepAttributes;
 import com.android.tools.r8.utils.DescriptorUtils;
 import com.android.tools.r8.utils.StringUtils;
 import com.android.tools.r8.utils.codeinspector.AnnotationSubject;
@@ -86,7 +85,7 @@
             // Keep UtilKt#comma*Join*(). Let R8 optimize (inline) others, such as joinOf*(String).
             .addKeepRules("-keep class **.UtilKt")
             .addKeepRules("-keepclassmembers class * { ** comma*Join*(...); }")
-            .addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
+            .addKeepKotlinMetadata()
             .compile()
             .inspect(this::inspectMerged)
             .writeToZip();
@@ -130,7 +129,7 @@
             .addKeepRules("-keepclassmembers class * { ** comma*Join*(...); }")
             // Keep yet rename joinOf*(String).
             .addKeepRules("-keepclassmembers,allowobfuscation class * { ** joinOf*(...); }")
-            .addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
+            .addKeepKotlinMetadata()
             .compile()
             .inspect(this::inspectRenamed)
             .writeToZip();