Initial support for converting jars to java9 system modules
Adds a java_system_modules module type that (when
EXPERIMENTAL_USE_OPENJDK9 is set to true) converts a list of
java library modules and prebuilt jars into system modules,
and plumbs the system modules through to the javac command
line.
Also exports the location of the system modules to make
variables, as well as the name of the default system module.
Test: TestClasspath in java_test.go, runs automatically as part of the build
Bug: 63986449
Change-Id: I27bd5d2010092422a27b69c91568e49010e02f40
diff --git a/java/builder.go b/java/builder.go
index 118f239..8992f68 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -126,6 +126,7 @@
dxFlags string
bootClasspath classpath
classpath classpath
+ systemModules classpath
desugarFlags string
aidlFlags string
javaVersion string
@@ -177,7 +178,16 @@
}
deps = append(deps, srcFileLists...)
- deps = append(deps, flags.bootClasspath...)
+
+ var bootClasspath string
+ if flags.javaVersion == "1.9" {
+ deps = append(deps, flags.systemModules...)
+ bootClasspath = flags.systemModules.JavaSystemModules(ctx.Device())
+ } else {
+ deps = append(deps, flags.bootClasspath...)
+ bootClasspath = flags.bootClasspath.JavaBootClasspath(ctx.Device())
+ }
+
deps = append(deps, flags.classpath...)
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
@@ -188,7 +198,7 @@
Implicits: deps,
Args: map[string]string{
"javacFlags": javacFlags,
- "bootClasspath": flags.bootClasspath.JavaBootClasspath(ctx.Device()),
+ "bootClasspath": bootClasspath,
"classpath": flags.classpath.JavaClasspath(),
"outDir": android.PathForModuleOut(ctx, "classes"+suffix).String(),
"annoDir": android.PathForModuleOut(ctx, "anno"+suffix).String(),
@@ -259,7 +269,7 @@
dumpDir := android.PathForModuleOut(ctx, "desugar_dumped_classes")
javaFlags := ""
- if ctx.AConfig().Getenv("EXPERIMENTAL_USE_OPENJDK9") != "" {
+ if ctx.AConfig().UseOpenJDK9() {
javaFlags = "--add-opens java.base/java.lang.invoke=ALL-UNNAMED"
}
@@ -359,6 +369,21 @@
}
}
+// Returns a --system argument in the form javac expects with -source 1.9. If forceEmpty is true,
+// returns --system=none if the list is empty to ensure javac does not fall back to the default
+// system modules.
+func (x *classpath) JavaSystemModules(forceEmpty bool) string {
+ if len(*x) > 1 {
+ panic("more than one system module")
+ } else if len(*x) == 1 {
+ return "--system=" + strings.TrimSuffix((*x)[0].String(), "lib/modules")
+ } else if forceEmpty {
+ return "--system=none"
+ } else {
+ return ""
+ }
+}
+
func (x *classpath) DesugarBootClasspath() []string {
if x == nil || *x == nil {
return nil