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 | "strings" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | const ( |
| 27 | // See cc/testing.go for more context |
| 28 | soongCcLibraryStaticPreamble = ` |
| 29 | cc_defaults { |
| 30 | name: "linux_bionic_supported", |
| 31 | } |
| 32 | |
| 33 | toolchain_library { |
| 34 | name: "libclang_rt.builtins-x86_64-android", |
| 35 | defaults: ["linux_bionic_supported"], |
| 36 | vendor_available: true, |
| 37 | vendor_ramdisk_available: true, |
| 38 | product_available: true, |
| 39 | recovery_available: true, |
| 40 | native_bridge_supported: true, |
| 41 | src: "", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 42 | }` |
| 43 | ) |
| 44 | |
| 45 | func TestCcLibraryStaticLoadStatement(t *testing.T) { |
| 46 | testCases := []struct { |
| 47 | bazelTargets BazelTargets |
| 48 | expectedLoadStatements string |
| 49 | }{ |
| 50 | { |
| 51 | bazelTargets: BazelTargets{ |
| 52 | BazelTarget{ |
| 53 | name: "cc_library_static_target", |
| 54 | ruleClass: "cc_library_static", |
| 55 | // NOTE: No bzlLoadLocation for native rules |
| 56 | }, |
| 57 | }, |
| 58 | expectedLoadStatements: ``, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | for _, testCase := range testCases { |
| 63 | actual := testCase.bazelTargets.LoadStatements() |
| 64 | expected := testCase.expectedLoadStatements |
| 65 | if actual != expected { |
| 66 | t.Fatalf("Expected load statements to be %s, got %s", expected, actual) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | func TestCcLibraryStaticBp2Build(t *testing.T) { |
| 73 | testCases := []struct { |
| 74 | description string |
| 75 | moduleTypeUnderTest string |
| 76 | moduleTypeUnderTestFactory android.ModuleFactory |
| 77 | moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext) |
| 78 | preArchMutators []android.RegisterMutatorFunc |
| 79 | depsMutators []android.RegisterMutatorFunc |
| 80 | bp string |
| 81 | expectedBazelTargets []string |
| 82 | filesystem map[string]string |
| 83 | dir string |
| 84 | }{ |
| 85 | { |
| 86 | description: "cc_library_static test", |
| 87 | moduleTypeUnderTest: "cc_library_static", |
| 88 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 89 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 90 | filesystem: map[string]string{ |
| 91 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 92 | "include_dir_1/include_dir_1_a.h": "", |
| 93 | "include_dir_1/include_dir_1_b.h": "", |
| 94 | "include_dir_2/include_dir_2_a.h": "", |
| 95 | "include_dir_2/include_dir_2_b.h": "", |
| 96 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 97 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 98 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 99 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 100 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 101 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 102 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 103 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 104 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 105 | "export_include_dir_2/export_include_dir_2_b.h": "", |
Rupert Shuttleworth | c58d3d2 | 2021-04-06 16:37:15 +0000 | [diff] [blame] | 106 | // NOTE: Soong implicitly includes headers in the current directory |
| 107 | "implicit_include_1.h": "", |
| 108 | "implicit_include_2.h": "", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 109 | }, |
| 110 | bp: soongCcLibraryStaticPreamble + ` |
| 111 | cc_library_headers { |
| 112 | name: "header_lib_1", |
| 113 | export_include_dirs: ["header_lib_1"], |
| 114 | } |
| 115 | |
| 116 | cc_library_headers { |
| 117 | name: "header_lib_2", |
| 118 | export_include_dirs: ["header_lib_2"], |
| 119 | } |
| 120 | |
| 121 | cc_library_static { |
| 122 | name: "static_lib_1", |
| 123 | srcs: ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | cc_library_static { |
| 127 | name: "static_lib_2", |
| 128 | srcs: ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | cc_library_static { |
| 132 | name: "whole_static_lib_1", |
| 133 | srcs: ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | cc_library_static { |
| 137 | name: "whole_static_lib_2", |
| 138 | srcs: ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | cc_library_static { |
| 142 | name: "foo_static", |
| 143 | srcs: [ |
| 144 | "foo_static1.cc", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 145 | "foo_static2.cc", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 146 | ], |
| 147 | cflags: [ |
| 148 | "-Dflag1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 149 | "-Dflag2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 150 | ], |
| 151 | static_libs: [ |
| 152 | "static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 153 | "static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 154 | ], |
| 155 | whole_static_libs: [ |
| 156 | "whole_static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 157 | "whole_static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 158 | ], |
| 159 | include_dirs: [ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 160 | "include_dir_1", |
| 161 | "include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 162 | ], |
| 163 | local_include_dirs: [ |
| 164 | "local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 165 | "local_include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 166 | ], |
| 167 | export_include_dirs: [ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 168 | "export_include_dir_1", |
| 169 | "export_include_dir_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 170 | ], |
| 171 | header_libs: [ |
| 172 | "header_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 173 | "header_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 174 | ], |
| 175 | |
| 176 | // TODO: Also support export_header_lib_headers |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 177 | }`, |
| 178 | expectedBazelTargets: []string{`cc_library_static( |
| 179 | name = "foo_static", |
| 180 | copts = [ |
| 181 | "-Dflag1", |
| 182 | "-Dflag2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 183 | "-Iinclude_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 184 | "-I$(BINDIR)/include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 185 | "-Iinclude_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 186 | "-I$(BINDIR)/include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 187 | "-Ilocal_include_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 188 | "-I$(BINDIR)/local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 189 | "-Ilocal_include_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 190 | "-I$(BINDIR)/local_include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 191 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 192 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 193 | ], |
| 194 | deps = [ |
| 195 | ":header_lib_1", |
| 196 | ":header_lib_2", |
| 197 | ":static_lib_1", |
| 198 | ":static_lib_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 199 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 200 | includes = [ |
| 201 | "export_include_dir_1", |
| 202 | "export_include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 203 | ], |
| 204 | linkstatic = True, |
| 205 | srcs = [ |
| 206 | "foo_static1.cc", |
| 207 | "foo_static2.cc", |
| 208 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 209 | whole_archive_deps = [ |
| 210 | ":whole_static_lib_1", |
| 211 | ":whole_static_lib_2", |
| 212 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 213 | )`, `cc_library_static( |
| 214 | name = "static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 215 | copts = [ |
| 216 | "-I.", |
| 217 | "-I$(BINDIR)/.", |
| 218 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 219 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 220 | srcs = ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 221 | )`, `cc_library_static( |
| 222 | name = "static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 223 | copts = [ |
| 224 | "-I.", |
| 225 | "-I$(BINDIR)/.", |
| 226 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 227 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 228 | srcs = ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 229 | )`, `cc_library_static( |
| 230 | name = "whole_static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 231 | copts = [ |
| 232 | "-I.", |
| 233 | "-I$(BINDIR)/.", |
| 234 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 235 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 236 | srcs = ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 237 | )`, `cc_library_static( |
| 238 | name = "whole_static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 239 | copts = [ |
| 240 | "-I.", |
| 241 | "-I$(BINDIR)/.", |
| 242 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 243 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 244 | srcs = ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 245 | )`}, |
| 246 | }, |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 247 | { |
| 248 | description: "cc_library_static subpackage test", |
| 249 | moduleTypeUnderTest: "cc_library_static", |
| 250 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 251 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 252 | filesystem: map[string]string{ |
| 253 | // subpackage with subdirectory |
| 254 | "subpackage/Android.bp": "", |
| 255 | "subpackage/subpackage_header.h": "", |
| 256 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 257 | // subsubpackage with subdirectory |
| 258 | "subpackage/subsubpackage/Android.bp": "", |
| 259 | "subpackage/subsubpackage/subsubpackage_header.h": "", |
| 260 | "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "", |
| 261 | // subsubsubpackage with subdirectory |
| 262 | "subpackage/subsubpackage/subsubsubpackage/Android.bp": "", |
| 263 | "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "", |
| 264 | "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "", |
| 265 | }, |
| 266 | bp: soongCcLibraryStaticPreamble + ` |
| 267 | cc_library_static { |
| 268 | name: "foo_static", |
| 269 | srcs: [ |
| 270 | ], |
| 271 | include_dirs: [ |
| 272 | "subpackage", |
| 273 | ], |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 274 | }`, |
| 275 | expectedBazelTargets: []string{`cc_library_static( |
| 276 | name = "foo_static", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 277 | copts = [ |
| 278 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 279 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 280 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 281 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 282 | ], |
| 283 | linkstatic = True, |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 284 | )`}, |
| 285 | }, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 286 | { |
| 287 | description: "cc_library_static export include dir", |
| 288 | moduleTypeUnderTest: "cc_library_static", |
| 289 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 290 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 291 | filesystem: map[string]string{ |
| 292 | // subpackage with subdirectory |
| 293 | "subpackage/Android.bp": "", |
| 294 | "subpackage/subpackage_header.h": "", |
| 295 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 296 | }, |
| 297 | bp: soongCcLibraryStaticPreamble + ` |
| 298 | cc_library_static { |
| 299 | name: "foo_static", |
| 300 | export_include_dirs: ["subpackage"], |
| 301 | }`, |
| 302 | expectedBazelTargets: []string{`cc_library_static( |
| 303 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 304 | copts = [ |
| 305 | "-I.", |
| 306 | "-I$(BINDIR)/.", |
| 307 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 308 | includes = ["subpackage"], |
| 309 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 310 | )`}, |
| 311 | }, |
| 312 | { |
| 313 | description: "cc_library_static export system include dir", |
| 314 | moduleTypeUnderTest: "cc_library_static", |
| 315 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 316 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 317 | filesystem: map[string]string{ |
| 318 | // subpackage with subdirectory |
| 319 | "subpackage/Android.bp": "", |
| 320 | "subpackage/subpackage_header.h": "", |
| 321 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 322 | }, |
| 323 | bp: soongCcLibraryStaticPreamble + ` |
| 324 | cc_library_static { |
| 325 | name: "foo_static", |
| 326 | export_system_include_dirs: ["subpackage"], |
| 327 | }`, |
| 328 | expectedBazelTargets: []string{`cc_library_static( |
| 329 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 330 | copts = [ |
| 331 | "-I.", |
| 332 | "-I$(BINDIR)/.", |
| 333 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 334 | includes = ["subpackage"], |
| 335 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 336 | )`}, |
| 337 | }, |
| 338 | { |
| 339 | description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)", |
| 340 | moduleTypeUnderTest: "cc_library_static", |
| 341 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 342 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 343 | dir: "subpackage", |
| 344 | filesystem: map[string]string{ |
| 345 | // subpackage with subdirectory |
| 346 | "subpackage/Android.bp": ` |
| 347 | cc_library_static { |
| 348 | name: "foo_static", |
| 349 | // include_dirs are workspace/root relative |
| 350 | include_dirs: [ |
| 351 | "subpackage/subsubpackage", |
| 352 | "subpackage2", |
| 353 | "subpackage3/subsubpackage" |
| 354 | ], |
| 355 | local_include_dirs: ["subsubpackage2"], // module dir relative |
| 356 | export_include_dirs: ["./exported_subsubpackage"], // module dir relative |
| 357 | include_build_directory: true, |
| 358 | bazel_module: { bp2build_available: true }, |
| 359 | }`, |
| 360 | "subpackage/subsubpackage/header.h": "", |
| 361 | "subpackage/subsubpackage2/header.h": "", |
| 362 | "subpackage/exported_subsubpackage/header.h": "", |
| 363 | "subpackage2/header.h": "", |
| 364 | "subpackage3/subsubpackage/header.h": "", |
| 365 | }, |
| 366 | bp: soongCcLibraryStaticPreamble, |
| 367 | expectedBazelTargets: []string{`cc_library_static( |
| 368 | name = "foo_static", |
| 369 | copts = [ |
| 370 | "-Isubpackage/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 371 | "-I$(BINDIR)/subpackage/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 372 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 373 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 374 | "-Isubpackage3/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 375 | "-I$(BINDIR)/subpackage3/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 376 | "-Isubpackage/subsubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 377 | "-I$(BINDIR)/subpackage/subsubpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 378 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 379 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 380 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 381 | includes = ["./exported_subsubpackage"], |
| 382 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 383 | )`}, |
| 384 | }, |
| 385 | { |
| 386 | description: "cc_library_static include_build_directory disabled", |
| 387 | moduleTypeUnderTest: "cc_library_static", |
| 388 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 389 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 390 | filesystem: map[string]string{ |
| 391 | // subpackage with subdirectory |
| 392 | "subpackage/Android.bp": "", |
| 393 | "subpackage/subpackage_header.h": "", |
| 394 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 395 | }, |
| 396 | bp: soongCcLibraryStaticPreamble + ` |
| 397 | cc_library_static { |
| 398 | name: "foo_static", |
| 399 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 400 | local_include_dirs: ["subpackage2"], |
| 401 | include_build_directory: false, |
| 402 | }`, |
| 403 | expectedBazelTargets: []string{`cc_library_static( |
| 404 | name = "foo_static", |
| 405 | copts = [ |
| 406 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 407 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 408 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 409 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 410 | ], |
| 411 | linkstatic = True, |
| 412 | )`}, |
| 413 | }, |
| 414 | { |
| 415 | description: "cc_library_static include_build_directory enabled", |
| 416 | moduleTypeUnderTest: "cc_library_static", |
| 417 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 418 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 419 | filesystem: map[string]string{ |
| 420 | // subpackage with subdirectory |
| 421 | "subpackage/Android.bp": "", |
| 422 | "subpackage/subpackage_header.h": "", |
| 423 | "subpackage2/Android.bp": "", |
| 424 | "subpackage2/subpackage2_header.h": "", |
| 425 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 426 | }, |
| 427 | bp: soongCcLibraryStaticPreamble + ` |
| 428 | cc_library_static { |
| 429 | name: "foo_static", |
| 430 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 431 | local_include_dirs: ["subpackage2"], |
| 432 | include_build_directory: true, |
| 433 | }`, |
| 434 | expectedBazelTargets: []string{`cc_library_static( |
| 435 | name = "foo_static", |
| 436 | copts = [ |
| 437 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 438 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 439 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 440 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 441 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 442 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 443 | ], |
| 444 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 445 | )`}, |
| 446 | }, |
| 447 | { |
| 448 | description: "cc_library_static arch-specific static_libs", |
| 449 | moduleTypeUnderTest: "cc_library_static", |
| 450 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 451 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 452 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 453 | filesystem: map[string]string{}, |
| 454 | bp: soongCcLibraryStaticPreamble + ` |
| 455 | cc_library_static { name: "static_dep" } |
| 456 | cc_library_static { name: "static_dep2" } |
| 457 | cc_library_static { |
| 458 | name: "foo_static", |
| 459 | arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 460 | }`, |
| 461 | expectedBazelTargets: []string{`cc_library_static( |
| 462 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 463 | copts = [ |
| 464 | "-I.", |
| 465 | "-I$(BINDIR)/.", |
| 466 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 467 | deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 468 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 469 | "//conditions:default": [], |
| 470 | }), |
| 471 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 472 | whole_archive_deps = select({ |
| 473 | "//build/bazel/platforms/arch:arm64": [":static_dep2"], |
| 474 | "//conditions:default": [], |
| 475 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 476 | )`, `cc_library_static( |
| 477 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 478 | copts = [ |
| 479 | "-I.", |
| 480 | "-I$(BINDIR)/.", |
| 481 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 482 | linkstatic = True, |
| 483 | )`, `cc_library_static( |
| 484 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 485 | copts = [ |
| 486 | "-I.", |
| 487 | "-I$(BINDIR)/.", |
| 488 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 489 | linkstatic = True, |
| 490 | )`}, |
| 491 | }, |
| 492 | { |
| 493 | description: "cc_library_static os-specific static_libs", |
| 494 | moduleTypeUnderTest: "cc_library_static", |
| 495 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 496 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 497 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 498 | filesystem: map[string]string{}, |
| 499 | bp: soongCcLibraryStaticPreamble + ` |
| 500 | cc_library_static { name: "static_dep" } |
| 501 | cc_library_static { name: "static_dep2" } |
| 502 | cc_library_static { |
| 503 | name: "foo_static", |
| 504 | target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 505 | }`, |
| 506 | expectedBazelTargets: []string{`cc_library_static( |
| 507 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 508 | copts = [ |
| 509 | "-I.", |
| 510 | "-I$(BINDIR)/.", |
| 511 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 512 | deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 513 | "//build/bazel/platforms/os:android": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 514 | "//conditions:default": [], |
| 515 | }), |
| 516 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 517 | whole_archive_deps = select({ |
| 518 | "//build/bazel/platforms/os:android": [":static_dep2"], |
| 519 | "//conditions:default": [], |
| 520 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 521 | )`, `cc_library_static( |
| 522 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 523 | copts = [ |
| 524 | "-I.", |
| 525 | "-I$(BINDIR)/.", |
| 526 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 527 | linkstatic = True, |
| 528 | )`, `cc_library_static( |
| 529 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 530 | copts = [ |
| 531 | "-I.", |
| 532 | "-I$(BINDIR)/.", |
| 533 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 534 | linkstatic = True, |
| 535 | )`}, |
| 536 | }, |
| 537 | { |
| 538 | description: "cc_library_static base, arch and os-specific static_libs", |
| 539 | moduleTypeUnderTest: "cc_library_static", |
| 540 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 541 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 542 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 543 | filesystem: map[string]string{}, |
| 544 | bp: soongCcLibraryStaticPreamble + ` |
| 545 | cc_library_static { name: "static_dep" } |
| 546 | cc_library_static { name: "static_dep2" } |
| 547 | cc_library_static { name: "static_dep3" } |
| 548 | cc_library_static { name: "static_dep4" } |
| 549 | cc_library_static { |
| 550 | name: "foo_static", |
| 551 | static_libs: ["static_dep"], |
| 552 | whole_static_libs: ["static_dep2"], |
| 553 | target: { android: { static_libs: ["static_dep3"] } }, |
| 554 | arch: { arm64: { static_libs: ["static_dep4"] } }, |
| 555 | }`, |
| 556 | expectedBazelTargets: []string{`cc_library_static( |
| 557 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 558 | copts = [ |
| 559 | "-I.", |
| 560 | "-I$(BINDIR)/.", |
| 561 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 562 | deps = [":static_dep"] + select({ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 563 | "//build/bazel/platforms/arch:arm64": [":static_dep4"], |
| 564 | "//conditions:default": [], |
| 565 | }) + select({ |
| 566 | "//build/bazel/platforms/os:android": [":static_dep3"], |
| 567 | "//conditions:default": [], |
| 568 | }), |
| 569 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 570 | whole_archive_deps = [":static_dep2"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 571 | )`, `cc_library_static( |
| 572 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 573 | copts = [ |
| 574 | "-I.", |
| 575 | "-I$(BINDIR)/.", |
| 576 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 577 | linkstatic = True, |
| 578 | )`, `cc_library_static( |
| 579 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 580 | copts = [ |
| 581 | "-I.", |
| 582 | "-I$(BINDIR)/.", |
| 583 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 584 | linkstatic = True, |
| 585 | )`, `cc_library_static( |
| 586 | name = "static_dep3", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 587 | copts = [ |
| 588 | "-I.", |
| 589 | "-I$(BINDIR)/.", |
| 590 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 591 | linkstatic = True, |
| 592 | )`, `cc_library_static( |
| 593 | name = "static_dep4", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 594 | copts = [ |
| 595 | "-I.", |
| 596 | "-I$(BINDIR)/.", |
| 597 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 598 | linkstatic = True, |
| 599 | )`}, |
| 600 | }, |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 601 | { |
| 602 | description: "cc_library_static simple exclude_srcs", |
| 603 | moduleTypeUnderTest: "cc_library_static", |
| 604 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 605 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 606 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 607 | filesystem: map[string]string{ |
| 608 | "common.c": "", |
| 609 | "foo-a.c": "", |
| 610 | "foo-excluded.c": "", |
| 611 | }, |
| 612 | bp: soongCcLibraryStaticPreamble + ` |
| 613 | cc_library_static { |
| 614 | name: "foo_static", |
| 615 | srcs: ["common.c", "foo-*.c"], |
| 616 | exclude_srcs: ["foo-excluded.c"], |
| 617 | }`, |
| 618 | expectedBazelTargets: []string{`cc_library_static( |
| 619 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 620 | copts = [ |
| 621 | "-I.", |
| 622 | "-I$(BINDIR)/.", |
| 623 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 624 | linkstatic = True, |
| 625 | srcs = [ |
| 626 | "common.c", |
| 627 | "foo-a.c", |
| 628 | ], |
| 629 | )`}, |
| 630 | }, |
| 631 | { |
| 632 | description: "cc_library_static one arch specific srcs", |
| 633 | moduleTypeUnderTest: "cc_library_static", |
| 634 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 635 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 636 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 637 | filesystem: map[string]string{ |
| 638 | "common.c": "", |
| 639 | "foo-arm.c": "", |
| 640 | }, |
| 641 | bp: soongCcLibraryStaticPreamble + ` |
| 642 | cc_library_static { |
| 643 | name: "foo_static", |
| 644 | srcs: ["common.c"], |
| 645 | arch: { arm: { srcs: ["foo-arm.c"] } } |
| 646 | }`, |
| 647 | expectedBazelTargets: []string{`cc_library_static( |
| 648 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 649 | copts = [ |
| 650 | "-I.", |
| 651 | "-I$(BINDIR)/.", |
| 652 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 653 | linkstatic = True, |
| 654 | srcs = ["common.c"] + select({ |
| 655 | "//build/bazel/platforms/arch:arm": ["foo-arm.c"], |
| 656 | "//conditions:default": [], |
| 657 | }), |
| 658 | )`}, |
| 659 | }, |
| 660 | { |
| 661 | description: "cc_library_static one arch specific srcs and exclude_srcs", |
| 662 | moduleTypeUnderTest: "cc_library_static", |
| 663 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 664 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 665 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 666 | filesystem: map[string]string{ |
| 667 | "common.c": "", |
| 668 | "for-arm.c": "", |
| 669 | "not-for-arm.c": "", |
| 670 | "not-for-anything.c": "", |
| 671 | }, |
| 672 | bp: soongCcLibraryStaticPreamble + ` |
| 673 | cc_library_static { |
| 674 | name: "foo_static", |
| 675 | srcs: ["common.c", "not-for-*.c"], |
| 676 | exclude_srcs: ["not-for-anything.c"], |
| 677 | arch: { |
| 678 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 679 | }, |
| 680 | }`, |
| 681 | expectedBazelTargets: []string{`cc_library_static( |
| 682 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 683 | copts = [ |
| 684 | "-I.", |
| 685 | "-I$(BINDIR)/.", |
| 686 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 687 | linkstatic = True, |
| 688 | srcs = ["common.c"] + select({ |
| 689 | "//build/bazel/platforms/arch:arm": ["for-arm.c"], |
| 690 | "//conditions:default": ["not-for-arm.c"], |
| 691 | }), |
| 692 | )`}, |
| 693 | }, |
| 694 | { |
| 695 | description: "cc_library_static arch specific exclude_srcs for 2 architectures", |
| 696 | moduleTypeUnderTest: "cc_library_static", |
| 697 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 698 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 699 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 700 | filesystem: map[string]string{ |
| 701 | "common.c": "", |
| 702 | "for-arm.c": "", |
| 703 | "for-x86.c": "", |
| 704 | "not-for-arm.c": "", |
| 705 | "not-for-x86.c": "", |
| 706 | }, |
| 707 | bp: soongCcLibraryStaticPreamble + ` |
| 708 | cc_library_static { |
| 709 | name: "foo_static", |
| 710 | srcs: ["common.c", "not-for-*.c"], |
| 711 | exclude_srcs: ["not-for-everything.c"], |
| 712 | arch: { |
| 713 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 714 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 715 | }, |
| 716 | } `, |
| 717 | expectedBazelTargets: []string{`cc_library_static( |
| 718 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 719 | copts = [ |
| 720 | "-I.", |
| 721 | "-I$(BINDIR)/.", |
| 722 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 723 | linkstatic = True, |
| 724 | srcs = ["common.c"] + select({ |
| 725 | "//build/bazel/platforms/arch:arm": [ |
| 726 | "for-arm.c", |
| 727 | "not-for-x86.c", |
| 728 | ], |
| 729 | "//build/bazel/platforms/arch:x86": [ |
| 730 | "for-x86.c", |
| 731 | "not-for-arm.c", |
| 732 | ], |
| 733 | "//conditions:default": [ |
| 734 | "not-for-arm.c", |
| 735 | "not-for-x86.c", |
| 736 | ], |
| 737 | }), |
| 738 | )`}, |
| 739 | }, |
| 740 | { |
| 741 | description: "cc_library_static arch specific exclude_srcs for 4 architectures", |
| 742 | moduleTypeUnderTest: "cc_library_static", |
| 743 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 744 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 745 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 746 | filesystem: map[string]string{ |
| 747 | "common.c": "", |
| 748 | "for-arm.c": "", |
| 749 | "for-arm64.c": "", |
| 750 | "for-x86.c": "", |
| 751 | "for-x86_64.c": "", |
| 752 | "not-for-arm.c": "", |
| 753 | "not-for-arm64.c": "", |
| 754 | "not-for-x86.c": "", |
| 755 | "not-for-x86_64.c": "", |
| 756 | "not-for-everything.c": "", |
| 757 | }, |
| 758 | bp: soongCcLibraryStaticPreamble + ` |
| 759 | cc_library_static { |
| 760 | name: "foo_static", |
| 761 | srcs: ["common.c", "not-for-*.c"], |
| 762 | exclude_srcs: ["not-for-everything.c"], |
| 763 | arch: { |
| 764 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 765 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 766 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 767 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 768 | }, |
| 769 | } `, |
| 770 | expectedBazelTargets: []string{`cc_library_static( |
| 771 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 772 | copts = [ |
| 773 | "-I.", |
| 774 | "-I$(BINDIR)/.", |
| 775 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 776 | linkstatic = True, |
| 777 | srcs = ["common.c"] + select({ |
| 778 | "//build/bazel/platforms/arch:arm": [ |
| 779 | "for-arm.c", |
| 780 | "not-for-arm64.c", |
| 781 | "not-for-x86.c", |
| 782 | "not-for-x86_64.c", |
| 783 | ], |
| 784 | "//build/bazel/platforms/arch:arm64": [ |
| 785 | "for-arm64.c", |
| 786 | "not-for-arm.c", |
| 787 | "not-for-x86.c", |
| 788 | "not-for-x86_64.c", |
| 789 | ], |
| 790 | "//build/bazel/platforms/arch:x86": [ |
| 791 | "for-x86.c", |
| 792 | "not-for-arm.c", |
| 793 | "not-for-arm64.c", |
| 794 | "not-for-x86_64.c", |
| 795 | ], |
| 796 | "//build/bazel/platforms/arch:x86_64": [ |
| 797 | "for-x86_64.c", |
| 798 | "not-for-arm.c", |
| 799 | "not-for-arm64.c", |
| 800 | "not-for-x86.c", |
| 801 | ], |
| 802 | "//conditions:default": [ |
| 803 | "not-for-arm.c", |
| 804 | "not-for-arm64.c", |
| 805 | "not-for-x86.c", |
| 806 | "not-for-x86_64.c", |
| 807 | ], |
| 808 | }), |
| 809 | )`}, |
| 810 | }, |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 811 | { |
| 812 | description: "cc_library_static multiple dep same name panic", |
| 813 | moduleTypeUnderTest: "cc_library_static", |
| 814 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 815 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 816 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 817 | filesystem: map[string]string{}, |
| 818 | bp: soongCcLibraryStaticPreamble + ` |
| 819 | cc_library_static { name: "static_dep" } |
| 820 | cc_library_static { |
| 821 | name: "foo_static", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 822 | static_libs: ["static_dep", "static_dep"], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 823 | }`, |
| 824 | expectedBazelTargets: []string{`cc_library_static( |
| 825 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 826 | copts = [ |
| 827 | "-I.", |
| 828 | "-I$(BINDIR)/.", |
| 829 | ], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 830 | deps = [":static_dep"], |
| 831 | linkstatic = True, |
| 832 | )`, `cc_library_static( |
| 833 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 834 | copts = [ |
| 835 | "-I.", |
| 836 | "-I$(BINDIR)/.", |
| 837 | ], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 838 | linkstatic = True, |
| 839 | )`}, |
| 840 | }, |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 841 | { |
| 842 | description: "cc_library_static 1 multilib srcs and exclude_srcs", |
| 843 | moduleTypeUnderTest: "cc_library_static", |
| 844 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 845 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 846 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 847 | filesystem: map[string]string{ |
| 848 | "common.c": "", |
| 849 | "for-lib32.c": "", |
| 850 | "not-for-lib32.c": "", |
| 851 | }, |
| 852 | bp: soongCcLibraryStaticPreamble + ` |
| 853 | cc_library_static { |
| 854 | name: "foo_static", |
| 855 | srcs: ["common.c", "not-for-*.c"], |
| 856 | multilib: { |
| 857 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 858 | }, |
| 859 | } `, |
| 860 | expectedBazelTargets: []string{`cc_library_static( |
| 861 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 862 | copts = [ |
| 863 | "-I.", |
| 864 | "-I$(BINDIR)/.", |
| 865 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 866 | linkstatic = True, |
| 867 | srcs = ["common.c"] + select({ |
| 868 | "//build/bazel/platforms/arch:arm": ["for-lib32.c"], |
| 869 | "//build/bazel/platforms/arch:x86": ["for-lib32.c"], |
| 870 | "//conditions:default": ["not-for-lib32.c"], |
| 871 | }), |
| 872 | )`}, |
| 873 | }, |
| 874 | { |
| 875 | description: "cc_library_static 2 multilib srcs and exclude_srcs", |
| 876 | moduleTypeUnderTest: "cc_library_static", |
| 877 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 878 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 879 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 880 | filesystem: map[string]string{ |
| 881 | "common.c": "", |
| 882 | "for-lib32.c": "", |
| 883 | "for-lib64.c": "", |
| 884 | "not-for-lib32.c": "", |
| 885 | "not-for-lib64.c": "", |
| 886 | }, |
| 887 | bp: soongCcLibraryStaticPreamble + ` |
| 888 | cc_library_static { |
| 889 | name: "foo_static2", |
| 890 | srcs: ["common.c", "not-for-*.c"], |
| 891 | multilib: { |
| 892 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 893 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 894 | }, |
| 895 | } `, |
| 896 | expectedBazelTargets: []string{`cc_library_static( |
| 897 | name = "foo_static2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 898 | copts = [ |
| 899 | "-I.", |
| 900 | "-I$(BINDIR)/.", |
| 901 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 902 | linkstatic = True, |
| 903 | srcs = ["common.c"] + select({ |
| 904 | "//build/bazel/platforms/arch:arm": [ |
| 905 | "for-lib32.c", |
| 906 | "not-for-lib64.c", |
| 907 | ], |
| 908 | "//build/bazel/platforms/arch:arm64": [ |
| 909 | "for-lib64.c", |
| 910 | "not-for-lib32.c", |
| 911 | ], |
| 912 | "//build/bazel/platforms/arch:x86": [ |
| 913 | "for-lib32.c", |
| 914 | "not-for-lib64.c", |
| 915 | ], |
| 916 | "//build/bazel/platforms/arch:x86_64": [ |
| 917 | "for-lib64.c", |
| 918 | "not-for-lib32.c", |
| 919 | ], |
| 920 | "//conditions:default": [ |
| 921 | "not-for-lib32.c", |
| 922 | "not-for-lib64.c", |
| 923 | ], |
| 924 | }), |
| 925 | )`}, |
| 926 | }, |
| 927 | { |
| 928 | description: "cc_library_static arch and multilib srcs and exclude_srcs", |
| 929 | moduleTypeUnderTest: "cc_library_static", |
| 930 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 931 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 932 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 933 | filesystem: map[string]string{ |
| 934 | "common.c": "", |
| 935 | "for-arm.c": "", |
| 936 | "for-arm64.c": "", |
| 937 | "for-x86.c": "", |
| 938 | "for-x86_64.c": "", |
| 939 | "for-lib32.c": "", |
| 940 | "for-lib64.c": "", |
| 941 | "not-for-arm.c": "", |
| 942 | "not-for-arm64.c": "", |
| 943 | "not-for-x86.c": "", |
| 944 | "not-for-x86_64.c": "", |
| 945 | "not-for-lib32.c": "", |
| 946 | "not-for-lib64.c": "", |
| 947 | "not-for-everything.c": "", |
| 948 | }, |
| 949 | bp: soongCcLibraryStaticPreamble + ` |
| 950 | cc_library_static { |
| 951 | name: "foo_static3", |
| 952 | srcs: ["common.c", "not-for-*.c"], |
| 953 | exclude_srcs: ["not-for-everything.c"], |
| 954 | arch: { |
| 955 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 956 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 957 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 958 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 959 | }, |
| 960 | multilib: { |
| 961 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 962 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 963 | }, |
| 964 | }`, |
| 965 | expectedBazelTargets: []string{`cc_library_static( |
| 966 | name = "foo_static3", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 967 | copts = [ |
| 968 | "-I.", |
| 969 | "-I$(BINDIR)/.", |
| 970 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 971 | linkstatic = True, |
| 972 | srcs = ["common.c"] + select({ |
| 973 | "//build/bazel/platforms/arch:arm": [ |
| 974 | "for-arm.c", |
| 975 | "for-lib32.c", |
| 976 | "not-for-arm64.c", |
| 977 | "not-for-lib64.c", |
| 978 | "not-for-x86.c", |
| 979 | "not-for-x86_64.c", |
| 980 | ], |
| 981 | "//build/bazel/platforms/arch:arm64": [ |
| 982 | "for-arm64.c", |
| 983 | "for-lib64.c", |
| 984 | "not-for-arm.c", |
| 985 | "not-for-lib32.c", |
| 986 | "not-for-x86.c", |
| 987 | "not-for-x86_64.c", |
| 988 | ], |
| 989 | "//build/bazel/platforms/arch:x86": [ |
| 990 | "for-lib32.c", |
| 991 | "for-x86.c", |
| 992 | "not-for-arm.c", |
| 993 | "not-for-arm64.c", |
| 994 | "not-for-lib64.c", |
| 995 | "not-for-x86_64.c", |
| 996 | ], |
| 997 | "//build/bazel/platforms/arch:x86_64": [ |
| 998 | "for-lib64.c", |
| 999 | "for-x86_64.c", |
| 1000 | "not-for-arm.c", |
| 1001 | "not-for-arm64.c", |
| 1002 | "not-for-lib32.c", |
| 1003 | "not-for-x86.c", |
| 1004 | ], |
| 1005 | "//conditions:default": [ |
| 1006 | "not-for-arm.c", |
| 1007 | "not-for-arm64.c", |
| 1008 | "not-for-lib32.c", |
| 1009 | "not-for-lib64.c", |
| 1010 | "not-for-x86.c", |
| 1011 | "not-for-x86_64.c", |
| 1012 | ], |
| 1013 | }), |
| 1014 | )`}, |
| 1015 | }, |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 1016 | { |
| 1017 | description: "cc_library_static arch srcs/exclude_srcs with generated files", |
| 1018 | moduleTypeUnderTest: "cc_library_static", |
| 1019 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1020 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1021 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1022 | filesystem: map[string]string{ |
| 1023 | "common.c": "", |
| 1024 | "for-x86.c": "", |
| 1025 | "not-for-x86.c": "", |
| 1026 | "not-for-everything.c": "", |
| 1027 | "dep/Android.bp": ` |
| 1028 | genrule { |
| 1029 | name: "generated_src_other_pkg", |
| 1030 | out: ["generated_src_other_pkg.cpp"], |
| 1031 | cmd: "nothing to see here", |
| 1032 | } |
| 1033 | |
| 1034 | genrule { |
| 1035 | name: "generated_hdr_other_pkg", |
| 1036 | out: ["generated_hdr_other_pkg.cpp"], |
| 1037 | cmd: "nothing to see here", |
| 1038 | } |
| 1039 | |
| 1040 | genrule { |
| 1041 | name: "generated_hdr_other_pkg_x86", |
| 1042 | out: ["generated_hdr_other_pkg_x86.cpp"], |
| 1043 | cmd: "nothing to see here", |
| 1044 | }`, |
| 1045 | }, |
| 1046 | bp: soongCcLibraryStaticPreamble + ` |
| 1047 | genrule { |
| 1048 | name: "generated_src", |
| 1049 | out: ["generated_src.cpp"], |
| 1050 | cmd: "nothing to see here", |
| 1051 | } |
| 1052 | |
| 1053 | genrule { |
| 1054 | name: "generated_src_x86", |
| 1055 | out: ["generated_src_x86.cpp"], |
| 1056 | cmd: "nothing to see here", |
| 1057 | } |
| 1058 | |
| 1059 | genrule { |
| 1060 | name: "generated_hdr", |
| 1061 | out: ["generated_hdr.h"], |
| 1062 | cmd: "nothing to see here", |
| 1063 | } |
| 1064 | |
| 1065 | cc_library_static { |
| 1066 | name: "foo_static3", |
| 1067 | srcs: ["common.c", "not-for-*.c"], |
| 1068 | exclude_srcs: ["not-for-everything.c"], |
| 1069 | generated_sources: ["generated_src", "generated_src_other_pkg"], |
| 1070 | generated_headers: ["generated_hdr", "generated_hdr_other_pkg"], |
| 1071 | arch: { |
| 1072 | x86: { |
| 1073 | srcs: ["for-x86.c"], |
| 1074 | exclude_srcs: ["not-for-x86.c"], |
| 1075 | generated_sources: ["generated_src_x86"], |
| 1076 | generated_headers: ["generated_hdr_other_pkg_x86"], |
| 1077 | }, |
| 1078 | }, |
| 1079 | } |
| 1080 | `, |
| 1081 | expectedBazelTargets: []string{`cc_library_static( |
| 1082 | name = "foo_static3", |
| 1083 | copts = [ |
| 1084 | "-I.", |
| 1085 | "-I$(BINDIR)/.", |
| 1086 | ], |
| 1087 | linkstatic = True, |
| 1088 | srcs = [ |
| 1089 | "//dep:generated_hdr_other_pkg", |
| 1090 | "//dep:generated_src_other_pkg", |
| 1091 | ":generated_hdr", |
| 1092 | ":generated_src", |
| 1093 | "common.c", |
| 1094 | ] + select({ |
| 1095 | "//build/bazel/platforms/arch:x86": [ |
| 1096 | "//dep:generated_hdr_other_pkg_x86", |
| 1097 | ":generated_src_x86", |
| 1098 | "for-x86.c", |
| 1099 | ], |
| 1100 | "//conditions:default": ["not-for-x86.c"], |
| 1101 | }), |
| 1102 | )`}, |
| 1103 | }, |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | dir := "." |
| 1107 | for _, testCase := range testCases { |
| 1108 | filesystem := make(map[string][]byte) |
| 1109 | toParse := []string{ |
| 1110 | "Android.bp", |
| 1111 | } |
| 1112 | for f, content := range testCase.filesystem { |
| 1113 | if strings.HasSuffix(f, "Android.bp") { |
| 1114 | toParse = append(toParse, f) |
| 1115 | } |
| 1116 | filesystem[f] = []byte(content) |
| 1117 | } |
| 1118 | config := android.TestConfig(buildDir, nil, testCase.bp, filesystem) |
| 1119 | ctx := android.NewTestContext(config) |
| 1120 | |
| 1121 | cc.RegisterCCBuildComponents(ctx) |
| 1122 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 1123 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame^] | 1124 | ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 1125 | |
| 1126 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
| 1127 | for _, m := range testCase.depsMutators { |
| 1128 | ctx.DepsBp2BuildMutators(m) |
| 1129 | } |
| 1130 | ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 1131 | ctx.RegisterBp2BuildConfig(bp2buildConfig) |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 1132 | ctx.RegisterForBazelConversion() |
| 1133 | |
| 1134 | _, errs := ctx.ParseFileList(dir, toParse) |
| 1135 | if Errored(t, testCase.description, errs) { |
| 1136 | continue |
| 1137 | } |
| 1138 | _, errs = ctx.ResolveDependencies(config) |
| 1139 | if Errored(t, testCase.description, errs) { |
| 1140 | continue |
| 1141 | } |
| 1142 | |
| 1143 | checkDir := dir |
| 1144 | if testCase.dir != "" { |
| 1145 | checkDir = testCase.dir |
| 1146 | } |
| 1147 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1148 | bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 1149 | if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { |
| 1150 | t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount) |
| 1151 | } else { |
| 1152 | for i, target := range bazelTargets { |
| 1153 | if w, g := testCase.expectedBazelTargets[i], target.content; w != g { |
| 1154 | t.Errorf( |
| 1155 | "%s: Expected generated Bazel target to be '%s', got '%s'", |
| 1156 | testCase.description, |
| 1157 | w, |
| 1158 | g, |
| 1159 | ) |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | } |