blob: a00197276cf35d600e840c6bbad5cd04bcb93c9e [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
24func runPrebuiltEtcTestCase(t *testing.T, tc bp2buildTestCase) {
25 t.Helper()
Liz Kammer78cfdaa2021-11-08 12:56:31 -050026 (&tc).moduleTypeUnderTest = "prebuilt_etc"
27 (&tc).moduleTypeUnderTestFactory = etc.PrebuiltEtcFactory
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040028 runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
29}
30
31func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) {
32}
33
34func TestPrebuiltEtcSimple(t *testing.T) {
35 runPrebuiltEtcTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050036 description: "prebuilt_etc - simple example",
37 filesystem: map[string]string{},
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040038 blueprint: `
39prebuilt_etc {
40 name: "apex_tz_version",
41 src: "version/tz_version",
42 filename: "tz_version",
43 sub_dir: "tz",
44 installable: false,
45}
46`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050047 expectedBazelTargets: []string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb81f77e2022-02-28 17:38:34 -050048 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"`,
52 "sub_dir": `"tz"`,
53 })}})
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040054}
Liz Kammerdff00ea2021-10-04 13:44:34 -040055
56func TestPrebuiltEtcArchVariant(t *testing.T) {
57 runPrebuiltEtcTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050058 description: "prebuilt_etc - arch variant",
59 filesystem: map[string]string{},
Liz Kammerdff00ea2021-10-04 13:44:34 -040060 blueprint: `
61prebuilt_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`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050077 expectedBazelTargets: []string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb81f77e2022-02-28 17:38:34 -050078 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 })`,
86 "sub_dir": `"tz"`,
87 })}})
Liz Kammerdff00ea2021-10-04 13:44:34 -040088}
Chris Parsons58852a02021-12-09 18:10:18 -050089
90func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) {
91 runPrebuiltEtcTestCase(t, bp2buildTestCase{
92 description: "prebuilt_etc - arch variant",
93 filesystem: map[string]string{},
94 blueprint: `
95prebuilt_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`,
116 expectedBazelTargets: []string{
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb81f77e2022-02-28 17:38:34 -0500117 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 })`,
128 "sub_dir": `"tz"`,
129 })}})
130}