Fix apex_test.go and add it to Android.bp
apex_test.go wasn't listed in the Android.bp file, which allowed
it to bitrot. Make the API level methods take a PathContext
so that they can be called from a test using configErrorWrapper.
Also fix an int that was converted to a string.
Test: apex_test.go
Change-Id: I1ff87134c837bd5d344d22550baabde10d1b0b2e
diff --git a/android/Android.bp b/android/Android.bp
index a1b5159..4ba5241 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -63,6 +63,7 @@
testSrcs: [
"android_test.go",
"androidmk_test.go",
+ "apex_test.go",
"arch_test.go",
"config_test.go",
"csuite_config_test.go",
diff --git a/android/apex.go b/android/apex.go
index c886962..1589a17 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -42,7 +42,7 @@
InApexes []string
}
-func (i ApexInfo) mergedName(ctx EarlyModuleContext) string {
+func (i ApexInfo) mergedName(ctx PathContext) string {
name := "apex" + strconv.Itoa(i.MinSdkVersion(ctx).FinalOrFutureInt())
for _, sdk := range i.RequiredSdks {
name += "_" + sdk.Name + "_" + sdk.Version
@@ -50,7 +50,7 @@
return name
}
-func (this *ApexInfo) MinSdkVersion(ctx EarlyModuleContext) ApiLevel {
+func (this *ApexInfo) MinSdkVersion(ctx PathContext) ApiLevel {
return ApiLevelOrPanic(ctx, this.MinSdkVersionStr)
}
@@ -358,7 +358,7 @@
// mergeApexVariations deduplicates APEX variations that would build identically into a common
// variation. It returns the reduced list of variations and a list of aliases from the original
// variation names to the new variation names.
-func mergeApexVariations(ctx EarlyModuleContext, apexVariations []ApexInfo) (merged []ApexInfo, aliases [][2]string) {
+func mergeApexVariations(ctx PathContext, apexVariations []ApexInfo) (merged []ApexInfo, aliases [][2]string) {
sort.Sort(byApexName(apexVariations))
seen := make(map[string]int)
for _, apexInfo := range apexVariations {
diff --git a/android/apex_test.go b/android/apex_test.go
index db02833..dd372f7 100644
--- a/android/apex_test.go
+++ b/android/apex_test.go
@@ -29,10 +29,10 @@
{
name: "single",
in: []ApexInfo{
- {"foo", 10000, false, nil, []string{"foo"}},
+ {"foo", "current", false, nil, []string{"foo"}},
},
wantMerged: []ApexInfo{
- {"apex10000", 10000, false, nil, []string{"foo"}},
+ {"apex10000", "current", false, nil, []string{"foo"}},
},
wantAliases: [][2]string{
{"foo", "apex10000"},
@@ -41,11 +41,11 @@
{
name: "merge",
in: []ApexInfo{
- {"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
- {"bar", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar"}},
+ {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
+ {"bar", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar"}},
},
wantMerged: []ApexInfo{
- {"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}},
+ {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}},
},
wantAliases: [][2]string{
{"bar", "apex10000_baz_1"},
@@ -55,12 +55,12 @@
{
name: "don't merge version",
in: []ApexInfo{
- {"foo", 10000, false, nil, []string{"foo"}},
- {"bar", 30, false, nil, []string{"bar"}},
+ {"foo", "current", false, nil, []string{"foo"}},
+ {"bar", "30", false, nil, []string{"bar"}},
},
wantMerged: []ApexInfo{
- {"apex30", 30, false, nil, []string{"bar"}},
- {"apex10000", 10000, false, nil, []string{"foo"}},
+ {"apex30", "30", false, nil, []string{"bar"}},
+ {"apex10000", "current", false, nil, []string{"foo"}},
},
wantAliases: [][2]string{
{"bar", "apex30"},
@@ -70,11 +70,11 @@
{
name: "merge updatable",
in: []ApexInfo{
- {"foo", 10000, false, nil, []string{"foo"}},
- {"bar", 10000, true, nil, []string{"bar"}},
+ {"foo", "current", false, nil, []string{"foo"}},
+ {"bar", "current", true, nil, []string{"bar"}},
},
wantMerged: []ApexInfo{
- {"apex10000", 10000, true, nil, []string{"bar", "foo"}},
+ {"apex10000", "current", true, nil, []string{"bar", "foo"}},
},
wantAliases: [][2]string{
{"bar", "apex10000"},
@@ -84,12 +84,12 @@
{
name: "don't merge sdks",
in: []ApexInfo{
- {"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
- {"bar", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
+ {"foo", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
+ {"bar", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
},
wantMerged: []ApexInfo{
- {"apex10000_baz_2", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
- {"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
+ {"apex10000_baz_2", "current", false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
+ {"apex10000_baz_1", "current", false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
},
wantAliases: [][2]string{
{"bar", "apex10000_baz_2"},
@@ -99,7 +99,9 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- gotMerged, gotAliases := mergeApexVariations(tt.in)
+ config := TestConfig(buildDir, nil, "", nil)
+ ctx := &configErrorWrapper{config: config}
+ gotMerged, gotAliases := mergeApexVariations(ctx, tt.in)
if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
}
diff --git a/android/api_levels.go b/android/api_levels.go
index 9768340..bace3d4 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -152,7 +152,7 @@
// * "30" -> "30"
// * "R" -> "30"
// * "S" -> "S"
-func ReplaceFinalizedCodenames(ctx EarlyModuleContext, raw string) string {
+func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
num, ok := getFinalCodenamesMap(ctx.Config())[raw]
if !ok {
return raw
@@ -175,7 +175,7 @@
//
// Inputs that are not "current", known previews, or convertible to an integer
// will return an error.
-func ApiLevelFromUser(ctx EarlyModuleContext, raw string) (ApiLevel, error) {
+func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
if raw == "" {
panic("API level string must be non-empty")
}
@@ -203,7 +203,7 @@
// Converts an API level string `raw` into an ApiLevel in the same method as
// `ApiLevelFromUser`, but the input is assumed to have no errors and any errors
// will panic instead of returning an error.
-func ApiLevelOrPanic(ctx EarlyModuleContext, raw string) ApiLevel {
+func ApiLevelOrPanic(ctx PathContext, raw string) ApiLevel {
value, err := ApiLevelFromUser(ctx, raw)
if err != nil {
panic(err.Error())