Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [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 ( |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 18 | "testing" |
| 19 | |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 22 | ) |
| 23 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 24 | func registerCcObjectModuleTypes(ctx android.RegistrationContext) { |
| 25 | // Always register cc_defaults module factory |
| 26 | ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() }) |
| 27 | } |
| 28 | |
| 29 | func runCcObjectTestCase(t *testing.T, tc bp2buildTestCase) { |
| 30 | runBp2BuildTestCase(t, registerCcObjectModuleTypes, tc) |
| 31 | } |
| 32 | |
| 33 | func TestCcObjectSimple(t *testing.T) { |
| 34 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 35 | description: "simple cc_object generates cc_object with include header dep", |
| 36 | moduleTypeUnderTest: "cc_object", |
| 37 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 38 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 39 | filesystem: map[string]string{ |
| 40 | "a/b/foo.h": "", |
| 41 | "a/b/bar.h": "", |
| 42 | "a/b/exclude.c": "", |
| 43 | "a/b/c.c": "", |
| 44 | }, |
| 45 | blueprint: `cc_object { |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 46 | name: "foo", |
| 47 | local_include_dirs: ["include"], |
| 48 | cflags: [ |
| 49 | "-Wno-gcc-compat", |
| 50 | "-Wall", |
| 51 | "-Werror", |
| 52 | ], |
| 53 | srcs: [ |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 54 | "a/b/*.c" |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 55 | ], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 56 | exclude_srcs: ["a/b/exclude.c"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 57 | } |
| 58 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 59 | expectedBazelTargets: []string{`cc_object( |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 60 | name = "foo", |
| 61 | copts = [ |
| 62 | "-fno-addrsig", |
| 63 | "-Wno-gcc-compat", |
| 64 | "-Wall", |
| 65 | "-Werror", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 66 | "-Iinclude", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 67 | "-I$(BINDIR)/include", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 68 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 69 | "-I$(BINDIR)/.", |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 70 | ], |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 71 | srcs = ["a/b/c.c"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 72 | )`, |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 73 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 74 | }) |
| 75 | } |
| 76 | |
| 77 | func TestCcObjectDefaults(t *testing.T) { |
| 78 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 79 | description: "simple cc_object with defaults", |
| 80 | moduleTypeUnderTest: "cc_object", |
| 81 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 82 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 83 | blueprint: `cc_object { |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 84 | name: "foo", |
| 85 | local_include_dirs: ["include"], |
| 86 | srcs: [ |
| 87 | "a/b/*.h", |
| 88 | "a/b/c.c" |
| 89 | ], |
| 90 | |
| 91 | defaults: ["foo_defaults"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | cc_defaults { |
| 95 | name: "foo_defaults", |
| 96 | defaults: ["foo_bar_defaults"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | cc_defaults { |
| 100 | name: "foo_bar_defaults", |
| 101 | cflags: [ |
| 102 | "-Wno-gcc-compat", |
| 103 | "-Wall", |
| 104 | "-Werror", |
| 105 | ], |
| 106 | } |
| 107 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 108 | expectedBazelTargets: []string{`cc_object( |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 109 | name = "foo", |
| 110 | copts = [ |
| 111 | "-Wno-gcc-compat", |
| 112 | "-Wall", |
| 113 | "-Werror", |
| 114 | "-fno-addrsig", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 115 | "-Iinclude", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 116 | "-I$(BINDIR)/include", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 117 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 118 | "-I$(BINDIR)/.", |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 119 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 120 | srcs = ["a/b/c.c"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 121 | )`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 122 | }}) |
| 123 | } |
| 124 | |
| 125 | func TestCcObjectCcObjetDepsInObjs(t *testing.T) { |
| 126 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 127 | description: "cc_object with cc_object deps in objs props", |
| 128 | moduleTypeUnderTest: "cc_object", |
| 129 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 130 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 131 | filesystem: map[string]string{ |
| 132 | "a/b/c.c": "", |
| 133 | "x/y/z.c": "", |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 134 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 135 | blueprint: `cc_object { |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 136 | name: "foo", |
| 137 | srcs: ["a/b/c.c"], |
| 138 | objs: ["bar"], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | cc_object { |
| 142 | name: "bar", |
| 143 | srcs: ["x/y/z.c"], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 144 | } |
| 145 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 146 | expectedBazelTargets: []string{`cc_object( |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 147 | name = "bar", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 148 | copts = [ |
| 149 | "-fno-addrsig", |
| 150 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 151 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 152 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 153 | srcs = ["x/y/z.c"], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 154 | )`, `cc_object( |
| 155 | name = "foo", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 156 | copts = [ |
| 157 | "-fno-addrsig", |
| 158 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 159 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 160 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 161 | deps = [":bar"], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 162 | srcs = ["a/b/c.c"], |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 163 | )`, |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 164 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 165 | }) |
| 166 | } |
| 167 | |
| 168 | func TestCcObjectIncludeBuildDirFalse(t *testing.T) { |
| 169 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 170 | description: "cc_object with include_build_dir: false", |
| 171 | moduleTypeUnderTest: "cc_object", |
| 172 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 173 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 174 | filesystem: map[string]string{ |
| 175 | "a/b/c.c": "", |
| 176 | "x/y/z.c": "", |
| 177 | }, |
| 178 | blueprint: `cc_object { |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 179 | name: "foo", |
| 180 | srcs: ["a/b/c.c"], |
| 181 | include_build_directory: false, |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 182 | } |
| 183 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 184 | expectedBazelTargets: []string{`cc_object( |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 185 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 186 | copts = ["-fno-addrsig"], |
| 187 | srcs = ["a/b/c.c"], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 188 | )`, |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 189 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 190 | }) |
| 191 | } |
| 192 | |
| 193 | func TestCcObjectProductVariable(t *testing.T) { |
| 194 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 195 | description: "cc_object with product variable", |
| 196 | moduleTypeUnderTest: "cc_object", |
| 197 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 198 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 199 | blueprint: `cc_object { |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 200 | name: "foo", |
| 201 | include_build_directory: false, |
| 202 | product_variables: { |
| 203 | platform_sdk_version: { |
| 204 | asflags: ["-DPLATFORM_SDK_VERSION=%d"], |
| 205 | }, |
| 206 | }, |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 207 | } |
| 208 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 209 | expectedBazelTargets: []string{`cc_object( |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 210 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 211 | asflags = ["-DPLATFORM_SDK_VERSION={Platform_sdk_version}"], |
| 212 | copts = ["-fno-addrsig"], |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 213 | )`, |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 214 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 215 | }) |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 216 | } |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 217 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 218 | func TestCcObjectCflagsOneArch(t *testing.T) { |
| 219 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 220 | description: "cc_object setting cflags for one arch", |
| 221 | moduleTypeUnderTest: "cc_object", |
| 222 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 223 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 224 | blueprint: `cc_object { |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 225 | name: "foo", |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 226 | srcs: ["a.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 227 | arch: { |
| 228 | x86: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 229 | cflags: ["-fPIC"], // string list |
| 230 | }, |
| 231 | arm: { |
| 232 | srcs: ["arch/arm/file.S"], // label list |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 233 | }, |
| 234 | }, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 235 | } |
| 236 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 237 | expectedBazelTargets: []string{ |
| 238 | `cc_object( |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 239 | name = "foo", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 240 | copts = [ |
| 241 | "-fno-addrsig", |
| 242 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 243 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 244 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 245 | "//build/bazel/platforms/arch:x86": ["-fPIC"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 246 | "//conditions:default": [], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 247 | }), |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 248 | srcs = ["a.cpp"] + select({ |
| 249 | "//build/bazel/platforms/arch:arm": ["arch/arm/file.S"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 250 | "//conditions:default": [], |
| 251 | }), |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 252 | )`, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 253 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 254 | }) |
| 255 | } |
| 256 | |
| 257 | func TestCcObjectCflagsFourArch(t *testing.T) { |
| 258 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 259 | description: "cc_object setting cflags for 4 architectures", |
| 260 | moduleTypeUnderTest: "cc_object", |
| 261 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 262 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 263 | blueprint: `cc_object { |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 264 | name: "foo", |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 265 | srcs: ["base.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 266 | arch: { |
| 267 | x86: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 268 | srcs: ["x86.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 269 | cflags: ["-fPIC"], |
| 270 | }, |
| 271 | x86_64: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 272 | srcs: ["x86_64.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 273 | cflags: ["-fPIC"], |
| 274 | }, |
| 275 | arm: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 276 | srcs: ["arm.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 277 | cflags: ["-Wall"], |
| 278 | }, |
| 279 | arm64: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 280 | srcs: ["arm64.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 281 | cflags: ["-Wall"], |
| 282 | }, |
| 283 | }, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 284 | } |
| 285 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 286 | expectedBazelTargets: []string{ |
| 287 | `cc_object( |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 288 | name = "foo", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 289 | copts = [ |
| 290 | "-fno-addrsig", |
| 291 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 292 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 293 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 294 | "//build/bazel/platforms/arch:arm": ["-Wall"], |
| 295 | "//build/bazel/platforms/arch:arm64": ["-Wall"], |
| 296 | "//build/bazel/platforms/arch:x86": ["-fPIC"], |
| 297 | "//build/bazel/platforms/arch:x86_64": ["-fPIC"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 298 | "//conditions:default": [], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 299 | }), |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 300 | srcs = ["base.cpp"] + select({ |
| 301 | "//build/bazel/platforms/arch:arm": ["arm.cpp"], |
| 302 | "//build/bazel/platforms/arch:arm64": ["arm64.cpp"], |
| 303 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 304 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 305 | "//conditions:default": [], |
| 306 | }), |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 307 | )`, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 308 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 309 | }) |
| 310 | } |
| 311 | |
| 312 | func TestCcObjectCflagsMultiOs(t *testing.T) { |
| 313 | runCcObjectTestCase(t, bp2buildTestCase{ |
| 314 | description: "cc_object setting cflags for multiple OSes", |
| 315 | moduleTypeUnderTest: "cc_object", |
| 316 | moduleTypeUnderTestFactory: cc.ObjectFactory, |
| 317 | moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build, |
| 318 | blueprint: `cc_object { |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 319 | name: "foo", |
| 320 | srcs: ["base.cpp"], |
| 321 | target: { |
| 322 | android: { |
| 323 | cflags: ["-fPIC"], |
| 324 | }, |
| 325 | windows: { |
| 326 | cflags: ["-fPIC"], |
| 327 | }, |
| 328 | darwin: { |
| 329 | cflags: ["-Wall"], |
| 330 | }, |
| 331 | }, |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 332 | } |
| 333 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 334 | expectedBazelTargets: []string{ |
| 335 | `cc_object( |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 336 | name = "foo", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 337 | copts = [ |
| 338 | "-fno-addrsig", |
| 339 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 340 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 341 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 342 | "//build/bazel/platforms/os:android": ["-fPIC"], |
| 343 | "//build/bazel/platforms/os:darwin": ["-Wall"], |
| 344 | "//build/bazel/platforms/os:windows": ["-fPIC"], |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 345 | "//conditions:default": [], |
| 346 | }), |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 347 | srcs = ["base.cpp"], |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 348 | )`, |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 349 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame^] | 350 | }) |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 351 | } |