blob: fce4c745b8f4a019f3dea82e12db7ad9d6c73f8b [file] [log] [blame]
Rupert Shuttleworth378fc1b2021-07-28 08:03: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/etc"
20
21 "testing"
22)
23
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) {
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 (&tc).ModuleTypeUnderTest = "prebuilt_etc"
27 (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory
28 RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040029}
30
31func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) {
32}
33
34func TestPrebuiltEtcSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000035 runPrebuiltEtcTestCase(t, Bp2buildTestCase{
36 Description: "prebuilt_etc - simple example",
37 Filesystem: map[string]string{},
38 Blueprint: `
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040039prebuilt_etc {
40 name: "apex_tz_version",
41 src: "version/tz_version",
42 filename: "tz_version",
43 sub_dir: "tz",
44 installable: false,
45}
46`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000047 ExpectedBazelTargets: []string{
48 makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050049 "filename": `"tz_version"`,
50 "installable": `False`,
51 "src": `"version/tz_version"`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -050052 "dir": `"etc/tz"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050053 })}})
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040054}
Liz Kammerdff00ea2021-10-04 13:44:34 -040055
56func TestPrebuiltEtcArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000057 runPrebuiltEtcTestCase(t, Bp2buildTestCase{
58 Description: "prebuilt_etc - arch variant",
59 Filesystem: map[string]string{},
60 Blueprint: `
Liz Kammerdff00ea2021-10-04 13:44:34 -040061prebuilt_etc {
62 name: "apex_tz_version",
63 src: "version/tz_version",
64 filename: "tz_version",
65 sub_dir: "tz",
66 installable: false,
67 arch: {
68 arm: {
69 src: "arm",
70 },
71 arm64: {
72 src: "arm64",
73 },
74 }
75}
76`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000077 ExpectedBazelTargets: []string{
78 makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050079 "filename": `"tz_version"`,
80 "installable": `False`,
81 "src": `select({
Liz Kammerdff00ea2021-10-04 13:44:34 -040082 "//build/bazel/platforms/arch:arm": "arm",
83 "//build/bazel/platforms/arch:arm64": "arm64",
84 "//conditions:default": "version/tz_version",
Liz Kammer78cfdaa2021-11-08 12:56:31 -050085 })`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -050086 "dir": `"etc/tz"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050087 })}})
Liz Kammerdff00ea2021-10-04 13:44:34 -040088}
Chris Parsons58852a02021-12-09 18:10:18 -050089
90func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000091 runPrebuiltEtcTestCase(t, Bp2buildTestCase{
92 Description: "prebuilt_etc - arch variant",
93 Filesystem: map[string]string{},
94 Blueprint: `
Chris Parsons58852a02021-12-09 18:10:18 -050095prebuilt_etc {
96 name: "apex_tz_version",
97 src: "version/tz_version",
98 filename: "tz_version",
99 sub_dir: "tz",
100 installable: false,
101 arch: {
102 arm: {
103 src: "arm",
104 },
105 arm64: {
106 src: "darwin_or_arm64",
107 },
108 },
109 target: {
110 darwin: {
111 src: "darwin_or_arm64",
112 }
113 },
114}
115`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000116 ExpectedBazelTargets: []string{
117 makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
Chris Parsons58852a02021-12-09 18:10:18 -0500118 "filename": `"tz_version"`,
119 "installable": `False`,
120 "src": `select({
121 "//build/bazel/platforms/os_arch:android_arm": "arm",
122 "//build/bazel/platforms/os_arch:android_arm64": "darwin_or_arm64",
123 "//build/bazel/platforms/os_arch:darwin_arm64": "darwin_or_arm64",
124 "//build/bazel/platforms/os_arch:darwin_x86_64": "darwin_or_arm64",
125 "//build/bazel/platforms/os_arch:linux_bionic_arm64": "darwin_or_arm64",
126 "//conditions:default": "version/tz_version",
127 })`,
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500128 "dir": `"etc/tz"`,
129 })}})
130}
131
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000132func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500133 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000134 (&tc).ModuleTypeUnderTest = "prebuilt_usr_share"
135 (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory
136 RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500137}
138
139func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) {
140}
141
142func TestPrebuiltUsrShareSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000143 runPrebuiltUsrShareTestCase(t, Bp2buildTestCase{
144 Description: "prebuilt_usr_share - simple example",
145 Filesystem: map[string]string{},
146 Blueprint: `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500147prebuilt_usr_share {
148 name: "apex_tz_version",
149 src: "version/tz_version",
150 filename: "tz_version",
151 sub_dir: "tz",
152 installable: false,
153}
154`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000155 ExpectedBazelTargets: []string{
156 makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500157 "filename": `"tz_version"`,
158 "installable": `False`,
159 "src": `"version/tz_version"`,
160 "dir": `"usr/share/tz"`,
161 })}})
162}
163
164func TestPrebuiltEtcNoSubdir(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000165 runPrebuiltEtcTestCase(t, Bp2buildTestCase{
166 Description: "prebuilt_etc - no subdir",
167 Filesystem: map[string]string{},
168 Blueprint: `
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500169prebuilt_etc {
170 name: "apex_tz_version",
171 src: "version/tz_version",
172 filename: "tz_version",
173 installable: false,
174}
175`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000176 ExpectedBazelTargets: []string{
177 makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc78604e2022-02-28 18:22:59 -0500178 "filename": `"tz_version"`,
179 "installable": `False`,
180 "src": `"version/tz_version"`,
181 "dir": `"etc"`,
Chris Parsons58852a02021-12-09 18:10:18 -0500182 })}})
183}