Make prebuilt_api test environment realistic

Previously, the fixture preparer for prebuilt_apis would add a
core-for-system-modules.jar file in every API directory even though
currently they only exist in the public API directories.

This change makes the test environment more realistic by only creating
them for the public API. Rather than hard code that into the test code
(which would duplicate the hard coding in the decodeSdkDep func) this
extracts a function that is used by both. That ensures that any changes
to that func will be reflected in both the test and runtime behavior.

Bug: 204189791
Test: m nothing
Change-Id: I346ac9c0dcf407c61de16b6027663a05821bcf62
This commit is contained in:
Paul Duffin 2021-10-29 13:30:59 +01:00
parent 6d448b7a0a
commit 1cad3a53db
2 changed files with 24 additions and 9 deletions

View file

@ -60,6 +60,12 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe
}
}
// systemModuleKind returns the kind of system modules to use.
func systemModuleKind() android.SdkKind {
// Currently, every sdk version uses the system modules for the public API.
return android.SdkPublic
}
func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
sdkVersion := sdkContext.SdkVersion(ctx)
if !sdkVersion.Valid() {
@ -105,7 +111,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext)
var systemModules string
if defaultJavaLanguageVersion(ctx, sdkVersion).usesJavaModules() {
systemModules = "sdk_public_" + sdkVersion.ApiLevel.String() + "_system_modules"
systemModuleKind := systemModuleKind()
systemModules = fmt.Sprintf("sdk_%s_%s_system_modules", systemModuleKind, sdkVersion.ApiLevel)
}
return sdkDep{

View file

@ -159,8 +159,7 @@ func FixtureWithPrebuiltApis(release2Modules map[string][]string) android.Fixtur
`, strings.Join(android.SortedStringKeys(release2Modules), `", "`))
for release, modules := range release2Modules {
libs := append([]string{"android", "core-for-system-modules"}, modules...)
mockFS.Merge(prebuiltApisFilesForLibs([]string{release}, libs))
mockFS.Merge(prebuiltApisFilesForModules([]string{release}, modules))
}
return android.GroupFixturePreparers(
android.FixtureAddTextFile(path, bp),
@ -168,16 +167,25 @@ func FixtureWithPrebuiltApis(release2Modules map[string][]string) android.Fixtur
)
}
func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][]byte {
func prebuiltApisFilesForModules(apiLevels []string, modules []string) map[string][]byte {
libs := append([]string{"android"}, modules...)
fs := make(map[string][]byte)
for _, level := range apiLevels {
for _, lib := range sdkLibs {
for _, scope := range []string{"public", "system", "module-lib", "system-server", "test"} {
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/%s.jar", level, scope, lib)] = nil
for _, sdkKind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkModule, android.SdkSystemServer, android.SdkTest} {
// A core-for-system-modules file must only be created for the sdk kind that supports it.
if sdkKind == systemModuleKind() {
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/core-for-system-modules.jar", level, sdkKind)] = nil
}
for _, lib := range libs {
// Create a jar file for every library.
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/%s.jar", level, sdkKind, lib)] = nil
// No finalized API files for "current"
if level != "current" {
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s.txt", level, scope, lib)] = nil
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s-removed.txt", level, scope, lib)] = nil
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s.txt", level, sdkKind, lib)] = nil
fs[fmt.Sprintf("prebuilts/sdk/%s/%s/api/%s-removed.txt", level, sdkKind, lib)] = nil
}
}
}