Skip to content

Commit f92fc63

Browse files
committed
Parse alwaysinline and identifiernamestring rules
1 parent f5f04cb commit f92fc63

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

base/src/main/java/proguard/ConfigurationConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public class ConfigurationConstants
116116
public static final String DONT_PROCESS_KOTLIN_METADATA = "-dontprocesskotlinmetadata";
117117
public static final String OPTIMIZE_AGGRESSIVELY = "-optimizeaggressively";
118118

119+
public static final String ALWAYS_INLINE = "-alwaysinline";
120+
public static final String IDENTIFIER_NAME_STRING = "-identifiernamestring";
121+
119122
public static final String ANY_FILE_KEYWORD = "**";
120123

121124
public static final String ANY_ATTRIBUTE_KEYWORD = "*";

base/src/main/java/proguard/ConfigurationParser.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ else if (ConfigurationConstants.REPACKAGE_CLASSES_OPTION
230230
else if (ConfigurationConstants.DUMP_OPTION .startsWith(nextWord)) configuration.dump = parseOptionalFile();
231231
else if (ConfigurationConstants.ADD_CONFIGURATION_DEBUGGING_OPTION .startsWith(nextWord)) configuration.addConfigurationDebugging = parseNoArgument(true);
232232
else if (ConfigurationConstants.OPTIMIZE_AGGRESSIVELY .startsWith(nextWord)) configuration.optimizeConservatively = parseNoArgument(false);
233+
else if (ConfigurationConstants.ALWAYS_INLINE .startsWith(nextWord)) parseUnsupportedR8Rules(ConfigurationConstants.ALWAYS_INLINE, true);
234+
else if (ConfigurationConstants.IDENTIFIER_NAME_STRING .startsWith(nextWord)) parseUnsupportedR8Rules(ConfigurationConstants.IDENTIFIER_NAME_STRING, true);
233235
else
234236
{
235237
throw new ParseException("Unknown option " + reader.locationDescription());
@@ -2027,6 +2029,21 @@ private void checkMethodAccessFlags(int requiredSetMemberAccessFlags,
20272029
}
20282030

20292031

2032+
private void parseUnsupportedR8Rules(String option, boolean parseClassSpecification) throws IOException, ParseException
2033+
{
2034+
readNextWord();
2035+
2036+
if (parseClassSpecification)
2037+
{
2038+
parseClassSpecificationArguments();
2039+
}
2040+
2041+
System.out.println("Warning: The R8 option " + option + " is currently not supported by ProGuard.\n" +
2042+
"This option will have no effect on the optimized artifact.");
2043+
2044+
}
2045+
2046+
20302047
/**
20312048
* A main method for testing configuration parsing.
20322049
*/

base/src/test/kotlin/proguard/ConfigurationParserTest.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import io.kotest.assertions.throwables.shouldThrow
1111
import io.kotest.core.spec.style.FreeSpec
1212
import io.kotest.matchers.shouldBe
1313
import io.kotest.matchers.shouldNotBe
14+
import io.kotest.matchers.string.shouldContain
1415
import proguard.classfile.AccessConstants.PUBLIC
1516
import testutils.asConfiguration
17+
import java.io.ByteArrayOutputStream
18+
import java.io.PrintStream
1619

1720
/**
1821
* Some simple testcases to catch special cases when parsing the Configuration.
@@ -93,6 +96,86 @@ class ConfigurationParserTest : FreeSpec({
9396
}
9497
}
9598

99+
"Testing -alwaysinline parsing" - {
100+
"Given an empty configuration" - {
101+
val savedPrintStream = System.out
102+
val customOutputStream = ByteArrayOutputStream()
103+
System.setOut(PrintStream(customOutputStream))
104+
105+
parseConfiguration("")
106+
107+
"The option does not print anything" {
108+
customOutputStream.toString() shouldContain ""
109+
System.setOut(savedPrintStream)
110+
}
111+
}
112+
113+
"Given a configuration with -alwaysinline" - {
114+
val savedPrintStream = System.out
115+
val customOutputStream = ByteArrayOutputStream()
116+
System.setOut(PrintStream(customOutputStream))
117+
118+
parseConfiguration(
119+
"""-alwaysinline class * {
120+
@org.chromium.build.annotations.AlwaysInline *;
121+
}
122+
"""
123+
)
124+
125+
"The option prints out a warning" {
126+
customOutputStream.toString() shouldContain "Warning: The R8 option -alwaysinline is currently not supported by ProGuard.\n" +
127+
"This option will have no effect on the optimized artifact."
128+
System.setOut(savedPrintStream)
129+
}
130+
}
131+
132+
"Given a configuration with -alwaysinline with no class specification" - {
133+
"The parsing should throw an exception" {
134+
shouldThrow<ParseException> { parseConfiguration("-alwaysinline") }
135+
}
136+
}
137+
}
138+
139+
"Testing -identifiernamestring parsing" - {
140+
"Given an empty configuration" - {
141+
val savedPrintStream = System.out
142+
val customOutputStream = ByteArrayOutputStream()
143+
System.setOut(PrintStream(customOutputStream))
144+
145+
parseConfiguration("")
146+
147+
"The option does not print anything" {
148+
customOutputStream.toString() shouldContain ""
149+
System.setOut(savedPrintStream)
150+
}
151+
}
152+
153+
"Given a configuration with -identifiernamestring" - {
154+
val savedPrintStream = System.out
155+
val customOutputStream = ByteArrayOutputStream()
156+
System.setOut(PrintStream(customOutputStream))
157+
158+
parseConfiguration(
159+
"""-identifiernamestring class * {
160+
@org.chromium.build.annotations.IdentifierNameString *;
161+
}
162+
"""
163+
)
164+
165+
"The option prints out a warning" {
166+
customOutputStream.toString() shouldContain "Warning: The R8 option -identifiernamestring is currently not supported by ProGuard.\n" +
167+
"This option will have no effect on the optimized artifact."
168+
System.setOut(savedPrintStream)
169+
}
170+
}
171+
172+
"Given a configuration with -identifiernamestring with no class specification" - {
173+
"The parsing should throw an exception" {
174+
shouldThrow<ParseException> { parseConfiguration("-identifiernamestring") }
175+
}
176+
}
177+
}
178+
96179
"Wildcard type tests" - {
97180
class TestConfig(
98181
val configOption: String,

base/src/test/kotlin/proguard/ConfigurationWriterTest.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,44 @@ class ConfigurationWriterTest : FreeSpec({
8686
}
8787
}
8888
}
89+
90+
"Given a -alwaysinline rule" - {
91+
val rules = "-alwaysinline class ** {*;}"
92+
93+
"When the rule is parsed and printed out again" - {
94+
val out = printConfiguration(rules)
95+
96+
"Then the rule should be not be present in the output" {
97+
out shouldBe ""
98+
}
99+
}
100+
101+
"When the rule does not exist it shouldn't be printed out" - {
102+
val out = printConfiguration("")
103+
104+
"Then the rule should not be present in the output" {
105+
out shouldBe ""
106+
}
107+
}
108+
}
109+
110+
"Given a -identifiernamestring rule" - {
111+
val rules = "-identifiernamestring class ** {*;}"
112+
113+
"When the rule is parsed and printed out again" - {
114+
val out = printConfiguration(rules)
115+
116+
"Then the rule should be not be present in the output" {
117+
out shouldBe ""
118+
}
119+
}
120+
121+
"When the rule does not exist it shouldn't be printed out" - {
122+
val out = printConfiguration("")
123+
124+
"Then the rule should not be present in the output" {
125+
out shouldBe ""
126+
}
127+
}
128+
}
89129
})

0 commit comments

Comments
 (0)