Support Java Lang level 9 for droiddoc in Soong.
Test: m -j docs / m -j metalava-api-stubs-docs Bug: b/70351683 Change-Id: I7220d04f508f6bb5ffd281cf31bc8c0069c219e5
This commit is contained in:
@@ -30,7 +30,7 @@ var (
|
|||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
|
Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
|
||||||
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
||||||
`${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
|
`${config.JavadocCmd} -source $javaVersion -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
|
||||||
`$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
|
`$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
|
||||||
`-d $outDir -quiet && ` +
|
`-d $outDir -quiet && ` +
|
||||||
`${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
|
`${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
|
||||||
@@ -44,7 +44,7 @@ var (
|
|||||||
RspfileContent: "$in",
|
RspfileContent: "$in",
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
|
"outDir", "srcJarDir", "stubsDir", "javaVersion", "srcJars", "opts",
|
||||||
"bootclasspathArgs", "classpathArgs", "sourcepath", "docZip")
|
"bootclasspathArgs", "classpathArgs", "sourcepath", "docZip")
|
||||||
|
|
||||||
apiCheck = pctx.AndroidStaticRule("apiCheck",
|
apiCheck = pctx.AndroidStaticRule("apiCheck",
|
||||||
@@ -69,7 +69,7 @@ var (
|
|||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
|
Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
|
||||||
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
||||||
`${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source 1.8 @$out.rsp @$srcJarDir/list ` +
|
`${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
|
||||||
`$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
|
`$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
|
||||||
`--stubs $stubsDir $opts && ` +
|
`--stubs $stubsDir $opts && ` +
|
||||||
`${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
|
`${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
|
||||||
@@ -85,7 +85,8 @@ var (
|
|||||||
RspfileContent: "$in",
|
RspfileContent: "$in",
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"outDir", "srcJarDir", "stubsDir", "srcJars", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "docZip")
|
"outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
|
||||||
|
"classpathArgs", "sourcepath", "opts", "docZip")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -141,6 +142,9 @@ type JavadocProperties struct {
|
|||||||
// Directories rooted at the Android.bp file to pass to aidl tool
|
// Directories rooted at the Android.bp file to pass to aidl tool
|
||||||
Local_include_dirs []string
|
Local_include_dirs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If not blank, set the java version passed to javadoc as -source
|
||||||
|
Java_version *string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiToCheck struct {
|
type ApiToCheck struct {
|
||||||
@@ -329,10 +333,16 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
|
|||||||
sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
|
||||||
if sdkDep.useDefaultLibs {
|
if sdkDep.useDefaultLibs {
|
||||||
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
||||||
|
if ctx.Config().TargetOpenJDK9() {
|
||||||
|
ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
|
||||||
|
}
|
||||||
if !Bool(j.properties.No_framework_libs) {
|
if !Bool(j.properties.No_framework_libs) {
|
||||||
ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
|
ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
|
||||||
}
|
}
|
||||||
} else if sdkDep.useModule {
|
} else if sdkDep.useModule {
|
||||||
|
if ctx.Config().TargetOpenJDK9() {
|
||||||
|
ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
|
||||||
|
}
|
||||||
ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,6 +480,15 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
default:
|
default:
|
||||||
ctx.ModuleErrorf("depends on non-java module %q", otherName)
|
ctx.ModuleErrorf("depends on non-java module %q", otherName)
|
||||||
}
|
}
|
||||||
|
case systemModulesTag:
|
||||||
|
if deps.systemModules != nil {
|
||||||
|
panic("Found two system module dependencies")
|
||||||
|
}
|
||||||
|
sm := module.(*SystemModules)
|
||||||
|
if sm.outputFile == nil {
|
||||||
|
panic("Missing directory for system module dependency")
|
||||||
|
}
|
||||||
|
deps.systemModules = sm.outputFile
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
|
// do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
|
||||||
@@ -508,13 +527,16 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
implicits = append(implicits, deps.classpath...)
|
implicits = append(implicits, deps.classpath...)
|
||||||
|
|
||||||
var bootClasspathArgs, classpathArgs string
|
var bootClasspathArgs, classpathArgs string
|
||||||
if ctx.Config().UseOpenJDK9() {
|
|
||||||
|
javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), String(j.properties.Sdk_version))
|
||||||
|
if javaVersion == "1.9" || ctx.Config().UseOpenJDK9() {
|
||||||
if len(deps.bootClasspath) > 0 {
|
if len(deps.bootClasspath) > 0 {
|
||||||
// For OpenJDK 9 we use --patch-module to define the core libraries code.
|
var systemModules classpath
|
||||||
// TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
|
if deps.systemModules != nil {
|
||||||
// modules. Here we treat all code in core libraries as being in java.base
|
systemModules = append(systemModules, deps.systemModules)
|
||||||
// to work around the OpenJDK 9 module system. http://b/62049770
|
}
|
||||||
bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
|
bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
|
||||||
|
bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(deps.bootClasspath.Strings()) > 0 {
|
if len(deps.bootClasspath.Strings()) > 0 {
|
||||||
@@ -541,6 +563,7 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
"outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
|
"outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
|
||||||
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
||||||
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
||||||
|
"javaVersion": javaVersion,
|
||||||
"srcJars": strings.Join(j.srcJars.Strings(), " "),
|
"srcJars": strings.Join(j.srcJars.Strings(), " "),
|
||||||
"opts": opts,
|
"opts": opts,
|
||||||
"bootclasspathArgs": bootClasspathArgs,
|
"bootclasspathArgs": bootClasspathArgs,
|
||||||
@@ -612,7 +635,23 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
implicits = append(implicits, deps.bootClasspath...)
|
implicits = append(implicits, deps.bootClasspath...)
|
||||||
implicits = append(implicits, deps.classpath...)
|
implicits = append(implicits, deps.classpath...)
|
||||||
|
|
||||||
bootClasspathArgs := deps.bootClasspath.FormJavaClassPath("-bootclasspath")
|
var bootClasspathArgs string
|
||||||
|
javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), String(d.Javadoc.properties.Sdk_version))
|
||||||
|
if javaVersion == "1.9" {
|
||||||
|
if len(deps.bootClasspath) > 0 {
|
||||||
|
var systemModules classpath
|
||||||
|
if deps.systemModules != nil {
|
||||||
|
systemModules = append(systemModules, deps.systemModules)
|
||||||
|
}
|
||||||
|
bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
|
||||||
|
bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(deps.bootClasspath.Strings()) > 0 {
|
||||||
|
// For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
|
||||||
|
bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
|
||||||
|
}
|
||||||
|
}
|
||||||
classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
|
classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
|
||||||
|
|
||||||
argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
|
argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
|
||||||
@@ -801,7 +840,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
date = `date -d`
|
date = `date -d`
|
||||||
}
|
}
|
||||||
|
|
||||||
doclavaOpts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
|
doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
|
||||||
"-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
|
"-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
|
||||||
"-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
|
"-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
|
||||||
"-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
|
"-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
|
||||||
@@ -829,6 +868,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
||||||
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
||||||
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
|
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
|
||||||
|
"javaVersion": javaVersion,
|
||||||
"opts": opts,
|
"opts": opts,
|
||||||
"bootclasspathArgs": bootClasspathArgs,
|
"bootclasspathArgs": bootClasspathArgs,
|
||||||
"classpathArgs": classpathArgs,
|
"classpathArgs": classpathArgs,
|
||||||
@@ -844,6 +884,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
"srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
|
||||||
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
"stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
|
||||||
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
|
"srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
|
||||||
|
"javaVersion": javaVersion,
|
||||||
"bootclasspathArgs": bootClasspathArgs,
|
"bootclasspathArgs": bootClasspathArgs,
|
||||||
"classpathArgs": classpathArgs,
|
"classpathArgs": classpathArgs,
|
||||||
"sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
|
"sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
|
||||||
|
34
java/java.go
34
java/java.go
@@ -788,6 +788,25 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getJavaVersion(ctx android.ModuleContext, javaVersion, sdkVersion string) string {
|
||||||
|
var ret string
|
||||||
|
sdk := sdkStringToNumber(ctx, sdkVersion)
|
||||||
|
if javaVersion != "" {
|
||||||
|
ret = javaVersion
|
||||||
|
} else if ctx.Device() && sdk <= 23 {
|
||||||
|
ret = "1.7"
|
||||||
|
} else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
|
||||||
|
ret = "1.8"
|
||||||
|
} else if ctx.Device() && sdkVersion != "" && sdk == android.FutureApiLevel {
|
||||||
|
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
|
||||||
|
ret = "1.8"
|
||||||
|
} else {
|
||||||
|
ret = "1.9"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
|
func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
|
||||||
|
|
||||||
var flags javaBuilderFlags
|
var flags javaBuilderFlags
|
||||||
@@ -813,19 +832,8 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
|
|||||||
}
|
}
|
||||||
|
|
||||||
// javaVersion flag.
|
// javaVersion flag.
|
||||||
sdk := sdkStringToNumber(ctx, String(j.deviceProperties.Sdk_version))
|
flags.javaVersion = getJavaVersion(ctx,
|
||||||
if j.properties.Java_version != nil {
|
String(j.properties.Java_version), String(j.deviceProperties.Sdk_version))
|
||||||
flags.javaVersion = *j.properties.Java_version
|
|
||||||
} else if ctx.Device() && sdk <= 23 {
|
|
||||||
flags.javaVersion = "1.7"
|
|
||||||
} else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
|
|
||||||
flags.javaVersion = "1.8"
|
|
||||||
} else if ctx.Device() && String(j.deviceProperties.Sdk_version) != "" && sdk == android.FutureApiLevel {
|
|
||||||
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
|
|
||||||
flags.javaVersion = "1.8"
|
|
||||||
} else {
|
|
||||||
flags.javaVersion = "1.9"
|
|
||||||
}
|
|
||||||
|
|
||||||
// classpath
|
// classpath
|
||||||
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
|
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
|
||||||
|
Reference in New Issue
Block a user