Register versioned sdk dependency in module_bp_java_deps.json

java modules that link against a versioned sdk (sdk_version: <num>) get
the appropriate stub jar on its classpath, but the dependency is not
registered in its build graph. This CL registers this dependency for
module_bp_java_deps.json. Ideally, we should move this to `decodeSdkDep`
so that this dependendency becomes known to other tools that analyze
soong's module graph (e.g. soongdbg)

Test: go test ./java
Bug: 358608607
Bug: 356572093
Change-Id: Iab6efe7826d18dedfadbe4d34d78e7eb2888bd8d
This commit is contained in:
Spandan Das
2024-08-09 00:07:03 +00:00
parent f5ee86c46f
commit 6e8bd1cc37
2 changed files with 25 additions and 0 deletions

View File

@@ -2229,6 +2229,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.classpath = append(deps.classpath, sdkDep.jars...)
deps.dexClasspath = append(deps.dexClasspath, sdkDep.jars...)
deps.aidlPreprocess = sdkDep.aidl
// Add the sdk module dependency to `compileDepNames`.
// This ensures that the dependency is reported in `module_bp_java_deps.json`
// TODO (b/358608607): Move this to decodeSdkDep
sdkSpec := android.SdkContext(j).SdkVersion(ctx)
j.compileDepNames = append(j.compileDepNames, fmt.Sprintf("sdk_%s_%s_android", sdkSpec.Kind.String(), sdkSpec.ApiLevel.String()))
} else {
deps.aidlPreprocess = sdkDep.aidl
}

View File

@@ -103,3 +103,23 @@ func TestCollectJavaLibraryPropertiesAddJarjarRules(t *testing.T) {
t.Errorf("Library.IDEInfo() Jarjar_rules = %v, want %v", dpInfo.Jarjar_rules[0], expected)
}
}
func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
ctx := android.GroupFixturePreparers(
prepareForJavaTest,
FixtureWithPrebuiltApis(map[string][]string{
"29": {},
})).RunTestWithBp(t,
`
java_library {
name: "javalib",
srcs: ["foo.java"],
sdk_version: "29",
}
`)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{}
module.IDEInfo(dpInfo)
android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android")
}