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