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 |
| 28 | (&tc).moduleTypeUnderTestBp2BuildMutator = etc.PrebuiltEtcBp2Build |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 29 | runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) |
| 30 | } |
| 31 | |
| 32 | func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) { |
| 33 | } |
| 34 | |
| 35 | func TestPrebuiltEtcSimple(t *testing.T) { |
| 36 | runPrebuiltEtcTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame^] | 37 | description: "prebuilt_etc - simple example", |
| 38 | filesystem: map[string]string{}, |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 39 | blueprint: ` |
| 40 | prebuilt_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 Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame^] | 48 | 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 Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 55 | } |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 56 | |
| 57 | func TestPrebuiltEtcArchVariant(t *testing.T) { |
| 58 | runPrebuiltEtcTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame^] | 59 | description: "prebuilt_etc - arch variant", |
| 60 | filesystem: map[string]string{}, |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 61 | blueprint: ` |
| 62 | prebuilt_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 Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame^] | 78 | expectedBazelTargets: []string{ |
| 79 | makeBazelTarget("prebuilt_etc", "apex_tz_version", attrNameToString{ |
| 80 | "filename": `"tz_version"`, |
| 81 | "installable": `False`, |
| 82 | "src": `select({ |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 83 | "//build/bazel/platforms/arch:arm": "arm", |
| 84 | "//build/bazel/platforms/arch:arm64": "arm64", |
| 85 | "//conditions:default": "version/tz_version", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame^] | 86 | })`, |
| 87 | "sub_dir": `"tz"`, |
| 88 | })}}) |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 89 | } |