Add support for min_sdk_version
Add min_sdk_version properties and use it for aapt2 --min-sdk-version and --target-sdk-version flags. Add an sdkContext interface that any function that needs an sdk version can take in order to get the values for the current module. Bug: 110848854 Test: m checkbuild Change-Id: Ic69f1f935d8b865ec77689350407df08bfac5925
This commit is contained in:
@@ -85,6 +85,7 @@ func init() {
|
|||||||
"LOCAL_MULTILIB": "compile_multilib",
|
"LOCAL_MULTILIB": "compile_multilib",
|
||||||
"LOCAL_ARM_MODE_HACK": "instruction_set",
|
"LOCAL_ARM_MODE_HACK": "instruction_set",
|
||||||
"LOCAL_SDK_VERSION": "sdk_version",
|
"LOCAL_SDK_VERSION": "sdk_version",
|
||||||
|
"LOCAL_MIN_SDK_VERSION": "min_sdk_version",
|
||||||
"LOCAL_NDK_STL_VARIANT": "stl",
|
"LOCAL_NDK_STL_VARIANT": "stl",
|
||||||
"LOCAL_JAR_MANIFEST": "manifest",
|
"LOCAL_JAR_MANIFEST": "manifest",
|
||||||
"LOCAL_JARJAR_RULES": "jarjar_rules",
|
"LOCAL_JARJAR_RULES": "jarjar_rules",
|
||||||
|
41
java/aar.go
41
java/aar.go
@@ -74,7 +74,7 @@ func (a *aapt) ExportPackage() android.Path {
|
|||||||
return a.exportPackage
|
return a.exportPackage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkVersion string) (flags []string, deps android.Paths,
|
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext) (flags []string, deps android.Paths,
|
||||||
resDirs, overlayDirs []globbedResourceDir, overlayFiles, rroDirs android.Paths, manifestPath android.Path) {
|
resDirs, overlayDirs []globbedResourceDir, overlayFiles, rroDirs android.Paths, manifestPath android.Path) {
|
||||||
|
|
||||||
hasVersionCode := false
|
hasVersionCode := false
|
||||||
@@ -125,20 +125,17 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkVersion string) (flags [
|
|||||||
linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A "))
|
linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A "))
|
||||||
linkDeps = append(linkDeps, assetFiles...)
|
linkDeps = append(linkDeps, assetFiles...)
|
||||||
|
|
||||||
transitiveStaticLibs, libDeps, libFlags := aaptLibs(ctx, sdkVersion)
|
transitiveStaticLibs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
||||||
|
|
||||||
overlayFiles = append(overlayFiles, transitiveStaticLibs...)
|
overlayFiles = append(overlayFiles, transitiveStaticLibs...)
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
linkDeps = append(linkDeps, libDeps...)
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
|
|
||||||
// SDK version flags
|
// SDK version flags
|
||||||
switch sdkVersion {
|
minSdkVersion := sdkVersionOrDefault(ctx, sdkContext.minSdkVersion())
|
||||||
case "", "current", "system_current", "test_current":
|
|
||||||
sdkVersion = proptools.NinjaEscape([]string{ctx.Config().DefaultAppTargetSdk()})[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
linkFlags = append(linkFlags, "--min-sdk-version "+sdkVersion)
|
linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion)
|
||||||
linkFlags = append(linkFlags, "--target-sdk-version "+sdkVersion)
|
linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
|
||||||
|
|
||||||
// Version code
|
// Version code
|
||||||
if !hasVersionCode {
|
if !hasVersionCode {
|
||||||
@@ -162,17 +159,17 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkVersion string) (flags [
|
|||||||
return linkFlags, linkDeps, resDirs, overlayDirs, overlayFiles, rroDirs, manifestPath
|
return linkFlags, linkDeps, resDirs, overlayDirs, overlayFiles, rroDirs, manifestPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkVersion string) {
|
func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) {
|
||||||
if !ctx.Config().UnbundledBuild() {
|
if !ctx.Config().UnbundledBuild() {
|
||||||
sdkDep := decodeSdkDep(ctx, sdkVersion)
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
||||||
if sdkDep.frameworkResModule != "" {
|
if sdkDep.frameworkResModule != "" {
|
||||||
ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule)
|
ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkVersion string, extraLinkFlags ...string) {
|
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
||||||
linkFlags, linkDeps, resDirs, overlayDirs, overlayFiles, rroDirs, manifestPath := a.aapt2Flags(ctx, sdkVersion)
|
linkFlags, linkDeps, resDirs, overlayDirs, overlayFiles, rroDirs, manifestPath := a.aapt2Flags(ctx, sdkContext)
|
||||||
|
|
||||||
linkFlags = append(linkFlags, extraLinkFlags...)
|
linkFlags = append(linkFlags, extraLinkFlags...)
|
||||||
|
|
||||||
@@ -206,12 +203,12 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkVersion string, extraL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
||||||
func aaptLibs(ctx android.ModuleContext, sdkVersion string) (transitiveStaticLibs, deps android.Paths,
|
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, deps android.Paths,
|
||||||
flags []string) {
|
flags []string) {
|
||||||
|
|
||||||
var sharedLibs android.Paths
|
var sharedLibs android.Paths
|
||||||
|
|
||||||
sdkDep := decodeSdkDep(ctx, sdkVersion)
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
||||||
if sdkDep.useFiles {
|
if sdkDep.useFiles {
|
||||||
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
||||||
}
|
}
|
||||||
@@ -277,12 +274,12 @@ var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
|||||||
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
a.Module.deps(ctx)
|
a.Module.deps(ctx)
|
||||||
if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
|
if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
|
||||||
a.aapt.deps(ctx, String(a.deviceProperties.Sdk_version))
|
a.aapt.deps(ctx, sdkContext(a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
a.aapt.buildActions(ctx, String(a.deviceProperties.Sdk_version), "--static-lib")
|
a.aapt.buildActions(ctx, sdkContext(a), "--static-lib")
|
||||||
|
|
||||||
ctx.CheckbuildFile(a.proguardOptionsFile)
|
ctx.CheckbuildFile(a.proguardOptionsFile)
|
||||||
ctx.CheckbuildFile(a.exportPackage)
|
ctx.CheckbuildFile(a.exportPackage)
|
||||||
@@ -359,6 +356,14 @@ type AARImport struct {
|
|||||||
exportedStaticPackages android.Paths
|
exportedStaticPackages android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AARImport) sdkVersion() string {
|
||||||
|
return String(a.properties.Sdk_version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AARImport) minSdkVersion() string {
|
||||||
|
return a.sdkVersion()
|
||||||
|
}
|
||||||
|
|
||||||
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
||||||
|
|
||||||
func (a *AARImport) ExportPackage() android.Path {
|
func (a *AARImport) ExportPackage() android.Path {
|
||||||
@@ -383,7 +388,7 @@ func (a *AARImport) Name() string {
|
|||||||
|
|
||||||
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
if !ctx.Config().UnbundledBuild() {
|
if !ctx.Config().UnbundledBuild() {
|
||||||
sdkDep := decodeSdkDep(ctx, String(a.properties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, sdkContext(a))
|
||||||
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
|
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
|
||||||
ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule)
|
ctx.AddDependency(ctx.Module(), frameworkResTag, sdkDep.frameworkResModule)
|
||||||
}
|
}
|
||||||
@@ -450,7 +455,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
||||||
linkDeps = append(linkDeps, a.manifest)
|
linkDeps = append(linkDeps, a.manifest)
|
||||||
|
|
||||||
transitiveStaticLibs, libDeps, libFlags := aaptLibs(ctx, String(a.properties.Sdk_version))
|
transitiveStaticLibs, libDeps, libFlags := aaptLibs(ctx, sdkContext(a))
|
||||||
|
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
linkDeps = append(linkDeps, libDeps...)
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
|
@@ -56,7 +56,7 @@ func (library *Library) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
|
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
|
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
|
||||||
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
|
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
|
||||||
|
|
||||||
if library.jacocoReportClassesFile != nil {
|
if library.jacocoReportClassesFile != nil {
|
||||||
@@ -121,7 +121,7 @@ func (prebuilt *Import) AndroidMk() android.AndroidMkData {
|
|||||||
func(w io.Writer, outputFile android.Path) {
|
func(w io.Writer, outputFile android.Path) {
|
||||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
|
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
|
||||||
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
|
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
|
||||||
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
|
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
|
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
|
||||||
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
|
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
|
||||||
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
|
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
|
||||||
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
|
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -81,7 +81,7 @@ type certificate struct {
|
|||||||
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
a.Module.deps(ctx)
|
a.Module.deps(ctx)
|
||||||
if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
|
if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
|
||||||
a.aapt.deps(ctx, String(a.deviceProperties.Sdk_version))
|
a.aapt.deps(ctx, sdkContext(a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
// TODO: LOCAL_PACKAGE_OVERRIDES
|
// TODO: LOCAL_PACKAGE_OVERRIDES
|
||||||
// $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
|
// $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
|
||||||
|
|
||||||
a.aapt.buildActions(ctx, String(a.deviceProperties.Sdk_version), linkFlags...)
|
a.aapt.buildActions(ctx, sdkContext(a), linkFlags...)
|
||||||
|
|
||||||
// apps manifests are handled by aapt, don't let Module see them
|
// apps manifests are handled by aapt, don't let Module see them
|
||||||
a.properties.Manifest = nil
|
a.properties.Manifest = nil
|
||||||
|
@@ -70,7 +70,12 @@ func (j *Module) dxFlags(ctx android.ModuleContext) []string {
|
|||||||
"--verbose")
|
"--verbose")
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = append(flags, "--min-api "+j.minSdkVersionNumber(ctx))
|
minSdkVersion, err := sdkVersionToNumberAsString(ctx, j.minSdkVersion())
|
||||||
|
if err != nil {
|
||||||
|
ctx.PropertyErrorf("min_sdk_version", "%s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = append(flags, "--min-api "+minSdkVersion)
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -332,9 +332,17 @@ func DroiddocHostFactory() android.Module {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Javadoc) sdkVersion() string {
|
||||||
|
return String(j.properties.Sdk_version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *Javadoc) minSdkVersion() string {
|
||||||
|
return j.sdkVersion()
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
|
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
||||||
if sdkDep.useDefaultLibs {
|
if sdkDep.useDefaultLibs {
|
||||||
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
||||||
if ctx.Config().TargetOpenJDK9() {
|
if ctx.Config().TargetOpenJDK9() {
|
||||||
@@ -432,7 +440,7 @@ func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|||||||
func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
|
func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
|
||||||
var deps deps
|
var deps deps
|
||||||
|
|
||||||
sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
||||||
if sdkDep.invalidVersion {
|
if sdkDep.invalidVersion {
|
||||||
ctx.AddMissingDependencies(sdkDep.modules)
|
ctx.AddMissingDependencies(sdkDep.modules)
|
||||||
} else if sdkDep.useFiles {
|
} else if sdkDep.useFiles {
|
||||||
@@ -455,7 +463,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
case Dependency:
|
case Dependency:
|
||||||
deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
|
deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
|
||||||
case SdkLibraryDependency:
|
case SdkLibraryDependency:
|
||||||
sdkVersion := String(j.properties.Sdk_version)
|
sdkVersion := j.sdkVersion()
|
||||||
linkType := javaSdk
|
linkType := javaSdk
|
||||||
if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
|
if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
|
||||||
linkType = javaSystem
|
linkType = javaSystem
|
||||||
@@ -539,7 +547,7 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
var bootClasspathArgs, classpathArgs string
|
var bootClasspathArgs, classpathArgs string
|
||||||
|
|
||||||
javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), String(j.properties.Sdk_version))
|
javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
|
||||||
if len(deps.bootClasspath) > 0 {
|
if len(deps.bootClasspath) > 0 {
|
||||||
var systemModules classpath
|
var systemModules classpath
|
||||||
if deps.systemModules != nil {
|
if deps.systemModules != nil {
|
||||||
@@ -639,7 +647,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
implicits = append(implicits, deps.classpath...)
|
implicits = append(implicits, deps.classpath...)
|
||||||
|
|
||||||
var bootClasspathArgs string
|
var bootClasspathArgs string
|
||||||
javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), String(d.Javadoc.properties.Sdk_version))
|
javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
|
||||||
// Doclava has problem with "-source 1.9", so override javaVersion when Doclava
|
// Doclava has problem with "-source 1.9", so override javaVersion when Doclava
|
||||||
// is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
|
// is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
|
||||||
// replaced by Metalava.
|
// replaced by Metalava.
|
||||||
|
118
java/java.go
118
java/java.go
@@ -168,9 +168,14 @@ type CompilerDeviceProperties struct {
|
|||||||
// list of module-specific flags that will be used for dex compiles
|
// list of module-specific flags that will be used for dex compiles
|
||||||
Dxflags []string `android:"arch_variant"`
|
Dxflags []string `android:"arch_variant"`
|
||||||
|
|
||||||
// if not blank, set to the version of the sdk to compile against
|
// if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
|
||||||
|
// sdk if platform_apis is not set.
|
||||||
Sdk_version *string
|
Sdk_version *string
|
||||||
|
|
||||||
|
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
|
||||||
|
// Defaults to sdk_version if not set.
|
||||||
|
Min_sdk_version *string
|
||||||
|
|
||||||
// if true, compile against the platform APIs instead of an SDK.
|
// if true, compile against the platform APIs instead of an SDK.
|
||||||
Platform_apis *bool
|
Platform_apis *bool
|
||||||
|
|
||||||
@@ -355,20 +360,6 @@ type sdkDep struct {
|
|||||||
aidl android.Path
|
aidl android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
func sdkStringToNumber(ctx android.BaseContext, v string) int {
|
|
||||||
switch v {
|
|
||||||
case "", "current", "system_current", "test_current", "core_current":
|
|
||||||
return android.FutureApiLevel
|
|
||||||
default:
|
|
||||||
if i, err := strconv.Atoi(android.GetNumericSdkVersion(v)); err != nil {
|
|
||||||
ctx.PropertyErrorf("sdk_version", "invalid sdk version")
|
|
||||||
return -1
|
|
||||||
} else {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
|
func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
|
||||||
return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
|
return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
|
||||||
}
|
}
|
||||||
@@ -379,10 +370,62 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
|
|||||||
ctx.Config().UnbundledBuild())
|
ctx.Config().UnbundledBuild())
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
|
func (j *Module) sdkVersion() string {
|
||||||
i := sdkStringToNumber(ctx, v)
|
return String(j.deviceProperties.Sdk_version)
|
||||||
if i == -1 {
|
}
|
||||||
// Invalid sdk version, error handled by sdkStringToNumber.
|
|
||||||
|
func (j *Module) minSdkVersion() string {
|
||||||
|
if j.deviceProperties.Min_sdk_version != nil {
|
||||||
|
return *j.deviceProperties.Min_sdk_version
|
||||||
|
}
|
||||||
|
return j.sdkVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
type sdkContext interface {
|
||||||
|
// sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
|
||||||
|
sdkVersion() string
|
||||||
|
// minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
|
||||||
|
minSdkVersion() string
|
||||||
|
}
|
||||||
|
|
||||||
|
func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
|
||||||
|
switch v {
|
||||||
|
case "", "current", "system_current", "test_current", "core_current":
|
||||||
|
return ctx.Config().DefaultAppTargetSdk()
|
||||||
|
default:
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
|
||||||
|
// it returns android.FutureApiLevel (10000).
|
||||||
|
func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
|
||||||
|
switch v {
|
||||||
|
case "", "current", "test_current", "system_current", "core_current":
|
||||||
|
return ctx.Config().DefaultAppTargetSdkInt(), nil
|
||||||
|
default:
|
||||||
|
n := android.GetNumericSdkVersion(v)
|
||||||
|
if i, err := strconv.Atoi(n); err != nil {
|
||||||
|
return -1, fmt.Errorf("invalid sdk version %q", n)
|
||||||
|
} else {
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) {
|
||||||
|
n, err := sdkVersionToNumber(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strconv.Itoa(n), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
|
||||||
|
v := sdkContext.sdkVersion()
|
||||||
|
i, err := sdkVersionToNumber(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
ctx.PropertyErrorf("sdk_version", "%s", err)
|
||||||
return sdkDep{}
|
return sdkDep{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,7 +528,7 @@ func decodeSdkDep(ctx android.BaseContext, v string) sdkDep {
|
|||||||
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
if !Bool(j.properties.No_standard_libs) {
|
if !Bool(j.properties.No_standard_libs) {
|
||||||
sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
||||||
if sdkDep.useDefaultLibs {
|
if sdkDep.useDefaultLibs {
|
||||||
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
||||||
if ctx.Config().TargetOpenJDK9() {
|
if ctx.Config().TargetOpenJDK9() {
|
||||||
@@ -638,7 +681,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getLinkType(m *Module, name string) linkType {
|
func getLinkType(m *Module, name string) linkType {
|
||||||
ver := String(m.deviceProperties.Sdk_version)
|
ver := m.sdkVersion()
|
||||||
noStdLibs := Bool(m.properties.No_standard_libs)
|
noStdLibs := Bool(m.properties.No_standard_libs)
|
||||||
switch {
|
switch {
|
||||||
case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
|
case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
|
||||||
@@ -697,7 +740,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
var deps deps
|
var deps deps
|
||||||
|
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
sdkDep := decodeSdkDep(ctx, String(j.deviceProperties.Sdk_version))
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
||||||
if sdkDep.invalidVersion {
|
if sdkDep.invalidVersion {
|
||||||
ctx.AddMissingDependencies(sdkDep.modules)
|
ctx.AddMissingDependencies(sdkDep.modules)
|
||||||
} else if sdkDep.useFiles {
|
} else if sdkDep.useFiles {
|
||||||
@@ -808,16 +851,19 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJavaVersion(ctx android.ModuleContext, javaVersion, sdkVersion string) string {
|
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
|
||||||
var ret string
|
var ret string
|
||||||
sdk := sdkStringToNumber(ctx, sdkVersion)
|
sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion())
|
||||||
|
if err != nil {
|
||||||
|
ctx.PropertyErrorf("sdk_version", "%s", err)
|
||||||
|
}
|
||||||
if javaVersion != "" {
|
if javaVersion != "" {
|
||||||
ret = javaVersion
|
ret = javaVersion
|
||||||
} else if ctx.Device() && sdk <= 23 {
|
} else if ctx.Device() && sdk <= 23 {
|
||||||
ret = "1.7"
|
ret = "1.7"
|
||||||
} else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
|
} else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
|
||||||
ret = "1.8"
|
ret = "1.8"
|
||||||
} else if ctx.Device() && sdkVersion != "" && sdk == android.FutureApiLevel {
|
} else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
|
||||||
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
|
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
|
||||||
ret = "1.8"
|
ret = "1.8"
|
||||||
} else {
|
} else {
|
||||||
@@ -864,8 +910,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
|
|||||||
}
|
}
|
||||||
|
|
||||||
// javaVersion flag.
|
// javaVersion flag.
|
||||||
flags.javaVersion = getJavaVersion(ctx,
|
flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
|
||||||
String(j.properties.Java_version), String(j.deviceProperties.Sdk_version))
|
|
||||||
|
|
||||||
// classpath
|
// classpath
|
||||||
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
|
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
|
||||||
@@ -1205,17 +1250,6 @@ func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||||||
return instrumentedJar
|
return instrumentedJar
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
|
|
||||||
// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
|
|
||||||
func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
|
|
||||||
switch String(j.deviceProperties.Sdk_version) {
|
|
||||||
case "", "current", "test_current", "system_current", "core_current":
|
|
||||||
return strconv.Itoa(ctx.Config().DefaultAppTargetSdkInt())
|
|
||||||
default:
|
|
||||||
return android.GetNumericSdkVersion(String(j.deviceProperties.Sdk_version))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Module) installable() bool {
|
func (j *Module) installable() bool {
|
||||||
return BoolDefault(j.properties.Installable, true)
|
return BoolDefault(j.properties.Installable, true)
|
||||||
}
|
}
|
||||||
@@ -1459,6 +1493,14 @@ type Import struct {
|
|||||||
exportedSdkLibs []string
|
exportedSdkLibs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Import) sdkVersion() string {
|
||||||
|
return String(j.properties.Sdk_version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *Import) minSdkVersion() string {
|
||||||
|
return j.sdkVersion()
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Import) Prebuilt() *android.Prebuilt {
|
func (j *Import) Prebuilt() *android.Prebuilt {
|
||||||
return &j.prebuilt
|
return &j.prebuilt
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user