Use command-line parsing in apiUsageSample
Extend build_r8lib.py so that it also runs the R8 command-line through
the API usage sample after linking with the minified r8lib.jar. This
ensures that we keep a large enough portion of the R8 API so that a user
could reimplement the R8 command-line.
Regenerate d8_api_usage_sample.jar and r8_api_usage_sample.jar by
running tools/gradle.py buildApiSampleJars.
Change-Id: I2342b395e07f2f9b6245ae746f47973948c39d57
diff --git a/tools/build_r8lib.py b/tools/build_r8lib.py
index e08c141..abaa619 100755
--- a/tools/build_r8lib.py
+++ b/tools/build_r8lib.py
@@ -40,7 +40,7 @@
def test_d8sample():
with utils.TempDir() as path:
- args = ['java', '-cp', '%s:%s' % (R8LIB_JAR, SAMPLE_JAR),
+ args = ['java', '-cp', '%s:%s' % (SAMPLE_JAR, R8LIB_JAR),
'com.android.tools.apiusagesample.D8ApiUsageSample',
'--output', path,
'--min-api', str(API_LEVEL),
@@ -52,12 +52,47 @@
subprocess.check_call(args)
+def test_r8command():
+ with utils.TempDir() as path:
+ # SAMPLE_JAR and R8LIB_JAR should not have any classes in common, since e.g.
+ # R8CommandParser should have been minified in R8LIB_JAR.
+ # Just in case R8CommandParser is also present in R8LIB_JAR, we put
+ # SAMPLE_JAR first on the classpath to use its version of R8CommandParser.
+ args = ['java', '-cp', '%s:%s' % (SAMPLE_JAR, R8LIB_JAR),
+ 'com.android.tools.r8.R8CommandParser',
+ '--output', path + "/output.zip",
+ '--min-api', str(API_LEVEL),
+ '--lib', ANDROID_JAR,
+ '--main-dex-list', '/dev/null',
+ os.path.join(utils.BUILD, 'test/examples/hello.jar')]
+ utils.PrintCmd(args)
+ subprocess.check_call(args)
+
+
+def test_r8cfcommand():
+ with utils.TempDir() as path:
+ # SAMPLE_JAR and R8LIB_JAR should not have any classes in common, since e.g.
+ # R8CommandParser should have been minified in R8LIB_JAR.
+ # Just in case R8CommandParser is also present in R8LIB_JAR, we put
+ # SAMPLE_JAR first on the classpath to use its version of R8CommandParser.
+ args = ['java', '-cp', '%s:%s' % (SAMPLE_JAR, R8LIB_JAR),
+ 'com.android.tools.r8.R8CommandParser',
+ '--classfile',
+ '--output', path + "/output.jar",
+ '--lib', utils.RT_JAR,
+ os.path.join(utils.BUILD, 'test/examples/hello.jar')]
+ utils.PrintCmd(args)
+ subprocess.check_call(args)
+
+
def main():
# Handle --help
parser.parse_args()
build_r8lib()
test_d8sample()
+ test_r8command()
+ test_r8cfcommand()
if __name__ == '__main__':