Split java 8 and 9 classpaths in TestClasspath

In preparation for adding the system modules jars to the classpath
for java 9, split the expected java 8 and java 9 classpaths into
separate fields.  Also replace the system: "bootclasspath" special
case with a bool that specifies that the module will always be
built using a java 8 style command line.

Test: TestClasspath
Change-Id: I661ec50d77a039c435c03bc8e6443cc5a57c206e
This commit is contained in:
Colin Cross 2019-10-25 15:22:50 -07:00
parent 5bce0931c1
commit 617b1451b4
1 changed files with 133 additions and 114 deletions

View File

@ -28,55 +28,65 @@ import (
func TestClasspath(t *testing.T) { func TestClasspath(t *testing.T) {
var classpathTestcases = []struct { var classpathTestcases = []struct {
name string name string
unbundled bool unbundled bool
pdk bool pdk bool
moduleType string moduleType string
host android.OsClass host android.OsClass
properties string properties string
bootclasspath []string
system string // for java 8
classpath []string bootclasspath []string
aidl string java8classpath []string
// for java 9
system string
java9classpath []string
forces8 bool // if set, javac will always be called with java 8 arguments
aidl string
}{ }{
{ {
name: "default", name: "default",
bootclasspath: config.DefaultBootclasspathLibraries, bootclasspath: config.DefaultBootclasspathLibraries,
system: config.DefaultSystemModules, system: config.DefaultSystemModules,
classpath: config.DefaultLibraries, java8classpath: config.DefaultLibraries,
aidl: "-Iframework/aidl", java9classpath: config.DefaultLibraries,
aidl: "-Iframework/aidl",
}, },
{ {
name: `sdk_version:"core_platform"`, name: `sdk_version:"core_platform"`,
properties: `sdk_version:"core_platform"`, properties: `sdk_version:"core_platform"`,
bootclasspath: config.DefaultBootclasspathLibraries, bootclasspath: config.DefaultBootclasspathLibraries,
system: config.DefaultSystemModules, system: config.DefaultSystemModules,
classpath: []string{}, java8classpath: []string{},
aidl: "", aidl: "",
}, },
{ {
name: "blank sdk version", name: "blank sdk version",
properties: `sdk_version: "",`, properties: `sdk_version: "",`,
bootclasspath: config.DefaultBootclasspathLibraries, bootclasspath: config.DefaultBootclasspathLibraries,
system: config.DefaultSystemModules, system: config.DefaultSystemModules,
classpath: config.DefaultLibraries, java8classpath: config.DefaultLibraries,
aidl: "-Iframework/aidl", java9classpath: config.DefaultLibraries,
aidl: "-Iframework/aidl",
}, },
{ {
name: "sdk v25", name: "sdk v25",
properties: `sdk_version: "25",`, properties: `sdk_version: "25",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
{ {
name: "current", name: "current",
properties: `sdk_version: "current",`, properties: `sdk_version: "current",`,
bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"}, bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
aidl: "-p" + buildDir + "/framework.aidl", aidl: "-p" + buildDir + "/framework.aidl",
}, },
{ {
@ -84,24 +94,24 @@ func TestClasspath(t *testing.T) {
name: "system_current", name: "system_current",
properties: `sdk_version: "system_current",`, properties: `sdk_version: "system_current",`,
bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"}, bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
aidl: "-p" + buildDir + "/framework.aidl", aidl: "-p" + buildDir + "/framework.aidl",
}, },
{ {
name: "system_25", name: "system_25",
properties: `sdk_version: "system_25",`, properties: `sdk_version: "system_25",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
{ {
name: "test_current", name: "test_current",
properties: `sdk_version: "test_current",`, properties: `sdk_version: "test_current",`,
bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"}, bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
aidl: "-p" + buildDir + "/framework.aidl", aidl: "-p" + buildDir + "/framework.aidl",
}, },
{ {
@ -109,93 +119,93 @@ func TestClasspath(t *testing.T) {
name: "core_current", name: "core_current",
properties: `sdk_version: "core_current",`, properties: `sdk_version: "core_current",`,
bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
}, },
{ {
name: "nostdlib", name: "nostdlib",
properties: `sdk_version: "none", system_modules: "none"`, properties: `sdk_version: "none", system_modules: "none"`,
system: "none", system: "none",
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
classpath: []string{}, java8classpath: []string{},
}, },
{ {
name: "nostdlib system_modules", name: "nostdlib system_modules",
properties: `sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules"`, properties: `sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules"`,
system: "core-platform-api-stubs-system-modules", system: "core-platform-api-stubs-system-modules",
bootclasspath: []string{"core-platform-api-stubs-system-modules-lib"}, bootclasspath: []string{"core-platform-api-stubs-system-modules-lib"},
classpath: []string{}, java8classpath: []string{},
}, },
{ {
name: "host default", name: "host default",
moduleType: "java_library_host", moduleType: "java_library_host",
properties: ``, properties: ``,
host: android.Host, host: android.Host,
bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
classpath: []string{}, java8classpath: []string{},
}, },
{ {
name: "host supported default", name: "host supported default",
host: android.Host, host: android.Host,
properties: `host_supported: true,`, properties: `host_supported: true,`,
classpath: []string{}, java8classpath: []string{},
bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
}, },
{ {
name: "host supported nostdlib", name: "host supported nostdlib",
host: android.Host, host: android.Host,
properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, properties: `host_supported: true, sdk_version: "none", system_modules: "none"`,
classpath: []string{}, java8classpath: []string{},
}, },
{ {
name: "unbundled sdk v25", name: "unbundled sdk v25",
unbundled: true, unbundled: true,
properties: `sdk_version: "25",`, properties: `sdk_version: "25",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
{ {
name: "unbundled current", name: "unbundled current",
unbundled: true, unbundled: true,
properties: `sdk_version: "current",`, properties: `sdk_version: "current",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/current/public/framework.aidl", aidl: "-pprebuilts/sdk/current/public/framework.aidl",
}, },
{ {
name: "pdk default", name: "pdk default",
pdk: true, pdk: true,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
{ {
name: "pdk current", name: "pdk current",
pdk: true, pdk: true,
properties: `sdk_version: "current",`, properties: `sdk_version: "current",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
{ {
name: "pdk 25", name: "pdk 25",
pdk: true, pdk: true,
properties: `sdk_version: "25",`, properties: `sdk_version: "25",`,
bootclasspath: []string{`""`}, bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath forces8: true,
classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, java8classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
aidl: "-pprebuilts/sdk/25/public/framework.aidl", aidl: "-pprebuilts/sdk/25/public/framework.aidl",
}, },
} }
@ -235,7 +245,8 @@ func TestClasspath(t *testing.T) {
} }
bootclasspath := convertModulesToPaths(testcase.bootclasspath) bootclasspath := convertModulesToPaths(testcase.bootclasspath)
classpath := convertModulesToPaths(testcase.classpath) java8classpath := convertModulesToPaths(testcase.java8classpath)
java9classpath := convertModulesToPaths(testcase.java9classpath)
bc := "" bc := ""
var bcDeps []string var bcDeps []string
@ -246,18 +257,20 @@ func TestClasspath(t *testing.T) {
} }
} }
c := "" j8c := ""
if len(classpath) > 0 { if len(java8classpath) > 0 {
c = "-classpath " + strings.Join(classpath, ":") j8c = "-classpath " + strings.Join(java8classpath, ":")
}
j9c := ""
if len(java9classpath) > 0 {
j9c = "-classpath " + strings.Join(java9classpath, ":")
} }
system := "" system := ""
var systemDeps []string var systemDeps []string
if testcase.system == "none" { if testcase.system == "none" {
system = "--system=none" system = "--system=none"
} else if testcase.system == "bootclasspath" {
system = bc
systemDeps = bcDeps
} else if testcase.system != "" { } else if testcase.system != "" {
system = "--system=" + filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system") system = "--system=" + filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system")
// The module-relative parts of these paths are hardcoded in system_modules.go: // The module-relative parts of these paths are hardcoded in system_modules.go:
@ -280,7 +293,7 @@ func TestClasspath(t *testing.T) {
got := javac.Args["bootClasspath"] got := javac.Args["bootClasspath"]
expected := "" expected := ""
if isJava8 { if isJava8 || testcase.forces8 {
expected = bc expected = bc
deps = append(deps, bcDeps...) deps = append(deps, bcDeps...)
} else { } else {
@ -291,11 +304,17 @@ func TestClasspath(t *testing.T) {
t.Errorf("bootclasspath expected %q != got %q", expected, got) t.Errorf("bootclasspath expected %q != got %q", expected, got)
} }
got = javac.Args["classpath"] if isJava8 || testcase.forces8 {
if got != c { expected = j8c
t.Errorf("classpath expected %q != got %q", c, got) deps = append(deps, java8classpath...)
} else {
expected = j9c
deps = append(deps, java9classpath...)
}
got = javac.Args["classpath"]
if got != expected {
t.Errorf("classpath expected %q != got %q", expected, got)
} }
deps = append(deps, classpath...)
if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings())