aboutsummaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2020-05-02 01:41:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-02 01:41:18 +0000
commit2a5fb91370d2d28b0bb0b9b32e2fe0b8af5d6c94 (patch)
tree33a59176fef76c8b5eb3d1171c2ea6ffe780285c /android
parentda831ae8a892a6d33f5c3fba1c81abcae557e088 (diff)
parent01fd7ccbc71c9eee7c56c73f05c4e7833a795aac (diff)
downloadbuild_soong-2a5fb91370d2d28b0bb0b9b32e2fe0b8af5d6c94.tar.gz
build_soong-2a5fb91370d2d28b0bb0b9b32e2fe0b8af5d6c94.tar.bz2
build_soong-2a5fb91370d2d28b0bb0b9b32e2fe0b8af5d6c94.zip
Merge changes from topic "sdk_version_variant" into rvc-dev
* changes: Add sdk mutator for native modules Require apps built against the SDK to use JNI built against the NDK
Diffstat (limited to 'android')
-rw-r--r--android/neverallow.go44
-rw-r--r--android/neverallow_test.go50
2 files changed, 94 insertions, 0 deletions
diff --git a/android/neverallow.go b/android/neverallow.go
index 4d3a16fb..cf09792e 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -54,6 +54,7 @@ func init() {
AddNeverAllowRules(createLibcoreRules()...)
AddNeverAllowRules(createMediaRules()...)
AddNeverAllowRules(createJavaDeviceForHostRules()...)
+ AddNeverAllowRules(createCcSdkVariantRules()...)
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -177,6 +178,37 @@ func createJavaDeviceForHostRules() []Rule {
}
}
+func createCcSdkVariantRules() []Rule {
+ sdkVersionOnlyWhitelist := []string{
+ // derive_sdk_prefer32 has stem: "derive_sdk" which conflicts with the derive_sdk.
+ // This sometimes works because the APEX modules that contain derive_sdk and
+ // derive_sdk_prefer32 suppress the platform installation rules, but fails when
+ // the APEX modules contain the SDK variant and the platform variant still exists.
+ "frameworks/base/apex/sdkextensions/derive_sdk",
+ }
+
+ platformVariantPropertiesWhitelist := []string{
+ // android_native_app_glue and libRSSupport use native_window.h but target old
+ // sdk versions (minimum and 9 respectively) where libnativewindow didn't exist,
+ // so they can't add libnativewindow to shared_libs to get the header directory
+ // for the platform variant. Allow them to use the platform variant
+ // property to set shared_libs.
+ "prebuilts/ndk",
+ "frameworks/rs",
+ }
+
+ return []Rule{
+ NeverAllow().
+ NotIn(sdkVersionOnlyWhitelist...).
+ WithMatcher("sdk_variant_only", isSetMatcherInstance).
+ Because("sdk_variant_only can only be used in whitelisted projects"),
+ NeverAllow().
+ NotIn(platformVariantPropertiesWhitelist...).
+ WithMatcher("platform.shared_libs", isSetMatcherInstance).
+ Because("platform variant properties can only be used in whitelisted projects"),
+ }
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
@@ -268,6 +300,18 @@ func (m *regexMatcher) String() string {
return ".regexp(" + m.re.String() + ")"
}
+type isSetMatcher struct{}
+
+func (m *isSetMatcher) Test(value string) bool {
+ return value != ""
+}
+
+func (m *isSetMatcher) String() string {
+ return ".is-set"
+}
+
+var isSetMatcherInstance = &isSetMatcher{}
+
type ruleProperty struct {
fields []string // e.x.: Vndk.Enabled
matcher ValueMatcher
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 83b22509..2fc42e31 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -259,6 +259,50 @@ var neverallowTests = []struct {
}`),
},
},
+ // 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 @@ type mockCcLibraryProperties struct {
Include_dirs []string
Vendor_available *bool
Static_libs []string
+ Sdk_version *string
+ Sdk_variant_only *bool
Vndk struct {
Enabled *bool
@@ -315,6 +361,10 @@ type mockCcLibraryProperties struct {
Cflags []string
}
}
+
+ Platform struct {
+ Shared_libs []string
+ }
}
type mockCcLibraryModule struct {