Add sdk mutator for native modules
Compiling native modules against the NDK disables platform features
like ASAN. For anything shipped on the system image there is no
reason to compile against the NDK. Add a new mutator to Soong that
creates a platform and an SDK variant for modules that set
sdk_version, and ignore sdk_version for the platform variant. The
SDK variant will be used for embedding in APKs that may be installed
on older platforms. Apexes use their own variants that enforce
backwards compatibility.
Test: sdk_test.go
Test: TestJNIPackaging
Bug: 149591340
Change-Id: I7d72934aaee2e1326cc0ba5f29f51f14feec4521
Merged-In: I7d72934aaee2e1326cc0ba5f29f51f14feec4521
(cherry picked from commit 82e192c3aeae55337e335101ba83126decd4ddac)
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 83b2250..2fc42e3 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -259,6 +259,50 @@
}`),
},
},
+ // CC sdk rule tests
+ {
+ name: `"sdk_variant_only" outside whitelist`,
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ cc_library {
+ name: "outside_whitelist",
+ sdk_version: "current",
+ sdk_variant_only: true,
+ }`),
+ },
+ expectedErrors: []string{
+ `module "outside_whitelist": violates neverallow`,
+ },
+ },
+ {
+ name: `"sdk_variant_only: false" outside whitelist`,
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ cc_library {
+ name: "outside_whitelist",
+ sdk_version: "current",
+ sdk_variant_only: false,
+ }`),
+ },
+ expectedErrors: []string{
+ `module "outside_whitelist": violates neverallow`,
+ },
+ },
+ {
+ name: `"platform" outside whitelist`,
+ fs: map[string][]byte{
+ "Android.bp": []byte(`
+ cc_library {
+ name: "outside_whitelist",
+ platform: {
+ shared_libs: ["libfoo"],
+ },
+ }`),
+ },
+ expectedErrors: []string{
+ `module "outside_whitelist": violates neverallow`,
+ },
+ },
}
func TestNeverallow(t *testing.T) {
@@ -299,6 +343,8 @@
Include_dirs []string
Vendor_available *bool
Static_libs []string
+ Sdk_version *string
+ Sdk_variant_only *bool
Vndk struct {
Enabled *bool
@@ -315,6 +361,10 @@
Cflags []string
}
}
+
+ Platform struct {
+ Shared_libs []string
+ }
}
type mockCcLibraryModule struct {