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

Commit 9053375b authored by Colin Cross's avatar Colin Cross Committed by android-build-merger
Browse files

Merge changes Ifcb338e6,Ie509ed80,I270fed60,Id825cb75,I92a963bd

am: cc2d1196

Change-Id: Iede0d74591eb60148ddd7c187b403ece2fc8dde5
parents 73e4b31a cc2d1196
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ bootstrap_go_package {
        "android/prebuilt_etc.go",
        "android/proto.go",
        "android/register.go",
        "android/rule_builder.go",
        "android/sh_binary.go",
        "android/singleton.go",
        "android/testing.go",
@@ -77,9 +78,11 @@ bootstrap_go_package {
        "android/expand_test.go",
        "android/namespace_test.go",
        "android/neverallow_test.go",
        "android/onceper_test.go",
        "android/paths_test.go",
        "android/prebuilt_test.go",
        "android/prebuilt_etc_test.go",
        "android/rule_builder_test.go",
        "android/util_test.go",
        "android/variable_test.go",
    ],
+2 −1
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blu

var apexData OncePer
var apexNamesMapMutex sync.Mutex
var apexNamesKey = NewOnceKey("apexNames")

// This structure maintains the global mapping in between modules and APEXes.
// Examples:
@@ -147,7 +148,7 @@ var apexNamesMapMutex sync.Mutex
// apexNamesMap()["foo"]["bar"] == false: module foo is indirectly depended on by APEX bar
// apexNamesMap()["foo"]["bar"] doesn't exist: foo is not built for APEX bar
func apexNamesMap() map[string]map[string]bool {
	return apexData.Once("apexNames", func() interface{} {
	return apexData.Once(apexNamesKey, func() interface{} {
		return make(map[string]map[string]bool)
	}).(map[string]map[string]bool)
}
+3 −1
Original line number Diff line number Diff line
@@ -51,8 +51,10 @@ func GetApiLevelsJson(ctx PathContext) WritablePath {
	return PathForOutput(ctx, "api_levels.json")
}

var apiLevelsMapKey = NewOnceKey("ApiLevelsMap")

func getApiLevelsMap(config Config) map[string]int {
	return config.Once("ApiLevelsMap", func() interface{} {
	return config.Once(apiLevelsMapKey, func() interface{} {
		baseApiLevel := 9000
		apiLevelsMap := map[string]int{
			"G":     9,
+1 −1
Original line number Diff line number Diff line
@@ -879,7 +879,7 @@ func InitArchModule(m Module) {
				propertiesValue.Interface()))
		}

		archPropTypes := archPropTypeMap.Once(t, func() interface{} {
		archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
			return createArchType(t)
		}).([]reflect.Type)

+22 −2
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ type OncePer struct {
	valuesLock sync.Mutex
}

type valueMap map[interface{}]interface{}

// Once computes a value the first time it is called with a given key per OncePer, and returns the
// value without recomputing when called with the same key.  key must be hashable.
func (once *OncePer) Once(key interface{}, value func() interface{}) interface{} {
@@ -50,6 +48,8 @@ func (once *OncePer) Once(key interface{}, value func() interface{}) interface{}
	return v
}

// Get returns the value previously computed with Once for a given key.  If Once has not been called for the given
// key Get will panic.
func (once *OncePer) Get(key interface{}) interface{} {
	v, ok := once.values.Load(key)
	if !ok {
@@ -59,10 +59,12 @@ func (once *OncePer) Get(key interface{}) interface{} {
	return v
}

// OnceStringSlice is the same as Once, but returns the value cast to a []string
func (once *OncePer) OnceStringSlice(key interface{}, value func() []string) []string {
	return once.Once(key, func() interface{} { return value() }).([]string)
}

// OnceStringSlice is the same as Once, but returns two values cast to []string
func (once *OncePer) Once2StringSlice(key interface{}, value func() ([]string, []string)) ([]string, []string) {
	type twoStringSlice [2][]string
	s := once.Once(key, func() interface{} {
@@ -72,3 +74,21 @@ func (once *OncePer) Once2StringSlice(key interface{}, value func() ([]string, [
	}).(twoStringSlice)
	return s[0], s[1]
}

// OnceKey is an opaque type to be used as the key in calls to Once.
type OnceKey struct {
	key interface{}
}

// NewOnceKey returns an opaque OnceKey object for the provided key.  Two calls to NewOnceKey with the same key string
// DO NOT produce the same OnceKey object.
func NewOnceKey(key string) OnceKey {
	return OnceKey{&key}
}

// NewCustomOnceKey returns an opaque OnceKey object for the provided key.  The key can be any type that is valid as the
// key in a map, i.e. comparable.  Two calls to NewCustomOnceKey with key values that compare equal will return OnceKey
// objects that access the same value stored with Once.
func NewCustomOnceKey(key interface{}) OnceKey {
	return OnceKey{key}
}
Loading