blob: a3825e663bc97af128ee5cddecb64a6e63ad0267 [file] [log] [blame]
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04001// 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
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/apex"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040020 "android/soong/cc"
21 "android/soong/java"
Jingwen Chenb07c9012021-12-08 10:05:45 +000022 "android/soong/sh"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040023
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040024 "testing"
25)
26
27func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
28 t.Helper()
29 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
30}
31
32func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040033 // CC module types needed as they can be APEX dependencies
34 cc.RegisterCCBuildComponents(ctx)
35
Jingwen Chenb07c9012021-12-08 10:05:45 +000036 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
37 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040038 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 Shuttlewortha9d76dd2021-07-02 07:17:16 -040042}
43
44func TestApexBundleSimple(t *testing.T) {
45 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040046 description: "apex - example with all props",
47 moduleTypeUnderTest: "apex",
48 moduleTypeUnderTestFactory: apex.BundleFactory,
49 filesystem: map[string]string{},
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040050 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040051apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000052 name: "com.android.apogee.key",
53 public_key: "com.android.apogee.avbpubkey",
54 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040055 bazel_module: { bp2build_available: false },
56}
57
58android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000059 name: "com.android.apogee.certificate",
60 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040061 bazel_module: { bp2build_available: false },
62}
63
64cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000065 name: "native_shared_lib_1",
66 bazel_module: { bp2build_available: false },
67}
68
69cc_library {
70 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040071 bazel_module: { bp2build_available: false },
72}
73
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040074// TODO(b/194878861): Add bp2build support for prebuilt_etc
75cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000076 name: "pretend_prebuilt_1",
77 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040078}
79
80// TODO(b/194878861): Add bp2build support for prebuilt_etc
81cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000082 name: "pretend_prebuilt_2",
83 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040084}
85
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040086filegroup {
87 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +000088 srcs: [
89 "com.android.apogee-file_contexts",
90 ],
91 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040092}
93
Jingwen Chenb07c9012021-12-08 10:05:45 +000094cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
95sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
96
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040097apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040098 name: "com.android.apogee",
99 manifest: "apogee_manifest.json",
100 androidManifest: "ApogeeAndroidManifest.xml",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000101 file_contexts: "com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400102 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 Chenb07c9012021-12-08 10:05:45 +0000112 "cc_binary_1",
113 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400114 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400115 prebuilts: [
116 "pretend_prebuilt_1",
117 "pretend_prebuilt_2",
118 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400119}
120`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500121 expectedBazelTargets: []string{
122 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
123 "android_manifest": `"ApogeeAndroidManifest.xml"`,
124 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000125 ":cc_binary_1",
126 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500127 ]`,
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 Shuttleworth6e4950a2021-07-27 01:34:59 -0400135 ":native_shared_lib_1",
136 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500137 ]`,
138 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400139 ":pretend_prebuilt_1",
140 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500141 ]`,
142 "updatable": "False",
143 }),
144 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400145}
146
147func TestApexBundleDefaultPropertyValues(t *testing.T) {
148 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400149 description: "apex - default property values",
150 moduleTypeUnderTest: "apex",
151 moduleTypeUnderTestFactory: apex.BundleFactory,
152 filesystem: map[string]string{},
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400153 blueprint: `
154apex {
155 name: "com.android.apogee",
156 manifest: "apogee_manifest.json",
157}
158`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500159 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
160 "manifest": `"apogee_manifest.json"`,
161 }),
162 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400163}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000164
165func TestApexBundleHasBazelModuleProps(t *testing.T) {
166 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400167 description: "apex - has bazel module props",
168 moduleTypeUnderTest: "apex",
169 moduleTypeUnderTestFactory: apex.BundleFactory,
170 filesystem: map[string]string{},
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000171 blueprint: `
172apex {
173 name: "apogee",
174 manifest: "manifest.json",
175 bazel_module: { bp2build_available: true },
176}
177`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500178 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
179 "manifest": `"manifest.json"`,
180 }),
181 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000182}