Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49b1e9b6 authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Gerrit Code Review
Browse files

Merge "Use common helper functions for getting sorted map keys."

parents bde92fc6 b8063c6a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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 {
+0 −11
Original line number Diff line number Diff line
@@ -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
+1 −11
Original line number Diff line number Diff line
@@ -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 {
+1 −1
Original line number Diff line number Diff line
@@ -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()...)
+1 −1
Original line number Diff line number Diff line
@@ -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)
		}