diff options
| author | 2025-01-13 11:19:54 -0800 | |
|---|---|---|
| committer | 2025-01-13 11:19:54 -0800 | |
| commit | ece2411f774bb8d52a2bdd5a5060ba4f8422a048 (patch) | |
| tree | 4e9706dc8eb86871748ad37c85d049bad1b2b56b /java | |
| parent | 403c3cd86480327c0b3eb15f47c4e10c7c25e614 (diff) | |
| parent | 27b74aa99ad90bc3e913edcdede208dac4db0f7c (diff) | |
Merge changes I4fb8fc36,I5d7150fe into main
* changes:
Convert classLoaderContextForUsesLibDeps to use ModuleProxy.
Convert checkSdkVersions to use ModuleProxy.
Diffstat (limited to 'java')
| -rw-r--r-- | java/aar.go | 8 | ||||
| -rw-r--r-- | java/app.go | 30 | ||||
| -rw-r--r-- | java/base.go | 22 | ||||
| -rw-r--r-- | java/java.go | 21 |
4 files changed, 55 insertions, 26 deletions
diff --git a/java/aar.go b/java/aar.go index 7c63a29b3..0db195c8a 100644 --- a/java/aar.go +++ b/java/aar.go @@ -939,6 +939,12 @@ func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, return staticResourcesNodes, sharedResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags } +type AndroidLibraryInfo struct { + // Empty for now +} + +var AndroidLibraryInfoProvider = blueprint.NewProvider[AndroidLibraryInfo]() + type AndroidLibrary struct { Library aapt @@ -1586,8 +1592,6 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { JniPackages: a.jniPackages, }) - android.SetProvider(ctx, AndroidLibraryInfoProvider, AndroidLibraryInfo{}) - ctx.SetOutputFiles([]android.Path{a.implementationAndResourcesJarFile}, "") ctx.SetOutputFiles([]android.Path{a.aarPath}, ".aar") } diff --git a/java/app.go b/java/app.go index 31c338f4a..9b756f76a 100644 --- a/java/app.go +++ b/java/app.go @@ -52,12 +52,6 @@ type FlagsPackages struct { var FlagsPackagesProvider = blueprint.NewProvider[FlagsPackages]() -type AndroidLibraryInfo struct { - // Empty for now -} - -var AndroidLibraryInfoProvider = blueprint.NewProvider[AndroidLibraryInfo]() - func RegisterAppBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("android_app", AndroidAppFactory) ctx.RegisterModuleType("android_test", AndroidTestFactory) @@ -430,8 +424,6 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { EmbeddedJNILibs: embeddedJniLibs, }) - android.SetProvider(ctx, AndroidLibraryInfoProvider, AndroidLibraryInfo{}) - a.requiredModuleNames = a.getRequiredModuleNames(ctx) } @@ -1952,7 +1944,7 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext return clcMap } - ctx.VisitDirectDeps(func(m android.Module) { + ctx.VisitDirectDepsProxy(func(m android.ModuleProxy) { tag, isUsesLibTag := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag) if !isUsesLibTag { return @@ -1960,31 +1952,35 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext dep := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(m)) + javaInfo, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider) + if !ok { + return + } // Skip stub libraries. A dependency on the implementation library has been added earlier, // so it will be added to CLC, but the stub shouldn't be. Stub libraries can be distingushed // from implementation libraries by their name, which is different as it has a suffix. - if comp, ok := m.(SdkLibraryComponentDependency); ok { - if impl := comp.OptionalSdkLibraryImplementation(); impl != nil && *impl != dep { + if comp := javaInfo.SdkLibraryComponentDependencyInfo; comp != nil { + if impl := comp.OptionalSdkLibraryImplementation; impl != nil && *impl != dep { return } } - if lib, ok := m.(UsesLibraryDependency); ok { + if lib := javaInfo.UsesLibraryDependencyInfo; lib != nil { if _, ok := android.OtherModuleProvider(ctx, m, SdkLibraryInfoProvider); ok { // Skip java_sdk_library dependencies that provide stubs, but not an implementation. // This will be restricted to optional_uses_libs - if tag == usesLibOptTag && lib.DexJarBuildPath(ctx).PathOrNil() == nil { + if tag == usesLibOptTag && lib.DexJarBuildPath.PathOrNil() == nil { u.shouldDisableDexpreopt = true return } } libName := dep - if ulib, ok := m.(ProvidesUsesLib); ok && ulib.ProvidesUsesLib() != nil { - libName = *ulib.ProvidesUsesLib() + if ulib := javaInfo.ProvidesUsesLibInfo; ulib != nil && ulib.ProvidesUsesLib != nil { + libName = *ulib.ProvidesUsesLib } clcMap.AddContext(ctx, tag.sdkVersion, libName, tag.optional, - lib.DexJarBuildPath(ctx).PathOrNil(), lib.DexJarInstallPath(), - lib.ClassLoaderContexts()) + lib.DexJarBuildPath.PathOrNil(), lib.DexJarInstallPath, + lib.ClassLoaderContexts) } else if ctx.Config().AllowMissingDependencies() { ctx.AddMissingDependencies([]string{dep}) } else { diff --git a/java/base.go b/java/base.go index f8050de91..1e0d4bf85 100644 --- a/java/base.go +++ b/java/base.go @@ -656,14 +656,17 @@ func (j *Module) checkSdkVersions(ctx android.ModuleContext) { // Make sure this module doesn't statically link to modules with lower-ranked SDK link type. // See rank() for details. - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { tag := ctx.OtherModuleDependencyTag(module) - switch module.(type) { - // TODO(satayev): cover other types as well, e.g. imports - case *Library, *AndroidLibrary: + _, isJavaLibrary := android.OtherModuleProvider(ctx, module, JavaLibraryInfoProvider) + _, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider) + _, isJavaAconfigLibrary := android.OtherModuleProvider(ctx, module, android.CodegenInfoProvider) + // Exclude java_aconfig_library modules to maintain consistency with existing behavior. + if (isJavaLibrary && !isJavaAconfigLibrary) || isAndroidLibrary { + // TODO(satayev): cover other types as well, e.g. imports switch tag { case bootClasspathTag, sdkLibTag, libTag, staticLibTag, java9LibTag: - j.checkSdkLinkType(ctx, module.(moduleWithSdkDep), tag.(dependencyTag)) + j.checkSdkLinkType(ctx, module) } } }) @@ -2391,7 +2394,7 @@ func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret // checkSdkLinkType make sures the given dependency doesn't have a lower SDK link type rank than // this module's. See the comment on rank() for details and an example. func (j *Module) checkSdkLinkType( - ctx android.ModuleContext, dep moduleWithSdkDep, tag dependencyTag) { + ctx android.ModuleContext, dep android.ModuleProxy) { if ctx.Host() { return } @@ -2400,7 +2403,12 @@ func (j *Module) checkSdkLinkType( if stubs { return } - depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep)) + info, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider) + if !ok || info.ModuleWithSdkDepInfo == nil { + panic(fmt.Errorf("dependency doesn't have ModuleWithSdkDepInfo: %v", dep)) + } + + depLinkType := info.ModuleWithSdkDepInfo.SdkLinkType if myLinkType.rank() < depLinkType.rank() { ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+ diff --git a/java/java.go b/java/java.go index 48ba8def2..3a1bc335a 100644 --- a/java/java.go +++ b/java/java.go @@ -276,6 +276,11 @@ type ModuleWithUsesLibraryInfo struct { UsesLibrary *usesLibrary } +type ModuleWithSdkDepInfo struct { + SdkLinkType sdkLinkType + Stubs bool +} + // JavaInfo contains information about a java module for use by modules that depend on it. type JavaInfo struct { // HeaderJars is a list of jars that can be passed as the javac classpath in order to link @@ -364,10 +369,16 @@ type JavaInfo struct { ProvidesUsesLibInfo *ProvidesUsesLibInfo ModuleWithUsesLibraryInfo *ModuleWithUsesLibraryInfo + + ModuleWithSdkDepInfo *ModuleWithSdkDepInfo } var JavaInfoProvider = blueprint.NewProvider[*JavaInfo]() +type JavaLibraryInfo struct{} + +var JavaLibraryInfoProvider = blueprint.NewProvider[JavaLibraryInfo]() + // SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to // the sysprop implementation library. type SyspropPublicStubInfo struct { @@ -1047,6 +1058,8 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { TopLevelTarget: j.sourceProperties.Top_level_test_target, }) + android.SetProvider(ctx, JavaLibraryInfoProvider, JavaLibraryInfo{}) + if javaInfo != nil { setExtraJavaInfo(ctx, j, javaInfo) android.SetProvider(ctx, JavaInfoProvider, javaInfo) @@ -3542,4 +3555,12 @@ func setExtraJavaInfo(ctx android.ModuleContext, module android.Module, javaInfo UsesLibrary: mwul.UsesLibrary(), } } + + if mwsd, ok := module.(moduleWithSdkDep); ok { + linkType, stubs := mwsd.getSdkLinkType(ctx, ctx.ModuleName()) + javaInfo.ModuleWithSdkDepInfo = &ModuleWithSdkDepInfo{ + SdkLinkType: linkType, + Stubs: stubs, + } + } } |