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
This commit is contained in:
@@ -63,6 +63,7 @@ bootstrap_go_package {
|
||||
testSrcs: [
|
||||
"android_test.go",
|
||||
"androidmk_test.go",
|
||||
"apex_test.go",
|
||||
"arch_test.go",
|
||||
"config_test.go",
|
||||
"csuite_config_test.go",
|
||||
|
@@ -42,7 +42,7 @@ type ApexInfo struct {
|
||||
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 @@ func (i ApexInfo) mergedName(ctx EarlyModuleContext) string {
|
||||
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 @@ func (a byApexName) Less(i, j int) bool { return a[i].ApexVariationName < a[j].A
|
||||
// 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 {
|
||||
|
@@ -29,10 +29,10 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
{
|
||||
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 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
{
|
||||
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 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
{
|
||||
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 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
{
|
||||
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 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
{
|
||||
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 @@ func Test_mergeApexVariations(t *testing.T) {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
@@ -152,7 +152,7 @@ var FirstNonLibAndroidSupportVersion = uncheckedFinalApiLevel(21)
|
||||
// * "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 @@ func ReplaceFinalizedCodenames(ctx EarlyModuleContext, raw string) string {
|
||||
//
|
||||
// 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 @@ func ApiLevelFromUser(ctx EarlyModuleContext, raw string) (ApiLevel, error) {
|
||||
// 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())
|
||||
|
Reference in New Issue
Block a user