summaryrefslogtreecommitdiff
path: root/api/api.go
diff options
context:
space:
mode:
author Spandan Das <spandandas@google.com> 2024-02-13 01:47:03 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-02-13 01:47:03 +0000
commit4671ab97f1185d7a8b78bfbdaeeb95ca3935de40 (patch)
tree986ba1f0a6737ea2baa9f9d65f7a31b736cc708a /api/api.go
parent48165939b653afe03215859666f01e7bdd667c9f (diff)
parent67b7906e5f4fbab2843efbb3ad145071665ab263 (diff)
Merge "Enforce bcp/sscp stubs do not compile against apps" into main
Diffstat (limited to 'api/api.go')
-rw-r--r--api/api.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/api/api.go b/api/api.go
index c733f5b5bffd..e8858230ba4e 100644
--- a/api/api.go
+++ b/api/api.go
@@ -79,7 +79,45 @@ func registerBuildComponents(ctx android.RegistrationContext) {
var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
+func (a *CombinedApis) apiFingerprintStubDeps() []string {
+ ret := []string{}
+ ret = append(
+ ret,
+ transformArray(a.properties.Bootclasspath, "", ".stubs")...,
+ )
+ ret = append(
+ ret,
+ transformArray(a.properties.Bootclasspath, "", ".stubs.system")...,
+ )
+ ret = append(
+ ret,
+ transformArray(a.properties.Bootclasspath, "", ".stubs.module_lib")...,
+ )
+ ret = append(
+ ret,
+ transformArray(a.properties.System_server_classpath, "", ".stubs.system_server")...,
+ )
+ return ret
+}
+
+func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) {
+ ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps()...)
+}
+
func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" {
+ // Stubs of BCP and SSCP libraries should not have any dependencies on apps
+ // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true
+ ctx.ModuleErrorf(
+ "Module %s is not a valid dependency of the stub library %s\n."+
+ "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n",
+ child.Name(), parent.Name())
+ return false // error detected
+ }
+ return true
+ })
+
}
type genruleProps struct {