sysprop_library correctly supports apex_available and min_sdk_version

This fixes a bug that apex_available and min_sdk_version properties of a
sysprop_library module are not forwarded to the generated cc or java
modules.

Bug: 181942475
Bug: 181940232
Test: m nothing

Change-Id: I03bcb5836f080aecd452021a3ffe003f36eb652e
This commit is contained in:
Jiyong Park 2021-03-08 10:09:52 +09:00
parent 6d3e726887
commit 5e914b286f
2 changed files with 115 additions and 44 deletions

View File

@ -165,6 +165,12 @@ type syspropLibraryProperties struct {
// Forwarded to cc_library.min_sdk_version
Min_sdk_version *string
}
Java struct {
// Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
// Forwarded to java_library.min_sdk_version
Min_sdk_version *string
}
}
var (
@ -403,6 +409,8 @@ type javaLibraryProperties struct {
Libs []string
Stem *string
SyspropPublicStub string
Apex_available []string
Min_sdk_version *string
}
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
@ -508,6 +516,8 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Sdk_version: proptools.StringPtr("core_current"),
Libs: []string{javaSyspropStub},
SyspropPublicStub: publicStub,
Apex_available: m.ApexProperties.Apex_available,
Min_sdk_version: m.properties.Java.Min_sdk_version,
})
if publicStub != "" {

View File

@ -81,6 +81,51 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) {
}
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
bp += `
cc_library {
name: "libbase",
host_supported: true,
}
cc_library_headers {
name: "libbase_headers",
vendor_available: true,
recovery_available: true,
}
cc_library {
name: "liblog",
no_libcrt: true,
nocrt: true,
system_shared_libs: [],
recovery_available: true,
host_supported: true,
llndk_stubs: "liblog.llndk",
}
llndk_library {
name: "liblog.llndk",
symbol_file: "",
}
java_library {
name: "sysprop-library-stub-platform",
sdk_version: "core_current",
}
java_library {
name: "sysprop-library-stub-vendor",
soc_specific: true,
sdk_version: "core_current",
}
java_library {
name: "sysprop-library-stub-product",
product_specific: true,
sdk_version: "core_current",
}
`
bp += cc.GatherRequiredDepsForTest(android.Android)
mockFS := map[string][]byte{
@ -250,54 +295,11 @@ func TestSyspropLibrary(t *testing.T) {
static_libs: ["sysprop-platform", "sysprop-vendor"],
}
cc_library {
name: "libbase",
host_supported: true,
}
cc_library_headers {
name: "libbase_headers",
vendor_available: true,
recovery_available: true,
}
cc_library {
name: "liblog",
no_libcrt: true,
nocrt: true,
system_shared_libs: [],
recovery_available: true,
host_supported: true,
llndk_stubs: "liblog.llndk",
}
cc_binary_host {
name: "hostbin",
static_libs: ["sysprop-platform"],
}
llndk_library {
name: "liblog.llndk",
symbol_file: "",
}
java_library {
name: "sysprop-library-stub-platform",
sdk_version: "core_current",
}
java_library {
name: "sysprop-library-stub-vendor",
soc_specific: true,
sdk_version: "core_current",
}
java_library {
name: "sysprop-library-stub-product",
product_specific: true,
sdk_version: "core_current",
}
`)
`)
// Check for generated cc_library
for _, variant := range []string{
@ -391,3 +393,62 @@ func TestSyspropLibrary(t *testing.T) {
t.Errorf("system api client should use public stub %q, got %q", w, g)
}
}
func TestApexAvailabilityIsForwarded(t *testing.T) {
ctx := test(t, `
sysprop_library {
name: "sysprop-platform",
apex_available: ["//apex_available:platform"],
srcs: ["android/sysprop/PlatformProperties.sysprop"],
api_packages: ["android.sysprop"],
property_owner: "Platform",
}
`)
expected := []string{"//apex_available:platform"}
ccModule := ctx.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
propFromCc := ccModule.ApexProperties.Apex_available
if !reflect.DeepEqual(propFromCc, expected) {
t.Errorf("apex_available not forwarded to cc module. expected %#v, got %#v",
expected, propFromCc)
}
javaModule := ctx.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
propFromJava := javaModule.ApexProperties.Apex_available
if !reflect.DeepEqual(propFromJava, expected) {
t.Errorf("apex_available not forwarded to java module. expected %#v, got %#v",
expected, propFromJava)
}
}
func TestMinSdkVersionIsForwarded(t *testing.T) {
ctx := test(t, `
sysprop_library {
name: "sysprop-platform",
srcs: ["android/sysprop/PlatformProperties.sysprop"],
api_packages: ["android.sysprop"],
property_owner: "Platform",
cpp: {
min_sdk_version: "29",
},
java: {
min_sdk_version: "30",
},
}
`)
ccModule := ctx.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
if propFromCc != "29" {
t.Errorf("min_sdk_version not forwarded to cc module. expected %#v, got %#v",
"29", propFromCc)
}
javaModule := ctx.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
propFromJava := javaModule.MinSdkVersion()
if propFromJava != "30" {
t.Errorf("min_sdk_version not forwarded to java module. expected %#v, got %#v",
"30", propFromJava)
}
}