blob: 118930994e070d1976abd2c72ed8500b623588f6 [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
28 (&tc).moduleTypeUnderTestBp2BuildMutator = etc.PrebuiltEtcBp2Build
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040029 runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
30}
31
32func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) {
33}
34
35func TestPrebuiltEtcSimple(t *testing.T) {
36 runPrebuiltEtcTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050037 description: "prebuilt_etc - simple example",
38 filesystem: map[string]string{},
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040039 blueprint: `
40prebuilt_etc {
41 name: "apex_tz_version",
42 src: "version/tz_version",
43 filename: "tz_version",
44 sub_dir: "tz",
45 installable: false,
46}
47`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050048 expectedBazelTargets: []string{
49 makeBazelTarget("prebuilt_etc", "apex_tz_version", attrNameToString{
50 "filename": `"tz_version"`,
51 "installable": `False`,
52 "src": `"version/tz_version"`,
53 "sub_dir": `"tz"`,
54 })}})
Rupert Shuttleworth378fc1b2021-07-28 08:03:16 -040055}
Liz Kammerdff00ea2021-10-04 13:44:34 -040056
57func TestPrebuiltEtcArchVariant(t *testing.T) {
58 runPrebuiltEtcTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050059 description: "prebuilt_etc - arch variant",
60 filesystem: map[string]string{},
Liz Kammerdff00ea2021-10-04 13:44:34 -040061 blueprint: `
62prebuilt_etc {
63 name: "apex_tz_version",
64 src: "version/tz_version",
65 filename: "tz_version",
66 sub_dir: "tz",
67 installable: false,
68 arch: {
69 arm: {
70 src: "arm",
71 },
72 arm64: {
73 src: "arm64",
74 },
75 }
76}
77`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050078 expectedBazelTargets: []string{
79 makeBazelTarget("prebuilt_etc", "apex_tz_version", attrNameToString{
80 "filename": `"tz_version"`,
81 "installable": `False`,
82 "src": `select({
Liz Kammerdff00ea2021-10-04 13:44:34 -040083 "//build/bazel/platforms/arch:arm": "arm",
84 "//build/bazel/platforms/arch:arm64": "arm64",
85 "//conditions:default": "version/tz_version",
Liz Kammer78cfdaa2021-11-08 12:56:31 -050086 })`,
87 "sub_dir": `"tz"`,
88 })}})
Liz Kammerdff00ea2021-10-04 13:44:34 -040089}