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{ |
| 48 | makeBazelTarget("prebuilt_etc", "apex_tz_version", attrNameToString{ |
| 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{ |
| 78 | makeBazelTarget("prebuilt_etc", "apex_tz_version", attrNameToString{ |
| 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 | } |