From 22890c466e8d69968b420af1e2b59341913f6042 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Tue, 5 Jan 2021 12:04:17 +0000 Subject: [PATCH] Enforce checks for android_app and android_app_import. Bug: 132357300 Test: lunch aosp_cf_x86_phone-userdebug && m Change-Id: Ib9653aa27a173f0f0c03c7c9b0963d8ea71bb155 --- java/app.go | 7 ++++++- java/app_import.go | 2 ++ java/app_import_test.go | 18 +++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/java/app.go b/java/app.go index 249313c35..574472c1b 100755 --- a/java/app.go +++ b/java/app.go @@ -905,6 +905,8 @@ func AndroidAppFactory() android.Module { &module.appProperties, &module.overridableAppProperties) + module.usesLibrary.enforce = true + android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.appProperties.Overrides) @@ -1175,6 +1177,9 @@ type UsesLibraryProperties struct { // with knowledge of their shared libraries. type usesLibrary struct { usesLibraryProperties UsesLibraryProperties + + // Whether to enforce verify_uses_library check. + enforce bool } func (u *usesLibrary) addLib(lib string, optional bool) { @@ -1241,7 +1246,7 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext func (u *usesLibrary) enforceUsesLibraries() bool { defaultEnforceUsesLibs := len(u.usesLibraryProperties.Uses_libs) > 0 || len(u.usesLibraryProperties.Optional_uses_libs) > 0 - return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, defaultEnforceUsesLibs) + return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, u.enforce || defaultEnforceUsesLibs) } // Freeze the value of `enforce_uses_libs` based on the current values of `uses_libs` and `optional_uses_libs`. diff --git a/java/app_import.go b/java/app_import.go index 2054785f5..df940f1ff 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -430,6 +430,8 @@ func AndroidAppImportFactory() android.Module { android.InitDefaultableModule(module) android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk") + module.usesLibrary.enforce = true + return module } diff --git a/java/app_import_test.go b/java/app_import_test.go index 3b55c814a..344d23b55 100644 --- a/java/app_import_test.go +++ b/java/app_import_test.go @@ -182,31 +182,31 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { name: "no preferred", aaptPreferredConfig: nil, aaptPrebuiltDPI: []string{}, - expected: "prebuilts/apk/app.apk", + expected: "verify_uses_libraries/apk/app.apk", }, { name: "AAPTPreferredConfig matches", aaptPreferredConfig: proptools.StringPtr("xhdpi"), aaptPrebuiltDPI: []string{"xxhdpi", "ldpi"}, - expected: "prebuilts/apk/app_xhdpi.apk", + expected: "verify_uses_libraries/apk/app_xhdpi.apk", }, { name: "AAPTPrebuiltDPI matches", aaptPreferredConfig: proptools.StringPtr("mdpi"), aaptPrebuiltDPI: []string{"xxhdpi", "xhdpi"}, - expected: "prebuilts/apk/app_xxhdpi.apk", + expected: "verify_uses_libraries/apk/app_xxhdpi.apk", }, { name: "non-first AAPTPrebuiltDPI matches", aaptPreferredConfig: proptools.StringPtr("mdpi"), aaptPrebuiltDPI: []string{"ldpi", "xhdpi"}, - expected: "prebuilts/apk/app_xhdpi.apk", + expected: "verify_uses_libraries/apk/app_xhdpi.apk", }, { name: "no matches", aaptPreferredConfig: proptools.StringPtr("mdpi"), aaptPrebuiltDPI: []string{"ldpi", "xxxhdpi"}, - expected: "prebuilts/apk/app.apk", + expected: "verify_uses_libraries/apk/app.apk", }, } @@ -225,7 +225,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } - if test.expected != matches[1] { + if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) } } @@ -302,7 +302,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { }, } `, - expected: "prebuilts/apk/app_arm64.apk", + expected: "verify_uses_libraries/apk/app_arm64.apk", }, { name: "no matching arch", @@ -321,7 +321,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { }, } `, - expected: "prebuilts/apk/app.apk", + expected: "verify_uses_libraries/apk/app.apk", }, { name: "no matching arch without default", @@ -359,7 +359,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } - if test.expected != matches[1] { + if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) } }