Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [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/cc" |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 20 | "android/soong/genrule" |
| 21 | |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | // See cc/testing.go for more context |
| 27 | soongCcLibraryStaticPreamble = ` |
| 28 | cc_defaults { |
| 29 | name: "linux_bionic_supported", |
| 30 | } |
| 31 | |
| 32 | toolchain_library { |
| 33 | name: "libclang_rt.builtins-x86_64-android", |
| 34 | defaults: ["linux_bionic_supported"], |
| 35 | vendor_available: true, |
| 36 | vendor_ramdisk_available: true, |
| 37 | product_available: true, |
| 38 | recovery_available: true, |
| 39 | native_bridge_supported: true, |
| 40 | src: "", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 41 | }` |
| 42 | ) |
| 43 | |
| 44 | func TestCcLibraryStaticLoadStatement(t *testing.T) { |
| 45 | testCases := []struct { |
| 46 | bazelTargets BazelTargets |
| 47 | expectedLoadStatements string |
| 48 | }{ |
| 49 | { |
| 50 | bazelTargets: BazelTargets{ |
| 51 | BazelTarget{ |
| 52 | name: "cc_library_static_target", |
| 53 | ruleClass: "cc_library_static", |
| 54 | // NOTE: No bzlLoadLocation for native rules |
| 55 | }, |
| 56 | }, |
| 57 | expectedLoadStatements: ``, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | for _, testCase := range testCases { |
| 62 | actual := testCase.bazelTargets.LoadStatements() |
| 63 | expected := testCase.expectedLoadStatements |
| 64 | if actual != expected { |
| 65 | t.Fatalf("Expected load statements to be %s, got %s", expected, actual) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 71 | func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) { |
| 72 | cc.RegisterCCBuildComponents(ctx) |
| 73 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 74 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 75 | ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 76 | // Required for system_shared_libs dependencies. |
| 77 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 81 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 82 | runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc) |
| 83 | } |
| 84 | |
| 85 | func TestCcLibraryStaticSimple(t *testing.T) { |
| 86 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 87 | description: "cc_library_static test", |
| 88 | moduleTypeUnderTest: "cc_library_static", |
| 89 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 90 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 91 | filesystem: map[string]string{ |
| 92 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 93 | "include_dir_1/include_dir_1_a.h": "", |
| 94 | "include_dir_1/include_dir_1_b.h": "", |
| 95 | "include_dir_2/include_dir_2_a.h": "", |
| 96 | "include_dir_2/include_dir_2_b.h": "", |
| 97 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 98 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 99 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 100 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 101 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 102 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 103 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 104 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 105 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 106 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 107 | // NOTE: Soong implicitly includes headers in the current directory |
| 108 | "implicit_include_1.h": "", |
| 109 | "implicit_include_2.h": "", |
| 110 | }, |
| 111 | blueprint: soongCcLibraryStaticPreamble + ` |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 112 | cc_library_headers { |
| 113 | name: "header_lib_1", |
| 114 | export_include_dirs: ["header_lib_1"], |
| 115 | } |
| 116 | |
| 117 | cc_library_headers { |
| 118 | name: "header_lib_2", |
| 119 | export_include_dirs: ["header_lib_2"], |
| 120 | } |
| 121 | |
| 122 | cc_library_static { |
| 123 | name: "static_lib_1", |
| 124 | srcs: ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | cc_library_static { |
| 128 | name: "static_lib_2", |
| 129 | srcs: ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | cc_library_static { |
| 133 | name: "whole_static_lib_1", |
| 134 | srcs: ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | cc_library_static { |
| 138 | name: "whole_static_lib_2", |
| 139 | srcs: ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | cc_library_static { |
| 143 | name: "foo_static", |
| 144 | srcs: [ |
| 145 | "foo_static1.cc", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 146 | "foo_static2.cc", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 147 | ], |
| 148 | cflags: [ |
| 149 | "-Dflag1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 150 | "-Dflag2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 151 | ], |
| 152 | static_libs: [ |
| 153 | "static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 154 | "static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 155 | ], |
| 156 | whole_static_libs: [ |
| 157 | "whole_static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 158 | "whole_static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 159 | ], |
| 160 | include_dirs: [ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 161 | "include_dir_1", |
| 162 | "include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 163 | ], |
| 164 | local_include_dirs: [ |
| 165 | "local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 166 | "local_include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 167 | ], |
| 168 | export_include_dirs: [ |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 169 | "export_include_dir_1", |
| 170 | "export_include_dir_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 171 | ], |
| 172 | header_libs: [ |
| 173 | "header_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 174 | "header_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 175 | ], |
| 176 | |
| 177 | // TODO: Also support export_header_lib_headers |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 178 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 179 | expectedBazelTargets: []string{`cc_library_static( |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 180 | name = "foo_static", |
| 181 | copts = [ |
| 182 | "-Dflag1", |
| 183 | "-Dflag2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 184 | "-Iinclude_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 185 | "-I$(BINDIR)/include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 186 | "-Iinclude_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 187 | "-I$(BINDIR)/include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 188 | "-Ilocal_include_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 189 | "-I$(BINDIR)/local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 190 | "-Ilocal_include_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 191 | "-I$(BINDIR)/local_include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 192 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 193 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 194 | ], |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame^] | 195 | export_includes = [ |
| 196 | "export_include_dir_1", |
| 197 | "export_include_dir_2", |
| 198 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 199 | implementation_deps = [ |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 200 | ":header_lib_1", |
| 201 | ":header_lib_2", |
| 202 | ":static_lib_1", |
| 203 | ":static_lib_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 204 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 205 | linkstatic = True, |
| 206 | srcs = [ |
| 207 | "foo_static1.cc", |
| 208 | "foo_static2.cc", |
| 209 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 210 | whole_archive_deps = [ |
| 211 | ":whole_static_lib_1", |
| 212 | ":whole_static_lib_2", |
| 213 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 214 | )`, `cc_library_static( |
| 215 | name = "static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 216 | copts = [ |
| 217 | "-I.", |
| 218 | "-I$(BINDIR)/.", |
| 219 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 220 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 221 | srcs = ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 222 | )`, `cc_library_static( |
| 223 | name = "static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 224 | copts = [ |
| 225 | "-I.", |
| 226 | "-I$(BINDIR)/.", |
| 227 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 228 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 229 | srcs = ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 230 | )`, `cc_library_static( |
| 231 | name = "whole_static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 232 | copts = [ |
| 233 | "-I.", |
| 234 | "-I$(BINDIR)/.", |
| 235 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 236 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 237 | srcs = ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 238 | )`, `cc_library_static( |
| 239 | name = "whole_static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 240 | copts = [ |
| 241 | "-I.", |
| 242 | "-I$(BINDIR)/.", |
| 243 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 244 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 245 | srcs = ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 246 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 247 | }) |
| 248 | } |
| 249 | |
| 250 | func TestCcLibraryStaticSubpackage(t *testing.T) { |
| 251 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 252 | description: "cc_library_static subpackage test", |
| 253 | moduleTypeUnderTest: "cc_library_static", |
| 254 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 255 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 256 | filesystem: map[string]string{ |
| 257 | // subpackage with subdirectory |
| 258 | "subpackage/Android.bp": "", |
| 259 | "subpackage/subpackage_header.h": "", |
| 260 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 261 | // subsubpackage with subdirectory |
| 262 | "subpackage/subsubpackage/Android.bp": "", |
| 263 | "subpackage/subsubpackage/subsubpackage_header.h": "", |
| 264 | "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "", |
| 265 | // subsubsubpackage with subdirectory |
| 266 | "subpackage/subsubpackage/subsubsubpackage/Android.bp": "", |
| 267 | "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "", |
| 268 | "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 269 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 270 | blueprint: soongCcLibraryStaticPreamble + ` |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 271 | cc_library_static { |
| 272 | name: "foo_static", |
| 273 | srcs: [ |
| 274 | ], |
| 275 | include_dirs: [ |
| 276 | "subpackage", |
| 277 | ], |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 278 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 279 | expectedBazelTargets: []string{`cc_library_static( |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 280 | name = "foo_static", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 281 | copts = [ |
| 282 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 283 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 284 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 285 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 286 | ], |
| 287 | linkstatic = True, |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 288 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 289 | }) |
| 290 | } |
| 291 | |
| 292 | func TestCcLibraryStaticExportIncludeDir(t *testing.T) { |
| 293 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 294 | description: "cc_library_static export include dir", |
| 295 | moduleTypeUnderTest: "cc_library_static", |
| 296 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 297 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 298 | filesystem: map[string]string{ |
| 299 | // subpackage with subdirectory |
| 300 | "subpackage/Android.bp": "", |
| 301 | "subpackage/subpackage_header.h": "", |
| 302 | "subpackage/subdirectory/subdirectory_header.h": "", |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 303 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 304 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 305 | cc_library_static { |
| 306 | name: "foo_static", |
| 307 | export_include_dirs: ["subpackage"], |
| 308 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 309 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 310 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 311 | copts = [ |
| 312 | "-I.", |
| 313 | "-I$(BINDIR)/.", |
| 314 | ], |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame^] | 315 | export_includes = ["subpackage"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 316 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 317 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 318 | }) |
| 319 | } |
| 320 | |
| 321 | func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) { |
| 322 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 323 | description: "cc_library_static export system include dir", |
| 324 | moduleTypeUnderTest: "cc_library_static", |
| 325 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 326 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 327 | filesystem: map[string]string{ |
| 328 | // subpackage with subdirectory |
| 329 | "subpackage/Android.bp": "", |
| 330 | "subpackage/subpackage_header.h": "", |
| 331 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 332 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 333 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 334 | cc_library_static { |
| 335 | name: "foo_static", |
| 336 | export_system_include_dirs: ["subpackage"], |
| 337 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 338 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 339 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 340 | copts = [ |
| 341 | "-I.", |
| 342 | "-I$(BINDIR)/.", |
| 343 | ], |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame^] | 344 | export_system_includes = ["subpackage"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 345 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 346 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 347 | }) |
| 348 | } |
| 349 | |
| 350 | func TestCcLibraryStaticManyIncludeDirs(t *testing.T) { |
| 351 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 352 | description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)", |
| 353 | moduleTypeUnderTest: "cc_library_static", |
| 354 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 355 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 356 | dir: "subpackage", |
| 357 | filesystem: map[string]string{ |
| 358 | // subpackage with subdirectory |
| 359 | "subpackage/Android.bp": ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 360 | cc_library_static { |
| 361 | name: "foo_static", |
| 362 | // include_dirs are workspace/root relative |
| 363 | include_dirs: [ |
| 364 | "subpackage/subsubpackage", |
| 365 | "subpackage2", |
| 366 | "subpackage3/subsubpackage" |
| 367 | ], |
| 368 | local_include_dirs: ["subsubpackage2"], // module dir relative |
| 369 | export_include_dirs: ["./exported_subsubpackage"], // module dir relative |
| 370 | include_build_directory: true, |
| 371 | bazel_module: { bp2build_available: true }, |
| 372 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 373 | "subpackage/subsubpackage/header.h": "", |
| 374 | "subpackage/subsubpackage2/header.h": "", |
| 375 | "subpackage/exported_subsubpackage/header.h": "", |
| 376 | "subpackage2/header.h": "", |
| 377 | "subpackage3/subsubpackage/header.h": "", |
| 378 | }, |
| 379 | blueprint: soongCcLibraryStaticPreamble, |
| 380 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 381 | name = "foo_static", |
| 382 | copts = [ |
| 383 | "-Isubpackage/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 384 | "-I$(BINDIR)/subpackage/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 385 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 386 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 387 | "-Isubpackage3/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 388 | "-I$(BINDIR)/subpackage3/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 389 | "-Isubpackage/subsubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 390 | "-I$(BINDIR)/subpackage/subsubpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 391 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 392 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 393 | ], |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame^] | 394 | export_includes = ["./exported_subsubpackage"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 395 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 396 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 397 | }) |
| 398 | } |
| 399 | |
| 400 | func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) { |
| 401 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 402 | description: "cc_library_static include_build_directory disabled", |
| 403 | moduleTypeUnderTest: "cc_library_static", |
| 404 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 405 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 406 | filesystem: map[string]string{ |
| 407 | // subpackage with subdirectory |
| 408 | "subpackage/Android.bp": "", |
| 409 | "subpackage/subpackage_header.h": "", |
| 410 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 411 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 412 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 413 | cc_library_static { |
| 414 | name: "foo_static", |
| 415 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 416 | local_include_dirs: ["subpackage2"], |
| 417 | include_build_directory: false, |
| 418 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 419 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 420 | name = "foo_static", |
| 421 | copts = [ |
| 422 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 423 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 424 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 425 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 426 | ], |
| 427 | linkstatic = True, |
| 428 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 429 | }) |
| 430 | } |
| 431 | |
| 432 | func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) { |
| 433 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 434 | description: "cc_library_static include_build_directory enabled", |
| 435 | moduleTypeUnderTest: "cc_library_static", |
| 436 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 437 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 438 | filesystem: map[string]string{ |
| 439 | // subpackage with subdirectory |
| 440 | "subpackage/Android.bp": "", |
| 441 | "subpackage/subpackage_header.h": "", |
| 442 | "subpackage2/Android.bp": "", |
| 443 | "subpackage2/subpackage2_header.h": "", |
| 444 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 445 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 446 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 447 | cc_library_static { |
| 448 | name: "foo_static", |
| 449 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 450 | local_include_dirs: ["subpackage2"], |
| 451 | include_build_directory: true, |
| 452 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 453 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 454 | name = "foo_static", |
| 455 | copts = [ |
| 456 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 457 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 458 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 459 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 460 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 461 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 462 | ], |
| 463 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 464 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 465 | }) |
| 466 | } |
| 467 | |
| 468 | func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) { |
| 469 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 470 | description: "cc_library_static arch-specific static_libs", |
| 471 | moduleTypeUnderTest: "cc_library_static", |
| 472 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 473 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 474 | filesystem: map[string]string{}, |
| 475 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 476 | cc_library_static { name: "static_dep" } |
| 477 | cc_library_static { name: "static_dep2" } |
| 478 | cc_library_static { |
| 479 | name: "foo_static", |
| 480 | arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 481 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 482 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 483 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 484 | copts = [ |
| 485 | "-I.", |
| 486 | "-I$(BINDIR)/.", |
| 487 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 488 | implementation_deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 489 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 490 | "//conditions:default": [], |
| 491 | }), |
| 492 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 493 | whole_archive_deps = select({ |
| 494 | "//build/bazel/platforms/arch:arm64": [":static_dep2"], |
| 495 | "//conditions:default": [], |
| 496 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 497 | )`, `cc_library_static( |
| 498 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 499 | copts = [ |
| 500 | "-I.", |
| 501 | "-I$(BINDIR)/.", |
| 502 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 503 | linkstatic = True, |
| 504 | )`, `cc_library_static( |
| 505 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 506 | copts = [ |
| 507 | "-I.", |
| 508 | "-I$(BINDIR)/.", |
| 509 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 510 | linkstatic = True, |
| 511 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 512 | }) |
| 513 | } |
| 514 | |
| 515 | func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) { |
| 516 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 517 | description: "cc_library_static os-specific static_libs", |
| 518 | moduleTypeUnderTest: "cc_library_static", |
| 519 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 520 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 521 | filesystem: map[string]string{}, |
| 522 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 523 | cc_library_static { name: "static_dep" } |
| 524 | cc_library_static { name: "static_dep2" } |
| 525 | cc_library_static { |
| 526 | name: "foo_static", |
| 527 | target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 528 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 529 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 530 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 531 | copts = [ |
| 532 | "-I.", |
| 533 | "-I$(BINDIR)/.", |
| 534 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 535 | implementation_deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 536 | "//build/bazel/platforms/os:android": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 537 | "//conditions:default": [], |
| 538 | }), |
| 539 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 540 | whole_archive_deps = select({ |
| 541 | "//build/bazel/platforms/os:android": [":static_dep2"], |
| 542 | "//conditions:default": [], |
| 543 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 544 | )`, `cc_library_static( |
| 545 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 546 | copts = [ |
| 547 | "-I.", |
| 548 | "-I$(BINDIR)/.", |
| 549 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 550 | linkstatic = True, |
| 551 | )`, `cc_library_static( |
| 552 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 553 | copts = [ |
| 554 | "-I.", |
| 555 | "-I$(BINDIR)/.", |
| 556 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 557 | linkstatic = True, |
| 558 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 559 | }) |
| 560 | } |
| 561 | |
| 562 | func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) { |
| 563 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 564 | description: "cc_library_static base, arch and os-specific static_libs", |
| 565 | moduleTypeUnderTest: "cc_library_static", |
| 566 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 567 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 568 | filesystem: map[string]string{}, |
| 569 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 570 | cc_library_static { name: "static_dep" } |
| 571 | cc_library_static { name: "static_dep2" } |
| 572 | cc_library_static { name: "static_dep3" } |
| 573 | cc_library_static { name: "static_dep4" } |
| 574 | cc_library_static { |
| 575 | name: "foo_static", |
| 576 | static_libs: ["static_dep"], |
| 577 | whole_static_libs: ["static_dep2"], |
| 578 | target: { android: { static_libs: ["static_dep3"] } }, |
| 579 | arch: { arm64: { static_libs: ["static_dep4"] } }, |
| 580 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 581 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 582 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 583 | copts = [ |
| 584 | "-I.", |
| 585 | "-I$(BINDIR)/.", |
| 586 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 587 | implementation_deps = [":static_dep"] + select({ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 588 | "//build/bazel/platforms/arch:arm64": [":static_dep4"], |
| 589 | "//conditions:default": [], |
| 590 | }) + select({ |
| 591 | "//build/bazel/platforms/os:android": [":static_dep3"], |
| 592 | "//conditions:default": [], |
| 593 | }), |
| 594 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 595 | whole_archive_deps = [":static_dep2"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 596 | )`, `cc_library_static( |
| 597 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 598 | copts = [ |
| 599 | "-I.", |
| 600 | "-I$(BINDIR)/.", |
| 601 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 602 | linkstatic = True, |
| 603 | )`, `cc_library_static( |
| 604 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 605 | copts = [ |
| 606 | "-I.", |
| 607 | "-I$(BINDIR)/.", |
| 608 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 609 | linkstatic = True, |
| 610 | )`, `cc_library_static( |
| 611 | name = "static_dep3", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 612 | copts = [ |
| 613 | "-I.", |
| 614 | "-I$(BINDIR)/.", |
| 615 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 616 | linkstatic = True, |
| 617 | )`, `cc_library_static( |
| 618 | name = "static_dep4", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 619 | copts = [ |
| 620 | "-I.", |
| 621 | "-I$(BINDIR)/.", |
| 622 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 623 | linkstatic = True, |
| 624 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 625 | }) |
| 626 | } |
| 627 | |
| 628 | func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) { |
| 629 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 630 | description: "cc_library_static simple exclude_srcs", |
| 631 | moduleTypeUnderTest: "cc_library_static", |
| 632 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 633 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 634 | filesystem: map[string]string{ |
| 635 | "common.c": "", |
| 636 | "foo-a.c": "", |
| 637 | "foo-excluded.c": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 638 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 639 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 640 | cc_library_static { |
| 641 | name: "foo_static", |
| 642 | srcs: ["common.c", "foo-*.c"], |
| 643 | exclude_srcs: ["foo-excluded.c"], |
| 644 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 645 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 646 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 647 | copts = [ |
| 648 | "-I.", |
| 649 | "-I$(BINDIR)/.", |
| 650 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 651 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 652 | srcs_c = [ |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 653 | "common.c", |
| 654 | "foo-a.c", |
| 655 | ], |
| 656 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 657 | }) |
| 658 | } |
| 659 | |
| 660 | func TestCcLibraryStaticOneArchSrcs(t *testing.T) { |
| 661 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 662 | description: "cc_library_static one arch specific srcs", |
| 663 | moduleTypeUnderTest: "cc_library_static", |
| 664 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 665 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 666 | filesystem: map[string]string{ |
| 667 | "common.c": "", |
| 668 | "foo-arm.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 669 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 670 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 671 | cc_library_static { |
| 672 | name: "foo_static", |
| 673 | srcs: ["common.c"], |
| 674 | arch: { arm: { srcs: ["foo-arm.c"] } } |
| 675 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 676 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 677 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 678 | copts = [ |
| 679 | "-I.", |
| 680 | "-I$(BINDIR)/.", |
| 681 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 682 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 683 | srcs_c = ["common.c"] + select({ |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 684 | "//build/bazel/platforms/arch:arm": ["foo-arm.c"], |
| 685 | "//conditions:default": [], |
| 686 | }), |
| 687 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 688 | }) |
| 689 | } |
| 690 | |
| 691 | func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) { |
| 692 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 693 | description: "cc_library_static one arch specific srcs and exclude_srcs", |
| 694 | moduleTypeUnderTest: "cc_library_static", |
| 695 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 696 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 697 | filesystem: map[string]string{ |
| 698 | "common.c": "", |
| 699 | "for-arm.c": "", |
| 700 | "not-for-arm.c": "", |
| 701 | "not-for-anything.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 702 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 703 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 704 | cc_library_static { |
| 705 | name: "foo_static", |
| 706 | srcs: ["common.c", "not-for-*.c"], |
| 707 | exclude_srcs: ["not-for-anything.c"], |
| 708 | arch: { |
| 709 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 710 | }, |
| 711 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 712 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 713 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 714 | copts = [ |
| 715 | "-I.", |
| 716 | "-I$(BINDIR)/.", |
| 717 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 718 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 719 | srcs_c = ["common.c"] + select({ |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 720 | "//build/bazel/platforms/arch:arm": ["for-arm.c"], |
| 721 | "//conditions:default": ["not-for-arm.c"], |
| 722 | }), |
| 723 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 724 | }) |
| 725 | } |
| 726 | |
| 727 | func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) { |
| 728 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 729 | description: "cc_library_static arch specific exclude_srcs for 2 architectures", |
| 730 | moduleTypeUnderTest: "cc_library_static", |
| 731 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 732 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 733 | filesystem: map[string]string{ |
| 734 | "common.c": "", |
| 735 | "for-arm.c": "", |
| 736 | "for-x86.c": "", |
| 737 | "not-for-arm.c": "", |
| 738 | "not-for-x86.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 739 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 740 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 741 | cc_library_static { |
| 742 | name: "foo_static", |
| 743 | srcs: ["common.c", "not-for-*.c"], |
| 744 | exclude_srcs: ["not-for-everything.c"], |
| 745 | arch: { |
| 746 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 747 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 748 | }, |
| 749 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 750 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 751 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 752 | copts = [ |
| 753 | "-I.", |
| 754 | "-I$(BINDIR)/.", |
| 755 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 756 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 757 | srcs_c = ["common.c"] + select({ |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 758 | "//build/bazel/platforms/arch:arm": [ |
| 759 | "for-arm.c", |
| 760 | "not-for-x86.c", |
| 761 | ], |
| 762 | "//build/bazel/platforms/arch:x86": [ |
| 763 | "for-x86.c", |
| 764 | "not-for-arm.c", |
| 765 | ], |
| 766 | "//conditions:default": [ |
| 767 | "not-for-arm.c", |
| 768 | "not-for-x86.c", |
| 769 | ], |
| 770 | }), |
| 771 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 772 | }) |
| 773 | } |
| 774 | func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) { |
| 775 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 776 | description: "cc_library_static arch specific exclude_srcs for 4 architectures", |
| 777 | moduleTypeUnderTest: "cc_library_static", |
| 778 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 779 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 780 | filesystem: map[string]string{ |
| 781 | "common.c": "", |
| 782 | "for-arm.c": "", |
| 783 | "for-arm64.c": "", |
| 784 | "for-x86.c": "", |
| 785 | "for-x86_64.c": "", |
| 786 | "not-for-arm.c": "", |
| 787 | "not-for-arm64.c": "", |
| 788 | "not-for-x86.c": "", |
| 789 | "not-for-x86_64.c": "", |
| 790 | "not-for-everything.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 791 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 792 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 793 | cc_library_static { |
| 794 | name: "foo_static", |
| 795 | srcs: ["common.c", "not-for-*.c"], |
| 796 | exclude_srcs: ["not-for-everything.c"], |
| 797 | arch: { |
| 798 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 799 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 800 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 801 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 802 | }, |
| 803 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 804 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 805 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 806 | copts = [ |
| 807 | "-I.", |
| 808 | "-I$(BINDIR)/.", |
| 809 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 810 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 811 | srcs_c = ["common.c"] + select({ |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 812 | "//build/bazel/platforms/arch:arm": [ |
| 813 | "for-arm.c", |
| 814 | "not-for-arm64.c", |
| 815 | "not-for-x86.c", |
| 816 | "not-for-x86_64.c", |
| 817 | ], |
| 818 | "//build/bazel/platforms/arch:arm64": [ |
| 819 | "for-arm64.c", |
| 820 | "not-for-arm.c", |
| 821 | "not-for-x86.c", |
| 822 | "not-for-x86_64.c", |
| 823 | ], |
| 824 | "//build/bazel/platforms/arch:x86": [ |
| 825 | "for-x86.c", |
| 826 | "not-for-arm.c", |
| 827 | "not-for-arm64.c", |
| 828 | "not-for-x86_64.c", |
| 829 | ], |
| 830 | "//build/bazel/platforms/arch:x86_64": [ |
| 831 | "for-x86_64.c", |
| 832 | "not-for-arm.c", |
| 833 | "not-for-arm64.c", |
| 834 | "not-for-x86.c", |
| 835 | ], |
| 836 | "//conditions:default": [ |
| 837 | "not-for-arm.c", |
| 838 | "not-for-arm64.c", |
| 839 | "not-for-x86.c", |
| 840 | "not-for-x86_64.c", |
| 841 | ], |
| 842 | }), |
| 843 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 844 | }) |
| 845 | } |
| 846 | |
Liz Kammer | 2b07ec7 | 2021-05-26 15:08:27 -0400 | [diff] [blame] | 847 | func TestCcLibraryStaticOneArchEmpty(t *testing.T) { |
| 848 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 849 | description: "cc_library_static one arch empty", |
| 850 | moduleTypeUnderTest: "cc_library_static", |
| 851 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 852 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Liz Kammer | 2b07ec7 | 2021-05-26 15:08:27 -0400 | [diff] [blame] | 853 | filesystem: map[string]string{ |
| 854 | "common.cc": "", |
| 855 | "foo-no-arm.cc": "", |
| 856 | "foo-excluded.cc": "", |
| 857 | }, |
| 858 | blueprint: soongCcLibraryStaticPreamble + ` |
| 859 | cc_library_static { |
| 860 | name: "foo_static", |
| 861 | srcs: ["common.cc", "foo-*.cc"], |
| 862 | exclude_srcs: ["foo-excluded.cc"], |
| 863 | arch: { |
| 864 | arm: { exclude_srcs: ["foo-no-arm.cc"] }, |
| 865 | }, |
| 866 | }`, |
| 867 | expectedBazelTargets: []string{`cc_library_static( |
| 868 | name = "foo_static", |
| 869 | copts = [ |
| 870 | "-I.", |
| 871 | "-I$(BINDIR)/.", |
| 872 | ], |
| 873 | linkstatic = True, |
| 874 | srcs = ["common.cc"] + select({ |
| 875 | "//build/bazel/platforms/arch:arm": [], |
| 876 | "//conditions:default": ["foo-no-arm.cc"], |
| 877 | }), |
| 878 | )`}, |
| 879 | }) |
| 880 | } |
| 881 | |
| 882 | func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) { |
| 883 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 884 | description: "cc_library_static one arch empty other set", |
| 885 | moduleTypeUnderTest: "cc_library_static", |
| 886 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 887 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Liz Kammer | 2b07ec7 | 2021-05-26 15:08:27 -0400 | [diff] [blame] | 888 | filesystem: map[string]string{ |
| 889 | "common.cc": "", |
| 890 | "foo-no-arm.cc": "", |
| 891 | "x86-only.cc": "", |
| 892 | "foo-excluded.cc": "", |
| 893 | }, |
| 894 | blueprint: soongCcLibraryStaticPreamble + ` |
| 895 | cc_library_static { |
| 896 | name: "foo_static", |
| 897 | srcs: ["common.cc", "foo-*.cc"], |
| 898 | exclude_srcs: ["foo-excluded.cc"], |
| 899 | arch: { |
| 900 | arm: { exclude_srcs: ["foo-no-arm.cc"] }, |
| 901 | x86: { srcs: ["x86-only.cc"] }, |
| 902 | }, |
| 903 | }`, |
| 904 | expectedBazelTargets: []string{`cc_library_static( |
| 905 | name = "foo_static", |
| 906 | copts = [ |
| 907 | "-I.", |
| 908 | "-I$(BINDIR)/.", |
| 909 | ], |
| 910 | linkstatic = True, |
| 911 | srcs = ["common.cc"] + select({ |
| 912 | "//build/bazel/platforms/arch:arm": [], |
| 913 | "//build/bazel/platforms/arch:x86": [ |
| 914 | "foo-no-arm.cc", |
| 915 | "x86-only.cc", |
| 916 | ], |
| 917 | "//conditions:default": ["foo-no-arm.cc"], |
| 918 | }), |
| 919 | )`}, |
| 920 | }) |
| 921 | } |
| 922 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 923 | func TestCcLibraryStaticMultipleDepSameName(t *testing.T) { |
| 924 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 925 | description: "cc_library_static multiple dep same name panic", |
| 926 | moduleTypeUnderTest: "cc_library_static", |
| 927 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 928 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 929 | filesystem: map[string]string{}, |
| 930 | blueprint: soongCcLibraryStaticPreamble + ` |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 931 | cc_library_static { name: "static_dep" } |
| 932 | cc_library_static { |
| 933 | name: "foo_static", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 934 | static_libs: ["static_dep", "static_dep"], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 935 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 936 | expectedBazelTargets: []string{`cc_library_static( |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 937 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 938 | copts = [ |
| 939 | "-I.", |
| 940 | "-I$(BINDIR)/.", |
| 941 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 942 | implementation_deps = [":static_dep"], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 943 | linkstatic = True, |
| 944 | )`, `cc_library_static( |
| 945 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 946 | copts = [ |
| 947 | "-I.", |
| 948 | "-I$(BINDIR)/.", |
| 949 | ], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 950 | linkstatic = True, |
| 951 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 952 | }) |
| 953 | } |
| 954 | |
| 955 | func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) { |
| 956 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 957 | description: "cc_library_static 1 multilib srcs and exclude_srcs", |
| 958 | moduleTypeUnderTest: "cc_library_static", |
| 959 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 960 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 961 | filesystem: map[string]string{ |
| 962 | "common.c": "", |
| 963 | "for-lib32.c": "", |
| 964 | "not-for-lib32.c": "", |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 965 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 966 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 967 | cc_library_static { |
| 968 | name: "foo_static", |
| 969 | srcs: ["common.c", "not-for-*.c"], |
| 970 | multilib: { |
| 971 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 972 | }, |
| 973 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 974 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 975 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 976 | copts = [ |
| 977 | "-I.", |
| 978 | "-I$(BINDIR)/.", |
| 979 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 980 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 981 | srcs_c = ["common.c"] + select({ |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 982 | "//build/bazel/platforms/arch:arm": ["for-lib32.c"], |
| 983 | "//build/bazel/platforms/arch:x86": ["for-lib32.c"], |
| 984 | "//conditions:default": ["not-for-lib32.c"], |
| 985 | }), |
| 986 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 987 | }) |
| 988 | } |
| 989 | |
| 990 | func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) { |
| 991 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 992 | description: "cc_library_static 2 multilib srcs and exclude_srcs", |
| 993 | moduleTypeUnderTest: "cc_library_static", |
| 994 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 995 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 996 | filesystem: map[string]string{ |
| 997 | "common.c": "", |
| 998 | "for-lib32.c": "", |
| 999 | "for-lib64.c": "", |
| 1000 | "not-for-lib32.c": "", |
| 1001 | "not-for-lib64.c": "", |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1002 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1003 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1004 | cc_library_static { |
| 1005 | name: "foo_static2", |
| 1006 | srcs: ["common.c", "not-for-*.c"], |
| 1007 | multilib: { |
| 1008 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 1009 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 1010 | }, |
| 1011 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1012 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1013 | name = "foo_static2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1014 | copts = [ |
| 1015 | "-I.", |
| 1016 | "-I$(BINDIR)/.", |
| 1017 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1018 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1019 | srcs_c = ["common.c"] + select({ |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1020 | "//build/bazel/platforms/arch:arm": [ |
| 1021 | "for-lib32.c", |
| 1022 | "not-for-lib64.c", |
| 1023 | ], |
| 1024 | "//build/bazel/platforms/arch:arm64": [ |
| 1025 | "for-lib64.c", |
| 1026 | "not-for-lib32.c", |
| 1027 | ], |
| 1028 | "//build/bazel/platforms/arch:x86": [ |
| 1029 | "for-lib32.c", |
| 1030 | "not-for-lib64.c", |
| 1031 | ], |
| 1032 | "//build/bazel/platforms/arch:x86_64": [ |
| 1033 | "for-lib64.c", |
| 1034 | "not-for-lib32.c", |
| 1035 | ], |
| 1036 | "//conditions:default": [ |
| 1037 | "not-for-lib32.c", |
| 1038 | "not-for-lib64.c", |
| 1039 | ], |
| 1040 | }), |
| 1041 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1042 | }) |
| 1043 | } |
| 1044 | |
| 1045 | func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) { |
| 1046 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1047 | description: "cc_library_static arch and multilib srcs and exclude_srcs", |
| 1048 | moduleTypeUnderTest: "cc_library_static", |
| 1049 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1050 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1051 | filesystem: map[string]string{ |
| 1052 | "common.c": "", |
| 1053 | "for-arm.c": "", |
| 1054 | "for-arm64.c": "", |
| 1055 | "for-x86.c": "", |
| 1056 | "for-x86_64.c": "", |
| 1057 | "for-lib32.c": "", |
| 1058 | "for-lib64.c": "", |
| 1059 | "not-for-arm.c": "", |
| 1060 | "not-for-arm64.c": "", |
| 1061 | "not-for-x86.c": "", |
| 1062 | "not-for-x86_64.c": "", |
| 1063 | "not-for-lib32.c": "", |
| 1064 | "not-for-lib64.c": "", |
| 1065 | "not-for-everything.c": "", |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1066 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1067 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1068 | cc_library_static { |
| 1069 | name: "foo_static3", |
| 1070 | srcs: ["common.c", "not-for-*.c"], |
| 1071 | exclude_srcs: ["not-for-everything.c"], |
| 1072 | arch: { |
| 1073 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 1074 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 1075 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 1076 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 1077 | }, |
| 1078 | multilib: { |
| 1079 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 1080 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 1081 | }, |
| 1082 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1083 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1084 | name = "foo_static3", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1085 | copts = [ |
| 1086 | "-I.", |
| 1087 | "-I$(BINDIR)/.", |
| 1088 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1089 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1090 | srcs_c = ["common.c"] + select({ |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1091 | "//build/bazel/platforms/arch:arm": [ |
| 1092 | "for-arm.c", |
| 1093 | "for-lib32.c", |
| 1094 | "not-for-arm64.c", |
| 1095 | "not-for-lib64.c", |
| 1096 | "not-for-x86.c", |
| 1097 | "not-for-x86_64.c", |
| 1098 | ], |
| 1099 | "//build/bazel/platforms/arch:arm64": [ |
| 1100 | "for-arm64.c", |
| 1101 | "for-lib64.c", |
| 1102 | "not-for-arm.c", |
| 1103 | "not-for-lib32.c", |
| 1104 | "not-for-x86.c", |
| 1105 | "not-for-x86_64.c", |
| 1106 | ], |
| 1107 | "//build/bazel/platforms/arch:x86": [ |
| 1108 | "for-lib32.c", |
| 1109 | "for-x86.c", |
| 1110 | "not-for-arm.c", |
| 1111 | "not-for-arm64.c", |
| 1112 | "not-for-lib64.c", |
| 1113 | "not-for-x86_64.c", |
| 1114 | ], |
| 1115 | "//build/bazel/platforms/arch:x86_64": [ |
| 1116 | "for-lib64.c", |
| 1117 | "for-x86_64.c", |
| 1118 | "not-for-arm.c", |
| 1119 | "not-for-arm64.c", |
| 1120 | "not-for-lib32.c", |
| 1121 | "not-for-x86.c", |
| 1122 | ], |
| 1123 | "//conditions:default": [ |
| 1124 | "not-for-arm.c", |
| 1125 | "not-for-arm64.c", |
| 1126 | "not-for-lib32.c", |
| 1127 | "not-for-lib64.c", |
| 1128 | "not-for-x86.c", |
| 1129 | "not-for-x86_64.c", |
| 1130 | ], |
| 1131 | }), |
| 1132 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1133 | }) |
| 1134 | } |
| 1135 | |
| 1136 | func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { |
| 1137 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1138 | description: "cc_library_static arch srcs/exclude_srcs with generated files", |
| 1139 | moduleTypeUnderTest: "cc_library_static", |
| 1140 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1141 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1142 | filesystem: map[string]string{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1143 | "common.cpp": "", |
| 1144 | "for-x86.cpp": "", |
| 1145 | "not-for-x86.cpp": "", |
| 1146 | "not-for-everything.cpp": "", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1147 | "dep/Android.bp": ` |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1148 | genrule { |
| 1149 | name: "generated_src_other_pkg", |
| 1150 | out: ["generated_src_other_pkg.cpp"], |
| 1151 | cmd: "nothing to see here", |
| 1152 | } |
| 1153 | |
| 1154 | genrule { |
| 1155 | name: "generated_hdr_other_pkg", |
| 1156 | out: ["generated_hdr_other_pkg.cpp"], |
| 1157 | cmd: "nothing to see here", |
| 1158 | } |
| 1159 | |
| 1160 | genrule { |
| 1161 | name: "generated_hdr_other_pkg_x86", |
| 1162 | out: ["generated_hdr_other_pkg_x86.cpp"], |
| 1163 | cmd: "nothing to see here", |
| 1164 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1165 | }, |
| 1166 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1167 | genrule { |
| 1168 | name: "generated_src", |
| 1169 | out: ["generated_src.cpp"], |
| 1170 | cmd: "nothing to see here", |
| 1171 | } |
| 1172 | |
| 1173 | genrule { |
| 1174 | name: "generated_src_x86", |
| 1175 | out: ["generated_src_x86.cpp"], |
| 1176 | cmd: "nothing to see here", |
| 1177 | } |
| 1178 | |
| 1179 | genrule { |
| 1180 | name: "generated_hdr", |
| 1181 | out: ["generated_hdr.h"], |
| 1182 | cmd: "nothing to see here", |
| 1183 | } |
| 1184 | |
| 1185 | cc_library_static { |
| 1186 | name: "foo_static3", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1187 | srcs: ["common.cpp", "not-for-*.cpp"], |
| 1188 | exclude_srcs: ["not-for-everything.cpp"], |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1189 | generated_sources: ["generated_src", "generated_src_other_pkg"], |
| 1190 | generated_headers: ["generated_hdr", "generated_hdr_other_pkg"], |
| 1191 | arch: { |
| 1192 | x86: { |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1193 | srcs: ["for-x86.cpp"], |
| 1194 | exclude_srcs: ["not-for-x86.cpp"], |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1195 | generated_sources: ["generated_src_x86"], |
| 1196 | generated_headers: ["generated_hdr_other_pkg_x86"], |
| 1197 | }, |
| 1198 | }, |
| 1199 | } |
| 1200 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1201 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1202 | name = "foo_static3", |
| 1203 | copts = [ |
| 1204 | "-I.", |
| 1205 | "-I$(BINDIR)/.", |
| 1206 | ], |
| 1207 | linkstatic = True, |
| 1208 | srcs = [ |
| 1209 | "//dep:generated_hdr_other_pkg", |
| 1210 | "//dep:generated_src_other_pkg", |
| 1211 | ":generated_hdr", |
| 1212 | ":generated_src", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1213 | "common.cpp", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1214 | ] + select({ |
| 1215 | "//build/bazel/platforms/arch:x86": [ |
| 1216 | "//dep:generated_hdr_other_pkg_x86", |
| 1217 | ":generated_src_x86", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1218 | "for-x86.cpp", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1219 | ], |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1220 | "//conditions:default": ["not-for-x86.cpp"], |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1221 | }), |
| 1222 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1223 | }) |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 1224 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1225 | |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1226 | func TestCcLibraryStaticGetTargetProperties(t *testing.T) { |
| 1227 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1228 | |
| 1229 | description: "cc_library_static complex GetTargetProperties", |
| 1230 | moduleTypeUnderTest: "cc_library_static", |
| 1231 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1232 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1233 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1234 | cc_library_static { |
| 1235 | name: "foo_static", |
| 1236 | target: { |
| 1237 | android: { |
| 1238 | srcs: ["android_src.c"], |
| 1239 | }, |
| 1240 | android_arm: { |
| 1241 | srcs: ["android_arm_src.c"], |
| 1242 | }, |
| 1243 | android_arm64: { |
| 1244 | srcs: ["android_arm64_src.c"], |
| 1245 | }, |
| 1246 | android_x86: { |
| 1247 | srcs: ["android_x86_src.c"], |
| 1248 | }, |
| 1249 | android_x86_64: { |
| 1250 | srcs: ["android_x86_64_src.c"], |
| 1251 | }, |
| 1252 | linux_bionic_arm64: { |
| 1253 | srcs: ["linux_bionic_arm64_src.c"], |
| 1254 | }, |
| 1255 | linux_bionic_x86_64: { |
| 1256 | srcs: ["linux_bionic_x86_64_src.c"], |
| 1257 | }, |
| 1258 | }, |
| 1259 | }`, |
| 1260 | expectedBazelTargets: []string{`cc_library_static( |
| 1261 | name = "foo_static", |
| 1262 | copts = [ |
| 1263 | "-I.", |
| 1264 | "-I$(BINDIR)/.", |
| 1265 | ], |
| 1266 | linkstatic = True, |
| 1267 | srcs_c = select({ |
| 1268 | "//build/bazel/platforms/os:android": ["android_src.c"], |
| 1269 | "//conditions:default": [], |
| 1270 | }) + select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 1271 | "//build/bazel/platforms/os_arch:android_arm": ["android_arm_src.c"], |
| 1272 | "//build/bazel/platforms/os_arch:android_arm64": ["android_arm64_src.c"], |
| 1273 | "//build/bazel/platforms/os_arch:android_x86": ["android_x86_src.c"], |
| 1274 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"], |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 1275 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"], |
| 1276 | "//build/bazel/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"], |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1277 | "//conditions:default": [], |
| 1278 | }), |
| 1279 | )`}, |
| 1280 | }) |
| 1281 | } |
| 1282 | |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1283 | func TestCcLibraryStaticProductVariableSelects(t *testing.T) { |
| 1284 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1285 | description: "cc_library_static product variable selects", |
| 1286 | moduleTypeUnderTest: "cc_library_static", |
| 1287 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1288 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1289 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1290 | cc_library_static { |
| 1291 | name: "foo_static", |
| 1292 | srcs: ["common.c"], |
| 1293 | product_variables: { |
| 1294 | malloc_not_svelte: { |
| 1295 | cflags: ["-Wmalloc_not_svelte"], |
| 1296 | }, |
| 1297 | malloc_zero_contents: { |
| 1298 | cflags: ["-Wmalloc_zero_contents"], |
| 1299 | }, |
| 1300 | binder32bit: { |
| 1301 | cflags: ["-Wbinder32bit"], |
| 1302 | }, |
| 1303 | }, |
| 1304 | } `, |
| 1305 | expectedBazelTargets: []string{`cc_library_static( |
| 1306 | name = "foo_static", |
| 1307 | copts = [ |
| 1308 | "-I.", |
| 1309 | "-I$(BINDIR)/.", |
| 1310 | ] + select({ |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 1311 | "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"], |
| 1312 | "//conditions:default": [], |
| 1313 | }) + select({ |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1314 | "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"], |
| 1315 | "//conditions:default": [], |
| 1316 | }) + select({ |
| 1317 | "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"], |
| 1318 | "//conditions:default": [], |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 1319 | }), |
| 1320 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1321 | srcs_c = ["common.c"], |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 1322 | )`}, |
| 1323 | }) |
| 1324 | } |
| 1325 | |
| 1326 | func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) { |
| 1327 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1328 | description: "cc_library_static arch-specific product variable selects", |
| 1329 | moduleTypeUnderTest: "cc_library_static", |
| 1330 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1331 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 1332 | filesystem: map[string]string{}, |
| 1333 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1334 | cc_library_static { |
| 1335 | name: "foo_static", |
| 1336 | srcs: ["common.c"], |
| 1337 | product_variables: { |
| 1338 | malloc_not_svelte: { |
| 1339 | cflags: ["-Wmalloc_not_svelte"], |
| 1340 | }, |
| 1341 | }, |
| 1342 | arch: { |
| 1343 | arm64: { |
| 1344 | product_variables: { |
| 1345 | malloc_not_svelte: { |
| 1346 | cflags: ["-Warm64_malloc_not_svelte"], |
| 1347 | }, |
| 1348 | }, |
| 1349 | }, |
| 1350 | }, |
| 1351 | multilib: { |
| 1352 | lib32: { |
| 1353 | product_variables: { |
| 1354 | malloc_not_svelte: { |
| 1355 | cflags: ["-Wlib32_malloc_not_svelte"], |
| 1356 | }, |
| 1357 | }, |
| 1358 | }, |
| 1359 | }, |
| 1360 | target: { |
| 1361 | android: { |
| 1362 | product_variables: { |
| 1363 | malloc_not_svelte: { |
| 1364 | cflags: ["-Wandroid_malloc_not_svelte"], |
| 1365 | }, |
| 1366 | }, |
| 1367 | } |
| 1368 | }, |
| 1369 | } `, |
| 1370 | expectedBazelTargets: []string{`cc_library_static( |
| 1371 | name = "foo_static", |
| 1372 | copts = [ |
| 1373 | "-I.", |
| 1374 | "-I$(BINDIR)/.", |
| 1375 | ] + select({ |
| 1376 | "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"], |
| 1377 | "//conditions:default": [], |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1378 | }) + select({ |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 1379 | "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"], |
| 1380 | "//conditions:default": [], |
| 1381 | }) + select({ |
| 1382 | "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"], |
| 1383 | "//conditions:default": [], |
| 1384 | }) + select({ |
| 1385 | "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"], |
| 1386 | "//conditions:default": [], |
| 1387 | }) + select({ |
| 1388 | "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"], |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1389 | "//conditions:default": [], |
| 1390 | }), |
| 1391 | linkstatic = True, |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1392 | srcs_c = ["common.c"], |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1393 | )`}, |
| 1394 | }) |
| 1395 | } |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1396 | |
| 1397 | func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) { |
| 1398 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 1399 | description: "cc_library_static product variable string replacement", |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1400 | moduleTypeUnderTest: "cc_library_static", |
| 1401 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1402 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1403 | filesystem: map[string]string{}, |
| 1404 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1405 | cc_library_static { |
| 1406 | name: "foo_static", |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 1407 | srcs: ["common.S"], |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1408 | product_variables: { |
| 1409 | platform_sdk_version: { |
| 1410 | asflags: ["-DPLATFORM_SDK_VERSION=%d"], |
| 1411 | }, |
| 1412 | }, |
| 1413 | } `, |
| 1414 | expectedBazelTargets: []string{`cc_library_static( |
| 1415 | name = "foo_static", |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 1416 | asflags = [ |
| 1417 | "-I.", |
| 1418 | "-I$(BINDIR)/.", |
| 1419 | ] + select({ |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1420 | "//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"], |
| 1421 | "//conditions:default": [], |
| 1422 | }), |
| 1423 | copts = [ |
| 1424 | "-I.", |
| 1425 | "-I$(BINDIR)/.", |
| 1426 | ], |
| 1427 | linkstatic = True, |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 1428 | srcs_as = ["common.S"], |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 1429 | )`}, |
| 1430 | }) |
| 1431 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1432 | |
| 1433 | func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
| 1434 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1435 | description: "cc_library_static system_shared_lib empty root", |
| 1436 | moduleTypeUnderTest: "cc_library_static", |
| 1437 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1438 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1439 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1440 | cc_library_static { |
| 1441 | name: "root_empty", |
| 1442 | system_shared_libs: [], |
| 1443 | } |
| 1444 | `, |
| 1445 | expectedBazelTargets: []string{`cc_library_static( |
| 1446 | name = "root_empty", |
| 1447 | copts = [ |
| 1448 | "-I.", |
| 1449 | "-I$(BINDIR)/.", |
| 1450 | ], |
| 1451 | linkstatic = True, |
| 1452 | system_dynamic_deps = [], |
| 1453 | )`}, |
| 1454 | }) |
| 1455 | } |
| 1456 | |
| 1457 | func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
| 1458 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1459 | description: "cc_library_static system_shared_lib empty static default", |
| 1460 | moduleTypeUnderTest: "cc_library_static", |
| 1461 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1462 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1463 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1464 | cc_defaults { |
| 1465 | name: "static_empty_defaults", |
| 1466 | static: { |
| 1467 | system_shared_libs: [], |
| 1468 | }, |
| 1469 | } |
| 1470 | cc_library_static { |
| 1471 | name: "static_empty", |
| 1472 | defaults: ["static_empty_defaults"], |
| 1473 | } |
| 1474 | `, |
| 1475 | expectedBazelTargets: []string{`cc_library_static( |
| 1476 | name = "static_empty", |
| 1477 | copts = [ |
| 1478 | "-I.", |
| 1479 | "-I$(BINDIR)/.", |
| 1480 | ], |
| 1481 | linkstatic = True, |
| 1482 | system_dynamic_deps = [], |
| 1483 | )`}, |
| 1484 | }) |
| 1485 | } |
| 1486 | |
| 1487 | func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
| 1488 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1489 | description: "cc_library_static system_shared_lib empty for bionic variant", |
| 1490 | moduleTypeUnderTest: "cc_library_static", |
| 1491 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1492 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1493 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1494 | cc_library_static { |
| 1495 | name: "target_bionic_empty", |
| 1496 | target: { |
| 1497 | bionic: { |
| 1498 | system_shared_libs: [], |
| 1499 | }, |
| 1500 | }, |
| 1501 | } |
| 1502 | `, |
| 1503 | expectedBazelTargets: []string{`cc_library_static( |
| 1504 | name = "target_bionic_empty", |
| 1505 | copts = [ |
| 1506 | "-I.", |
| 1507 | "-I$(BINDIR)/.", |
| 1508 | ], |
| 1509 | linkstatic = True, |
| 1510 | system_dynamic_deps = [], |
| 1511 | )`}, |
| 1512 | }) |
| 1513 | } |
| 1514 | |
| 1515 | func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1516 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1517 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1518 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1519 | // b/195791252 tracks the fix. |
| 1520 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1521 | description: "cc_library_static system_shared_lib empty for linux_bionic variant", |
| 1522 | moduleTypeUnderTest: "cc_library_static", |
| 1523 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1524 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1525 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1526 | cc_library_static { |
| 1527 | name: "target_linux_bionic_empty", |
| 1528 | target: { |
| 1529 | linux_bionic: { |
| 1530 | system_shared_libs: [], |
| 1531 | }, |
| 1532 | }, |
| 1533 | } |
| 1534 | `, |
| 1535 | expectedBazelTargets: []string{`cc_library_static( |
| 1536 | name = "target_linux_bionic_empty", |
| 1537 | copts = [ |
| 1538 | "-I.", |
| 1539 | "-I$(BINDIR)/.", |
| 1540 | ], |
| 1541 | linkstatic = True, |
| 1542 | system_dynamic_deps = [], |
| 1543 | )`}, |
| 1544 | }) |
| 1545 | } |
| 1546 | |
| 1547 | func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) { |
| 1548 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1549 | description: "cc_library_static system_shared_libs set for bionic variant", |
| 1550 | moduleTypeUnderTest: "cc_library_static", |
| 1551 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1552 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1553 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1554 | cc_library{name: "libc"} |
| 1555 | |
| 1556 | cc_library_static { |
| 1557 | name: "target_bionic", |
| 1558 | target: { |
| 1559 | bionic: { |
| 1560 | system_shared_libs: ["libc"], |
| 1561 | }, |
| 1562 | }, |
| 1563 | } |
| 1564 | `, |
| 1565 | expectedBazelTargets: []string{`cc_library_static( |
| 1566 | name = "target_bionic", |
| 1567 | copts = [ |
| 1568 | "-I.", |
| 1569 | "-I$(BINDIR)/.", |
| 1570 | ], |
| 1571 | linkstatic = True, |
| 1572 | system_dynamic_deps = select({ |
| 1573 | "//build/bazel/platforms/os:bionic": [":libc"], |
| 1574 | "//conditions:default": [], |
| 1575 | }), |
| 1576 | )`}, |
| 1577 | }) |
| 1578 | } |
| 1579 | |
| 1580 | func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) { |
| 1581 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1582 | description: "cc_library_static system_shared_libs set for root and linux_bionic variant", |
| 1583 | moduleTypeUnderTest: "cc_library_static", |
| 1584 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1585 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1586 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1587 | cc_library{name: "libc"} |
| 1588 | cc_library{name: "libm"} |
| 1589 | |
| 1590 | cc_library_static { |
| 1591 | name: "target_linux_bionic", |
| 1592 | system_shared_libs: ["libc"], |
| 1593 | target: { |
| 1594 | linux_bionic: { |
| 1595 | system_shared_libs: ["libm"], |
| 1596 | }, |
| 1597 | }, |
| 1598 | } |
| 1599 | `, |
| 1600 | expectedBazelTargets: []string{`cc_library_static( |
| 1601 | name = "target_linux_bionic", |
| 1602 | copts = [ |
| 1603 | "-I.", |
| 1604 | "-I$(BINDIR)/.", |
| 1605 | ], |
| 1606 | linkstatic = True, |
| 1607 | system_dynamic_deps = [":libc"] + select({ |
| 1608 | "//build/bazel/platforms/os:linux_bionic": [":libm"], |
| 1609 | "//conditions:default": [], |
| 1610 | }), |
| 1611 | )`}, |
| 1612 | }) |
| 1613 | } |