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