Track the current java_sdk_library(_import) deps

Adds some tests to track the current dependencies between
java_sdk_library, java_sdk_library_import and their child modules in
various configurations. This is in preparation for a series of changes
that will update the dependencies to ensure that the java_sdk_library
always depends on the source modules that it creates and
java_sdk_library_import always depends on the prebuilt modules that it
creates.

Comments in the tests highlight the parts that will be affected by the
follow up changes.

Bug: 159902351
Test: m nothing
Change-Id: I8eea3ac80061f5cbbc9dec201750c4b59e224b4b
This commit is contained in:
Paul Duffin 2020-06-26 22:20:25 +01:00
parent 5e291c238f
commit ca8d9a5018

View file

@ -25,6 +25,7 @@ import (
"strings"
"testing"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
"android/soong/android"
@ -171,6 +172,20 @@ func moduleToPath(name string) string {
}
}
func checkModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
t.Helper()
module := ctx.ModuleForTests(name, variant).Module()
deps := []string{}
ctx.VisitDirectDeps(module, func(m blueprint.Module) {
deps = append(deps, m.Name())
})
sort.Strings(deps)
if actual := deps; !reflect.DeepEqual(expected, actual) {
t.Errorf("expected %#q, found %#q", expected, actual)
}
}
func TestJavaLinkType(t *testing.T) {
testJava(t, `
java_library {
@ -630,6 +645,90 @@ func TestJavaSdkLibraryImport(t *testing.T) {
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String())
}
}
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
`prebuilt_sdklib.stubs`,
`prebuilt_sdklib.stubs.source.test`,
`prebuilt_sdklib.stubs.system`,
`prebuilt_sdklib.stubs.test`,
})
}
func TestJavaSdkLibraryImport_WithSource(t *testing.T) {
ctx, _ := testJava(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "none",
public: {
enabled: true,
},
}
java_sdk_library_import {
name: "sdklib",
public: {
jars: ["a.jar"],
},
}
`)
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
`dex2oatd`,
`prebuilt_sdklib`,
`sdklib.impl`,
`sdklib.stubs`,
`sdklib.stubs.source`,
`sdklib.xml`,
})
checkModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
`sdklib.impl`,
// This should be prebuilt_sdklib.stubs but is set to sdklib.stubs because the
// dependency is added after prebuilts may have been renamed and so has to use
// the renamed name.
`sdklib.stubs`,
`sdklib.xml`,
})
}
func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
ctx, _ := testJava(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "none",
public: {
enabled: true,
},
}
java_sdk_library_import {
name: "sdklib",
prefer: true,
public: {
jars: ["a.jar"],
},
}
`)
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
`dex2oatd`,
`prebuilt_sdklib`,
// This should be sdklib.stubs but is switched to the prebuilt because it is preferred.
`prebuilt_sdklib.stubs`,
`sdklib.impl`,
`sdklib.stubs.source`,
`sdklib.xml`,
})
checkModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{
`prebuilt_sdklib.stubs`,
`sdklib.impl`,
`sdklib.xml`,
})
}
func TestDefaults(t *testing.T) {
@ -1379,6 +1478,28 @@ func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) {
`)
}
func TestJavaSdkLibrary_Deps(t *testing.T) {
ctx, _ := testJava(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
sdk_version: "none",
system_modules: "none",
public: {
enabled: true,
},
}
`)
checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{
`dex2oatd`,
`sdklib.impl`,
`sdklib.stubs`,
`sdklib.stubs.source`,
`sdklib.xml`,
})
}
func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) {
testJava(t, `
java_sdk_library_import {