diff options
author | 2021-01-22 15:05:04 +0000 | |
---|---|---|
committer | 2021-01-25 10:58:41 +0000 | |
commit | 370fd0b0500e8817eb1f4cc94ba0fbc29b8444a8 (patch) | |
tree | 1562809fe93e9bf55b4e787e1b13518d62685a57 /java/prebuilt_apis.go | |
parent | f17b07fc52b49896d0a357f3deeba7177180907c (diff) |
Minor cleanup in prebuilt_apis
Use ints instead of strings for version comparison.
Bug: 178171189
Test: m
Change-Id: I53d71b138a64b902b3f00adafec5d354630a5e35
Diffstat (limited to 'java/prebuilt_apis.go')
-rw-r--r-- | java/prebuilt_apis.go | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index bcc6cc0cf..0ffbaaa40 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -15,7 +15,7 @@ package java import ( - "sort" + "strconv" "strings" "github.com/google/blueprint/proptools" @@ -173,39 +173,38 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { // construct a map to find out the latest api file path // for each (<module>, <scope>) pair. type latestApiInfo struct { - module string - scope string - apiver string - path string + module string + scope string + version int + path string } - m := make(map[string]latestApiInfo) + // Create filegroups for all (<module>, <scope, <version>) triplets, + // and a "latest" filegroup variant for each (<module>, <scope>) pair + m := make(map[string]latestApiInfo) for _, f := range files { - // create a filegroup for each api txt file localPath := strings.TrimPrefix(f, mydir) module, apiver, scope := parseApiFilePath(mctx, localPath) createFilegroup(mctx, module, scope, apiver, localPath) - // find the latest apiver + version, err := strconv.Atoi(apiver) + if err != nil { + mctx.ModuleErrorf("Found finalized API files in non-numeric dir %v", apiver) + return + } + key := module + "." + scope info, ok := m[key] if !ok { - m[key] = latestApiInfo{module, scope, apiver, localPath} - } else if len(apiver) > len(info.apiver) || (len(apiver) == len(info.apiver) && - strings.Compare(apiver, info.apiver) > 0) { - info.apiver = apiver + m[key] = latestApiInfo{module, scope, version, localPath} + } else if version > info.version { + info.version = version info.path = localPath m[key] = info } } - // create filegroups for the latest version of (<module>, <scope>) pairs - // sort the keys in order to make build.ninja stable - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { + // Sort the keys in order to make build.ninja stable + for _, k := range android.SortedStringKeys(m) { info := m[k] createFilegroup(mctx, info.module, info.scope, "latest", info.path) } |