Use common helper functions for getting sorted map keys.
Add a new helper SortedIntKeys similar to SortedStringKeys.
Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: I08a43ec2cae7d1a82531295aca1a0658e3a0dd6f
diff --git a/android/util.go b/android/util.go
index 8dbf214..65c5f1b 100644
--- a/android/util.go
+++ b/android/util.go
@@ -79,6 +79,20 @@
return string(ret)
}
+func SortedIntKeys(m interface{}) []int {
+ v := reflect.ValueOf(m)
+ if v.Kind() != reflect.Map {
+ panic(fmt.Sprintf("%#v is not a map", m))
+ }
+ keys := v.MapKeys()
+ s := make([]int, 0, len(keys))
+ for _, key := range keys {
+ s = append(s, int(key.Int()))
+ }
+ sort.Ints(s)
+ return s
+}
+
func SortedStringKeys(m interface{}) []string {
v := reflect.ValueOf(m)
if v.Kind() != reflect.Map {
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 064d9d9..1ff2a6e 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -17,7 +17,6 @@
import (
"encoding/json"
"fmt"
- "sort"
"strings"
"github.com/google/blueprint"
@@ -142,16 +141,6 @@
}
}
-// Return sorted names of the libraries in the map.
-func (libPaths LibraryPaths) Names() []string {
- keys := make([]string, 0, len(libPaths))
- for k := range libPaths {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- return keys
-}
-
type ModuleConfig struct {
Name string
DexLocation string // dex location on device
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 8c9f0a2..8deb0a3 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -37,7 +37,6 @@
"fmt"
"path/filepath"
"runtime"
- "sort"
"strings"
"android/soong/android"
@@ -208,15 +207,6 @@
const anySdkVersion int = 9999 // should go last in class loader context
-func (m classLoaderContextMap) getSortedKeys() []int {
- keys := make([]int, 0, len(m))
- for k := range m {
- keys = append(keys, k)
- }
- sort.Ints(keys)
- return keys
-}
-
func (m classLoaderContextMap) getValue(sdkVer int) *classLoaderContext {
if _, ok := m[sdkVer]; !ok {
m[sdkVer] = &classLoaderContext{}
@@ -342,7 +332,7 @@
cmd := rule.Command().
Text(`eval "$(`).Tool(globalSoong.ConstructContext).
Text(` --target-sdk-version ${target_sdk_version}`)
- for _, ver := range classLoaderContexts.getSortedKeys() {
+ for _, ver := range android.SortedIntKeys(classLoaderContexts) {
clc := classLoaderContexts.getValue(ver)
verString := fmt.Sprintf("%d", ver)
if ver == anySdkVersion {
diff --git a/java/androidmk.go b/java/androidmk.go
index 144268f..b1582d9 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -121,7 +121,7 @@
entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile)
}
- entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", library.exportedSdkLibs.Names()...)
+ entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", android.SortedStringKeys(library.exportedSdkLibs)...)
if len(library.additionalCheckedModules) != 0 {
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
diff --git a/java/java_test.go b/java/java_test.go
index 0089545..0e93611 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1495,7 +1495,7 @@
// test if baz has exported SDK lib names foo and bar to qux
qux := ctx.ModuleForTests("qux", "android_common")
if quxLib, ok := qux.Module().(*Library); ok {
- sdkLibs := quxLib.ExportedSdkLibs().Names()
+ sdkLibs := android.SortedStringKeys(quxLib.ExportedSdkLibs())
if w := []string{"bar", "foo", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) {
t.Errorf("qux should export %q but exports %q", w, sdkLibs)
}