Merge "Enforce stub libraries should have a single apex_available"
This commit is contained in:
@@ -3218,10 +3218,7 @@ func TestStaticLinking(t *testing.T) {
|
|||||||
stubs: {
|
stubs: {
|
||||||
versions: ["1", "2", "3"],
|
versions: ["1", "2", "3"],
|
||||||
},
|
},
|
||||||
apex_available: [
|
apex_available: ["myapex"],
|
||||||
"//apex_available:platform",
|
|
||||||
"myapex",
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_binary {
|
cc_binary {
|
||||||
@@ -4221,7 +4218,7 @@ func TestDependenciesInApexManifest(t *testing.T) {
|
|||||||
apex {
|
apex {
|
||||||
name: "myapex_selfcontained",
|
name: "myapex_selfcontained",
|
||||||
key: "myapex.key",
|
key: "myapex.key",
|
||||||
native_shared_libs: ["lib_dep", "libfoo"],
|
native_shared_libs: ["lib_dep_on_bar", "libbar"],
|
||||||
compile_multilib: "both",
|
compile_multilib: "both",
|
||||||
file_contexts: ":myapex-file_contexts",
|
file_contexts: ":myapex-file_contexts",
|
||||||
updatable: false,
|
updatable: false,
|
||||||
@@ -4254,6 +4251,18 @@ func TestDependenciesInApexManifest(t *testing.T) {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "lib_dep_on_bar",
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
shared_libs: ["libbar"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
apex_available: [
|
||||||
|
"myapex_selfcontained",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "libfoo",
|
name: "libfoo",
|
||||||
srcs: ["mytest.cpp"],
|
srcs: ["mytest.cpp"],
|
||||||
@@ -4264,9 +4273,22 @@ func TestDependenciesInApexManifest(t *testing.T) {
|
|||||||
stl: "none",
|
stl: "none",
|
||||||
apex_available: [
|
apex_available: [
|
||||||
"myapex_provider",
|
"myapex_provider",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "libbar",
|
||||||
|
srcs: ["mytest.cpp"],
|
||||||
|
stubs: {
|
||||||
|
versions: ["1"],
|
||||||
|
},
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
apex_available: [
|
||||||
"myapex_selfcontained",
|
"myapex_selfcontained",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
var apexManifestRule android.TestingBuildParams
|
var apexManifestRule android.TestingBuildParams
|
||||||
@@ -4293,7 +4315,7 @@ func TestDependenciesInApexManifest(t *testing.T) {
|
|||||||
apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
|
apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
|
||||||
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
||||||
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
||||||
ensureListContains(t, provideNativeLibs, "libfoo.so")
|
ensureListContains(t, provideNativeLibs, "libbar.so")
|
||||||
ensureListEmpty(t, requireNativeLibs)
|
ensureListEmpty(t, requireNativeLibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8575,14 +8597,14 @@ func TestTestForForLibInOtherApex(t *testing.T) {
|
|||||||
apex {
|
apex {
|
||||||
name: "com.android.art",
|
name: "com.android.art",
|
||||||
key: "myapex.key",
|
key: "myapex.key",
|
||||||
native_shared_libs: ["mylib"],
|
native_shared_libs: ["libnativebridge"],
|
||||||
updatable: false,
|
updatable: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
apex {
|
apex {
|
||||||
name: "com.android.art.debug",
|
name: "com.android.art.debug",
|
||||||
key: "myapex.key",
|
key: "myapex.key",
|
||||||
native_shared_libs: ["mylib", "mytestlib"],
|
native_shared_libs: ["libnativebridge", "libnativebrdige_test"],
|
||||||
updatable: false,
|
updatable: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8593,8 +8615,8 @@ func TestTestForForLibInOtherApex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "mylib",
|
name: "libnativebridge",
|
||||||
srcs: ["mylib.cpp"],
|
srcs: ["libnativebridge.cpp"],
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
stubs: {
|
stubs: {
|
||||||
@@ -8604,10 +8626,10 @@ func TestTestForForLibInOtherApex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "mytestlib",
|
name: "libnativebrdige_test",
|
||||||
srcs: ["mylib.cpp"],
|
srcs: ["mylib.cpp"],
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
shared_libs: ["mylib"],
|
shared_libs: ["libnativebridge"],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
apex_available: ["com.android.art.debug"],
|
apex_available: ["com.android.art.debug"],
|
||||||
test_for: ["com.android.art"],
|
test_for: ["com.android.art"],
|
||||||
@@ -10279,3 +10301,77 @@ func TestCannedFsConfig_HasCustomConfig(t *testing.T) {
|
|||||||
// Ensure that canned_fs_config has "cat my_config" at the end
|
// Ensure that canned_fs_config has "cat my_config" at the end
|
||||||
ensureContains(t, cmd, `( echo '/ 1000 1000 0755'; echo '/apex_manifest.json 1000 1000 0644'; echo '/apex_manifest.pb 1000 1000 0644'; cat my_config ) >`)
|
ensureContains(t, cmd, `( echo '/ 1000 1000 0755'; echo '/apex_manifest.json 1000 1000 0644'; echo '/apex_manifest.pb 1000 1000 0644'; cat my_config ) >`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStubLibrariesMultipleApexViolation(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
hasStubs bool
|
||||||
|
apexAvailable string
|
||||||
|
expectedError string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "non-stub library can have multiple apex_available",
|
||||||
|
hasStubs: false,
|
||||||
|
apexAvailable: `["myapex", "otherapex"]`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "stub library should not be available to anyapex",
|
||||||
|
hasStubs: true,
|
||||||
|
apexAvailable: `["//apex_available:anyapex"]`,
|
||||||
|
expectedError: "Stub libraries should have a single apex_available.*anyapex",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "stub library should not be available to multiple apexes",
|
||||||
|
hasStubs: true,
|
||||||
|
apexAvailable: `["myapex", "otherapex"]`,
|
||||||
|
expectedError: "Stub libraries should have a single apex_available.*myapex.*otherapex",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "stub library can be available to a core apex and a test apex",
|
||||||
|
hasStubs: true,
|
||||||
|
apexAvailable: `["myapex", "test_myapex"]`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
bpTemplate := `
|
||||||
|
cc_library {
|
||||||
|
name: "libfoo",
|
||||||
|
%v
|
||||||
|
apex_available: %v,
|
||||||
|
}
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
key: "apex.key",
|
||||||
|
updatable: false,
|
||||||
|
native_shared_libs: ["libfoo"],
|
||||||
|
}
|
||||||
|
apex {
|
||||||
|
name: "otherapex",
|
||||||
|
key: "apex.key",
|
||||||
|
updatable: false,
|
||||||
|
}
|
||||||
|
apex_test {
|
||||||
|
name: "test_myapex",
|
||||||
|
key: "apex.key",
|
||||||
|
updatable: false,
|
||||||
|
native_shared_libs: ["libfoo"],
|
||||||
|
}
|
||||||
|
apex_key {
|
||||||
|
name: "apex.key",
|
||||||
|
}
|
||||||
|
`
|
||||||
|
for _, tc := range testCases {
|
||||||
|
stubs := ""
|
||||||
|
if tc.hasStubs {
|
||||||
|
stubs = `stubs: {symbol_file: "libfoo.map.txt"},`
|
||||||
|
}
|
||||||
|
bp := fmt.Sprintf(bpTemplate, stubs, tc.apexAvailable)
|
||||||
|
mockFsFixturePreparer := android.FixtureModifyMockFS(func(fs android.MockFS) {
|
||||||
|
fs["system/sepolicy/apex/test_myapex-file_contexts"] = nil
|
||||||
|
})
|
||||||
|
if tc.expectedError == "" {
|
||||||
|
testApex(t, bp, mockFsFixturePreparer)
|
||||||
|
} else {
|
||||||
|
testApexError(t, tc.expectedError, bp, mockFsFixturePreparer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
54
cc/cc.go
54
cc/cc.go
@@ -1987,6 +1987,56 @@ func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO (b/277651159): Remove this allowlist
|
||||||
|
var (
|
||||||
|
skipStubLibraryMultipleApexViolation = map[string]bool{
|
||||||
|
"libclang_rt.asan": true,
|
||||||
|
"libclang_rt.hwasan": true,
|
||||||
|
// runtime apex
|
||||||
|
"libc": true,
|
||||||
|
"libc_hwasan": true,
|
||||||
|
"libdl_android": true,
|
||||||
|
"libm": true,
|
||||||
|
"libdl": true,
|
||||||
|
// art apex
|
||||||
|
"libandroidio": true,
|
||||||
|
"libdexfile": true,
|
||||||
|
"libnativebridge": true,
|
||||||
|
"libnativehelper": true,
|
||||||
|
"libnativeloader": true,
|
||||||
|
"libsigchain": true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Returns true if a stub library could be installed in multiple apexes
|
||||||
|
func (c *Module) stubLibraryMultipleApexViolation(ctx android.ModuleContext) bool {
|
||||||
|
// If this is not an apex variant, no check necessary
|
||||||
|
if !c.InAnyApex() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// If this is not a stub library, no check necessary
|
||||||
|
if !c.HasStubsVariants() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Skip the allowlist
|
||||||
|
// Use BaseModuleName so that this matches prebuilts.
|
||||||
|
if _, exists := skipStubLibraryMultipleApexViolation[c.BaseModuleName()]; exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
_, aaWithoutTestApexes, _ := android.ListSetDifference(c.ApexAvailable(), c.TestApexes())
|
||||||
|
// Stub libraries should not have more than one apex_available
|
||||||
|
if len(aaWithoutTestApexes) > 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Stub libraries should not use the wildcard
|
||||||
|
if aaWithoutTestApexes[0] == android.AvailableToAnyApex {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Default: no violation
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||||
// Handle the case of a test module split by `test_per_src` mutator.
|
// Handle the case of a test module split by `test_per_src` mutator.
|
||||||
//
|
//
|
||||||
@@ -2013,6 +2063,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.stubLibraryMultipleApexViolation(actx) {
|
||||||
|
actx.PropertyErrorf("apex_available",
|
||||||
|
"Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
|
||||||
|
}
|
||||||
if c.Properties.Clang != nil && *c.Properties.Clang == false {
|
if c.Properties.Clang != nil && *c.Properties.Clang == false {
|
||||||
ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
|
ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
|
||||||
} else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
|
} else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
|
||||||
|
Reference in New Issue
Block a user