summaryrefslogtreecommitdiff
path: root/java/builder.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2017-09-29 17:58:17 -0700
committer Colin Cross <ccross@android.com> 2017-10-16 15:00:02 -0700
commit1369cdb28013ece5eecf51dc9facc822ea9222b3 (patch)
tree7f1c21ddd0440c663f2d665efd9bef915be7c801 /java/builder.go
parent070879e69eec3647424169767790993330222430 (diff)
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
Diffstat (limited to 'java/builder.go')
-rw-r--r--java/builder.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/java/builder.go b/java/builder.go
index 118f23979..8992f681a 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -126,6 +126,7 @@ type javaBuilderFlags struct {
dxFlags string
bootClasspath classpath
classpath classpath
+ systemModules classpath
desugarFlags string
aidlFlags string
javaVersion string
@@ -177,7 +178,16 @@ func transformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists an
}
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 @@ func transformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists an
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 @@ func TransformDesugar(ctx android.ModuleContext, classesJar android.Path,
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 @@ func (x *classpath) JavaBootClasspath(forceEmpty bool) string {
}
}
+// 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