Pass shared library updatability attributes as strings

Migrate from ints to Strings so we can pass codenames. Otherwise we
can't use these attributes representing a release in progress until that
release is finalized. I.e. if release T is in progress, we don't get the
correct behaviour if we use "T" in those attributes

Bug: 191978330

Test: m nothing
Change-Id: I35389da0a01549ba2f820f5e5b78f6ea88c2aea1
This commit is contained in:
Pedro Loureiro 2021-12-22 15:28:05 +00:00
parent 104ecf6708
commit b638c62620
2 changed files with 17 additions and 11 deletions

View file

@ -21,7 +21,6 @@ import (
"reflect" "reflect"
"regexp" "regexp"
"sort" "sort"
"strconv"
"strings" "strings"
"sync" "sync"
@ -2551,8 +2550,14 @@ func formattedOptionalSdkLevelAttribute(ctx android.ModuleContext, attrName stri
ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), err.Error()) ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), err.Error())
return "" return ""
} }
intStr := strconv.Itoa(apiLevel.FinalOrPreviewInt()) if apiLevel.IsCurrent() {
return formattedOptionalAttribute(attrName, &intStr) // passing "current" would always mean a future release, never the current (or the current in
// progress) which means some conditions would never be triggered.
ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"),
`"current" is not an allowed value for this attribute`)
return ""
}
return formattedOptionalAttribute(attrName, value)
} }
// formats an attribute for the xml permissions file if the value is not null // formats an attribute for the xml permissions file if the value is not null

View file

@ -182,7 +182,7 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) {
"30": {"foo", "fooUpdatable", "fooUpdatableErr"}, "30": {"foo", "fooUpdatable", "fooUpdatableErr"},
}), }),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.Platform_version_active_codenames = []string{"Tiramisu", "U", "V", "W"} variables.Platform_version_active_codenames = []string{"Tiramisu", "U", "V", "W", "X"}
}), }),
).RunTestWithBp(t, ).RunTestWithBp(t,
` `
@ -193,7 +193,7 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) {
on_bootclasspath_since: "U", on_bootclasspath_since: "U",
on_bootclasspath_before: "V", on_bootclasspath_before: "V",
min_device_sdk: "W", min_device_sdk: "W",
max_device_sdk: "current", max_device_sdk: "X",
min_sdk_version: "S", min_sdk_version: "S",
} }
java_sdk_library { java_sdk_library {
@ -202,12 +202,13 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) {
api_packages: ["foo"], api_packages: ["foo"],
} }
`) `)
// test that updatability attributes are passed on correctly // test that updatability attributes are passed on correctly
fooUpdatable := result.ModuleForTests("fooUpdatable.xml", "android_common").Rule("java_sdk_xml") fooUpdatable := result.ModuleForTests("fooUpdatable.xml", "android_common").Rule("java_sdk_xml")
android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-since=\"9001\"`) android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-since=\"U\"`)
android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-before=\"9002\"`) android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-before=\"V\"`)
android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `min-device-sdk=\"9003\"`) android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `min-device-sdk=\"W\"`)
android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `max-device-sdk=\"10000\"`) android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `max-device-sdk=\"X\"`)
// double check that updatability attributes are not written if they don't exist in the bp file // double check that updatability attributes are not written if they don't exist in the bp file
// the permissions file for the foo library defined above // the permissions file for the foo library defined above
@ -230,7 +231,7 @@ func TestJavaSdkLibrary_UpdatableLibrary_Validation_ValidVersion(t *testing.T) {
`on_bootclasspath_since: "aaa" could not be parsed as an integer and is not a recognized codename`, `on_bootclasspath_since: "aaa" could not be parsed as an integer and is not a recognized codename`,
`on_bootclasspath_before: "bbc" could not be parsed as an integer and is not a recognized codename`, `on_bootclasspath_before: "bbc" could not be parsed as an integer and is not a recognized codename`,
`min_device_sdk: "ccc" could not be parsed as an integer and is not a recognized codename`, `min_device_sdk: "ccc" could not be parsed as an integer and is not a recognized codename`,
`max_device_sdk: "ddd" could not be parsed as an integer and is not a recognized codename`, `max_device_sdk: "current" is not an allowed value for this attribute`,
})).RunTestWithBp(t, })).RunTestWithBp(t,
` `
java_sdk_library { java_sdk_library {
@ -240,7 +241,7 @@ func TestJavaSdkLibrary_UpdatableLibrary_Validation_ValidVersion(t *testing.T) {
on_bootclasspath_since: "aaa", on_bootclasspath_since: "aaa",
on_bootclasspath_before: "bbc", on_bootclasspath_before: "bbc",
min_device_sdk: "ccc", min_device_sdk: "ccc",
max_device_sdk: "ddd", max_device_sdk: "current",
} }
`) `)
} }