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