diff options
author | 2022-02-15 12:55:11 +0000 | |
---|---|---|
committer | 2022-02-21 16:43:43 +0000 | |
commit | 3a3f169b5634ef6a7c9ad1040e7cf92dd60a37da (patch) | |
tree | e9cf98d7bdf017d4225e0b2baef544eb456734ea /java/prebuilt_apis.go | |
parent | 377318b33fca4bde6cea3b5d5059c3aceab73890 (diff) |
Add support for sdk extensions in prebuilt_apis
This makes it possible to pass an extensions_dir containing finalized
module APIs to prebuilt_apis. The extension versions are compared to the
api level versions to figure out what the "latest" finalized API is for
each module. This is done using the base_sdk_extension_version, such
that any extension higher than than base_sdk_extension_version is
assumed to be finalized after any of the existing api level versions.
Bug: 220086085
Test: prebuilt_apis_test.go
Test: existing module in prebuilts/sdk
Change-Id: Ib792f84202d436f594ba5e8716c6a187f9cd60dc
Diffstat (limited to 'java/prebuilt_apis.go')
-rw-r--r-- | java/prebuilt_apis.go | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index f7841b53d..44650a6d0 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -38,6 +38,11 @@ type prebuiltApisProperties struct { // list of api version directories Api_dirs []string + // Directory containing finalized api txt files for extension versions. + // Extension versions higher than the base sdk extension version will + // be assumed to be finalized later than all Api_dirs. + Extensions_dir *string + // The next API directory can optionally point to a directory where // files incompatibility-tracking files are stored for the current // "in progress" API. Each module present in one of the api_dirs will have @@ -152,6 +157,13 @@ func globApiDirs(mctx android.LoadHookContext, p *prebuiltApis, api_dir_glob str return files } +// globExtensionDirs collects all the files under the extension dir (for all versions and scopes) that match the given glob +// <extension-dir>/<version>/<scope>/<glob> for all version and scope. +func globExtensionDirs(mctx android.LoadHookContext, p *prebuiltApis, extension_dir_glob string) []string { + // <extensions-dir>/<num>/<extension-dir-glob> + return globScopeDir(mctx, *p.properties.Extensions_dir+"/*", extension_dir_glob) +} + // globScopeDir collects all the files in the given subdir across all scopes that match the given glob, e.g. '*.jar' or 'api/*.txt'. // <subdir>/<scope>/<glob> for all scope. func globScopeDir(mctx android.LoadHookContext, subdir string, subdir_glob string) []string { @@ -222,17 +234,32 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { version int } - latest := make(map[string]latestApiInfo) - for _, f := range apiLevelFiles { - module, version, scope := parseFinalizedPrebuiltPath(mctx, f) - if strings.HasSuffix(module, "incompatibilities") { - continue + getLatest := func(files []string) map[string]latestApiInfo { + m := make(map[string]latestApiInfo) + for _, f := range files { + module, version, scope := parseFinalizedPrebuiltPath(mctx, f) + if strings.HasSuffix(module, "incompatibilities") { + continue + } + key := module + "." + scope + info, exists := m[key] + if !exists || version > info.version { + m[key] = latestApiInfo{module, scope, f, version} + } } + return m + } - key := module + "." + scope - info, exists := latest[key] - if !exists || version > info.version { - latest[key] = latestApiInfo{module, scope, f, version} + latest := getLatest(apiLevelFiles) + if p.properties.Extensions_dir != nil { + extensionApiFiles := globExtensionDirs(mctx, p, "api/*.txt") + for k, v := range getLatest(extensionApiFiles) { + if v.version > mctx.Config().PlatformBaseSdkExtensionVersion() { + if _, exists := latest[k]; !exists { + mctx.ModuleErrorf("Module %v finalized for extension %d but never during an API level; likely error", v.module, v.version) + } + latest[k] = v + } } } |