Remove unused attributes from ProguardKeepAttributes
Change-Id: Icb259025363d592679c5e957e0302971962299ee
diff --git a/src/main/java/com/android/tools/r8/metadata/impl/R8KeepAttributesMetadataImpl.java b/src/main/java/com/android/tools/r8/metadata/impl/R8KeepAttributesMetadataImpl.java
index ee9f918..dabb6de 100644
--- a/src/main/java/com/android/tools/r8/metadata/impl/R8KeepAttributesMetadataImpl.java
+++ b/src/main/java/com/android/tools/r8/metadata/impl/R8KeepAttributesMetadataImpl.java
@@ -39,14 +39,6 @@
private final boolean isInnerClassesKept;
@Expose
- @SerializedName("isLocalVariableTableKept")
- private final boolean isLocalVariableTableKept;
-
- @Expose
- @SerializedName("isLocalVariableTypeTableKept")
- private final boolean isLocalVariableTypeTableKept;
-
- @Expose
@SerializedName("isMethodParametersKept")
private final boolean isMethodParametersKept;
@@ -87,10 +79,6 @@
private final boolean isSourceDebugExtensionKept;
@Expose
- @SerializedName("isSourceDirKept")
- private final boolean isSourceDirKept;
-
- @Expose
@SerializedName("isSourceFileKept")
private final boolean isSourceFileKept;
@@ -103,8 +91,6 @@
this.isEnclosingMethodKept = keepAttributes.enclosingMethod;
this.isExceptionsKept = keepAttributes.exceptions;
this.isInnerClassesKept = keepAttributes.innerClasses;
- this.isLocalVariableTableKept = keepAttributes.localVariableTable;
- this.isLocalVariableTypeTableKept = keepAttributes.localVariableTypeTable;
this.isMethodParametersKept = keepAttributes.methodParameters;
this.isPermittedSubclassesKept = keepAttributes.permittedSubclasses;
this.isRuntimeInvisibleAnnotationsKept = keepAttributes.runtimeInvisibleAnnotations;
@@ -117,7 +103,6 @@
this.isRuntimeVisibleTypeAnnotationsKept = keepAttributes.runtimeVisibleTypeAnnotations;
this.isSignatureKept = keepAttributes.signature;
this.isSourceDebugExtensionKept = keepAttributes.sourceDebugExtension;
- this.isSourceDirKept = keepAttributes.sourceDir;
this.isSourceFileKept = keepAttributes.sourceFile;
this.isStackMapTableKept = keepAttributes.stackMapTable;
}
@@ -144,12 +129,12 @@
@Override
public boolean isLocalVariableTableKept() {
- return isLocalVariableTableKept;
+ return false;
}
@Override
public boolean isLocalVariableTypeTableKept() {
- return isLocalVariableTypeTableKept;
+ return false;
}
@Override
@@ -204,7 +189,7 @@
@Override
public boolean isSourceDirKept() {
- return isSourceDirKept;
+ return false;
}
@Override
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardKeepAttributes.java b/src/main/java/com/android/tools/r8/shaking/ProguardKeepAttributes.java
index e8a384f..954a409 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardKeepAttributes.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardKeepAttributes.java
@@ -10,14 +10,11 @@
public class ProguardKeepAttributes {
public static final String SOURCE_FILE = "SourceFile";
- public static final String SOURCE_DIR = "SourceDir";
public static final String INNER_CLASSES = "InnerClasses";
public static final String ENCLOSING_METHOD = "EnclosingMethod";
public static final String SIGNATURE = "Signature";
public static final String EXCEPTIONS = "Exceptions";
public static final String LINE_NUMBER_TABLE = "LineNumberTable";
- public static final String LOCAL_VARIABLE_TABLE = "LocalVariableTable";
- public static final String LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
public static final String METHOD_PARAMETERS = "MethodParameters";
public static final String SOURCE_DEBUG_EXTENSION = "SourceDebugExtension";
public static final String RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations";
@@ -34,13 +31,10 @@
public static final String STACK_MAP_TABLE = "StackMapTable";
public boolean sourceFile = false;
- public boolean sourceDir = false;
public boolean innerClasses = false;
public boolean enclosingMethod = false;
public boolean signature = false;
public boolean exceptions = false;
- public boolean localVariableTable = false;
- public boolean localVariableTypeTable = false;
public boolean methodParameters = false;
public boolean sourceDebugExtension = false;
public boolean runtimeVisibleAnnotations = false;
@@ -57,13 +51,10 @@
public ProguardKeepAttributes keepAllAttributesExceptRuntimeInvisibleAnnotations() {
sourceFile = true;
- sourceDir = true;
innerClasses = true;
enclosingMethod = true;
signature = true;
exceptions = true;
- localVariableTable = true;
- localVariableTypeTable = true;
methodParameters = true;
sourceDebugExtension = true;
runtimeVisibleAnnotations = true;
@@ -124,10 +115,8 @@
public void applyPatterns(List<String> patterns) {
sourceFile = update(sourceFile, SOURCE_FILE, patterns);
- sourceDir = update(sourceDir, SOURCE_DIR, patterns);
innerClasses = update(innerClasses, INNER_CLASSES, patterns);
enclosingMethod = update(enclosingMethod, ENCLOSING_METHOD, patterns);
- localVariableTypeTable = update(localVariableTypeTable, LOCAL_VARIABLE_TYPE_TABLE, patterns);
exceptions = update(exceptions, EXCEPTIONS, patterns);
methodParameters = update(methodParameters, METHOD_PARAMETERS, patterns);
signature = update(signature, SIGNATURE, patterns);
@@ -174,7 +163,6 @@
}
ProguardKeepAttributes other = (ProguardKeepAttributes) o;
return this.sourceFile == other.sourceFile
- && this.sourceDir == other.sourceDir
&& this.innerClasses == other.innerClasses
&& this.enclosingMethod == other.enclosingMethod
&& this.signature == other.signature
@@ -195,7 +183,6 @@
@Override
public int hashCode() {
return (this.sourceFile ? 1 : 0)
- + (this.sourceDir ? 1 << 1 : 0)
+ (this.innerClasses ? 1 << 2 : 0)
+ (this.enclosingMethod ? 1 << 3 : 0)
+ (this.signature ? 1 << 4 : 0)
@@ -215,7 +202,6 @@
public boolean isEmpty() {
return !sourceFile
- && !sourceDir
&& !innerClasses
&& !enclosingMethod
&& !signature
@@ -238,9 +224,6 @@
if (sourceFile) {
attributes.add(SOURCE_FILE);
}
- if (sourceDir) {
- attributes.add(SOURCE_DIR);
- }
if (innerClasses) {
attributes.add(INNER_CLASSES);
}
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index bd3cdcf..9292f76 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -345,8 +345,6 @@
assert !proguardConfiguration.isObfuscating();
getProguardConfiguration().getKeepAttributes().sourceFile = true;
getProguardConfiguration().getKeepAttributes().sourceDebugExtension = true;
- getProguardConfiguration().getKeepAttributes().localVariableTable = true;
- getProguardConfiguration().getKeepAttributes().localVariableTypeTable = true;
}
void enableProtoShrinking() {
diff --git a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
index 31b2154..d2cd044 100644
--- a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
@@ -1388,10 +1388,10 @@
public void testRenameSourceFileAttribute() throws Exception {
for (String lineSeparator : lineSeparators) {
reset();
- Path proguardConfig = writeTextToTempFile(lineSeparator,
- ImmutableList.of(
- "-renamesourcefileattribute PG",
- "-keepattributes SourceFile,SourceDir"));
+ Path proguardConfig =
+ writeTextToTempFile(
+ lineSeparator,
+ ImmutableList.of("-renamesourcefileattribute PG", "-keepattributes SourceFile"));
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(proguardConfig);
@@ -1399,7 +1399,6 @@
ProguardConfiguration config = parser.getConfigRawForTesting();
assertEquals("PG", config.getRenameSourceFileAttribute());
assertTrue(config.getKeepAttributes().sourceFile);
- assertTrue(config.getKeepAttributes().sourceDir);
}
}
@@ -1418,7 +1417,6 @@
ProguardConfiguration config = parser.getConfigRawForTesting();
assertEquals("", config.getRenameSourceFileAttribute());
assertTrue(config.getKeepAttributes().sourceFile);
- assertFalse(config.getKeepAttributes().sourceDir);
}
}
@@ -1438,7 +1436,6 @@
ProguardConfiguration config = parser.getConfigRawForTesting();
assertEquals("PG", config.getRenameSourceFileAttribute());
assertTrue(config.getKeepAttributes().sourceFile);
- assertFalse(config.getKeepAttributes().sourceDir);
}
}
}
@@ -1459,7 +1456,6 @@
ProguardConfiguration config = parser.getConfigRawForTesting();
assertEquals("", config.getRenameSourceFileAttribute());
assertTrue(config.getKeepAttributes().sourceFile);
- assertFalse(config.getKeepAttributes().sourceDir);
}
}
}
diff --git a/src/test/java/com/android/tools/r8/shaking/attributes/KeepAttributesTest.java b/src/test/java/com/android/tools/r8/shaking/attributes/KeepAttributesTest.java
index 9eadede..bf46563 100644
--- a/src/test/java/com/android/tools/r8/shaking/attributes/KeepAttributesTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/attributes/KeepAttributesTest.java
@@ -81,12 +81,9 @@
@Test
public void keepLineNumberTableAndLocalVariableTable()
throws CompilationFailedException, IOException, ExecutionException {
- List<String> keepRules = ImmutableList.of(
- "-keepattributes "
- + ProguardKeepAttributes.LINE_NUMBER_TABLE
- + ", "
- + ProguardKeepAttributes.LOCAL_VARIABLE_TABLE
- );
+ List<String> keepRules =
+ ImmutableList.of(
+ "-keepattributes " + ProguardKeepAttributes.LINE_NUMBER_TABLE + ", LocalVariableTable");
MethodSubject mainMethod = compileRunAndGetMain(keepRules, CompilationMode.RELEASE);
assertEquals(doesNotHavePcSupport(), mainMethod.hasLineNumberTable());
// Locals are never included in release builds.
@@ -95,9 +92,7 @@
@Test
public void keepLocalVariableTable() throws Exception {
- List<String> keepRules = ImmutableList.of(
- "-keepattributes " + ProguardKeepAttributes.LOCAL_VARIABLE_TABLE
- );
+ List<String> keepRules = ImmutableList.of("-keepattributes LocalVariableTable");
// Compiling with a keep rule for locals but no line table no longer results in an error in R8.
compileRunAndGetMain(keepRules, CompilationMode.RELEASE);
}
diff --git a/src/test/testbase/java/com/android/tools/r8/TestShrinkerBuilder.java b/src/test/testbase/java/com/android/tools/r8/TestShrinkerBuilder.java
index 4b11d03..baf96b4 100644
--- a/src/test/testbase/java/com/android/tools/r8/TestShrinkerBuilder.java
+++ b/src/test/testbase/java/com/android/tools/r8/TestShrinkerBuilder.java
@@ -434,10 +434,6 @@
return addKeepAttributes(ProguardKeepAttributes.LINE_NUMBER_TABLE);
}
- public T addKeepAttributeLocalVariableTable() {
- return addKeepAttributes(ProguardKeepAttributes.LOCAL_VARIABLE_TABLE);
- }
-
public T addKeepAttributeSignature() {
return addKeepAttributes(ProguardKeepAttributes.SIGNATURE);
}