diff options
-rw-r--r-- | android/apex.go | 40 | ||||
-rw-r--r-- | android/api_levels.go | 3 | ||||
-rw-r--r-- | android/module.go | 8 | ||||
-rw-r--r-- | android/vintf_fragment.go | 5 | ||||
-rw-r--r-- | cc/cc.go | 30 | ||||
-rw-r--r-- | genrule/genrule.go | 7 | ||||
-rw-r--r-- | java/aar.go | 5 | ||||
-rw-r--r-- | java/app.go | 17 | ||||
-rw-r--r-- | java/app_import.go | 6 | ||||
-rw-r--r-- | java/base.go | 14 | ||||
-rw-r--r-- | java/bootclasspath_fragment.go | 6 | ||||
-rw-r--r-- | java/java.go | 21 | ||||
-rw-r--r-- | java/sdk_library.go | 9 | ||||
-rw-r--r-- | java/sdk_library_internal.go | 6 | ||||
-rw-r--r-- | java/systemserver_classpath_fragment.go | 6 | ||||
-rw-r--r-- | rust/rust.go | 17 | ||||
-rw-r--r-- | sysprop/sysprop_library.go | 5 |
17 files changed, 100 insertions, 105 deletions
diff --git a/android/apex.go b/android/apex.go index 780d091bf..91fa2c718 100644 --- a/android/apex.go +++ b/android/apex.go @@ -282,11 +282,8 @@ type ApexModule interface { // check-platform-availability mutator in the apex package. SetNotAvailableForPlatform() - // Returns nil (success) if this module should support the given sdk version. Returns an - // error if not. No default implementation is provided for this method. A module type - // implementing this interface should provide an implementation. A module supports an sdk - // version when the module's min_sdk_version is equal to or less than the given sdk version. - ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error + // Returns the min sdk version that the module supports, . + MinSdkVersionSupported(ctx BaseModuleContext) ApiLevel // Returns true if this module needs a unique variation per apex, effectively disabling the // deduping. This is turned on when, for example if use_apex_name_macro is set so that each @@ -729,22 +726,21 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl if !IsDepInSameApex(ctx, from, to) { return false } - if m, ok := to.(ModuleWithMinSdkVersionCheck); ok { - // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version - // to trigger the check. - if !m.MinSdkVersion(ctx).Specified() { - ctx.OtherModuleErrorf(m, "must set min_sdk_version") + if info, ok := OtherModuleProvider(ctx, to, CommonModuleInfoKey); ok && info.ModuleWithMinSdkVersionCheck { + if info.MinSdkVersion.ApiLevel == nil || !info.MinSdkVersion.ApiLevel.Specified() { + // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version + // to trigger the check. + ctx.OtherModuleErrorf(to, "must set min_sdk_version") } return false } - if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil { - toName := ctx.OtherModuleName(to) + if err := ShouldSupportSdkVersion(ctx, to, minSdkVersion); err != nil { ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+ "\n\nDependency path: %s\n\n"+ "Consider adding 'min_sdk_version: %q' to %q", minSdkVersion, ctx.ModuleName(), err.Error(), ctx.GetPathString(false), - minSdkVersion, toName) + minSdkVersion, ctx.OtherModuleName(to)) return false } return true @@ -757,6 +753,24 @@ type MinSdkVersionFromValueContext interface { ModuleErrorContext } +// Returns nil (success) if this module should support the given sdk version. Returns an +// error if not. No default implementation is provided for this method. A module type +// implementing this interface should provide an implementation. A module supports an sdk +// version when the module's min_sdk_version is equal to or less than the given sdk version. +func ShouldSupportSdkVersion(ctx BaseModuleContext, module Module, sdkVersion ApiLevel) error { + info, ok := OtherModuleProvider(ctx, module, CommonModuleInfoKey) + if !ok || info.MinSdkVersionSupported.IsNone() { + return fmt.Errorf("min_sdk_version is not specified") + } + minVer := info.MinSdkVersionSupported + + if minVer.GreaterThan(sdkVersion) { + return fmt.Errorf("newer SDK(%v)", minVer) + } + + return nil +} + // Construct ApiLevel object from min_sdk_version string value func MinSdkVersionFromValue(ctx MinSdkVersionFromValueContext, value string) ApiLevel { if value == "" { diff --git a/android/api_levels.go b/android/api_levels.go index b4fa251bc..6d0c3891f 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -252,6 +252,9 @@ var NoneApiLevel = ApiLevel{ isPreview: true, } +// A special ApiLevel that all modules should at least support. +var MinApiLevel = ApiLevel{number: 1} + // Sentinel ApiLevel to validate that an apiLevel is either an int or a recognized codename. var InvalidApiLevel = NewInvalidApiLevel("invalid") diff --git a/android/module.go b/android/module.go index 55dd119e0..0ffb6cb53 100644 --- a/android/module.go +++ b/android/module.go @@ -1912,6 +1912,8 @@ type CommonModuleInfo struct { SkipInstall bool IsStubsModule bool Host bool + MinSdkVersionSupported ApiLevel + ModuleWithMinSdkVersionCheck bool } type ApiLevelOrPlatform struct { @@ -2292,7 +2294,13 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) commonData.CanHaveApexVariants = am.CanHaveApexVariants() commonData.NotAvailableForPlatform = am.NotAvailableForPlatform() commonData.NotInPlatform = am.NotInPlatform() + commonData.MinSdkVersionSupported = am.MinSdkVersionSupported(ctx) } + + if _, ok := m.module.(ModuleWithMinSdkVersionCheck); ok { + commonData.ModuleWithMinSdkVersionCheck = true + } + if st, ok := m.module.(StubsAvailableModule); ok { commonData.IsStubsModule = st.IsStubsModule() } diff --git a/android/vintf_fragment.go b/android/vintf_fragment.go index 85beb725c..49cf99972 100644 --- a/android/vintf_fragment.go +++ b/android/vintf_fragment.go @@ -91,7 +91,6 @@ func (m *VintfFragmentModule) AndroidMkEntries() []AndroidMkEntries { var _ ApexModule = (*VintfFragmentModule)(nil) // Implements android.ApexModule -func (m *VintfFragmentModule) ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error { - // VintfFragmetModule is independent from the SDK version. - return nil +func (m *VintfFragmentModule) MinSdkVersionSupported(ctx BaseModuleContext) ApiLevel { + return MinApiLevel } @@ -4124,20 +4124,19 @@ func (c CcDepInSameApexChecker) IncomingDepIsInSameApex(depTag blueprint.Depende } // Implements android.ApexModule -func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { +func (c *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700) if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") { - return nil + return android.MinApiLevel } // We don't check for prebuilt modules if _, ok := c.linker.(prebuiltLinkerInterface); ok { - return nil + return android.MinApiLevel } minSdkVersion := c.MinSdkVersion() if minSdkVersion == "apex_inherit" { - return nil + return android.MinApiLevel } if minSdkVersion == "" { // JNI libs within APK-in-APEX fall into here @@ -4146,14 +4145,16 @@ func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, // non-SDK variant resets sdk_version, which works too. minSdkVersion = c.SdkVersion() } + if minSdkVersion == "" { - return fmt.Errorf("neither min_sdk_version nor sdk_version specificed") + return android.NoneApiLevel } + // Not using nativeApiLevelFromUser because the context here is not // necessarily a native context. - ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) + ver, err := android.ApiLevelFromUserWithConfig(ctx.Config(), minSdkVersion) if err != nil { - return err + return android.NoneApiLevel } // A dependency only needs to support a min_sdk_version at least @@ -4161,15 +4162,14 @@ func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, // This allows introducing new architectures in the platform that // need to be included in apexes that normally require an older // min_sdk_version. - minApiForArch := MinApiForArch(ctx, c.Target().Arch.ArchType) - if sdkVersion.LessThan(minApiForArch) { - sdkVersion = minApiForArch + if c.Enabled(ctx) { + minApiForArch := MinApiForArch(ctx, c.Target().Arch.ArchType) + if ver.LessThanOrEqualTo(minApiForArch) { + ver = android.MinApiLevel + } } - if ver.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", ver) - } - return nil + return ver } // Implements android.ApexModule diff --git a/genrule/genrule.go b/genrule/genrule.go index 92f038f6d..6bd1fcc8d 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -727,11 +727,8 @@ func (g *Module) AndroidMk() android.AndroidMkData { var _ android.ApexModule = (*Module)(nil) // Implements android.ApexModule -func (g *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // Because generated outputs are checked by client modules(e.g. cc_library, ...) - // we can safely ignore the check here. - return nil +func (m *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module { diff --git a/java/aar.go b/java/aar.go index 95387a358..f7c5c13de 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1638,9 +1638,8 @@ func (m AARImportDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.Dep } // Implements android.ApexModule -func (a *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - return nil +func (a *AARImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } var _ android.PrebuiltInterface = (*AARImport)(nil) diff --git a/java/app.go b/java/app.go index a634f9c32..89d688d62 100644 --- a/java/app.go +++ b/java/app.go @@ -1281,7 +1281,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { // Skip dependencies that are only available to APEXes; they are developed with updatability // in mind and don't need manual approval. - if to.(android.ApexModule).NotAvailableForPlatform() { + if android.OtherModuleProviderOrDefault(ctx, to, android.CommonModuleInfoKey).NotAvailableForPlatform { return true } @@ -1291,18 +1291,9 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { depsInfo[depName] = info } else { toMinSdkVersion := "(no version)" - if m, ok := to.(interface { - MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel - }); ok { - if v := m.MinSdkVersion(ctx); !v.IsNone() { - toMinSdkVersion = v.String() - } - } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { - // TODO(b/175678607) eliminate the use of MinSdkVersion returning - // string - if v := m.MinSdkVersion(); v != "" { - toMinSdkVersion = v - } + if info, ok := android.OtherModuleProvider(ctx, to, android.CommonModuleInfoKey); ok && + !info.MinSdkVersion.IsPlatform && info.MinSdkVersion.ApiLevel != nil { + toMinSdkVersion = info.MinSdkVersion.ApiLevel.String() } depsInfo[depName] = android.ApexModuleDepInfo{ To: depName, diff --git a/java/app_import.go b/java/app_import.go index a122510de..919266f28 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -654,10 +654,8 @@ func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android var _ android.ApexModule = (*AndroidAppImport)(nil) // Implements android.ApexModule -func (j *AndroidAppImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // Do not check for prebuilts against the min_sdk_version of enclosing APEX - return nil +func (m *AndroidAppImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } func createVariantGroupType(variants []string, variantGroupName string) reflect.Type { diff --git a/java/base.go b/java/base.go index 730554896..21ad73f84 100644 --- a/java/base.go +++ b/java/base.go @@ -2267,20 +2267,16 @@ func (m JavaDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.Dependen } // Implements android.ApexModule -func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { +func (j *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { sdkVersionSpec := j.SdkVersion(ctx) minSdkVersion := j.MinSdkVersion(ctx) - if !minSdkVersion.Specified() { - return fmt.Errorf("min_sdk_version is not specified") - } + // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { - return nil + return android.MinApiLevel } - if minSdkVersion.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", minSdkVersion) - } - return nil + + return minSdkVersion } func (j *Module) Stem() string { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 8383a5a1e..7a3c21e44 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -252,6 +252,8 @@ type BootclasspathFragmentModule struct { profilePathErr error } +var _ android.ApexModule = (*BootclasspathFragmentModule)(nil) + // commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt // bootclasspath fragment modules. type commonBootclasspathFragment interface { @@ -454,8 +456,8 @@ func (b BootclasspathFragmentDepInSameApexChecker) OutgoingDepIsInSameApex(tag b panic(fmt.Errorf("boot_image module should not have a dependency tag %s", android.PrettyPrintTag(tag))) } -func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { - return nil +func (m *BootclasspathFragmentModule) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a diff --git a/java/java.go b/java/java.go index 33941e9ea..c5dee0c97 100644 --- a/java/java.go +++ b/java/java.go @@ -3292,21 +3292,16 @@ func (m JavaImportDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.De } // Implements android.ApexModule -func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { +func (j *Import) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { sdkVersionSpec := j.SdkVersion(ctx) minSdkVersion := j.MinSdkVersion(ctx) - if !minSdkVersion.Specified() { - return fmt.Errorf("min_sdk_version is not specified") - } + // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { - return nil - } - if minSdkVersion.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", minSdkVersion) + return android.MinApiLevel } - return nil + + return minSdkVersion } // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or @@ -3522,10 +3517,8 @@ func (j *DexImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDex var _ android.ApexModule = (*DexImport)(nil) // Implements android.ApexModule -func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // we don't check prebuilt modules for sdk_version - return nil +func (m *DexImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // dex_import imports a `.jar` file containing classes.dex files. diff --git a/java/sdk_library.go b/java/sdk_library.go index fafb44801..cf31b5095 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -931,6 +931,8 @@ type commonSdkLibraryAndImportModule interface { RootLibraryName() string } +var _ android.ApexModule = (*SdkLibrary)(nil) + func (m *SdkLibrary) RootLibraryName() string { return m.BaseModuleName() } @@ -2153,13 +2155,10 @@ func (m SdkLibraryImportDepIsInSameApexChecker) OutgoingDepIsInSameApex(tag blue } // Implements android.ApexModule -func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // we don't check prebuilt modules for sdk_version - return nil +func (m *SdkLibraryImport) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } -// Implements android.ApexModule func (module *SdkLibraryImport) UniqueApexVariations() bool { return module.uniqueApexVariations() } diff --git a/java/sdk_library_internal.go b/java/sdk_library_internal.go index db9cd24ce..578969223 100644 --- a/java/sdk_library_internal.go +++ b/java/sdk_library_internal.go @@ -807,10 +807,8 @@ func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { var _ android.ApexModule = (*sdkLibraryXml)(nil) // Implements android.ApexModule -func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - // sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked - return nil +func (m *sdkLibraryXml) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // File path to the runtime implementation library diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index 6f746b45a..a60f6b82c 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -95,8 +95,10 @@ type SystemServerClasspathModule struct { properties systemServerClasspathFragmentProperties } -func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { - return nil +var _ android.ApexModule = (*SystemServerClasspathModule)(nil) + +func (m *SystemServerClasspathModule) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } type systemServerClasspathFragmentProperties struct { diff --git a/rust/rust.go b/rust/rust.go index 4fd800282..7a7b1064c 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -2085,26 +2085,23 @@ func (mod *Module) MinSdkVersion() string { } // Implements android.ApexModule -func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { +func (mod *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { minSdkVersion := mod.MinSdkVersion() if minSdkVersion == "apex_inherit" { - return nil + return android.MinApiLevel } + if minSdkVersion == "" { - return fmt.Errorf("min_sdk_version is not specificed") + return android.NoneApiLevel } - // Not using nativeApiLevelFromUser because the context here is not // necessarily a native context. - ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) + ver, err := android.ApiLevelFromUserWithConfig(ctx.Config(), minSdkVersion) if err != nil { - return err + return android.NoneApiLevel } - if ver.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", ver) - } - return nil + return ver } // Implements android.ApexModule diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go index 25fbc41d3..af1eaf606 100644 --- a/sysprop/sysprop_library.go +++ b/sysprop/sysprop_library.go @@ -459,9 +459,8 @@ func (m *syspropLibrary) AndroidMk() android.AndroidMkData { var _ android.ApexModule = (*syspropLibrary)(nil) // Implements android.ApexModule -func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext, - sdkVersion android.ApiLevel) error { - return fmt.Errorf("sysprop_library is not supposed to be part of apex modules") +func (m *syspropLibrary) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { + return android.MinApiLevel } // sysprop_library creates schematized APIs from sysprop description files (.sysprop). |