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/sdk_library.go b/java/sdk_library.go
index 72c4a7c..530e02c 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -650,27 +650,27 @@
mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
}
-func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
- var api, v string
- if sdkVersion == "" || sdkVersion == "none" {
- api = "system"
- v = "current"
- } else if strings.Contains(sdkVersion, "_") {
- t := strings.Split(sdkVersion, "_")
- api = t[0]
- v = t[1]
+func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec) android.Paths {
+ var ver sdkVersion
+ var kind sdkKind
+ if s.usePrebuilt(ctx) {
+ ver = s.version
+ kind = s.kind
} else {
- api = "public"
- v = sdkVersion
+ // We don't have prebuilt SDK for the specific sdkVersion.
+ // Instead of breaking the build, fallback to use "system_current"
+ ver = sdkVersionCurrent
+ kind = sdkSystem
}
- dir := filepath.Join("prebuilts", "sdk", v, api)
+
+ dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String())
jar := filepath.Join(dir, module.BaseModuleName()+".jar")
jarPath := android.ExistentPathForSource(ctx, jar)
if !jarPath.Valid() {
if ctx.Config().AllowMissingDependencies() {
return android.Paths{android.PathForSource(ctx, jar)}
} else {
- ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", sdkVersion, jar)
+ ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar)
}
return nil
}
@@ -678,32 +678,34 @@
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
+func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the stubs.
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return module.PrebuiltJars(ctx, sdkVersion)
} else {
- if strings.HasPrefix(sdkVersion, "system_") {
+ switch sdkVersion.kind {
+ case sdkSystem:
return module.systemApiStubsPath
- } else if sdkVersion == "" {
+ case sdkPrivate:
return module.Library.HeaderJars()
- } else {
+ default:
return module.publicApiStubsPath
}
}
}
// to satisfy SdkLibraryDependency interface
-func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
+func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the stubs.
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return module.PrebuiltJars(ctx, sdkVersion)
} else {
- if strings.HasPrefix(sdkVersion, "system_") {
+ switch sdkVersion.kind {
+ case sdkSystem:
return module.systemApiStubsImplPath
- } else if sdkVersion == "" {
+ case sdkPrivate:
return module.Library.ImplementationJars()
- } else {
+ default:
return module.publicApiStubsImplPath
}
}
@@ -923,13 +925,13 @@
}
// to satisfy SdkLibraryDependency interface
-func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
+func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the prebuilt stubs.
return module.stubsPath
}
// to satisfy SdkLibraryDependency interface
-func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
+func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
// This module is just a wrapper for the stubs.
return module.stubsPath
}