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