Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 1 | // Copyright 2022 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 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 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 | package bp2build |
| 15 | |
| 16 | import ( |
| 17 | "fmt" |
| 18 | "testing" |
| 19 | |
Spandan Das | e12d252 | 2023-09-12 21:42:31 +0000 | [diff] [blame] | 20 | "android/soong/android" |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 21 | "android/soong/cc" |
| 22 | ) |
| 23 | |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 24 | func runCcPrebuiltLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | (&tc).ModuleTypeUnderTest = "cc_prebuilt_library" |
| 27 | (&tc).ModuleTypeUnderTestFactory = cc.PrebuiltLibraryFactory |
| 28 | RunBp2BuildTestCaseSimple(t, tc) |
| 29 | } |
| 30 | |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 31 | func TestPrebuiltLibraryStaticAndSharedSimple(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 32 | runCcPrebuiltLibraryTestCase(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 33 | Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 34 | Description: "prebuilt library static and shared simple", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 35 | Filesystem: map[string]string{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 36 | "libf.so": "", |
| 37 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 38 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 39 | cc_prebuilt_library { |
| 40 | name: "libtest", |
| 41 | srcs: ["libf.so"], |
| 42 | bazel_module: { bp2build_available: true }, |
| 43 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 44 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 45 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 46 | "static_library": `"libf.so"`, |
| 47 | }), |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c353abd | 2023-03-10 20:57:38 +0000 | [diff] [blame] | 48 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 49 | "static_library": `"libf.so"`, |
| 50 | "alwayslink": "True", |
| 51 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 52 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 53 | "shared_library": `"libf.so"`, |
| 54 | }), |
| 55 | }, |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | func TestPrebuiltLibraryWithArchVariance(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 60 | runCcPrebuiltLibraryTestCase(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 61 | Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 62 | Description: "prebuilt library with arch variance", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 63 | Filesystem: map[string]string{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 64 | "libf.so": "", |
| 65 | "libg.so": "", |
| 66 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 67 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 68 | cc_prebuilt_library { |
| 69 | name: "libtest", |
| 70 | arch: { |
| 71 | arm64: { srcs: ["libf.so"], }, |
| 72 | arm: { srcs: ["libg.so"], }, |
| 73 | }, |
| 74 | bazel_module: { bp2build_available: true }, |
| 75 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 76 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 77 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 78 | "static_library": `select({ |
| 79 | "//build/bazel/platforms/arch:arm": "libg.so", |
| 80 | "//build/bazel/platforms/arch:arm64": "libf.so", |
| 81 | "//conditions:default": None, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c353abd | 2023-03-10 20:57:38 +0000 | [diff] [blame] | 82 | })`}), |
| 83 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 84 | "alwayslink": "True", |
| 85 | "static_library": `select({ |
| 86 | "//build/bazel/platforms/arch:arm": "libg.so", |
| 87 | "//build/bazel/platforms/arch:arm64": "libf.so", |
| 88 | "//conditions:default": None, |
| 89 | })`}), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 90 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 91 | "shared_library": `select({ |
| 92 | "//build/bazel/platforms/arch:arm": "libg.so", |
| 93 | "//build/bazel/platforms/arch:arm64": "libf.so", |
| 94 | "//conditions:default": None, |
| 95 | })`, |
| 96 | }), |
| 97 | }, |
| 98 | }) |
| 99 | } |
| 100 | |
| 101 | func TestPrebuiltLibraryAdditionalAttrs(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 102 | runCcPrebuiltLibraryTestCase(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 103 | Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 104 | Description: "prebuilt library additional attributes", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 105 | Filesystem: map[string]string{ |
Paul Duffin | 4c0765a | 2022-10-29 17:48:00 +0100 | [diff] [blame] | 106 | "libf.so": "", |
| 107 | "testdir/1/include.h": "", |
| 108 | "testdir/2/other.h": "", |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 109 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 110 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 111 | cc_prebuilt_library { |
| 112 | name: "libtest", |
| 113 | srcs: ["libf.so"], |
| 114 | export_include_dirs: ["testdir/1/"], |
| 115 | export_system_include_dirs: ["testdir/2/"], |
| 116 | bazel_module: { bp2build_available: true }, |
| 117 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 118 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 119 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 120 | "static_library": `"libf.so"`, |
| 121 | "export_includes": `["testdir/1/"]`, |
| 122 | "export_system_includes": `["testdir/2/"]`, |
| 123 | }), |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c353abd | 2023-03-10 20:57:38 +0000 | [diff] [blame] | 124 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 125 | "static_library": `"libf.so"`, |
| 126 | "export_includes": `["testdir/1/"]`, |
| 127 | "export_system_includes": `["testdir/2/"]`, |
| 128 | "alwayslink": "True", |
| 129 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 130 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 131 | "shared_library": `"libf.so"`, |
| 132 | "export_includes": `["testdir/1/"]`, |
| 133 | "export_system_includes": `["testdir/2/"]`, |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 134 | }), |
| 135 | }, |
| 136 | }) |
| 137 | } |
| 138 | |
| 139 | func TestPrebuiltLibrarySharedStanzaFails(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 140 | runCcPrebuiltLibraryTestCase(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 141 | Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 142 | Description: "prebuilt library with shared stanza fails because multiple sources", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 143 | Filesystem: map[string]string{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 144 | "libf.so": "", |
| 145 | "libg.so": "", |
| 146 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 147 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 148 | cc_prebuilt_library { |
| 149 | name: "libtest", |
| 150 | srcs: ["libf.so"], |
| 151 | shared: { |
| 152 | srcs: ["libg.so"], |
| 153 | }, |
| 154 | bazel_module: { bp2build_available: true }, |
| 155 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 156 | ExpectedErr: fmt.Errorf("Expected at most one source file"), |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 157 | }) |
| 158 | } |
| 159 | |
| 160 | func TestPrebuiltLibraryStaticStanzaFails(t *testing.T) { |
Trevor Radcliffe | 1b4b2d9 | 2022-09-01 18:57:01 +0000 | [diff] [blame] | 161 | RunBp2BuildTestCaseSimple(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 162 | Bp2buildTestCase{ |
| 163 | Description: "prebuilt library with static stanza fails because multiple sources", |
| 164 | ModuleTypeUnderTest: "cc_prebuilt_library", |
| 165 | ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory, |
| 166 | Filesystem: map[string]string{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 167 | "libf.so": "", |
| 168 | "libg.so": "", |
| 169 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 170 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 171 | cc_prebuilt_library { |
| 172 | name: "libtest", |
| 173 | srcs: ["libf.so"], |
| 174 | static: { |
| 175 | srcs: ["libg.so"], |
| 176 | }, |
| 177 | bazel_module: { bp2build_available: true }, |
| 178 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 179 | ExpectedErr: fmt.Errorf("Expected at most one source file"), |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 180 | }) |
| 181 | } |
| 182 | |
| 183 | func TestPrebuiltLibrarySharedAndStaticStanzas(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 184 | runCcPrebuiltLibraryTestCase(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 185 | Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 186 | Description: "prebuilt library with both shared and static stanzas", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 187 | Filesystem: map[string]string{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 188 | "libf.so": "", |
| 189 | "libg.so": "", |
| 190 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 191 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 192 | cc_prebuilt_library { |
| 193 | name: "libtest", |
| 194 | static: { |
| 195 | srcs: ["libf.so"], |
| 196 | }, |
| 197 | shared: { |
| 198 | srcs: ["libg.so"], |
| 199 | }, |
| 200 | bazel_module: { bp2build_available: true }, |
| 201 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 202 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 203 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 204 | "static_library": `"libf.so"`, |
| 205 | }), |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c353abd | 2023-03-10 20:57:38 +0000 | [diff] [blame] | 206 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 207 | "static_library": `"libf.so"`, |
| 208 | "alwayslink": "True", |
| 209 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 210 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 211 | "shared_library": `"libg.so"`, |
| 212 | }), |
| 213 | }, |
| 214 | }) |
| 215 | } |
| 216 | |
| 217 | // TODO(b/228623543): When this bug is fixed, enable this test |
| 218 | //func TestPrebuiltLibraryOnlyShared(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 219 | // runCcPrebuiltLibraryTestCase(t, |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 220 | // bp2buildTestCase{ |
| 221 | // description: "prebuilt library shared only", |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 222 | // filesystem: map[string]string{ |
| 223 | // "libf.so": "", |
| 224 | // }, |
| 225 | // blueprint: ` |
| 226 | //cc_prebuilt_library { |
| 227 | // name: "libtest", |
| 228 | // srcs: ["libf.so"], |
| 229 | // static: { |
| 230 | // enabled: false, |
| 231 | // }, |
| 232 | // bazel_module: { bp2build_available: true }, |
| 233 | //}`, |
| 234 | // expectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 235 | // makeBazelTarget("cc_prebuilt_library_shared", "libtest", attrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 236 | // "shared_library": `"libf.so"`, |
| 237 | // }), |
| 238 | // }, |
| 239 | // }) |
| 240 | //} |
| 241 | |
| 242 | // TODO(b/228623543): When this bug is fixed, enable this test |
| 243 | //func TestPrebuiltLibraryOnlyStatic(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 244 | // runCcPrebuiltLibraryTestCase(t, |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 245 | // bp2buildTestCase{ |
| 246 | // description: "prebuilt library static only", |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 247 | // filesystem: map[string]string{ |
| 248 | // "libf.so": "", |
| 249 | // }, |
| 250 | // blueprint: ` |
| 251 | //cc_prebuilt_library { |
| 252 | // name: "libtest", |
| 253 | // srcs: ["libf.so"], |
| 254 | // shared: { |
| 255 | // enabled: false, |
| 256 | // }, |
| 257 | // bazel_module: { bp2build_available: true }, |
| 258 | //}`, |
| 259 | // expectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 260 | // makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 261 | // "static_library": `"libf.so"`, |
| 262 | // }), |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c353abd | 2023-03-10 20:57:38 +0000 | [diff] [blame] | 263 | // makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_always", attrNameToString{ |
| 264 | // "static_library": `"libf.so"`, |
| 265 | // "alwayslink": "True", |
| 266 | // }), |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 267 | // }, |
| 268 | // }) |
| 269 | //} |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 270 | |
| 271 | func TestPrebuiltLibraryWithExportIncludesArchVariant(t *testing.T) { |
| 272 | runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{ |
| 273 | Description: "cc_prebuilt_library correctly translates export_includes with arch variance", |
| 274 | Filesystem: map[string]string{ |
| 275 | "libf.so": "", |
| 276 | "libg.so": "", |
| 277 | }, |
| 278 | Blueprint: ` |
| 279 | cc_prebuilt_library { |
| 280 | name: "libtest", |
| 281 | srcs: ["libf.so"], |
| 282 | arch: { |
| 283 | arm: { export_include_dirs: ["testdir/1/"], }, |
| 284 | arm64: { export_include_dirs: ["testdir/2/"], }, |
| 285 | }, |
| 286 | bazel_module: { bp2build_available: true }, |
| 287 | }`, |
| 288 | ExpectedBazelTargets: []string{ |
| 289 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
| 290 | "shared_library": `"libf.so"`, |
| 291 | "export_includes": `select({ |
| 292 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 293 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 294 | "//conditions:default": [], |
| 295 | })`, |
| 296 | }), |
| 297 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
| 298 | "static_library": `"libf.so"`, |
| 299 | "export_includes": `select({ |
| 300 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 301 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 302 | "//conditions:default": [], |
| 303 | })`, |
| 304 | }), |
| 305 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 306 | "alwayslink": "True", |
| 307 | "static_library": `"libf.so"`, |
| 308 | "export_includes": `select({ |
| 309 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 310 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 311 | "//conditions:default": [], |
| 312 | })`, |
| 313 | }), |
| 314 | }, |
| 315 | }) |
| 316 | } |
| 317 | |
| 318 | func TestPrebuiltLibraryWithExportSystemIncludesArchVariant(t *testing.T) { |
| 319 | runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{ |
| 320 | Description: "cc_prebuilt_ibrary correctly translates export_system_includes with arch variance", |
| 321 | Filesystem: map[string]string{ |
| 322 | "libf.so": "", |
| 323 | "libg.so": "", |
| 324 | }, |
| 325 | Blueprint: ` |
| 326 | cc_prebuilt_library { |
| 327 | name: "libtest", |
| 328 | srcs: ["libf.so"], |
| 329 | arch: { |
| 330 | arm: { export_system_include_dirs: ["testdir/1/"], }, |
| 331 | arm64: { export_system_include_dirs: ["testdir/2/"], }, |
| 332 | }, |
| 333 | bazel_module: { bp2build_available: true }, |
| 334 | }`, |
| 335 | ExpectedBazelTargets: []string{ |
| 336 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
| 337 | "shared_library": `"libf.so"`, |
| 338 | "export_system_includes": `select({ |
| 339 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 340 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 341 | "//conditions:default": [], |
| 342 | })`, |
| 343 | }), |
| 344 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{ |
| 345 | "static_library": `"libf.so"`, |
| 346 | "export_system_includes": `select({ |
| 347 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 348 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 349 | "//conditions:default": [], |
| 350 | })`, |
| 351 | }), |
| 352 | MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{ |
| 353 | "alwayslink": "True", |
| 354 | "static_library": `"libf.so"`, |
| 355 | "export_system_includes": `select({ |
| 356 | "//build/bazel/platforms/arch:arm": ["testdir/1/"], |
| 357 | "//build/bazel/platforms/arch:arm64": ["testdir/2/"], |
| 358 | "//conditions:default": [], |
| 359 | })`, |
| 360 | }), |
| 361 | }, |
| 362 | }) |
| 363 | } |
Spandan Das | e12d252 | 2023-09-12 21:42:31 +0000 | [diff] [blame] | 364 | |
| 365 | func TestPrebuiltNdkStlConversion(t *testing.T) { |
| 366 | registerNdkStlModuleTypes := func(ctx android.RegistrationContext) { |
| 367 | ctx.RegisterModuleType("ndk_prebuilt_static_stl", cc.NdkPrebuiltStaticStlFactory) |
| 368 | ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory) |
| 369 | } |
| 370 | RunBp2BuildTestCase(t, registerNdkStlModuleTypes, Bp2buildTestCase{ |
| 371 | Description: "TODO", |
| 372 | Blueprint: ` |
| 373 | ndk_prebuilt_static_stl { |
| 374 | name: "ndk_libfoo_static", |
| 375 | export_include_dirs: ["dir1", "dir2"], |
| 376 | } |
| 377 | ndk_prebuilt_shared_stl { |
| 378 | name: "ndk_libfoo_shared", |
| 379 | export_include_dirs: ["dir1", "dir2"], |
| 380 | }`, |
| 381 | ExpectedBazelTargets: []string{ |
| 382 | MakeBazelTarget("cc_prebuilt_library_static", "ndk_libfoo_static", AttrNameToString{ |
| 383 | "static_library": `select({ |
| 384 | "//build/bazel/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_static.a", |
| 385 | "//build/bazel/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_static.a", |
| 386 | "//build/bazel/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_static.a", |
| 387 | "//build/bazel/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_static.a", |
| 388 | "//build/bazel/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_static.a", |
| 389 | "//conditions:default": None, |
| 390 | })`, |
| 391 | "export_system_includes": `[ |
| 392 | "dir1", |
| 393 | "dir2", |
| 394 | ]`, |
| 395 | }), |
| 396 | MakeBazelTarget("cc_prebuilt_library_shared", "ndk_libfoo_shared", AttrNameToString{ |
| 397 | "shared_library": `select({ |
| 398 | "//build/bazel/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_shared.so", |
| 399 | "//build/bazel/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_shared.so", |
| 400 | "//build/bazel/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_shared.so", |
| 401 | "//build/bazel/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_shared.so", |
| 402 | "//build/bazel/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_shared.so", |
| 403 | "//conditions:default": None, |
| 404 | })`, |
| 405 | "export_system_includes": `[ |
| 406 | "dir1", |
| 407 | "dir2", |
| 408 | ]`, |
| 409 | }), |
| 410 | }, |
| 411 | }) |
| 412 | } |