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