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" |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 22 | "android/soong/sh" |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 23 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 24 | "testing" |
| 25 | ) |
| 26 | |
| 27 | func runApexTestCase(t *testing.T, tc bp2buildTestCase) { |
| 28 | t.Helper() |
| 29 | runBp2BuildTestCase(t, registerApexModuleTypes, tc) |
| 30 | } |
| 31 | |
| 32 | func registerApexModuleTypes(ctx android.RegistrationContext) { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 33 | // CC module types needed as they can be APEX dependencies |
| 34 | cc.RegisterCCBuildComponents(ctx) |
| 35 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 36 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
| 37 | ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 38 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 39 | ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) |
| 40 | ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) |
| 41 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | func TestApexBundleSimple(t *testing.T) { |
| 45 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 46 | description: "apex - example with all props", |
| 47 | moduleTypeUnderTest: "apex", |
| 48 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 49 | filesystem: map[string]string{}, |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 50 | blueprint: ` |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 51 | apex_key { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 52 | name: "com.android.apogee.key", |
| 53 | public_key: "com.android.apogee.avbpubkey", |
| 54 | private_key: "com.android.apogee.pem", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 55 | bazel_module: { bp2build_available: false }, |
| 56 | } |
| 57 | |
| 58 | android_app_certificate { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 59 | name: "com.android.apogee.certificate", |
| 60 | certificate: "com.android.apogee", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 61 | bazel_module: { bp2build_available: false }, |
| 62 | } |
| 63 | |
| 64 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 65 | name: "native_shared_lib_1", |
| 66 | bazel_module: { bp2build_available: false }, |
| 67 | } |
| 68 | |
| 69 | cc_library { |
| 70 | name: "native_shared_lib_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 71 | bazel_module: { bp2build_available: false }, |
| 72 | } |
| 73 | |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 74 | // TODO(b/194878861): Add bp2build support for prebuilt_etc |
| 75 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 76 | name: "pretend_prebuilt_1", |
| 77 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // TODO(b/194878861): Add bp2build support for prebuilt_etc |
| 81 | cc_library { |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 82 | name: "pretend_prebuilt_2", |
| 83 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 86 | filegroup { |
| 87 | name: "com.android.apogee-file_contexts", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 88 | srcs: [ |
| 89 | "com.android.apogee-file_contexts", |
| 90 | ], |
| 91 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 94 | cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } |
| 95 | sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } |
| 96 | |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 97 | apex { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 98 | name: "com.android.apogee", |
| 99 | manifest: "apogee_manifest.json", |
| 100 | androidManifest: "ApogeeAndroidManifest.xml", |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 101 | file_contexts: "com.android.apogee-file_contexts", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 102 | min_sdk_version: "29", |
| 103 | key: "com.android.apogee.key", |
| 104 | certificate: "com.android.apogee.certificate", |
| 105 | updatable: false, |
| 106 | installable: false, |
| 107 | native_shared_libs: [ |
| 108 | "native_shared_lib_1", |
| 109 | "native_shared_lib_2", |
| 110 | ], |
| 111 | binaries: [ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 112 | "cc_binary_1", |
| 113 | "sh_binary_2", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 114 | ], |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 115 | prebuilts: [ |
| 116 | "pretend_prebuilt_1", |
| 117 | "pretend_prebuilt_2", |
| 118 | ], |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 119 | } |
| 120 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 121 | expectedBazelTargets: []string{ |
| 122 | makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 123 | "android_manifest": `"ApogeeAndroidManifest.xml"`, |
| 124 | "binaries": `[ |
Jingwen Chen | b07c901 | 2021-12-08 10:05:45 +0000 | [diff] [blame] | 125 | ":cc_binary_1", |
| 126 | ":sh_binary_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 127 | ]`, |
| 128 | "certificate": `":com.android.apogee.certificate"`, |
| 129 | "file_contexts": `":com.android.apogee-file_contexts"`, |
| 130 | "installable": "False", |
| 131 | "key": `":com.android.apogee.key"`, |
| 132 | "manifest": `"apogee_manifest.json"`, |
| 133 | "min_sdk_version": `"29"`, |
| 134 | "native_shared_libs": `[ |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 135 | ":native_shared_lib_1", |
| 136 | ":native_shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 137 | ]`, |
| 138 | "prebuilts": `[ |
Rupert Shuttleworth | 9447e1e | 2021-07-28 05:53:42 -0400 | [diff] [blame] | 139 | ":pretend_prebuilt_1", |
| 140 | ":pretend_prebuilt_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 141 | ]`, |
| 142 | "updatable": "False", |
| 143 | }), |
| 144 | }}) |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | func TestApexBundleDefaultPropertyValues(t *testing.T) { |
| 148 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 149 | description: "apex - default property values", |
| 150 | moduleTypeUnderTest: "apex", |
| 151 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 152 | filesystem: map[string]string{}, |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 153 | blueprint: ` |
| 154 | apex { |
| 155 | name: "com.android.apogee", |
| 156 | manifest: "apogee_manifest.json", |
| 157 | } |
| 158 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 159 | expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{ |
| 160 | "manifest": `"apogee_manifest.json"`, |
| 161 | }), |
| 162 | }}) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 163 | } |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 164 | |
| 165 | func TestApexBundleHasBazelModuleProps(t *testing.T) { |
| 166 | runApexTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 167 | description: "apex - has bazel module props", |
| 168 | moduleTypeUnderTest: "apex", |
| 169 | moduleTypeUnderTestFactory: apex.BundleFactory, |
| 170 | filesystem: map[string]string{}, |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 171 | blueprint: ` |
| 172 | apex { |
| 173 | name: "apogee", |
| 174 | manifest: "manifest.json", |
| 175 | bazel_module: { bp2build_available: true }, |
| 176 | } |
| 177 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 178 | expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{ |
| 179 | "manifest": `"manifest.json"`, |
| 180 | }), |
| 181 | }}) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 182 | } |