Merge "Use common helper functions for getting sorted map keys."
This commit is contained in:
commit
49b1e9b6ce
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()...)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue