summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/aar.go22
-rw-r--r--java/android_manifest.go6
-rw-r--r--java/androidmk.go6
-rwxr-xr-xjava/app.go42
-rw-r--r--java/app_import.go8
-rw-r--r--java/base.go59
-rw-r--r--java/droiddoc.go14
-rw-r--r--java/hiddenapi.go7
-rw-r--r--java/java.go37
-rw-r--r--java/platform_bootclasspath.go55
-rw-r--r--java/prebuilt_apis.go10
-rw-r--r--java/rro.go14
-rw-r--r--java/sdk.go2
-rw-r--r--java/sdk_library.go2
14 files changed, 171 insertions, 113 deletions
diff --git a/java/aar.go b/java/aar.go
index a122a94cb..04727e4b9 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -218,7 +218,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte
linkDeps = append(linkDeps, assetDeps...)
// SDK version flags
- minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
@@ -609,6 +609,9 @@ type AARImport struct {
hideApexVariantFromMake bool
aarPath android.Path
+
+ sdkVersion android.SdkSpec
+ minSdkVersion android.SdkSpec
}
var _ android.OutputFileProducer = (*AARImport)(nil)
@@ -625,23 +628,23 @@ func (a *AARImport) OutputFiles(tag string) (android.Paths, error) {
}
}
-func (a *AARImport) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom(String(a.properties.Sdk_version))
+func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version))
}
func (a *AARImport) SystemModules() string {
return ""
}
-func (a *AARImport) MinSdkVersion() android.SdkSpec {
+func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if a.properties.Min_sdk_version != nil {
- return android.SdkSpecFrom(*a.properties.Min_sdk_version)
+ return android.SdkSpecFrom(ctx, *a.properties.Min_sdk_version)
}
- return a.SdkVersion()
+ return a.SdkVersion(ctx)
}
-func (a *AARImport) TargetSdkVersion() android.SdkSpec {
- return a.SdkVersion()
+func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return a.SdkVersion(ctx)
}
func (a *AARImport) javaVersion() string {
@@ -727,6 +730,9 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return
}
+ a.sdkVersion = a.SdkVersion(ctx)
+ a.minSdkVersion = a.MinSdkVersion(ctx)
+
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
aarName := ctx.ModuleName() + ".aar"
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 8510f30dd..331f941ec 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -51,7 +51,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
if isLibrary {
args = append(args, "--library")
} else {
- minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersion(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersion(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
@@ -87,7 +87,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
args = append(args, "--logging-parent", loggingParent)
}
var deps android.Paths
- targetSdkVersion, err := sdkContext.TargetSdkVersion().EffectiveVersionString(ctx)
+ targetSdkVersion, err := sdkContext.TargetSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
}
@@ -96,7 +96,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
deps = append(deps, ApiFingerprintPath(ctx))
}
- minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx)
+ minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
}
diff --git a/java/androidmk.go b/java/androidmk.go
index 75661a7a5..4e594a2fa 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -106,7 +106,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
if len(library.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
}
- entries.SetString("LOCAL_SDK_VERSION", library.SdkVersion().Raw)
+ entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion.String())
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
@@ -205,7 +205,7 @@ func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
}
entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
- entries.SetString("LOCAL_SDK_VERSION", prebuilt.makeSdkVersion())
+ entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
},
},
@@ -255,7 +255,7 @@ func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
- entries.SetString("LOCAL_SDK_VERSION", prebuilt.SdkVersion().Raw)
+ entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
},
},
}}
diff --git a/java/app.go b/java/app.go
index 04406e734..5695022f9 100755
--- a/java/app.go
+++ b/java/app.go
@@ -213,7 +213,7 @@ func (c Certificate) AndroidMkString() string {
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx)
- if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion().Specified() {
+ if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion(ctx).Specified() {
ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
}
@@ -222,7 +222,7 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.aapt.deps(ctx, sdkDep)
}
- usesSDK := a.SdkVersion().Specified() && a.SdkVersion().Kind != android.SdkCorePlatform
+ usesSDK := a.SdkVersion(ctx).Specified() && a.SdkVersion(ctx).Kind != android.SdkCorePlatform
if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) {
ctx.PropertyErrorf("jni_uses_sdk_apis",
@@ -279,14 +279,14 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
if a.Updatable() {
- if !a.SdkVersion().Stable() {
- ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion())
+ if !a.SdkVersion(ctx).Stable() {
+ ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx))
}
if String(a.deviceProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
}
- if minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx); err == nil {
+ if minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx); err == nil {
a.checkJniLibsSdkVersion(ctx, minSdkVersion)
android.CheckMinSdkVersion(a, ctx, minSdkVersion)
} else {
@@ -314,7 +314,7 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer
// The domain of cc.sdk_version is "current" and <number>
// We can rely on android.SdkSpec to convert it to <number> so that "current" is
// handled properly regardless of sdk finalization.
- jniSdkVersion, err := android.SdkSpecFrom(dep.SdkVersion()).EffectiveVersion(ctx)
+ jniSdkVersion, err := android.SdkSpecFrom(ctx, dep.SdkVersion()).EffectiveVersion(ctx)
if err != nil || minSdkVersion.LessThan(jniSdkVersion) {
ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
@@ -327,9 +327,9 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer
// Returns true if the native libraries should be stored in the APK uncompressed and the
// extractNativeLibs application flag should be set to false in the manifest.
func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
- minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx)
+ minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx)
if err != nil {
- ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(), err)
+ ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(ctx), err)
}
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
@@ -381,7 +381,7 @@ func (a *AndroidApp) renameResourcesPackage() bool {
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
- if ctx.Module().(android.SdkContext).SdkVersion().Kind == android.SdkModule {
+ if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule {
usePlatformAPI = true
}
a.aapt.usesNonSdkApis = usePlatformAPI
@@ -724,8 +724,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
}
type appDepsInterface interface {
- SdkVersion() android.SdkSpec
- MinSdkVersion() android.SdkSpec
+ SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
+ MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
RequiresStableAPIs(ctx android.BaseModuleContext) bool
}
@@ -738,8 +738,8 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
seenModulePaths := make(map[string]bool)
if checkNativeSdkVersion {
- checkNativeSdkVersion = app.SdkVersion().Specified() &&
- app.SdkVersion().Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx)
+ checkNativeSdkVersion = app.SdkVersion(ctx).Specified() &&
+ app.SdkVersion(ctx).Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx)
}
ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
@@ -829,12 +829,16 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
depsInfo[depName] = info
} else {
toMinSdkVersion := "(no version)"
- if m, ok := to.(interface{ MinSdkVersion() string }); ok {
- if v := m.MinSdkVersion(); v != "" {
- toMinSdkVersion = v
+ if m, ok := to.(interface {
+ MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
+ }); ok {
+ if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() {
+ toMinSdkVersion = v.ApiLevel.String()
}
- } else if m, ok := to.(interface{ MinSdkVersionString() string }); ok {
- if v := m.MinSdkVersionString(); v != "" {
+ } 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
}
}
@@ -848,7 +852,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
return true
})
- a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersionString(), depsInfo)
+ a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depsInfo)
}
func (a *AndroidApp) Updatable() bool {
diff --git a/java/app_import.go b/java/app_import.go
index 32cec2309..839051ea8 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -394,12 +394,12 @@ func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ androi
return false
}
-func (a *AndroidAppImport) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom("")
+func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecPrivate
}
-func (a *AndroidAppImport) MinSdkVersion() android.SdkSpec {
- return android.SdkSpecFrom("")
+func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecPrivate
}
var _ android.ApexModule = (*AndroidAppImport)(nil)
diff --git a/java/base.go b/java/base.go
index 9bc0738e6..19c85cd75 100644
--- a/java/base.go
+++ b/java/base.go
@@ -370,10 +370,13 @@ type Module struct {
modulePaths []string
hideApexVariantFromMake bool
+
+ sdkVersion android.SdkSpec
+ minSdkVersion android.SdkSpec
}
-func (j *Module) CheckStableSdkVersion() error {
- sdkVersion := j.SdkVersion()
+func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
+ sdkVersion := j.SdkVersion(ctx)
if sdkVersion.Stable() {
return nil
}
@@ -393,7 +396,7 @@ func (j *Module) CheckStableSdkVersion() error {
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
if j.RequiresStableAPIs(ctx) {
if sc, ok := ctx.Module().(android.SdkContext); ok {
- if !sc.SdkVersion().Specified() {
+ if !sc.SdkVersion(ctx).Specified() {
ctx.PropertyErrorf("sdk_version",
"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
}
@@ -418,7 +421,7 @@ func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
if sc, ok := ctx.Module().(android.SdkContext); ok {
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
- sdkVersionSpecified := sc.SdkVersion().Specified()
+ sdkVersionSpecified := sc.SdkVersion(ctx).Specified()
if usePlatformAPI && sdkVersionSpecified {
ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
} else if !usePlatformAPI && !sdkVersionSpecified {
@@ -512,30 +515,30 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
return false
}
-func (j *Module) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom(String(j.deviceProperties.Sdk_version))
+func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
}
func (j *Module) SystemModules() string {
return proptools.String(j.deviceProperties.System_modules)
}
-func (j *Module) MinSdkVersion() android.SdkSpec {
+func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if j.deviceProperties.Min_sdk_version != nil {
- return android.SdkSpecFrom(*j.deviceProperties.Min_sdk_version)
+ return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version)
}
- return j.SdkVersion()
+ return j.SdkVersion(ctx)
}
-func (j *Module) TargetSdkVersion() android.SdkSpec {
- if j.deviceProperties.Target_sdk_version != nil {
- return android.SdkSpecFrom(*j.deviceProperties.Target_sdk_version)
- }
- return j.SdkVersion()
+func (j *Module) MinSdkVersionString() string {
+ return j.minSdkVersion.Raw
}
-func (j *Module) MinSdkVersionString() string {
- return j.MinSdkVersion().ApiLevel.String()
+func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ if j.deviceProperties.Target_sdk_version != nil {
+ return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version)
+ }
+ return j.SdkVersion(ctx)
}
func (j *Module) AvailableFor(what string) bool {
@@ -1209,7 +1212,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
}
// Dex compilation
var dexOutputFile android.OutputPath
- dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName)
+ dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
if ctx.Failed() {
return
}
@@ -1267,9 +1270,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.linter.srcJars = srcJars
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
j.linter.classes = j.implementationJarFile
- j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion())
- j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion())
- j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion())
+ j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion(ctx))
+ j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion(ctx))
+ j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion(ctx))
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"
if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
@@ -1471,7 +1474,7 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
// Implements android.ApexModule
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
- sdkSpec := j.MinSdkVersion()
+ sdkSpec := j.MinSdkVersion(ctx)
if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
}
@@ -1551,10 +1554,10 @@ func (lt sdkLinkType) rank() int {
type moduleWithSdkDep interface {
android.Module
- getSdkLinkType(name string) (ret sdkLinkType, stubs bool)
+ getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool)
}
-func (m *Module) getSdkLinkType(name string) (ret sdkLinkType, stubs bool) {
+func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) {
switch name {
case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
"stub-annotations", "private-stub-annotations-jar",
@@ -1576,7 +1579,7 @@ func (m *Module) getSdkLinkType(name string) (ret sdkLinkType, stubs bool) {
return linkType, true
}
- ver := m.SdkVersion()
+ ver := m.SdkVersion(ctx)
switch ver.Kind {
case android.SdkCore:
return javaCore, false
@@ -1606,11 +1609,11 @@ func (j *Module) checkSdkLinkType(
return
}
- myLinkType, stubs := j.getSdkLinkType(ctx.ModuleName())
+ myLinkType, stubs := j.getSdkLinkType(ctx, ctx.ModuleName())
if stubs {
return
}
- depLinkType, _ := dep.getSdkLinkType(ctx.OtherModuleName(dep))
+ depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep))
if myLinkType.rank() < depLinkType.rank() {
ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
@@ -1638,7 +1641,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
}
}
- sdkLinkType, _ := j.getSdkLinkType(ctx.ModuleName())
+ sdkLinkType, _ := j.getSdkLinkType(ctx, ctx.ModuleName())
ctx.VisitDirectDeps(func(module android.Module) {
otherName := ctx.OtherModuleName(module)
@@ -1656,7 +1659,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
if dep, ok := module.(SdkLibraryDependency); ok {
switch tag {
case libTag:
- deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
+ deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
case staticLibTag:
ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index e527d59bc..01c0f16ff 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -261,20 +261,20 @@ func JavadocHostFactory() android.Module {
var _ android.OutputFileProducer = (*Javadoc)(nil)
-func (j *Javadoc) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom(String(j.properties.Sdk_version))
+func (j *Javadoc) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
}
func (j *Javadoc) SystemModules() string {
return proptools.String(j.properties.System_modules)
}
-func (j *Javadoc) MinSdkVersion() android.SdkSpec {
- return j.SdkVersion()
+func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return j.SdkVersion(ctx)
}
-func (j *Javadoc) TargetSdkVersion() android.SdkSpec {
- return j.SdkVersion()
+func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return j.SdkVersion(ctx)
}
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
@@ -386,7 +386,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
}
case libTag:
if dep, ok := module.(SdkLibraryDependency); ok {
- deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
+ deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
} else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
deps.classpath = append(deps.classpath, dep.HeaderJars...)
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 208ced769..3ecb9772a 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -111,6 +111,13 @@ type hiddenAPIIntf interface {
var _ hiddenAPIIntf = (*hiddenAPI)(nil)
+// hiddenAPISupportingModule is the interface that is implemented by any module that supports
+// contributing to the hidden API processing.
+type hiddenAPISupportingModule interface {
+ android.Module
+ hiddenAPIIntf
+}
+
// Initialize the hiddenapi structure
func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, configurationName string) {
// If hiddenapi processing is disabled treat this as inactive.
diff --git a/java/java.go b/java/java.go
index fa7c96eff..ee4f2eb0b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -356,7 +356,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an
if javaVersion != "" {
return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() {
- return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion())
+ return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
} else {
return JAVA_VERSION_9
}
@@ -463,6 +463,9 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// would the <x> library if <x> was configured as a boot jar.
j.initHiddenAPI(ctx, j.ConfigurationName())
+ j.sdkVersion = j.SdkVersion(ctx)
+ j.minSdkVersion = j.MinSdkVersion(ctx)
+
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {
j.hideApexVariantFromMake = true
@@ -1130,33 +1133,28 @@ type Import struct {
exportAidlIncludeDirs android.Paths
hideApexVariantFromMake bool
-}
-func (j *Import) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom(String(j.properties.Sdk_version))
+ sdkVersion android.SdkSpec
+ minSdkVersion android.SdkSpec
}
-func (j *Import) makeSdkVersion() string {
- return j.SdkVersion().Raw
+func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
}
func (j *Import) SystemModules() string {
return "none"
}
-func (j *Import) MinSdkVersion() android.SdkSpec {
+func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if j.properties.Min_sdk_version != nil {
- return android.SdkSpecFrom(*j.properties.Min_sdk_version)
+ return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version)
}
- return j.SdkVersion()
+ return j.SdkVersion(ctx)
}
-func (j *Import) TargetSdkVersion() android.SdkSpec {
- return j.SdkVersion()
-}
-
-func (j *Import) MinSdkVersionString() string {
- return j.MinSdkVersion().ApiLevel.String()
+func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return j.SdkVersion(ctx)
}
func (j *Import) Prebuilt() *android.Prebuilt {
@@ -1192,6 +1190,9 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ j.sdkVersion = j.SdkVersion(ctx)
+ j.minSdkVersion = j.MinSdkVersion(ctx)
+
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, j.BaseModuleName())
@@ -1230,7 +1231,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else if dep, ok := module.(SdkLibraryDependency); ok {
switch tag {
case libTag:
- flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
+ flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
}
}
@@ -1291,7 +1292,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
var dexOutputFile android.OutputPath
- dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName)
+ dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
if ctx.Failed() {
return
}
@@ -1359,7 +1360,7 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
// Implements android.ApexModule
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
- sdkSpec := j.MinSdkVersion()
+ sdkSpec := j.MinSdkVersion(ctx)
if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
}
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index d98ce6719..621119ef3 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -208,7 +208,30 @@ func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex st
// error, unless missing dependencies are allowed. The simplest way to handle that is to add a
// dependency that will not be satisfied and the default behavior will handle it.
if !addedDep {
- ctx.AddFarVariationDependencies(variations, tag, name)
+ // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does
+ // not exist. The resulting error message will contain useful information about the available
+ // variants.
+ reportMissingVariationDependency(ctx, variations, name)
+
+ // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists
+ // so that information about its available variants will be reported too.
+ if ctx.OtherModuleExists(prebuiltName) {
+ reportMissingVariationDependency(ctx, variations, prebuiltName)
+ }
+ }
+}
+
+// reportMissingVariationDependency intentionally adds a dependency on a missing variation in order
+// to generate an appropriate error message with information about the available variations.
+func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) {
+ modules := ctx.AddFarVariationDependencies(variations, nil, name)
+ if len(modules) != 1 {
+ panic(fmt.Errorf("Internal Error: expected one module, found %d", len(modules)))
+ return
+ }
+ if modules[0] != nil {
+ panic(fmt.Errorf("Internal Error: expected module to be missing but was found: %q", modules[0]))
+ return
}
}
@@ -280,17 +303,37 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.
return
}
- moduleSpecificFlagsPaths := android.Paths{}
+ hiddenAPISupportingModules := []hiddenAPISupportingModule{}
for _, module := range modules {
- if h, ok := module.(hiddenAPIIntf); ok {
- if csv := h.flagsCSV(); csv != nil {
- moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, csv)
+ if h, ok := module.(hiddenAPISupportingModule); ok {
+ if h.bootDexJar() == nil {
+ ctx.ModuleErrorf("module %s does not provide a bootDexJar file", module)
}
+ if h.flagsCSV() == nil {
+ ctx.ModuleErrorf("module %s does not provide a flagsCSV file", module)
+ }
+ if h.indexCSV() == nil {
+ ctx.ModuleErrorf("module %s does not provide an indexCSV file", module)
+ }
+ if h.metadataCSV() == nil {
+ ctx.ModuleErrorf("module %s does not provide a metadataCSV file", module)
+ }
+
+ if ctx.Failed() {
+ continue
+ }
+
+ hiddenAPISupportingModules = append(hiddenAPISupportingModules, h)
} else {
- ctx.ModuleErrorf("module %s of type %s does not implement hiddenAPIIntf", module, ctx.OtherModuleType(module))
+ ctx.ModuleErrorf("module %s of type %s does not support hidden API processing", module, ctx.OtherModuleType(module))
}
}
+ moduleSpecificFlagsPaths := android.Paths{}
+ for _, module := range hiddenAPISupportingModules {
+ moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, module.flagsCSV())
+ }
+
augmentationInfo := b.properties.Hidden_api.hiddenAPIAugmentationInfo(ctx)
outputPath := hiddenAPISingletonPaths(ctx).flags
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go
index 8a442b5ff..c33e6c229 100644
--- a/java/prebuilt_apis.go
+++ b/java/prebuilt_apis.go
@@ -253,14 +253,8 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) {
files := getPrebuiltFilesInSubdir(mctx, nextApiDir, "api/*incompatibilities.txt")
for _, f := range files {
localPath := strings.TrimPrefix(f, mydir)
- module, _, scope := parseApiFilePath(mctx, localPath)
-
- // Figure out which module is referenced by this file. Special case for "android".
- referencedModule := strings.TrimSuffix(module, "incompatibilities")
- referencedModule = strings.TrimSuffix(referencedModule, "-")
- if referencedModule == "" {
- referencedModule = "android"
- }
+ filename, _, scope := parseApiFilePath(mctx, localPath)
+ referencedModule := strings.TrimSuffix(filename, "-incompatibilities")
createApiModule(mctx, apiModuleName(referencedModule+"-incompatibilities", scope, "latest"), localPath)
diff --git a/java/rro.go b/java/rro.go
index 4ae0014db..2e58c042f 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -141,23 +141,23 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
}
-func (r *RuntimeResourceOverlay) SdkVersion() android.SdkSpec {
- return android.SdkSpecFrom(String(r.properties.Sdk_version))
+func (r *RuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(r.properties.Sdk_version))
}
func (r *RuntimeResourceOverlay) SystemModules() string {
return ""
}
-func (r *RuntimeResourceOverlay) MinSdkVersion() android.SdkSpec {
+func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if r.properties.Min_sdk_version != nil {
- return android.SdkSpecFrom(*r.properties.Min_sdk_version)
+ return android.SdkSpecFrom(ctx, *r.properties.Min_sdk_version)
}
- return r.SdkVersion()
+ return r.SdkVersion(ctx)
}
-func (r *RuntimeResourceOverlay) TargetSdkVersion() android.SdkSpec {
- return r.SdkVersion()
+func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return r.SdkVersion(ctx)
}
func (r *RuntimeResourceOverlay) Certificate() Certificate {
diff --git a/java/sdk.go b/java/sdk.go
index f324b7661..d6e20a78f 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -61,7 +61,7 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe
}
func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
- sdkVersion := sdkContext.SdkVersion()
+ sdkVersion := sdkContext.SdkVersion(ctx)
if !sdkVersion.Valid() {
ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw)
return sdkDep{}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 96135c3d4..e5ee39705 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1512,7 +1512,7 @@ func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion andr
// force override sdk_version to module_current so that the closest possible API
// surface could be found in selectHeaderJarsForSdkVersion
if module.defaultsToStubs() && !sdkVersion.Specified() {
- sdkVersion = android.SdkSpecFrom("module_current")
+ sdkVersion = android.SdkSpecFrom(ctx, "module_current")
}
// Only provide access to the implementation library if it is actually built.