Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 1 | // 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/etc" |
| 20 | |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func runPrebuiltEtcTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 26 | (&tc).moduleTypeUnderTest = "prebuilt_etc" |
| 27 | (&tc).moduleTypeUnderTestFactory = etc.PrebuiltEtcFactory |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 28 | runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) |
| 29 | } |
| 30 | |
| 31 | func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) { |
| 32 | } |
| 33 | |
| 34 | func TestPrebuiltEtcSimple(t *testing.T) { |
| 35 | runPrebuiltEtcTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 36 | description: "prebuilt_etc - simple example", |
| 37 | filesystem: map[string]string{}, |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 38 | blueprint: ` |
| 39 | prebuilt_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 Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 47 | expectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b81f77e | 2022-02-28 17:38:34 -0500 | [diff] [blame^] | 48 | makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 49 | "filename": `"tz_version"`, |
| 50 | "installable": `False`, |
| 51 | "src": `"version/tz_version"`, |
| 52 | "sub_dir": `"tz"`, |
| 53 | })}}) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 54 | } |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 55 | |
| 56 | func TestPrebuiltEtcArchVariant(t *testing.T) { |
| 57 | runPrebuiltEtcTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 58 | description: "prebuilt_etc - arch variant", |
| 59 | filesystem: map[string]string{}, |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 60 | blueprint: ` |
| 61 | prebuilt_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 Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 77 | expectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b81f77e | 2022-02-28 17:38:34 -0500 | [diff] [blame^] | 78 | makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 79 | "filename": `"tz_version"`, |
| 80 | "installable": `False`, |
| 81 | "src": `select({ |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 82 | "//build/bazel/platforms/arch:arm": "arm", |
| 83 | "//build/bazel/platforms/arch:arm64": "arm64", |
| 84 | "//conditions:default": "version/tz_version", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 85 | })`, |
| 86 | "sub_dir": `"tz"`, |
| 87 | })}}) |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 88 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 89 | |
| 90 | func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) { |
| 91 | runPrebuiltEtcTestCase(t, bp2buildTestCase{ |
| 92 | description: "prebuilt_etc - arch variant", |
| 93 | filesystem: map[string]string{}, |
| 94 | blueprint: ` |
| 95 | prebuilt_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 Thaureaux | b81f77e | 2022-02-28 17:38:34 -0500 | [diff] [blame^] | 117 | makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 118 | "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 | } |