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