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) |
| 76 | } |
| 77 | |
| 78 | func runCcLibraryStaticTestCase(t *testing.T, tc bp2buildTestCase) { |
| 79 | runBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc) |
| 80 | } |
| 81 | |
| 82 | func TestCcLibraryStaticSimple(t *testing.T) { |
| 83 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 84 | description: "cc_library_static test", |
| 85 | moduleTypeUnderTest: "cc_library_static", |
| 86 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 87 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 88 | filesystem: map[string]string{ |
| 89 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 90 | "include_dir_1/include_dir_1_a.h": "", |
| 91 | "include_dir_1/include_dir_1_b.h": "", |
| 92 | "include_dir_2/include_dir_2_a.h": "", |
| 93 | "include_dir_2/include_dir_2_b.h": "", |
| 94 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 95 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 96 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 97 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 98 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 99 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 100 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 101 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 102 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 103 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 104 | // NOTE: Soong implicitly includes headers in the current directory |
| 105 | "implicit_include_1.h": "", |
| 106 | "implicit_include_2.h": "", |
| 107 | }, |
| 108 | blueprint: soongCcLibraryStaticPreamble + ` |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 109 | cc_library_headers { |
| 110 | name: "header_lib_1", |
| 111 | export_include_dirs: ["header_lib_1"], |
| 112 | } |
| 113 | |
| 114 | cc_library_headers { |
| 115 | name: "header_lib_2", |
| 116 | export_include_dirs: ["header_lib_2"], |
| 117 | } |
| 118 | |
| 119 | cc_library_static { |
| 120 | name: "static_lib_1", |
| 121 | srcs: ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | cc_library_static { |
| 125 | name: "static_lib_2", |
| 126 | srcs: ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | cc_library_static { |
| 130 | name: "whole_static_lib_1", |
| 131 | srcs: ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | cc_library_static { |
| 135 | name: "whole_static_lib_2", |
| 136 | srcs: ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | cc_library_static { |
| 140 | name: "foo_static", |
| 141 | srcs: [ |
| 142 | "foo_static1.cc", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 143 | "foo_static2.cc", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 144 | ], |
| 145 | cflags: [ |
| 146 | "-Dflag1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 147 | "-Dflag2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 148 | ], |
| 149 | static_libs: [ |
| 150 | "static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 151 | "static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 152 | ], |
| 153 | whole_static_libs: [ |
| 154 | "whole_static_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 155 | "whole_static_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 156 | ], |
| 157 | include_dirs: [ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 158 | "include_dir_1", |
| 159 | "include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 160 | ], |
| 161 | local_include_dirs: [ |
| 162 | "local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 163 | "local_include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 164 | ], |
| 165 | export_include_dirs: [ |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 166 | "export_include_dir_1", |
| 167 | "export_include_dir_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 168 | ], |
| 169 | header_libs: [ |
| 170 | "header_lib_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 171 | "header_lib_2" |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 172 | ], |
| 173 | |
| 174 | // TODO: Also support export_header_lib_headers |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 175 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 176 | expectedBazelTargets: []string{`cc_library_static( |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 177 | name = "foo_static", |
| 178 | copts = [ |
| 179 | "-Dflag1", |
| 180 | "-Dflag2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 181 | "-Iinclude_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 182 | "-I$(BINDIR)/include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 183 | "-Iinclude_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 184 | "-I$(BINDIR)/include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 185 | "-Ilocal_include_dir_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 186 | "-I$(BINDIR)/local_include_dir_1", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 187 | "-Ilocal_include_dir_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 188 | "-I$(BINDIR)/local_include_dir_2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 189 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 190 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 191 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 192 | implementation_deps = [ |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 193 | ":header_lib_1", |
| 194 | ":header_lib_2", |
| 195 | ":static_lib_1", |
| 196 | ":static_lib_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 197 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 198 | includes = [ |
| 199 | "export_include_dir_1", |
| 200 | "export_include_dir_2", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 201 | ], |
| 202 | linkstatic = True, |
| 203 | srcs = [ |
| 204 | "foo_static1.cc", |
| 205 | "foo_static2.cc", |
| 206 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 207 | whole_archive_deps = [ |
| 208 | ":whole_static_lib_1", |
| 209 | ":whole_static_lib_2", |
| 210 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 211 | )`, `cc_library_static( |
| 212 | name = "static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 213 | copts = [ |
| 214 | "-I.", |
| 215 | "-I$(BINDIR)/.", |
| 216 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 217 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 218 | srcs = ["static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 219 | )`, `cc_library_static( |
| 220 | name = "static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 221 | copts = [ |
| 222 | "-I.", |
| 223 | "-I$(BINDIR)/.", |
| 224 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 225 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 226 | srcs = ["static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 227 | )`, `cc_library_static( |
| 228 | name = "whole_static_lib_1", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 229 | copts = [ |
| 230 | "-I.", |
| 231 | "-I$(BINDIR)/.", |
| 232 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 233 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 234 | srcs = ["whole_static_lib_1.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 235 | )`, `cc_library_static( |
| 236 | name = "whole_static_lib_2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 237 | copts = [ |
| 238 | "-I.", |
| 239 | "-I$(BINDIR)/.", |
| 240 | ], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 241 | linkstatic = True, |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 242 | srcs = ["whole_static_lib_2.cc"], |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 243 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 244 | }) |
| 245 | } |
| 246 | |
| 247 | func TestCcLibraryStaticSubpackage(t *testing.T) { |
| 248 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 249 | description: "cc_library_static subpackage test", |
| 250 | moduleTypeUnderTest: "cc_library_static", |
| 251 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 252 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 253 | filesystem: map[string]string{ |
| 254 | // subpackage with subdirectory |
| 255 | "subpackage/Android.bp": "", |
| 256 | "subpackage/subpackage_header.h": "", |
| 257 | "subpackage/subdirectory/subdirectory_header.h": "", |
| 258 | // subsubpackage with subdirectory |
| 259 | "subpackage/subsubpackage/Android.bp": "", |
| 260 | "subpackage/subsubpackage/subsubpackage_header.h": "", |
| 261 | "subpackage/subsubpackage/subdirectory/subdirectory_header.h": "", |
| 262 | // subsubsubpackage with subdirectory |
| 263 | "subpackage/subsubpackage/subsubsubpackage/Android.bp": "", |
| 264 | "subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "", |
| 265 | "subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "", |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 266 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 267 | blueprint: soongCcLibraryStaticPreamble + ` |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 268 | cc_library_static { |
| 269 | name: "foo_static", |
| 270 | srcs: [ |
| 271 | ], |
| 272 | include_dirs: [ |
| 273 | "subpackage", |
| 274 | ], |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 275 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 276 | expectedBazelTargets: []string{`cc_library_static( |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 277 | name = "foo_static", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 278 | copts = [ |
| 279 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 280 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 281 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 282 | "-I$(BINDIR)/.", |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 283 | ], |
| 284 | linkstatic = True, |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 285 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 286 | }) |
| 287 | } |
| 288 | |
| 289 | func TestCcLibraryStaticExportIncludeDir(t *testing.T) { |
| 290 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 291 | description: "cc_library_static export include dir", |
| 292 | moduleTypeUnderTest: "cc_library_static", |
| 293 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 294 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 295 | filesystem: map[string]string{ |
| 296 | // subpackage with subdirectory |
| 297 | "subpackage/Android.bp": "", |
| 298 | "subpackage/subpackage_header.h": "", |
| 299 | "subpackage/subdirectory/subdirectory_header.h": "", |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 300 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 301 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 302 | cc_library_static { |
| 303 | name: "foo_static", |
| 304 | export_include_dirs: ["subpackage"], |
| 305 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 306 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 307 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 308 | copts = [ |
| 309 | "-I.", |
| 310 | "-I$(BINDIR)/.", |
| 311 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 312 | includes = ["subpackage"], |
| 313 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 314 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 315 | }) |
| 316 | } |
| 317 | |
| 318 | func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) { |
| 319 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 320 | description: "cc_library_static export system include dir", |
| 321 | moduleTypeUnderTest: "cc_library_static", |
| 322 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 323 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 324 | filesystem: map[string]string{ |
| 325 | // subpackage with subdirectory |
| 326 | "subpackage/Android.bp": "", |
| 327 | "subpackage/subpackage_header.h": "", |
| 328 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 329 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 330 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 331 | cc_library_static { |
| 332 | name: "foo_static", |
| 333 | export_system_include_dirs: ["subpackage"], |
| 334 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 335 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 336 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 337 | copts = [ |
| 338 | "-I.", |
| 339 | "-I$(BINDIR)/.", |
| 340 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 341 | includes = ["subpackage"], |
| 342 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 343 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 344 | }) |
| 345 | } |
| 346 | |
| 347 | func TestCcLibraryStaticManyIncludeDirs(t *testing.T) { |
| 348 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 349 | description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)", |
| 350 | moduleTypeUnderTest: "cc_library_static", |
| 351 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 352 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 353 | dir: "subpackage", |
| 354 | filesystem: map[string]string{ |
| 355 | // subpackage with subdirectory |
| 356 | "subpackage/Android.bp": ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 357 | cc_library_static { |
| 358 | name: "foo_static", |
| 359 | // include_dirs are workspace/root relative |
| 360 | include_dirs: [ |
| 361 | "subpackage/subsubpackage", |
| 362 | "subpackage2", |
| 363 | "subpackage3/subsubpackage" |
| 364 | ], |
| 365 | local_include_dirs: ["subsubpackage2"], // module dir relative |
| 366 | export_include_dirs: ["./exported_subsubpackage"], // module dir relative |
| 367 | include_build_directory: true, |
| 368 | bazel_module: { bp2build_available: true }, |
| 369 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 370 | "subpackage/subsubpackage/header.h": "", |
| 371 | "subpackage/subsubpackage2/header.h": "", |
| 372 | "subpackage/exported_subsubpackage/header.h": "", |
| 373 | "subpackage2/header.h": "", |
| 374 | "subpackage3/subsubpackage/header.h": "", |
| 375 | }, |
| 376 | blueprint: soongCcLibraryStaticPreamble, |
| 377 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 378 | name = "foo_static", |
| 379 | copts = [ |
| 380 | "-Isubpackage/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 381 | "-I$(BINDIR)/subpackage/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 382 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 383 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 384 | "-Isubpackage3/subsubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 385 | "-I$(BINDIR)/subpackage3/subsubpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 386 | "-Isubpackage/subsubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 387 | "-I$(BINDIR)/subpackage/subsubpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 388 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 389 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 390 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 391 | includes = ["./exported_subsubpackage"], |
| 392 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 393 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 394 | }) |
| 395 | } |
| 396 | |
| 397 | func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) { |
| 398 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 399 | description: "cc_library_static include_build_directory disabled", |
| 400 | moduleTypeUnderTest: "cc_library_static", |
| 401 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 402 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 403 | filesystem: map[string]string{ |
| 404 | // subpackage with subdirectory |
| 405 | "subpackage/Android.bp": "", |
| 406 | "subpackage/subpackage_header.h": "", |
| 407 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 408 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 409 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 410 | cc_library_static { |
| 411 | name: "foo_static", |
| 412 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 413 | local_include_dirs: ["subpackage2"], |
| 414 | include_build_directory: false, |
| 415 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 416 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 417 | name = "foo_static", |
| 418 | copts = [ |
| 419 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 420 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 421 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 422 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 423 | ], |
| 424 | linkstatic = True, |
| 425 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 426 | }) |
| 427 | } |
| 428 | |
| 429 | func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) { |
| 430 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 431 | description: "cc_library_static include_build_directory enabled", |
| 432 | moduleTypeUnderTest: "cc_library_static", |
| 433 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 434 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 435 | filesystem: map[string]string{ |
| 436 | // subpackage with subdirectory |
| 437 | "subpackage/Android.bp": "", |
| 438 | "subpackage/subpackage_header.h": "", |
| 439 | "subpackage2/Android.bp": "", |
| 440 | "subpackage2/subpackage2_header.h": "", |
| 441 | "subpackage/subdirectory/subdirectory_header.h": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 442 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 443 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 444 | cc_library_static { |
| 445 | name: "foo_static", |
| 446 | include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended |
| 447 | local_include_dirs: ["subpackage2"], |
| 448 | include_build_directory: true, |
| 449 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 450 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 451 | name = "foo_static", |
| 452 | copts = [ |
| 453 | "-Isubpackage", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 454 | "-I$(BINDIR)/subpackage", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 455 | "-Isubpackage2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 456 | "-I$(BINDIR)/subpackage2", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 457 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 458 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 459 | ], |
| 460 | linkstatic = True, |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 461 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 462 | }) |
| 463 | } |
| 464 | |
| 465 | func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) { |
| 466 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 467 | description: "cc_library_static arch-specific static_libs", |
| 468 | moduleTypeUnderTest: "cc_library_static", |
| 469 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 470 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 471 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 472 | filesystem: map[string]string{}, |
| 473 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 474 | cc_library_static { name: "static_dep" } |
| 475 | cc_library_static { name: "static_dep2" } |
| 476 | cc_library_static { |
| 477 | name: "foo_static", |
| 478 | arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 479 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 480 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 481 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 482 | copts = [ |
| 483 | "-I.", |
| 484 | "-I$(BINDIR)/.", |
| 485 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 486 | implementation_deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 487 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 488 | "//conditions:default": [], |
| 489 | }), |
| 490 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 491 | whole_archive_deps = select({ |
| 492 | "//build/bazel/platforms/arch:arm64": [":static_dep2"], |
| 493 | "//conditions:default": [], |
| 494 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 495 | )`, `cc_library_static( |
| 496 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 497 | copts = [ |
| 498 | "-I.", |
| 499 | "-I$(BINDIR)/.", |
| 500 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 501 | linkstatic = True, |
| 502 | )`, `cc_library_static( |
| 503 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 504 | copts = [ |
| 505 | "-I.", |
| 506 | "-I$(BINDIR)/.", |
| 507 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 508 | linkstatic = True, |
| 509 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 510 | }) |
| 511 | } |
| 512 | |
| 513 | func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) { |
| 514 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 515 | description: "cc_library_static os-specific static_libs", |
| 516 | moduleTypeUnderTest: "cc_library_static", |
| 517 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 518 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 519 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 520 | filesystem: map[string]string{}, |
| 521 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 522 | cc_library_static { name: "static_dep" } |
| 523 | cc_library_static { name: "static_dep2" } |
| 524 | cc_library_static { |
| 525 | name: "foo_static", |
| 526 | target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } }, |
| 527 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 528 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 529 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 530 | copts = [ |
| 531 | "-I.", |
| 532 | "-I$(BINDIR)/.", |
| 533 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 534 | implementation_deps = select({ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 535 | "//build/bazel/platforms/os:android": [":static_dep"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 536 | "//conditions:default": [], |
| 537 | }), |
| 538 | linkstatic = True, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 539 | whole_archive_deps = select({ |
| 540 | "//build/bazel/platforms/os:android": [":static_dep2"], |
| 541 | "//conditions:default": [], |
| 542 | }), |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 543 | )`, `cc_library_static( |
| 544 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 545 | copts = [ |
| 546 | "-I.", |
| 547 | "-I$(BINDIR)/.", |
| 548 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 549 | linkstatic = True, |
| 550 | )`, `cc_library_static( |
| 551 | name = "static_dep2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 552 | copts = [ |
| 553 | "-I.", |
| 554 | "-I$(BINDIR)/.", |
| 555 | ], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 556 | linkstatic = True, |
| 557 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 558 | }) |
| 559 | } |
| 560 | |
| 561 | func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) { |
| 562 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 563 | description: "cc_library_static base, arch and os-specific static_libs", |
| 564 | moduleTypeUnderTest: "cc_library_static", |
| 565 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 566 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 567 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 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, |
| 634 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 635 | filesystem: map[string]string{ |
| 636 | "common.c": "", |
| 637 | "foo-a.c": "", |
| 638 | "foo-excluded.c": "", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 639 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 640 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 641 | cc_library_static { |
| 642 | name: "foo_static", |
| 643 | srcs: ["common.c", "foo-*.c"], |
| 644 | exclude_srcs: ["foo-excluded.c"], |
| 645 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 646 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 647 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 648 | copts = [ |
| 649 | "-I.", |
| 650 | "-I$(BINDIR)/.", |
| 651 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 652 | linkstatic = True, |
| 653 | srcs = [ |
| 654 | "common.c", |
| 655 | "foo-a.c", |
| 656 | ], |
| 657 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 658 | }) |
| 659 | } |
| 660 | |
| 661 | func TestCcLibraryStaticOneArchSrcs(t *testing.T) { |
| 662 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 663 | description: "cc_library_static one arch specific srcs", |
| 664 | moduleTypeUnderTest: "cc_library_static", |
| 665 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 666 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 667 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 668 | filesystem: map[string]string{ |
| 669 | "common.c": "", |
| 670 | "foo-arm.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 671 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 672 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 673 | cc_library_static { |
| 674 | name: "foo_static", |
| 675 | srcs: ["common.c"], |
| 676 | arch: { arm: { srcs: ["foo-arm.c"] } } |
| 677 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 678 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 679 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 680 | copts = [ |
| 681 | "-I.", |
| 682 | "-I$(BINDIR)/.", |
| 683 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 684 | linkstatic = True, |
| 685 | srcs = ["common.c"] + select({ |
| 686 | "//build/bazel/platforms/arch:arm": ["foo-arm.c"], |
| 687 | "//conditions:default": [], |
| 688 | }), |
| 689 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 690 | }) |
| 691 | } |
| 692 | |
| 693 | func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) { |
| 694 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 695 | description: "cc_library_static one arch specific srcs and exclude_srcs", |
| 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 | "not-for-arm.c": "", |
| 704 | "not-for-anything.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 705 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 706 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 707 | cc_library_static { |
| 708 | name: "foo_static", |
| 709 | srcs: ["common.c", "not-for-*.c"], |
| 710 | exclude_srcs: ["not-for-anything.c"], |
| 711 | arch: { |
| 712 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 713 | }, |
| 714 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 715 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 716 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 717 | copts = [ |
| 718 | "-I.", |
| 719 | "-I$(BINDIR)/.", |
| 720 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 721 | linkstatic = True, |
| 722 | srcs = ["common.c"] + select({ |
| 723 | "//build/bazel/platforms/arch:arm": ["for-arm.c"], |
| 724 | "//conditions:default": ["not-for-arm.c"], |
| 725 | }), |
| 726 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 727 | }) |
| 728 | } |
| 729 | |
| 730 | func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) { |
| 731 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 732 | description: "cc_library_static arch specific exclude_srcs for 2 architectures", |
| 733 | moduleTypeUnderTest: "cc_library_static", |
| 734 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 735 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 736 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 737 | filesystem: map[string]string{ |
| 738 | "common.c": "", |
| 739 | "for-arm.c": "", |
| 740 | "for-x86.c": "", |
| 741 | "not-for-arm.c": "", |
| 742 | "not-for-x86.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 743 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 744 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 745 | cc_library_static { |
| 746 | name: "foo_static", |
| 747 | srcs: ["common.c", "not-for-*.c"], |
| 748 | exclude_srcs: ["not-for-everything.c"], |
| 749 | arch: { |
| 750 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 751 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 752 | }, |
| 753 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 754 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 755 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 756 | copts = [ |
| 757 | "-I.", |
| 758 | "-I$(BINDIR)/.", |
| 759 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 760 | linkstatic = True, |
| 761 | srcs = ["common.c"] + select({ |
| 762 | "//build/bazel/platforms/arch:arm": [ |
| 763 | "for-arm.c", |
| 764 | "not-for-x86.c", |
| 765 | ], |
| 766 | "//build/bazel/platforms/arch:x86": [ |
| 767 | "for-x86.c", |
| 768 | "not-for-arm.c", |
| 769 | ], |
| 770 | "//conditions:default": [ |
| 771 | "not-for-arm.c", |
| 772 | "not-for-x86.c", |
| 773 | ], |
| 774 | }), |
| 775 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 776 | }) |
| 777 | } |
| 778 | func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) { |
| 779 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 780 | description: "cc_library_static arch specific exclude_srcs for 4 architectures", |
| 781 | moduleTypeUnderTest: "cc_library_static", |
| 782 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 783 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 784 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 785 | filesystem: map[string]string{ |
| 786 | "common.c": "", |
| 787 | "for-arm.c": "", |
| 788 | "for-arm64.c": "", |
| 789 | "for-x86.c": "", |
| 790 | "for-x86_64.c": "", |
| 791 | "not-for-arm.c": "", |
| 792 | "not-for-arm64.c": "", |
| 793 | "not-for-x86.c": "", |
| 794 | "not-for-x86_64.c": "", |
| 795 | "not-for-everything.c": "", |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 796 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 797 | blueprint: soongCcLibraryStaticPreamble + ` |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 798 | cc_library_static { |
| 799 | name: "foo_static", |
| 800 | srcs: ["common.c", "not-for-*.c"], |
| 801 | exclude_srcs: ["not-for-everything.c"], |
| 802 | arch: { |
| 803 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 804 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 805 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 806 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 807 | }, |
| 808 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 809 | expectedBazelTargets: []string{`cc_library_static( |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 810 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 811 | copts = [ |
| 812 | "-I.", |
| 813 | "-I$(BINDIR)/.", |
| 814 | ], |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 815 | linkstatic = True, |
| 816 | srcs = ["common.c"] + select({ |
| 817 | "//build/bazel/platforms/arch:arm": [ |
| 818 | "for-arm.c", |
| 819 | "not-for-arm64.c", |
| 820 | "not-for-x86.c", |
| 821 | "not-for-x86_64.c", |
| 822 | ], |
| 823 | "//build/bazel/platforms/arch:arm64": [ |
| 824 | "for-arm64.c", |
| 825 | "not-for-arm.c", |
| 826 | "not-for-x86.c", |
| 827 | "not-for-x86_64.c", |
| 828 | ], |
| 829 | "//build/bazel/platforms/arch:x86": [ |
| 830 | "for-x86.c", |
| 831 | "not-for-arm.c", |
| 832 | "not-for-arm64.c", |
| 833 | "not-for-x86_64.c", |
| 834 | ], |
| 835 | "//build/bazel/platforms/arch:x86_64": [ |
| 836 | "for-x86_64.c", |
| 837 | "not-for-arm.c", |
| 838 | "not-for-arm64.c", |
| 839 | "not-for-x86.c", |
| 840 | ], |
| 841 | "//conditions:default": [ |
| 842 | "not-for-arm.c", |
| 843 | "not-for-arm64.c", |
| 844 | "not-for-x86.c", |
| 845 | "not-for-x86_64.c", |
| 846 | ], |
| 847 | }), |
| 848 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 849 | }) |
| 850 | } |
| 851 | |
| 852 | func TestCcLibraryStaticMultipleDepSameName(t *testing.T) { |
| 853 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 854 | description: "cc_library_static multiple dep same name panic", |
| 855 | moduleTypeUnderTest: "cc_library_static", |
| 856 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 857 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 858 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 859 | filesystem: map[string]string{}, |
| 860 | blueprint: soongCcLibraryStaticPreamble + ` |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 861 | cc_library_static { name: "static_dep" } |
| 862 | cc_library_static { |
| 863 | name: "foo_static", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 864 | static_libs: ["static_dep", "static_dep"], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 865 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 866 | expectedBazelTargets: []string{`cc_library_static( |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 867 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 868 | copts = [ |
| 869 | "-I.", |
| 870 | "-I$(BINDIR)/.", |
| 871 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 872 | implementation_deps = [":static_dep"], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 873 | linkstatic = True, |
| 874 | )`, `cc_library_static( |
| 875 | name = "static_dep", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 876 | copts = [ |
| 877 | "-I.", |
| 878 | "-I$(BINDIR)/.", |
| 879 | ], |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 880 | linkstatic = True, |
| 881 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 882 | }) |
| 883 | } |
| 884 | |
| 885 | func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) { |
| 886 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 887 | description: "cc_library_static 1 multilib srcs and exclude_srcs", |
| 888 | moduleTypeUnderTest: "cc_library_static", |
| 889 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 890 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 891 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 892 | filesystem: map[string]string{ |
| 893 | "common.c": "", |
| 894 | "for-lib32.c": "", |
| 895 | "not-for-lib32.c": "", |
Liz Kammer | 2b50ce6 | 2021-04-26 15:47:28 -0400 | [diff] [blame] | 896 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 897 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 898 | cc_library_static { |
| 899 | name: "foo_static", |
| 900 | srcs: ["common.c", "not-for-*.c"], |
| 901 | multilib: { |
| 902 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 903 | }, |
| 904 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 905 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 906 | name = "foo_static", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 907 | copts = [ |
| 908 | "-I.", |
| 909 | "-I$(BINDIR)/.", |
| 910 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 911 | linkstatic = True, |
| 912 | srcs = ["common.c"] + select({ |
| 913 | "//build/bazel/platforms/arch:arm": ["for-lib32.c"], |
| 914 | "//build/bazel/platforms/arch:x86": ["for-lib32.c"], |
| 915 | "//conditions:default": ["not-for-lib32.c"], |
| 916 | }), |
| 917 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 918 | }) |
| 919 | } |
| 920 | |
| 921 | func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) { |
| 922 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 923 | description: "cc_library_static 2 multilib srcs and exclude_srcs", |
| 924 | moduleTypeUnderTest: "cc_library_static", |
| 925 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 926 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 927 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 928 | filesystem: map[string]string{ |
| 929 | "common.c": "", |
| 930 | "for-lib32.c": "", |
| 931 | "for-lib64.c": "", |
| 932 | "not-for-lib32.c": "", |
| 933 | "not-for-lib64.c": "", |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 934 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 935 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 936 | cc_library_static { |
| 937 | name: "foo_static2", |
| 938 | srcs: ["common.c", "not-for-*.c"], |
| 939 | multilib: { |
| 940 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 941 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 942 | }, |
| 943 | } `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 944 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 945 | name = "foo_static2", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 946 | copts = [ |
| 947 | "-I.", |
| 948 | "-I$(BINDIR)/.", |
| 949 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 950 | linkstatic = True, |
| 951 | srcs = ["common.c"] + select({ |
| 952 | "//build/bazel/platforms/arch:arm": [ |
| 953 | "for-lib32.c", |
| 954 | "not-for-lib64.c", |
| 955 | ], |
| 956 | "//build/bazel/platforms/arch:arm64": [ |
| 957 | "for-lib64.c", |
| 958 | "not-for-lib32.c", |
| 959 | ], |
| 960 | "//build/bazel/platforms/arch:x86": [ |
| 961 | "for-lib32.c", |
| 962 | "not-for-lib64.c", |
| 963 | ], |
| 964 | "//build/bazel/platforms/arch:x86_64": [ |
| 965 | "for-lib64.c", |
| 966 | "not-for-lib32.c", |
| 967 | ], |
| 968 | "//conditions:default": [ |
| 969 | "not-for-lib32.c", |
| 970 | "not-for-lib64.c", |
| 971 | ], |
| 972 | }), |
| 973 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 974 | }) |
| 975 | } |
| 976 | |
| 977 | func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) { |
| 978 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 979 | description: "cc_library_static arch and multilib srcs and exclude_srcs", |
| 980 | moduleTypeUnderTest: "cc_library_static", |
| 981 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 982 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 983 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 984 | filesystem: map[string]string{ |
| 985 | "common.c": "", |
| 986 | "for-arm.c": "", |
| 987 | "for-arm64.c": "", |
| 988 | "for-x86.c": "", |
| 989 | "for-x86_64.c": "", |
| 990 | "for-lib32.c": "", |
| 991 | "for-lib64.c": "", |
| 992 | "not-for-arm.c": "", |
| 993 | "not-for-arm64.c": "", |
| 994 | "not-for-x86.c": "", |
| 995 | "not-for-x86_64.c": "", |
| 996 | "not-for-lib32.c": "", |
| 997 | "not-for-lib64.c": "", |
| 998 | "not-for-everything.c": "", |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 999 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1000 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1001 | cc_library_static { |
| 1002 | name: "foo_static3", |
| 1003 | srcs: ["common.c", "not-for-*.c"], |
| 1004 | exclude_srcs: ["not-for-everything.c"], |
| 1005 | arch: { |
| 1006 | arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] }, |
| 1007 | arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] }, |
| 1008 | x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] }, |
| 1009 | x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] }, |
| 1010 | }, |
| 1011 | multilib: { |
| 1012 | lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] }, |
| 1013 | lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] }, |
| 1014 | }, |
| 1015 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1016 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1017 | name = "foo_static3", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1018 | copts = [ |
| 1019 | "-I.", |
| 1020 | "-I$(BINDIR)/.", |
| 1021 | ], |
Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1022 | linkstatic = True, |
| 1023 | srcs = ["common.c"] + select({ |
| 1024 | "//build/bazel/platforms/arch:arm": [ |
| 1025 | "for-arm.c", |
| 1026 | "for-lib32.c", |
| 1027 | "not-for-arm64.c", |
| 1028 | "not-for-lib64.c", |
| 1029 | "not-for-x86.c", |
| 1030 | "not-for-x86_64.c", |
| 1031 | ], |
| 1032 | "//build/bazel/platforms/arch:arm64": [ |
| 1033 | "for-arm64.c", |
| 1034 | "for-lib64.c", |
| 1035 | "not-for-arm.c", |
| 1036 | "not-for-lib32.c", |
| 1037 | "not-for-x86.c", |
| 1038 | "not-for-x86_64.c", |
| 1039 | ], |
| 1040 | "//build/bazel/platforms/arch:x86": [ |
| 1041 | "for-lib32.c", |
| 1042 | "for-x86.c", |
| 1043 | "not-for-arm.c", |
| 1044 | "not-for-arm64.c", |
| 1045 | "not-for-lib64.c", |
| 1046 | "not-for-x86_64.c", |
| 1047 | ], |
| 1048 | "//build/bazel/platforms/arch:x86_64": [ |
| 1049 | "for-lib64.c", |
| 1050 | "for-x86_64.c", |
| 1051 | "not-for-arm.c", |
| 1052 | "not-for-arm64.c", |
| 1053 | "not-for-lib32.c", |
| 1054 | "not-for-x86.c", |
| 1055 | ], |
| 1056 | "//conditions:default": [ |
| 1057 | "not-for-arm.c", |
| 1058 | "not-for-arm64.c", |
| 1059 | "not-for-lib32.c", |
| 1060 | "not-for-lib64.c", |
| 1061 | "not-for-x86.c", |
| 1062 | "not-for-x86_64.c", |
| 1063 | ], |
| 1064 | }), |
| 1065 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1066 | }) |
| 1067 | } |
| 1068 | |
| 1069 | func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { |
| 1070 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1071 | description: "cc_library_static arch srcs/exclude_srcs with generated files", |
| 1072 | moduleTypeUnderTest: "cc_library_static", |
| 1073 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1074 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1075 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1076 | filesystem: map[string]string{ |
| 1077 | "common.c": "", |
| 1078 | "for-x86.c": "", |
| 1079 | "not-for-x86.c": "", |
| 1080 | "not-for-everything.c": "", |
| 1081 | "dep/Android.bp": ` |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1082 | genrule { |
| 1083 | name: "generated_src_other_pkg", |
| 1084 | out: ["generated_src_other_pkg.cpp"], |
| 1085 | cmd: "nothing to see here", |
| 1086 | } |
| 1087 | |
| 1088 | genrule { |
| 1089 | name: "generated_hdr_other_pkg", |
| 1090 | out: ["generated_hdr_other_pkg.cpp"], |
| 1091 | cmd: "nothing to see here", |
| 1092 | } |
| 1093 | |
| 1094 | genrule { |
| 1095 | name: "generated_hdr_other_pkg_x86", |
| 1096 | out: ["generated_hdr_other_pkg_x86.cpp"], |
| 1097 | cmd: "nothing to see here", |
| 1098 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1099 | }, |
| 1100 | blueprint: soongCcLibraryStaticPreamble + ` |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1101 | genrule { |
| 1102 | name: "generated_src", |
| 1103 | out: ["generated_src.cpp"], |
| 1104 | cmd: "nothing to see here", |
| 1105 | } |
| 1106 | |
| 1107 | genrule { |
| 1108 | name: "generated_src_x86", |
| 1109 | out: ["generated_src_x86.cpp"], |
| 1110 | cmd: "nothing to see here", |
| 1111 | } |
| 1112 | |
| 1113 | genrule { |
| 1114 | name: "generated_hdr", |
| 1115 | out: ["generated_hdr.h"], |
| 1116 | cmd: "nothing to see here", |
| 1117 | } |
| 1118 | |
| 1119 | cc_library_static { |
| 1120 | name: "foo_static3", |
| 1121 | srcs: ["common.c", "not-for-*.c"], |
| 1122 | exclude_srcs: ["not-for-everything.c"], |
| 1123 | generated_sources: ["generated_src", "generated_src_other_pkg"], |
| 1124 | generated_headers: ["generated_hdr", "generated_hdr_other_pkg"], |
| 1125 | arch: { |
| 1126 | x86: { |
| 1127 | srcs: ["for-x86.c"], |
| 1128 | exclude_srcs: ["not-for-x86.c"], |
| 1129 | generated_sources: ["generated_src_x86"], |
| 1130 | generated_headers: ["generated_hdr_other_pkg_x86"], |
| 1131 | }, |
| 1132 | }, |
| 1133 | } |
| 1134 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1135 | expectedBazelTargets: []string{`cc_library_static( |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 1136 | name = "foo_static3", |
| 1137 | copts = [ |
| 1138 | "-I.", |
| 1139 | "-I$(BINDIR)/.", |
| 1140 | ], |
| 1141 | linkstatic = True, |
| 1142 | srcs = [ |
| 1143 | "//dep:generated_hdr_other_pkg", |
| 1144 | "//dep:generated_src_other_pkg", |
| 1145 | ":generated_hdr", |
| 1146 | ":generated_src", |
| 1147 | "common.c", |
| 1148 | ] + select({ |
| 1149 | "//build/bazel/platforms/arch:x86": [ |
| 1150 | "//dep:generated_hdr_other_pkg_x86", |
| 1151 | ":generated_src_x86", |
| 1152 | "for-x86.c", |
| 1153 | ], |
| 1154 | "//conditions:default": ["not-for-x86.c"], |
| 1155 | }), |
| 1156 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1157 | }) |
Rupert Shuttleworth | 095081c | 2021-03-25 09:06:03 +0000 | [diff] [blame] | 1158 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1159 | |
| 1160 | func TestCcLibraryStaticProductVariableSelects(t *testing.T) { |
| 1161 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1162 | description: "cc_library_static product variable selects", |
| 1163 | moduleTypeUnderTest: "cc_library_static", |
| 1164 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1165 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1166 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1167 | filesystem: map[string]string{}, |
| 1168 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1169 | cc_library_static { |
| 1170 | name: "foo_static", |
| 1171 | srcs: ["common.c"], |
| 1172 | product_variables: { |
| 1173 | malloc_not_svelte: { |
| 1174 | cflags: ["-Wmalloc_not_svelte"], |
| 1175 | }, |
| 1176 | malloc_zero_contents: { |
| 1177 | cflags: ["-Wmalloc_zero_contents"], |
| 1178 | }, |
| 1179 | binder32bit: { |
| 1180 | cflags: ["-Wbinder32bit"], |
| 1181 | }, |
| 1182 | }, |
| 1183 | } `, |
| 1184 | expectedBazelTargets: []string{`cc_library_static( |
| 1185 | name = "foo_static", |
| 1186 | copts = [ |
| 1187 | "-I.", |
| 1188 | "-I$(BINDIR)/.", |
| 1189 | ] + select({ |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame^] | 1190 | "//build/bazel/product_variables:binder32bit": ["-Wbinder32bit"], |
| 1191 | "//conditions:default": [], |
| 1192 | }) + select({ |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1193 | "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"], |
| 1194 | "//conditions:default": [], |
| 1195 | }) + select({ |
| 1196 | "//build/bazel/product_variables:malloc_zero_contents": ["-Wmalloc_zero_contents"], |
| 1197 | "//conditions:default": [], |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame^] | 1198 | }), |
| 1199 | linkstatic = True, |
| 1200 | srcs = ["common.c"], |
| 1201 | )`}, |
| 1202 | }) |
| 1203 | } |
| 1204 | |
| 1205 | func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) { |
| 1206 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1207 | description: "cc_library_static arch-specific product variable selects", |
| 1208 | moduleTypeUnderTest: "cc_library_static", |
| 1209 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 1210 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, |
| 1211 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1212 | filesystem: map[string]string{}, |
| 1213 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1214 | cc_library_static { |
| 1215 | name: "foo_static", |
| 1216 | srcs: ["common.c"], |
| 1217 | product_variables: { |
| 1218 | malloc_not_svelte: { |
| 1219 | cflags: ["-Wmalloc_not_svelte"], |
| 1220 | }, |
| 1221 | }, |
| 1222 | arch: { |
| 1223 | arm64: { |
| 1224 | product_variables: { |
| 1225 | malloc_not_svelte: { |
| 1226 | cflags: ["-Warm64_malloc_not_svelte"], |
| 1227 | }, |
| 1228 | }, |
| 1229 | }, |
| 1230 | }, |
| 1231 | multilib: { |
| 1232 | lib32: { |
| 1233 | product_variables: { |
| 1234 | malloc_not_svelte: { |
| 1235 | cflags: ["-Wlib32_malloc_not_svelte"], |
| 1236 | }, |
| 1237 | }, |
| 1238 | }, |
| 1239 | }, |
| 1240 | target: { |
| 1241 | android: { |
| 1242 | product_variables: { |
| 1243 | malloc_not_svelte: { |
| 1244 | cflags: ["-Wandroid_malloc_not_svelte"], |
| 1245 | }, |
| 1246 | }, |
| 1247 | } |
| 1248 | }, |
| 1249 | } `, |
| 1250 | expectedBazelTargets: []string{`cc_library_static( |
| 1251 | name = "foo_static", |
| 1252 | copts = [ |
| 1253 | "-I.", |
| 1254 | "-I$(BINDIR)/.", |
| 1255 | ] + select({ |
| 1256 | "//build/bazel/product_variables:malloc_not_svelte": ["-Wmalloc_not_svelte"], |
| 1257 | "//conditions:default": [], |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1258 | }) + select({ |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame^] | 1259 | "//build/bazel/product_variables:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"], |
| 1260 | "//conditions:default": [], |
| 1261 | }) + select({ |
| 1262 | "//build/bazel/product_variables:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"], |
| 1263 | "//conditions:default": [], |
| 1264 | }) + select({ |
| 1265 | "//build/bazel/product_variables:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"], |
| 1266 | "//conditions:default": [], |
| 1267 | }) + select({ |
| 1268 | "//build/bazel/product_variables:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"], |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 1269 | "//conditions:default": [], |
| 1270 | }), |
| 1271 | linkstatic = True, |
| 1272 | srcs = ["common.c"], |
| 1273 | )`}, |
| 1274 | }) |
| 1275 | } |