Add current build release
Previously, the build releases only included named releases so did not have a way to represent the latest build release. This adds the current build release (named after the current API level) to represent that. Bug: 240406019 Test: m nothing Change-Id: Ib8336da716b447448b23bc9684ce3be1ab78648a
This commit is contained in:
@@ -16,6 +16,7 @@ package sdk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -29,7 +30,10 @@ type buildRelease struct {
|
|||||||
// The name of the release, e.g. S, Tiramisu, etc.
|
// The name of the release, e.g. S, Tiramisu, etc.
|
||||||
name string
|
name string
|
||||||
|
|
||||||
// The index of this structure within the buildReleases list.
|
// The index of this structure within the dessertBuildReleases list.
|
||||||
|
//
|
||||||
|
// The buildReleaseCurrent does not appear in the dessertBuildReleases list as it has an ordinal value
|
||||||
|
// that is larger than the size of the dessertBuildReleases.
|
||||||
ordinal int
|
ordinal int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +60,7 @@ func (s *buildReleaseSet) addItem(release *buildRelease) {
|
|||||||
// addRange adds all the build releases from start (inclusive) to end (inclusive).
|
// addRange adds all the build releases from start (inclusive) to end (inclusive).
|
||||||
func (s *buildReleaseSet) addRange(start *buildRelease, end *buildRelease) {
|
func (s *buildReleaseSet) addRange(start *buildRelease, end *buildRelease) {
|
||||||
for i := start.ordinal; i <= end.ordinal; i += 1 {
|
for i := start.ordinal; i <= end.ordinal; i += 1 {
|
||||||
s.addItem(buildReleases[i])
|
s.addItem(dessertBuildReleases[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,11 +73,17 @@ func (s *buildReleaseSet) contains(release *buildRelease) bool {
|
|||||||
// String returns a string representation of the set, sorted from earliest to latest release.
|
// String returns a string representation of the set, sorted from earliest to latest release.
|
||||||
func (s *buildReleaseSet) String() string {
|
func (s *buildReleaseSet) String() string {
|
||||||
list := []string{}
|
list := []string{}
|
||||||
for _, release := range buildReleases {
|
addRelease := func(release *buildRelease) {
|
||||||
if _, ok := s.contents[release]; ok {
|
if _, ok := s.contents[release]; ok {
|
||||||
list = append(list, release.name)
|
list = append(list, release.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add the names of the build releases in this set in the order in which they were created.
|
||||||
|
for _, release := range dessertBuildReleases {
|
||||||
|
addRelease(release)
|
||||||
|
}
|
||||||
|
// Always add "current" to the list of names last if it is present in the set.
|
||||||
|
addRelease(buildReleaseCurrent)
|
||||||
return fmt.Sprintf("[%s]", strings.Join(list, ","))
|
return fmt.Sprintf("[%s]", strings.Join(list, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,30 +91,46 @@ var (
|
|||||||
// nameToBuildRelease contains a map from name to build release.
|
// nameToBuildRelease contains a map from name to build release.
|
||||||
nameToBuildRelease = map[string]*buildRelease{}
|
nameToBuildRelease = map[string]*buildRelease{}
|
||||||
|
|
||||||
// buildReleases lists all the available build releases.
|
// dessertBuildReleases lists all the available dessert build releases, i.e. excluding current.
|
||||||
buildReleases = []*buildRelease{}
|
dessertBuildReleases = []*buildRelease{}
|
||||||
|
|
||||||
// allBuildReleaseSet is the set of all build releases.
|
// allBuildReleaseSet is the set of all build releases.
|
||||||
allBuildReleaseSet = &buildReleaseSet{contents: map[*buildRelease]struct{}{}}
|
allBuildReleaseSet = &buildReleaseSet{contents: map[*buildRelease]struct{}{}}
|
||||||
|
|
||||||
// Add the build releases from oldest to newest.
|
// Add the dessert build releases from oldest to newest.
|
||||||
buildReleaseS = initBuildRelease("S")
|
buildReleaseS = initBuildRelease("S")
|
||||||
buildReleaseT = initBuildRelease("Tiramisu")
|
buildReleaseT = initBuildRelease("Tiramisu")
|
||||||
|
|
||||||
|
// Add the current build release which is always treated as being more recent than any other
|
||||||
|
// build release, including those added in tests.
|
||||||
|
buildReleaseCurrent = initBuildRelease("current")
|
||||||
)
|
)
|
||||||
|
|
||||||
// initBuildRelease creates a new build release with the specified name.
|
// initBuildRelease creates a new build release with the specified name.
|
||||||
func initBuildRelease(name string) *buildRelease {
|
func initBuildRelease(name string) *buildRelease {
|
||||||
ordinal := len(nameToBuildRelease)
|
ordinal := len(dessertBuildReleases)
|
||||||
|
if name == "current" {
|
||||||
|
// The current build release is more recent than all other build releases, including those
|
||||||
|
// created in tests so use the max int value. It cannot just rely on being created after all
|
||||||
|
// the other build releases as some are created in tests which run after the current build
|
||||||
|
// release has been created.
|
||||||
|
ordinal = math.MaxInt
|
||||||
|
}
|
||||||
release := &buildRelease{name: name, ordinal: ordinal}
|
release := &buildRelease{name: name, ordinal: ordinal}
|
||||||
nameToBuildRelease[name] = release
|
nameToBuildRelease[name] = release
|
||||||
buildReleases = append(buildReleases, release)
|
|
||||||
allBuildReleaseSet.addItem(release)
|
allBuildReleaseSet.addItem(release)
|
||||||
|
if name != "current" {
|
||||||
|
// As the current build release has an ordinal value that does not correspond to its position
|
||||||
|
// in the dessertBuildReleases list do not add it to the list.
|
||||||
|
dessertBuildReleases = append(dessertBuildReleases, release)
|
||||||
|
}
|
||||||
return release
|
return release
|
||||||
}
|
}
|
||||||
|
|
||||||
// latestBuildRelease returns the latest build release, i.e. the last one added.
|
// latestDessertBuildRelease returns the latest dessert release build name, i.e. the last dessert
|
||||||
func latestBuildRelease() *buildRelease {
|
// release added to the list, which does not include current.
|
||||||
return buildReleases[len(buildReleases)-1]
|
func latestDessertBuildRelease() *buildRelease {
|
||||||
|
return dessertBuildReleases[len(dessertBuildReleases)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// nameToRelease maps from build release name to the corresponding build release (if it exists) or
|
// nameToRelease maps from build release name to the corresponding build release (if it exists) or
|
||||||
@@ -134,8 +160,10 @@ func parseBuildReleaseSet(specification string) (*buildReleaseSet, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
end := latestBuildRelease()
|
end := latestDessertBuildRelease()
|
||||||
set.addRange(start, end)
|
set.addRange(start, end)
|
||||||
|
// An open-ended range always includes the current release.
|
||||||
|
set.addItem(buildReleaseCurrent)
|
||||||
} else if strings.Contains(specification, "-") {
|
} else if strings.Contains(specification, "-") {
|
||||||
limits := strings.SplitN(specification, "-", 2)
|
limits := strings.SplitN(specification, "-", 2)
|
||||||
start, err := nameToRelease(limits[0])
|
start, err := nameToRelease(limits[0])
|
||||||
|
@@ -42,7 +42,7 @@ func TestNameToRelease(t *testing.T) {
|
|||||||
android.AssertDeepEquals(t, "release", (*buildRelease)(nil), release)
|
android.AssertDeepEquals(t, "release", (*buildRelease)(nil), release)
|
||||||
// Uses a wildcard in the error message to allow for additional build releases to be added to
|
// Uses a wildcard in the error message to allow for additional build releases to be added to
|
||||||
// the supported set without breaking this test.
|
// the supported set without breaking this test.
|
||||||
android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,T.*,F1,F2\]`, []error{err})
|
android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,Tiramisu,F1,F2,current\]`, []error{err})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func TestParseBuildReleaseSet(t *testing.T) {
|
|||||||
t.Run("open range", func(t *testing.T) {
|
t.Run("open range", func(t *testing.T) {
|
||||||
set, err := parseBuildReleaseSet("F1+")
|
set, err := parseBuildReleaseSet("F1+")
|
||||||
android.AssertDeepEquals(t, "errors", nil, err)
|
android.AssertDeepEquals(t, "errors", nil, err)
|
||||||
android.AssertStringEquals(t, "set", "[F1,F2]", set.String())
|
android.AssertStringEquals(t, "set", "[F1,F2,current]", set.String())
|
||||||
})
|
})
|
||||||
t.Run("closed range", func(t *testing.T) {
|
t.Run("closed range", func(t *testing.T) {
|
||||||
set, err := parseBuildReleaseSet("S-F1")
|
set, err := parseBuildReleaseSet("S-F1")
|
||||||
|
@@ -262,8 +262,7 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st
|
|||||||
|
|
||||||
// If the generated snapshot builders not for the current release then it cannot be loaded by
|
// If the generated snapshot builders not for the current release then it cannot be loaded by
|
||||||
// the current release.
|
// the current release.
|
||||||
currentBuildRelease := latestBuildRelease()
|
if snapshotBuildInfo.targetBuildRelease != buildReleaseCurrent {
|
||||||
if snapshotBuildInfo.targetBuildRelease != currentBuildRelease {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -387,12 +387,11 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) {
|
|||||||
// Always add -current to the end
|
// Always add -current to the end
|
||||||
snapshotFileSuffix := "-current"
|
snapshotFileSuffix := "-current"
|
||||||
|
|
||||||
currentBuildRelease := latestBuildRelease()
|
targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", buildReleaseCurrent.name)
|
||||||
targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name)
|
|
||||||
targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv)
|
targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err)
|
ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err)
|
||||||
targetBuildRelease = currentBuildRelease
|
targetBuildRelease = buildReleaseCurrent
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := &snapshotBuilder{
|
builder := &snapshotBuilder{
|
||||||
@@ -472,7 +471,7 @@ be unnecessary as every module in the sdk already has its own licenses property.
|
|||||||
contents := bp.content.String()
|
contents := bp.content.String()
|
||||||
// If the snapshot is being generated for the current build release then check the syntax to make
|
// If the snapshot is being generated for the current build release then check the syntax to make
|
||||||
// sure that it is compatible.
|
// sure that it is compatible.
|
||||||
if targetBuildRelease == currentBuildRelease {
|
if targetBuildRelease == buildReleaseCurrent {
|
||||||
syntaxCheckSnapshotBpFile(ctx, contents)
|
syntaxCheckSnapshotBpFile(ctx, contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user