Merge "Refactor and strengthen sdk_test.go."
am: e195591829
Change-Id: I2c11b96b41f685e1159e11ec1ac10c4558269659
This commit is contained in:
commit
8f344a659c
|
@ -1073,6 +1073,40 @@ func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName str
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPatchModule(t *testing.T) {
|
func TestPatchModule(t *testing.T) {
|
||||||
|
t.Run("Java language level 8", func(t *testing.T) {
|
||||||
|
// Test with legacy javac -source 1.8 -target 1.8
|
||||||
|
bp := `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
java_version: "1.8",
|
||||||
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "bar",
|
||||||
|
srcs: ["b.java"],
|
||||||
|
sdk_version: "none",
|
||||||
|
system_modules: "none",
|
||||||
|
patch_module: "java.base",
|
||||||
|
java_version: "1.8",
|
||||||
|
}
|
||||||
|
|
||||||
|
java_library {
|
||||||
|
name: "baz",
|
||||||
|
srcs: ["c.java"],
|
||||||
|
patch_module: "java.base",
|
||||||
|
java_version: "1.8",
|
||||||
|
}
|
||||||
|
`
|
||||||
|
ctx, _ := testJava(t, bp)
|
||||||
|
|
||||||
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
||||||
|
checkPatchModuleFlag(t, ctx, "bar", "")
|
||||||
|
checkPatchModuleFlag(t, ctx, "baz", "")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Java language level 9", func(t *testing.T) {
|
||||||
|
// Test with default javac -source 9 -target 9
|
||||||
bp := `
|
bp := `
|
||||||
java_library {
|
java_library {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
@ -1093,20 +1127,6 @@ func TestPatchModule(t *testing.T) {
|
||||||
patch_module: "java.base",
|
patch_module: "java.base",
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
t.Run("Java language level 8", func(t *testing.T) {
|
|
||||||
// Test with legacy javac -source 1.8 -target 1.8
|
|
||||||
config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
|
|
||||||
ctx := testContext(bp, nil)
|
|
||||||
run(t, ctx, config)
|
|
||||||
|
|
||||||
checkPatchModuleFlag(t, ctx, "foo", "")
|
|
||||||
checkPatchModuleFlag(t, ctx, "bar", "")
|
|
||||||
checkPatchModuleFlag(t, ctx, "baz", "")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Java language level 9", func(t *testing.T) {
|
|
||||||
// Test with default javac -source 9 -target 9
|
|
||||||
ctx, _ := testJava(t, bp)
|
ctx, _ := testJava(t, bp)
|
||||||
|
|
||||||
checkPatchModuleFlag(t, ctx, "foo", "")
|
checkPatchModuleFlag(t, ctx, "foo", "")
|
||||||
|
|
|
@ -206,7 +206,7 @@ func TestClasspath(t *testing.T) {
|
||||||
moduleType = testcase.moduleType
|
moduleType = testcase.moduleType
|
||||||
}
|
}
|
||||||
|
|
||||||
bp := moduleType + ` {
|
props := `
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
target: {
|
target: {
|
||||||
|
@ -214,6 +214,10 @@ func TestClasspath(t *testing.T) {
|
||||||
srcs: ["bar-doc/IFoo.aidl"],
|
srcs: ["bar-doc/IFoo.aidl"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
`
|
||||||
|
bp := moduleType + " {" + props + testcase.properties + `
|
||||||
|
}`
|
||||||
|
bpJava8 := moduleType + " {" + props + `java_version: "1.8",
|
||||||
` + testcase.properties + `
|
` + testcase.properties + `
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
@ -233,45 +237,64 @@ func TestClasspath(t *testing.T) {
|
||||||
bootclasspath := convertModulesToPaths(testcase.bootclasspath)
|
bootclasspath := convertModulesToPaths(testcase.bootclasspath)
|
||||||
classpath := convertModulesToPaths(testcase.classpath)
|
classpath := convertModulesToPaths(testcase.classpath)
|
||||||
|
|
||||||
bc := strings.Join(bootclasspath, ":")
|
bc := ""
|
||||||
if bc != "" {
|
var bcDeps []string
|
||||||
bc = "-bootclasspath " + bc
|
if len(bootclasspath) > 0 {
|
||||||
|
bc = "-bootclasspath " + strings.Join(bootclasspath, ":")
|
||||||
|
if bootclasspath[0] != `""` {
|
||||||
|
bcDeps = bootclasspath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c := strings.Join(classpath, ":")
|
c := ""
|
||||||
if c != "" {
|
if len(classpath) > 0 {
|
||||||
c = "-classpath " + c
|
c = "-classpath " + strings.Join(classpath, ":")
|
||||||
}
|
}
|
||||||
|
|
||||||
system := ""
|
system := ""
|
||||||
|
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:
|
||||||
|
systemDeps = []string{
|
||||||
|
filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "lib", "modules"),
|
||||||
|
filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "lib", "jrt-fs.jar"),
|
||||||
|
filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "release"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkClasspath := func(t *testing.T, ctx *android.TestContext) {
|
checkClasspath := func(t *testing.T, ctx *android.TestContext, isJava8 bool) {
|
||||||
foo := ctx.ModuleForTests("foo", variant)
|
foo := ctx.ModuleForTests("foo", variant)
|
||||||
javac := foo.Rule("javac")
|
javac := foo.Rule("javac")
|
||||||
|
var deps []string
|
||||||
|
|
||||||
aidl := foo.MaybeRule("aidl")
|
aidl := foo.MaybeRule("aidl")
|
||||||
|
if aidl.Rule != nil {
|
||||||
|
deps = append(deps, aidl.Output.String())
|
||||||
|
}
|
||||||
|
|
||||||
got := javac.Args["bootClasspath"]
|
got := javac.Args["bootClasspath"]
|
||||||
if got != bc {
|
expected := ""
|
||||||
t.Errorf("bootclasspath expected %q != got %q", bc, got)
|
if isJava8 {
|
||||||
|
expected = bc
|
||||||
|
deps = append(deps, bcDeps...)
|
||||||
|
} else {
|
||||||
|
expected = system
|
||||||
|
deps = append(deps, systemDeps...)
|
||||||
|
}
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("bootclasspath expected %q != got %q", expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
got = javac.Args["classpath"]
|
got = javac.Args["classpath"]
|
||||||
if got != c {
|
if got != c {
|
||||||
t.Errorf("classpath expected %q != got %q", c, got)
|
t.Errorf("classpath expected %q != got %q", c, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
var deps []string
|
|
||||||
if aidl.Rule != nil {
|
|
||||||
deps = append(deps, aidl.Output.String())
|
|
||||||
}
|
|
||||||
if len(bootclasspath) > 0 && bootclasspath[0] != `""` {
|
|
||||||
deps = append(deps, bootclasspath...)
|
|
||||||
}
|
|
||||||
deps = append(deps, classpath...)
|
deps = append(deps, classpath...)
|
||||||
|
|
||||||
if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
|
if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
|
||||||
|
@ -281,17 +304,17 @@ func TestClasspath(t *testing.T) {
|
||||||
|
|
||||||
// Test with legacy javac -source 1.8 -target 1.8
|
// Test with legacy javac -source 1.8 -target 1.8
|
||||||
t.Run("Java language level 8", func(t *testing.T) {
|
t.Run("Java language level 8", func(t *testing.T) {
|
||||||
config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
|
config := testConfig(nil)
|
||||||
if testcase.unbundled {
|
if testcase.unbundled {
|
||||||
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
|
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
|
||||||
}
|
}
|
||||||
if testcase.pdk {
|
if testcase.pdk {
|
||||||
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
|
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
|
||||||
}
|
}
|
||||||
ctx := testContext(bp, nil)
|
ctx := testContext(bpJava8, nil)
|
||||||
run(t, ctx, config)
|
run(t, ctx, config)
|
||||||
|
|
||||||
checkClasspath(t, ctx)
|
checkClasspath(t, ctx, true /* isJava8 */)
|
||||||
|
|
||||||
if testcase.host != android.Host {
|
if testcase.host != android.Host {
|
||||||
aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
|
aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
|
||||||
|
@ -314,21 +337,20 @@ func TestClasspath(t *testing.T) {
|
||||||
ctx := testContext(bp, nil)
|
ctx := testContext(bp, nil)
|
||||||
run(t, ctx, config)
|
run(t, ctx, config)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
checkClasspath(t, ctx, false /* isJava8 */)
|
||||||
got := javac.Args["bootClasspath"]
|
|
||||||
expected := system
|
if testcase.host != android.Host {
|
||||||
if testcase.system == "bootclasspath" {
|
aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
|
||||||
expected = bc
|
|
||||||
|
if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) {
|
||||||
|
t.Errorf("want aidl command to contain %q, got %q", w, g)
|
||||||
}
|
}
|
||||||
if got != expected {
|
|
||||||
t.Errorf("bootclasspath expected %q != got %q", expected, got)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Test again with PLATFORM_VERSION_CODENAME=REL
|
// Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8
|
||||||
t.Run("REL", func(t *testing.T) {
|
t.Run("REL + Java language level 8", func(t *testing.T) {
|
||||||
// TODO(b/115604102): This test should be rewritten with language level 9
|
config := testConfig(nil)
|
||||||
config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
|
|
||||||
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
|
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
|
||||||
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
|
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
|
||||||
|
|
||||||
|
@ -338,11 +360,13 @@ func TestClasspath(t *testing.T) {
|
||||||
if testcase.pdk {
|
if testcase.pdk {
|
||||||
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
|
config.TestProductVariables.Pdk = proptools.BoolPtr(true)
|
||||||
}
|
}
|
||||||
ctx := testContext(bp, nil)
|
ctx := testContext(bpJava8, nil)
|
||||||
run(t, ctx, config)
|
run(t, ctx, config)
|
||||||
|
|
||||||
checkClasspath(t, ctx)
|
checkClasspath(t, ctx, true /* isJava8 */)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO(b/142896162): Add a with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9, when that all works.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue