Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
diff --git a/java/app.go b/java/app.go
index 4f06087..19995d5 100755
--- a/java/app.go
+++ b/java/app.go
@@ -164,7 +164,7 @@
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx)
- if String(a.appProperties.Stl) == "c++_shared" && a.sdkVersion() == "" {
+ if String(a.appProperties.Stl) == "c++_shared" && !a.sdkVersion().specified() {
ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
}
@@ -213,7 +213,7 @@
// 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 := sdkVersionToNumber(ctx, a.minSdkVersion())
+ minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx)
if err != nil {
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
}
@@ -1273,22 +1273,22 @@
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
}
-func (r *RuntimeResourceOverlay) sdkVersion() string {
- return String(r.properties.Sdk_version)
+func (r *RuntimeResourceOverlay) sdkVersion() sdkSpec {
+ return sdkSpecFrom(String(r.properties.Sdk_version))
}
func (r *RuntimeResourceOverlay) systemModules() string {
return ""
}
-func (r *RuntimeResourceOverlay) minSdkVersion() string {
+func (r *RuntimeResourceOverlay) minSdkVersion() sdkSpec {
if r.properties.Min_sdk_version != nil {
- return *r.properties.Min_sdk_version
+ return sdkSpecFrom(*r.properties.Min_sdk_version)
}
return r.sdkVersion()
}
-func (r *RuntimeResourceOverlay) targetSdkVersion() string {
+func (r *RuntimeResourceOverlay) targetSdkVersion() sdkSpec {
return r.sdkVersion()
}