Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e8bd1cc authored by Spandan Das's avatar Spandan Das
Browse files

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
parent f5ee86c4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
		}
+20 −0
Original line number Diff line number Diff line
@@ -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")
}