Merge "Support testing versioned/unversioned sdk Android.bp files separately"

This commit is contained in:
Paul Duffin
2021-02-23 15:29:20 +00:00
committed by Gerrit Code Review
2 changed files with 65 additions and 8 deletions

View File

@@ -243,11 +243,11 @@ type testSdkResult struct {
// e.g. find the src/dest pairs from each cp command, the various zip files
// generated, etc.
func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo {
androidBpContents := sdk.GetAndroidBpContentsForTests()
info := &snapshotBuildInfo{
r: r,
androidBpContents: androidBpContents,
androidBpContents: sdk.GetAndroidBpContentsForTests(),
androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(),
}
buildParams := sdk.BuildParamsForTests()
@@ -365,6 +365,33 @@ func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
}
}
// Check that the snapshot's unversioned generated Android.bp is correct.
//
// This func should be used to check the general snapshot generation code.
//
// Both the expected and actual string are both trimmed before comparing.
func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
info.r.t.Helper()
info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
}
}
// Check that the snapshot's versioned generated Android.bp is correct.
//
// This func should only be used to check the version specific snapshot generation code,
// i.e. the encoding of version into module names and the generation of the _snapshot module. The
// general snapshot generation code should be checked using the checkUnversionedAndroidBpContents()
// func.
//
// Both the expected and actual string are both trimmed before comparing.
func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
info.r.t.Helper()
info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
}
}
// Check that the snapshot's copy rules are correct.
//
// The copy rules are formatted as <src> -> <dest>, one per line and then compared
@@ -407,6 +434,12 @@ type snapshotBuildInfo struct {
// The contents of the generated Android.bp file
androidBpContents string
// The contents of the unversioned Android.bp file
androidUnversionedBpContents string
// The contents of the versioned Android.bp file
androidVersionedBpContents string
// The paths, relative to the snapshot root, of all files and directories copied into the
// snapshot.
snapshotContents []string

View File

@@ -572,14 +572,22 @@ func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string,
}
func generateBpContents(contents *generatedContents, bpFile *bpFile) {
generateFilteredBpContents(contents, bpFile, func(*bpModule) bool {
return true
})
}
func generateFilteredBpContents(contents *generatedContents, bpFile *bpFile, moduleFilter func(module *bpModule) bool) {
contents.Printfln("// This is auto-generated. DO NOT EDIT.")
for _, bpModule := range bpFile.order {
if moduleFilter(bpModule) {
contents.Printfln("")
contents.Printfln("%s {", bpModule.moduleType)
outputPropertySet(contents, bpModule.bpPropertySet)
contents.Printfln("}")
}
}
}
func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
contents.Indent()
@@ -639,6 +647,22 @@ func (s *sdk) GetAndroidBpContentsForTests() string {
return contents.content.String()
}
func (s *sdk) GetUnversionedAndroidBpContentsForTests() string {
contents := &generatedContents{}
generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
return !strings.Contains(module.properties["name"].(string), "@")
})
return contents.content.String()
}
func (s *sdk) GetVersionedAndroidBpContentsForTests() string {
contents := &generatedContents{}
generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
return strings.Contains(module.properties["name"].(string), "@")
})
return contents.content.String()
}
type snapshotBuilder struct {
ctx android.ModuleContext
sdk *sdk