diff --git a/android/util.go b/android/util.go index 8dbf21459..65c5f1b28 100644 --- a/android/util.go +++ b/android/util.go @@ -79,6 +79,20 @@ func JoinWithSuffix(strs []string, suffix string, separator string) string { 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 064d9d9c5..1ff2a6eb6 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go @@ -17,7 +17,6 @@ package dexpreopt import ( "encoding/json" "fmt" - "sort" "strings" "github.com/google/blueprint" @@ -142,16 +141,6 @@ func (libPaths LibraryPaths) AddLibraryPaths(otherPaths LibraryPaths) { } } -// 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 8c9f0a2b5..8deb0a3a6 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -37,7 +37,6 @@ import ( "fmt" "path/filepath" "runtime" - "sort" "strings" "android/soong/android" @@ -208,15 +207,6 @@ type classLoaderContextMap map[int]*classLoaderContext 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 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g 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 e3622dda7..c822add74 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -121,7 +121,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { 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 0089545ca..0e936118c 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1495,7 +1495,7 @@ func TestJavaSdkLibrary(t *testing.T) { // 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) }