blob: 64440dfa3f629ad245d6462e7ba873e9fb18f50b [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{
Jingwen Chenb07c9012021-12-08 10:05:45 +000046 description: "apex - example with all props",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040047 moduleTypeUnderTest: "apex",
48 moduleTypeUnderTestFactory: apex.BundleFactory,
49 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
50 filesystem: map[string]string{},
51 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040052apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000053 name: "com.android.apogee.key",
54 public_key: "com.android.apogee.avbpubkey",
55 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040056 bazel_module: { bp2build_available: false },
57}
58
59android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000060 name: "com.android.apogee.certificate",
61 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040062 bazel_module: { bp2build_available: false },
63}
64
65cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000066 name: "native_shared_lib_1",
67 bazel_module: { bp2build_available: false },
68}
69
70cc_library {
71 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040072 bazel_module: { bp2build_available: false },
73}
74
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040075// TODO(b/194878861): Add bp2build support for prebuilt_etc
76cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000077 name: "pretend_prebuilt_1",
78 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040079}
80
81// TODO(b/194878861): Add bp2build support for prebuilt_etc
82cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000083 name: "pretend_prebuilt_2",
84 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040085}
86
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040087filegroup {
88 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +000089 srcs: [
90 "com.android.apogee-file_contexts",
91 ],
92 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040093}
94
Jingwen Chenb07c9012021-12-08 10:05:45 +000095cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
96sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
97
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040098apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040099 name: "com.android.apogee",
100 manifest: "apogee_manifest.json",
101 androidManifest: "ApogeeAndroidManifest.xml",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000102 file_contexts: "com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400103 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 Chenb07c9012021-12-08 10:05:45 +0000113 "cc_binary_1",
114 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400115 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400116 prebuilts: [
117 "pretend_prebuilt_1",
118 "pretend_prebuilt_2",
119 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400120}
121`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500122 expectedBazelTargets: []string{
123 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
124 "android_manifest": `"ApogeeAndroidManifest.xml"`,
125 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000126 ":cc_binary_1",
127 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500128 ]`,
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 Shuttleworth6e4950a2021-07-27 01:34:59 -0400136 ":native_shared_lib_1",
137 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500138 ]`,
139 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400140 ":pretend_prebuilt_1",
141 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500142 ]`,
143 "updatable": "False",
144 }),
145 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400146}
147
148func 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: `
156apex {
157 name: "com.android.apogee",
158 manifest: "apogee_manifest.json",
159}
160`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500161 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
162 "manifest": `"apogee_manifest.json"`,
163 }),
164 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400165}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000166
167func 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: `
175apex {
176 name: "apogee",
177 manifest: "manifest.json",
178 bazel_module: { bp2build_available: true },
179}
180`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500181 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
182 "manifest": `"manifest.json"`,
183 }),
184 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000185}