blob: e2e08bddd1e7cd2a3e289bc5b6da5b4719179484 [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"
22
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040023 "testing"
24)
25
26func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
27 t.Helper()
28 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
29}
30
31func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040032 // 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 Shuttlewortha9d76dd2021-07-02 07:17:16 -040039}
40
41func 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 Shuttleworth6e4950a2021-07-27 01:34:59 -040049apex_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
56android_app_certificate {
57 name: "com.android.apogee.certificate",
58 certificate: "com.android.apogee",
59 bazel_module: { bp2build_available: false },
60}
61
62cc_library {
63 name: "native_shared_lib_1",
64 bazel_module: { bp2build_available: false },
65}
66
67cc_library {
68 name: "native_shared_lib_2",
69 bazel_module: { bp2build_available: false },
70}
71
72filegroup {
73 name: "com.android.apogee-file_contexts",
74 srcs: [
75 "com.android.apogee-file_contexts",
76 ],
77 bazel_module: { bp2build_available: false },
78}
79
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040080apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040081 name: "com.android.apogee",
82 manifest: "apogee_manifest.json",
83 androidManifest: "ApogeeAndroidManifest.xml",
84 file_contexts: "com.android.apogee-file_contexts",
85 min_sdk_version: "29",
86 key: "com.android.apogee.key",
87 certificate: "com.android.apogee.certificate",
88 updatable: false,
89 installable: false,
90 native_shared_libs: [
91 "native_shared_lib_1",
92 "native_shared_lib_2",
93 ],
94 binaries: [
95 "binary_1",
96 "binary_2",
97 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040098}
99`,
100 expectedBazelTargets: []string{`apex(
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400101 name = "com.android.apogee",
102 android_manifest = "ApogeeAndroidManifest.xml",
103 binaries = [
104 "binary_1",
105 "binary_2",
106 ],
107 certificate = ":com.android.apogee.certificate",
108 file_contexts = ":com.android.apogee-file_contexts",
109 installable = False,
110 key = ":com.android.apogee.key",
111 manifest = "apogee_manifest.json",
112 min_sdk_version = "29",
113 native_shared_libs = [
114 ":native_shared_lib_1",
115 ":native_shared_lib_2",
116 ],
117 updatable = False,
118)`}})
119}
120
121func TestApexBundleDefaultPropertyValues(t *testing.T) {
122 runApexTestCase(t, bp2buildTestCase{
123 description: "apex - default property values",
124 moduleTypeUnderTest: "apex",
125 moduleTypeUnderTestFactory: apex.BundleFactory,
126 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
127 filesystem: map[string]string{},
128 blueprint: `
129apex {
130 name: "com.android.apogee",
131 manifest: "apogee_manifest.json",
132}
133`,
134 expectedBazelTargets: []string{`apex(
135 name = "com.android.apogee",
136 manifest = "apogee_manifest.json",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400137)`}})
138}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000139
140func TestApexBundleHasBazelModuleProps(t *testing.T) {
141 runApexTestCase(t, bp2buildTestCase{
142 description: "apex - has bazel module props",
143 moduleTypeUnderTest: "apex",
144 moduleTypeUnderTestFactory: apex.BundleFactory,
145 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
146 filesystem: map[string]string{},
147 blueprint: `
148apex {
149 name: "apogee",
150 manifest: "manifest.json",
151 bazel_module: { bp2build_available: true },
152}
153`,
154 expectedBazelTargets: []string{`apex(
155 name = "apogee",
156 manifest = "manifest.json",
157)`}})
158}