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

Commit b6fd6f75 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Clean up sortedKeys function"

parents 90ef4b9c 1a365c6a
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ import (
	"fmt"
	"path"
	"path/filepath"
	"sort"
	"strings"
	"text/scanner"

@@ -1658,17 +1657,8 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
		return
	}

	sortedKeys := func(m map[string]Paths) []string {
		s := make([]string, 0, len(m))
		for k := range m {
			s = append(s, k)
		}
		sort.Strings(s)
		return s
	}

	// Ensure ancestor directories are in modulesInDir
	dirs := sortedKeys(modulesInDir)
	dirs := SortedStringKeys(modulesInDir)
	for _, dir := range dirs {
		dir := parentDir(dir)
		for dir != "." && dir != "/" {
@@ -1681,7 +1671,6 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
	}

	// Make directories build their direct subdirectories
	dirs = sortedKeys(modulesInDir)
	for _, dir := range dirs {
		p := parentDir(dir)
		if p != "." && p != "/" {
@@ -1738,8 +1727,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
	}

	// Wrap those into host|host-cross|target phony rules
	osClasses := sortedKeys(osClass)
	for _, class := range osClasses {
	for _, class := range SortedStringKeys(osClass) {
		ctx.Build(pctx, BuildParams{
			Rule:      blueprint.Phony,
			Output:    PathForPhony(ctx, class),
+10 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package android

import (
	"fmt"
	"reflect"
	"regexp"
	"runtime"
	"sort"
@@ -77,10 +78,15 @@ func JoinWithSuffix(strs []string, suffix string, separator string) string {
	return string(ret)
}

func sortedKeys(m map[string][]string) []string {
	s := make([]string, 0, len(m))
	for k := range m {
		s = append(s, k)
func SortedStringKeys(m interface{}) []string {
	v := reflect.ValueOf(m)
	if v.Kind() != reflect.Map {
		panic(fmt.Sprintf("%#v is not a map", m))
	}
	keys := v.MapKeys()
	s := make([]string, 0, len(keys))
	for _, key := range keys {
		s = append(s, key.String())
	}
	sort.Strings(s)
	return s
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ blueprint_go_binary {
        "androidmk-parser",
        "blueprint-parser",
        "bpfix-lib",
        "soong-android",
    ],
}

+2 −11
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@
package main

import (
	"android/soong/android"
	mkparser "android/soong/androidmk/parser"
	"fmt"
	"sort"
	"strings"

	bpparser "github.com/google/blueprint/parser"
@@ -335,15 +335,6 @@ func classifyLocalOrGlobalPath(value bpparser.Expression) (string, bpparser.Expr
	}
}

func sortedMapKeys(inputMap map[string]string) (sortedKeys []string) {
	keys := make([]string, 0, len(inputMap))
	for key := range inputMap {
		keys = append(keys, key)
	}
	sort.Strings(keys)
	return keys
}

// splitAndAssign splits a Make list into components and then
// creates the corresponding variable assignments.
func splitAndAssign(ctx variableAssignmentContext, splitFunc listSplitFunc, namesByClassification map[string]string) error {
@@ -357,7 +348,7 @@ func splitAndAssign(ctx variableAssignmentContext, splitFunc listSplitFunc, name
		return err
	}

	for _, nameClassification := range sortedMapKeys(namesByClassification) {
	for _, nameClassification := range android.SortedStringKeys(namesByClassification) {
		name := namesByClassification[nameClassification]
		if component, ok := lists[nameClassification]; ok && !emptyList(component) {
			err = setVariable(ctx.file, ctx.append, ctx.prefix, name, component, true)