Pass OpenJDK 8's bootclasspath for host tools targeting <= 1.8. am: 7fdd2b788c

am: 193524e978

Change-Id: I447bd321531df03d0ce48633890d7092fa01a393
This commit is contained in:
Colin Cross 2018-01-03 05:16:06 +00:00 committed by android-build-merger
commit 4ead13ea00
2 changed files with 43 additions and 9 deletions

View file

@ -597,6 +597,29 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
// classpath // classpath
flags.bootClasspath.AddPaths(deps.bootClasspath) flags.bootClasspath.AddPaths(deps.bootClasspath)
flags.classpath.AddPaths(deps.classpath) flags.classpath.AddPaths(deps.classpath)
if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
!Bool(j.properties.No_standard_libs) &&
inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
// Give host-side tools a version of OpenJDK's standard libraries
// close to what they're targeting. As of Dec 2017, AOSP is only
// bundling OpenJDK 8 and 9, so nothing < 8 is available.
//
// When building with OpenJDK 8, the following should have no
// effect since those jars would be available by default.
//
// When building with OpenJDK 9 but targeting a version < 1.8,
// putting them on the bootclasspath means that:
// a) code can't (accidentally) refer to OpenJDK 9 specific APIs
// b) references to existing APIs are not reinterpreted in an
// OpenJDK 9-specific way, eg. calls to subclasses of
// java.nio.Buffer as in http://b/70862583
java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
flags.bootClasspath = append(flags.bootClasspath,
android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
}
// systemModules // systemModules
if deps.systemModules != nil { if deps.systemModules != nil {
flags.systemModules = append(flags.systemModules, deps.systemModules) flags.systemModules = append(flags.systemModules, deps.systemModules)

View file

@ -53,6 +53,12 @@ func TestMain(m *testing.M) {
} }
func testConfig(env map[string]string) android.Config { func testConfig(env map[string]string) android.Config {
if env == nil {
env = make(map[string]string)
}
if env["ANDROID_JAVA8_HOME"] == "" {
env["ANDROID_JAVA8_HOME"] = "jdk8"
}
return android.TestArchConfig(buildDir, env) return android.TestArchConfig(buildDir, env)
} }
@ -150,6 +156,9 @@ func testContext(config android.Config, bp string,
"build/target/product/security/testkey": nil, "build/target/product/security/testkey": nil,
"build/soong/scripts/jar-wrapper.sh": nil, "build/soong/scripts/jar-wrapper.sh": nil,
"jdk8/jre/lib/jce.jar": nil,
"jdk8/jre/lib/rt.jar": nil,
} }
for k, v := range fs { for k, v := range fs {
@ -364,11 +373,12 @@ var classpathTestcases = []struct {
}, },
{ {
name: "host default", name: "host default",
moduleType: "java_library_host", moduleType: "java_library_host",
properties: ``, properties: ``,
host: android.Host, host: android.Host,
classpath: []string{}, bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
classpath: []string{},
}, },
{ {
name: "host nostdlib", name: "host nostdlib",
@ -379,10 +389,11 @@ var classpathTestcases = []struct {
}, },
{ {
name: "host supported default", name: "host supported default",
host: android.Host, host: android.Host,
properties: `host_supported: true,`, properties: `host_supported: true,`,
classpath: []string{}, classpath: []string{},
bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
}, },
{ {
name: "host supported nostdlib", name: "host supported nostdlib",