blob: d38300e279ce7a2589235cf0f0d8c1dfed0d6585 [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 Shuttleworth69bf4c02021-07-26 04:03:40 -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 Shuttleworth69bf4c02021-07-26 04:03:40 -040032 // CC module types needed as they can be APEX dependencies viathe native_shared_libs property
33 cc.RegisterCCBuildComponents(ctx)
34 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
35
36 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
37
38 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
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 Shuttleworth69bf4c02021-07-26 04:03:40 -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
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040072apex {
Rupert Shuttleworth69bf4c02021-07-26 04:03:40 -040073 name: "com.android.apogee",
74 manifest: "apogee_manifest.json",
75 androidManifest: "ApogeeAndroidManifest.xml",
76 file_contexts: "com.android.apogee-file_contexts",
77 min_sdk_version: "29",
78 key: "com.android.apogee.key",
79 certificate: "com.android.apogee.certificate",
80 updatable: false,
81 installable: false,
82 native_shared_libs: [
83 "native_shared_lib_1",
84 "native_shared_lib_2",
85 ],
86 binaries: [
87 "binary_1",
88 "binary_2",
89 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040090}
91`,
92 expectedBazelTargets: []string{`apex(
Rupert Shuttleworth69bf4c02021-07-26 04:03:40 -040093 name = "com.android.apogee",
94 android_manifest = "ApogeeAndroidManifest.xml",
95 binaries = [
96 "binary_1",
97 "binary_2",
98 ],
99 certificate = ":com.android.apogee.certificate",
100 file_contexts = "com.android.apogee-file_contexts",
101 installable = False,
102 key = ":com.android.apogee.key",
103 manifest = "apogee_manifest.json",
104 min_sdk_version = "29",
105 native_shared_libs = [
106 ":native_shared_lib_1",
107 ":native_shared_lib_2",
108 ],
109 updatable = False,
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400110)`}})
111}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000112
113func TestApexBundleHasBazelModuleProps(t *testing.T) {
114 runApexTestCase(t, bp2buildTestCase{
115 description: "apex - has bazel module props",
116 moduleTypeUnderTest: "apex",
117 moduleTypeUnderTestFactory: apex.BundleFactory,
118 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
119 filesystem: map[string]string{},
120 blueprint: `
121apex {
122 name: "apogee",
123 manifest: "manifest.json",
124 bazel_module: { bp2build_available: true },
125}
126`,
127 expectedBazelTargets: []string{`apex(
128 name = "apogee",
129 manifest = "manifest.json",
130)`}})
131}