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 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 24 | func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) { |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 25 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 26 | (&tc).ModuleTypeUnderTest = "prebuilt_etc" |
| 27 | (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory |
| 28 | RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) { |
| 32 | } |
| 33 | |
| 34 | func TestPrebuiltEtcSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 35 | runPrebuiltEtcTestCase(t, Bp2buildTestCase{ |
| 36 | Description: "prebuilt_etc - simple example", |
| 37 | Filesystem: map[string]string{}, |
| 38 | Blueprint: ` |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 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 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 47 | ExpectedBazelTargets: []string{ |
| 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"`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 52 | "dir": `"etc/tz"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 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) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 57 | runPrebuiltEtcTestCase(t, Bp2buildTestCase{ |
| 58 | Description: "prebuilt_etc - arch variant", |
| 59 | Filesystem: map[string]string{}, |
| 60 | Blueprint: ` |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 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 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 77 | ExpectedBazelTargets: []string{ |
| 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 | })`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 86 | "dir": `"etc/tz"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 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) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 91 | runPrebuiltEtcTestCase(t, Bp2buildTestCase{ |
| 92 | Description: "prebuilt_etc - arch variant", |
| 93 | Filesystem: map[string]string{}, |
| 94 | Blueprint: ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 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 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 116 | ExpectedBazelTargets: []string{ |
| 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 | })`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 128 | "dir": `"etc/tz"`, |
| 129 | })}}) |
| 130 | } |
| 131 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 132 | func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 133 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 134 | (&tc).ModuleTypeUnderTest = "prebuilt_usr_share" |
| 135 | (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory |
| 136 | RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) { |
| 140 | } |
| 141 | |
| 142 | func TestPrebuiltUsrShareSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 143 | runPrebuiltUsrShareTestCase(t, Bp2buildTestCase{ |
| 144 | Description: "prebuilt_usr_share - simple example", |
| 145 | Filesystem: map[string]string{}, |
| 146 | Blueprint: ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 147 | prebuilt_usr_share { |
| 148 | name: "apex_tz_version", |
| 149 | src: "version/tz_version", |
| 150 | filename: "tz_version", |
| 151 | sub_dir: "tz", |
| 152 | installable: false, |
| 153 | } |
| 154 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 155 | ExpectedBazelTargets: []string{ |
| 156 | makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 157 | "filename": `"tz_version"`, |
| 158 | "installable": `False`, |
| 159 | "src": `"version/tz_version"`, |
| 160 | "dir": `"usr/share/tz"`, |
| 161 | })}}) |
| 162 | } |
| 163 | |
| 164 | func TestPrebuiltEtcNoSubdir(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 165 | runPrebuiltEtcTestCase(t, Bp2buildTestCase{ |
| 166 | Description: "prebuilt_etc - no subdir", |
| 167 | Filesystem: map[string]string{}, |
| 168 | Blueprint: ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 169 | prebuilt_etc { |
| 170 | name: "apex_tz_version", |
| 171 | src: "version/tz_version", |
| 172 | filename: "tz_version", |
| 173 | installable: false, |
| 174 | } |
| 175 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame^] | 176 | ExpectedBazelTargets: []string{ |
| 177 | makeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 178 | "filename": `"tz_version"`, |
| 179 | "installable": `False`, |
| 180 | "src": `"version/tz_version"`, |
| 181 | "dir": `"etc"`, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 182 | })}}) |
| 183 | } |