Call external script to create r8lib.
Change-Id: I2eb39404246da88abd86ae6615648e8606922d1b
diff --git a/build.gradle b/build.gradle
index 0eace9e..7f93d4a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -988,14 +988,19 @@
return baseD8CommandLine(allArgs)
}
-def r8LibCreateTask(name, pgConfs = [], r8Task, output, args = ["--release"], libs = []) {
+def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = []) {
return tasks.create("r8Lib${name}", Exec) {
- inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs, libs])
+ inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
outputs.file output
dependsOn downloadOpenJDKrt
dependsOn r8WithRelocatedDeps
dependsOn r8Task
- commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConfs, args, libs)
+ commandLine ([
+ "tools/create_r8lib.py",
+ "--r8jar", r8Task.outputs.files[0],
+ "--output", output]
+ + (pgConfs.collectMany { ["--pg-conf", it] })
+ + (libs.collectMany { ["--lib", it] }))
workingDir = projectDir
}
}
@@ -1090,11 +1095,10 @@
task R8LibNoDeps {
dependsOn r8LibCreateTask(
- "NoDeps",
+ "MainNoDeps",
["src/main/keep.txt"],
r8NoManifestWithoutDeps,
r8LibExludeDepsPath,
- "--release",
repackageDeps.outputs.files
).dependsOn(repackageDeps)
inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
diff --git a/tools/create_r8lib.py b/tools/create_r8lib.py
new file mode 100755
index 0000000..21dd48c
--- /dev/null
+++ b/tools/create_r8lib.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+import argparse
+import subprocess
+import sys
+
+import jdk
+
+
+def parse_options():
+ parser = argparse.ArgumentParser(description='Tag R8 Versions')
+ parser.add_argument(
+ '--r8jar',
+ required=True,
+ help='The R8 jar to compile')
+ parser.add_argument(
+ '--output',
+ required=True,
+ help='The output path for the r8lib')
+ parser.add_argument(
+ '--pg-conf',
+ action='append',
+ help='Keep configuration')
+ parser.add_argument(
+ '--lib',
+ action='append',
+ help='Additional libraries (JDK 1.8 rt.jar already included)')
+ return parser.parse_args()
+
+def main():
+ args = parse_options()
+ # TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
+ cmd = [jdk.GetJavaExecutable(), '-Xmx8g', '-ea']
+ cmd.extend(['-cp', 'build/libs/r8_with_deps.jar', 'com.android.tools.r8.R8'])
+ cmd.append(args.r8jar)
+ cmd.append('--classfile')
+ cmd.extend(['--output', args.output])
+ cmd.extend(['--pg-map-output', args.output + '.map'])
+ cmd.extend(['--lib', 'third_party/openjdk/openjdk-rt-1.8/rt.jar'])
+ if args.pg_conf:
+ for pgconf in args.pg_conf:
+ cmd.extend(['--pg-conf', pgconf])
+ if args.lib:
+ for lib in args.lib:
+ cmd.extend(['--lib', lib])
+ print(' '.join(cmd))
+ subprocess.check_call(cmd)
+
+if __name__ == '__main__':
+ sys.exit(main())