Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/apex" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 20 | "android/soong/cc" |
| 21 | "android/soong/java" |
| 22 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | func runApexTestCase(t *testing.T, tc bp2buildTestCase) { |
| 27 | t.Helper() |
| 28 | runBp2BuildTestCase(t, registerApexModuleTypes, tc) |
| 29 | } |
| 30 | |
| 31 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 32 | // CC module types needed as they can be APEX dependencies |
| 33 | cc.RegisterCCBuildComponents(ctx) |
| 34 | |
| 35 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 36 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 37 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 38 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func TestApexBundleSimple(t *testing.T) { |
| 42 | runApexTestCase(t, bp2buildTestCase{ |
| 43 | description: "apex - simple example", |
| 44 | moduleTypeUnderTest: "apex", |
| 45 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 46 | moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build, |
| 47 | filesystem: map[string]string{}, |
| 48 | blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 49 | apex_key { |
| 50 | name: "com.android.apogee.key", |
| 51 | public_key: "com.android.apogee.avbpubkey", |
| 52 | private_key: "com.android.apogee.pem", |
| 53 | bazel_module: { bp2build_available: false }, |
| 54 | } |
| 55 | |
| 56 | android_app_certificate { |
| 57 | name: "com.android.apogee.certificate", |
| 58 | certificate: "com.android.apogee", |
| 59 | bazel_module: { bp2build_available: false }, |
| 60 | } |
| 61 | |
| 62 | cc_library { |
| 63 | name: "native_shared_lib_1", |
| 64 | bazel_module: { bp2build_available: false }, |
| 65 | } |
| 66 | |
| 67 | cc_library { |
| 68 | name: "native_shared_lib_2", |
| 69 | bazel_module: { bp2build_available: false }, |
| 70 | } |
| 71 | |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 72 | // TODO(b/194878861): Add bp2build support for prebuilt_etc |
| 73 | cc_library { |
| 74 | name: "pretend_prebuilt_1", |
| 75 | bazel_module: { bp2build_available: false }, |
| 76 | } |
| 77 | |
| 78 | // TODO(b/194878861): Add bp2build support for prebuilt_etc |
| 79 | cc_library { |
| 80 | name: "pretend_prebuilt_2", |
| 81 | bazel_module: { bp2build_available: false }, |
| 82 | } |
| 83 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 84 | filegroup { |
| 85 | name: "com.android.apogee-file_contexts", |
| 86 | srcs: [ |
| 87 | "com.android.apogee-file_contexts", |
| 88 | ], |
| 89 | bazel_module: { bp2build_available: false }, |
| 90 | } |
| 91 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 92 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 93 | name: "com.android.apogee", |
| 94 | manifest: "apogee_manifest.json", |
| 95 | androidManifest: "ApogeeAndroidManifest.xml", |
| 96 | file_contexts: "com.android.apogee-file_contexts", |
| 97 | min_sdk_version: "29", |
| 98 | key: "com.android.apogee.key", |
| 99 | certificate: "com.android.apogee.certificate", |
| 100 | updatable: false, |
| 101 | installable: false, |
| 102 | native_shared_libs: [ |
| 103 | "native_shared_lib_1", |
| 104 | "native_shared_lib_2", |
| 105 | ], |
| 106 | binaries: [ |
| 107 | "binary_1", |
| 108 | "binary_2", |
| 109 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 110 | prebuilts: [ |
| 111 | "pretend_prebuilt_1", |
| 112 | "pretend_prebuilt_2", |
| 113 | ], |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 114 | } |
| 115 | `, |
| 116 | expectedBazelTargets: []string{`apex( |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 117 | name = "com.android.apogee", |
| 118 | android_manifest = "ApogeeAndroidManifest.xml", |
| 119 | binaries = [ |
| 120 | "binary_1", |
| 121 | "binary_2", |
| 122 | ], |
| 123 | certificate = ":com.android.apogee.certificate", |
| 124 | file_contexts = ":com.android.apogee-file_contexts", |
| 125 | installable = False, |
| 126 | key = ":com.android.apogee.key", |
| 127 | manifest = "apogee_manifest.json", |
| 128 | min_sdk_version = "29", |
| 129 | native_shared_libs = [ |
| 130 | ":native_shared_lib_1", |
| 131 | ":native_shared_lib_2", |
| 132 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 133 | prebuilts = [ |
| 134 | ":pretend_prebuilt_1", |
| 135 | ":pretend_prebuilt_2", |
| 136 | ], |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 137 | updatable = False, |
| 138 | )`}}) |
| 139 | } |
| 140 | |
| 141 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
| 142 | runApexTestCase(t, bp2buildTestCase{ |
| 143 | description: "apex - default property values", |
| 144 | moduleTypeUnderTest: "apex", |
| 145 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 146 | moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build, |
| 147 | filesystem: map[string]string{}, |
| 148 | blueprint: ` |
| 149 | apex { |
| 150 | name: "com.android.apogee", |
| 151 | manifest: "apogee_manifest.json", |
| 152 | } |
| 153 | `, |
| 154 | expectedBazelTargets: []string{`apex( |
| 155 | name = "com.android.apogee", |
| 156 | manifest = "apogee_manifest.json", |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 157 | )`}}) |
| 158 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 159 | |
| 160 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
| 161 | runApexTestCase(t, bp2buildTestCase{ |
| 162 | description: "apex - has bazel module props", |
| 163 | moduleTypeUnderTest: "apex", |
| 164 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 165 | moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build, |
| 166 | filesystem: map[string]string{}, |
| 167 | blueprint: ` |
| 168 | apex { |
| 169 | name: "apogee", |
| 170 | manifest: "manifest.json", |
| 171 | bazel_module: { bp2build_available: true }, |
| 172 | } |
| 173 | `, |
| 174 | expectedBazelTargets: []string{`apex( |
| 175 | name = "apogee", |
| 176 | manifest = "manifest.json", |
| 177 | )`}}) |
| 178 | } |