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 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 29 | func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 30 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 31 | (&tc).ModuleTypeUnderTest = "cc_object" |
| 32 | (&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory |
| 33 | RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | func TestCcObjectSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 37 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 38 | Description: "simple cc_object generates cc_object with include header dep", |
| 39 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 40 | "a/b/foo.h": "", |
| 41 | "a/b/bar.h": "", |
| 42 | "a/b/exclude.c": "", |
| 43 | "a/b/c.c": "", |
| 44 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 45 | Blueprint: `cc_object { |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 46 | name: "foo", |
| 47 | local_include_dirs: ["include"], |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 48 | system_shared_libs: [], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 49 | cflags: [ |
| 50 | "-Wno-gcc-compat", |
| 51 | "-Wall", |
| 52 | "-Werror", |
| 53 | ], |
| 54 | srcs: [ |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 55 | "a/b/*.c" |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 56 | ], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 57 | exclude_srcs: ["a/b/exclude.c"], |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 58 | sdk_version: "current", |
| 59 | min_sdk_version: "29", |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 60 | } |
| 61 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 62 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 63 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 64 | "copts": `[ |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 65 | "-fno-addrsig", |
| 66 | "-Wno-gcc-compat", |
| 67 | "-Wall", |
| 68 | "-Werror", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 69 | ]`, |
| 70 | "local_includes": `[ |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 71 | "include", |
| 72 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 73 | ]`, |
| 74 | "srcs": `["a/b/c.c"]`, |
| 75 | "system_dynamic_deps": `[]`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 76 | "sdk_version": `"current"`, |
| 77 | "min_sdk_version": `"29"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 78 | }), |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 79 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 80 | }) |
| 81 | } |
| 82 | |
| 83 | func TestCcObjectDefaults(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 84 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 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 | srcs: [ |
| 89 | "a/b/*.h", |
| 90 | "a/b/c.c" |
| 91 | ], |
| 92 | |
| 93 | defaults: ["foo_defaults"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | cc_defaults { |
| 97 | name: "foo_defaults", |
| 98 | defaults: ["foo_bar_defaults"], |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | cc_defaults { |
| 102 | name: "foo_bar_defaults", |
| 103 | cflags: [ |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 104 | "-Werror", |
| 105 | ], |
| 106 | } |
| 107 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 108 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 109 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 110 | "copts": `[ |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 111 | "-Werror", |
| 112 | "-fno-addrsig", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 113 | ]`, |
| 114 | "local_includes": `["."]`, |
| 115 | "srcs": `["a/b/c.c"]`, |
| 116 | "system_dynamic_deps": `[]`, |
| 117 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 118 | }}) |
| 119 | } |
| 120 | |
| 121 | func TestCcObjectCcObjetDepsInObjs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 122 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 123 | Description: "cc_object with cc_object deps in objs props", |
| 124 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 125 | "a/b/c.c": "", |
| 126 | "x/y/z.c": "", |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 127 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 128 | Blueprint: `cc_object { |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 129 | name: "foo", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 130 | system_shared_libs: [], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 131 | srcs: ["a/b/c.c"], |
| 132 | objs: ["bar"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 133 | include_build_directory: false, |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | cc_object { |
| 137 | name: "bar", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 138 | system_shared_libs: [], |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 139 | srcs: ["x/y/z.c"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 140 | include_build_directory: false, |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 141 | } |
| 142 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 143 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 144 | MakeBazelTarget("cc_object", "bar", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 145 | "copts": `["-fno-addrsig"]`, |
| 146 | "srcs": `["x/y/z.c"]`, |
| 147 | "system_dynamic_deps": `[]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 148 | }), MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 149 | "copts": `["-fno-addrsig"]`, |
| 150 | "deps": `[":bar"]`, |
| 151 | "srcs": `["a/b/c.c"]`, |
| 152 | "system_dynamic_deps": `[]`, |
| 153 | }), |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 154 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 155 | }) |
| 156 | } |
| 157 | |
| 158 | func TestCcObjectIncludeBuildDirFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 159 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 160 | Description: "cc_object with include_build_dir: false", |
| 161 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 162 | "a/b/c.c": "", |
| 163 | "x/y/z.c": "", |
| 164 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 165 | Blueprint: `cc_object { |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 166 | name: "foo", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 167 | system_shared_libs: [], |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 168 | srcs: ["a/b/c.c"], |
| 169 | include_build_directory: false, |
Liz Kammer | a4aa430 | 2021-03-18 16:56:36 -0400 | [diff] [blame] | 170 | } |
| 171 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 172 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 173 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 174 | "copts": `["-fno-addrsig"]`, |
| 175 | "srcs": `["a/b/c.c"]`, |
| 176 | "system_dynamic_deps": `[]`, |
| 177 | }), |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 178 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 179 | }) |
| 180 | } |
| 181 | |
| 182 | func TestCcObjectProductVariable(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 183 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 184 | Description: "cc_object with product variable", |
| 185 | Blueprint: `cc_object { |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 186 | name: "foo", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 187 | system_shared_libs: [], |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 188 | include_build_directory: false, |
| 189 | product_variables: { |
| 190 | platform_sdk_version: { |
| 191 | asflags: ["-DPLATFORM_SDK_VERSION=%d"], |
| 192 | }, |
| 193 | }, |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 194 | srcs: ["src.S"], |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 195 | } |
| 196 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 197 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 198 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 199 | "asflags": `select({ |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 200 | "//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] | 201 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 202 | })`, |
| 203 | "copts": `["-fno-addrsig"]`, |
| 204 | "srcs_as": `["src.S"]`, |
| 205 | "system_dynamic_deps": `[]`, |
| 206 | }), |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 207 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 208 | }) |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 209 | } |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 210 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 211 | func TestCcObjectCflagsOneArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 212 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 213 | Description: "cc_object setting cflags for one arch", |
| 214 | Blueprint: `cc_object { |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 215 | name: "foo", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 216 | system_shared_libs: [], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 217 | srcs: ["a.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 218 | arch: { |
| 219 | x86: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 220 | cflags: ["-fPIC"], // string list |
| 221 | }, |
| 222 | arm: { |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 223 | srcs: ["arch/arm/file.cpp"], // label list |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 224 | }, |
| 225 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 226 | include_build_directory: false, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 227 | } |
| 228 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 229 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 230 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 231 | "copts": `["-fno-addrsig"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 232 | "//build/bazel/platforms/arch:x86": ["-fPIC"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 233 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 234 | })`, |
| 235 | "srcs": `["a.cpp"] + select({ |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 236 | "//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 237 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 238 | })`, |
| 239 | "system_dynamic_deps": `[]`, |
| 240 | }), |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 241 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 242 | }) |
| 243 | } |
| 244 | |
| 245 | func TestCcObjectCflagsFourArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 246 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 247 | Description: "cc_object setting cflags for 4 architectures", |
| 248 | Blueprint: `cc_object { |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 249 | name: "foo", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 250 | system_shared_libs: [], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 251 | srcs: ["base.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 252 | arch: { |
| 253 | x86: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 254 | srcs: ["x86.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 255 | cflags: ["-fPIC"], |
| 256 | }, |
| 257 | x86_64: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 258 | srcs: ["x86_64.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 259 | cflags: ["-fPIC"], |
| 260 | }, |
| 261 | arm: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 262 | srcs: ["arm.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 263 | cflags: ["-Wall"], |
| 264 | }, |
| 265 | arm64: { |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 266 | srcs: ["arm64.cpp"], |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 267 | cflags: ["-Wall"], |
| 268 | }, |
| 269 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 270 | include_build_directory: false, |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 271 | } |
| 272 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 273 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 274 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 275 | "copts": `["-fno-addrsig"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 276 | "//build/bazel/platforms/arch:arm": ["-Wall"], |
| 277 | "//build/bazel/platforms/arch:arm64": ["-Wall"], |
| 278 | "//build/bazel/platforms/arch:x86": ["-fPIC"], |
| 279 | "//build/bazel/platforms/arch:x86_64": ["-fPIC"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 280 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 281 | })`, |
| 282 | "srcs": `["base.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 283 | "//build/bazel/platforms/arch:arm": ["arm.cpp"], |
| 284 | "//build/bazel/platforms/arch:arm64": ["arm64.cpp"], |
| 285 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 286 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 287 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 288 | })`, |
| 289 | "system_dynamic_deps": `[]`, |
| 290 | }), |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 291 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 292 | }) |
| 293 | } |
| 294 | |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 295 | func TestCcObjectLinkerScript(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 296 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 297 | Description: "cc_object setting linker_script", |
| 298 | Blueprint: `cc_object { |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 299 | name: "foo", |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 300 | srcs: ["base.cpp"], |
| 301 | linker_script: "bunny.lds", |
| 302 | include_build_directory: false, |
| 303 | } |
| 304 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 305 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 306 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 307 | "copts": `["-fno-addrsig"]`, |
| 308 | "linker_script": `"bunny.lds"`, |
| 309 | "srcs": `["base.cpp"]`, |
| 310 | }), |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 311 | }, |
| 312 | }) |
| 313 | } |
| 314 | |
| 315 | func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 316 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 317 | Description: "cc_object setting deps and linker_script across archs", |
| 318 | Blueprint: `cc_object { |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 319 | name: "foo", |
| 320 | srcs: ["base.cpp"], |
| 321 | arch: { |
| 322 | x86: { |
| 323 | objs: ["x86_obj"], |
| 324 | linker_script: "x86.lds", |
| 325 | }, |
| 326 | x86_64: { |
| 327 | objs: ["x86_64_obj"], |
| 328 | linker_script: "x86_64.lds", |
| 329 | }, |
| 330 | arm: { |
| 331 | objs: ["arm_obj"], |
| 332 | linker_script: "arm.lds", |
| 333 | }, |
| 334 | }, |
| 335 | include_build_directory: false, |
| 336 | } |
| 337 | |
| 338 | cc_object { |
| 339 | name: "x86_obj", |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 340 | system_shared_libs: [], |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 341 | srcs: ["x86.cpp"], |
| 342 | include_build_directory: false, |
| 343 | bazel_module: { bp2build_available: false }, |
| 344 | } |
| 345 | |
| 346 | cc_object { |
| 347 | name: "x86_64_obj", |
| 348 | system_shared_libs: [], |
| 349 | srcs: ["x86_64.cpp"], |
| 350 | include_build_directory: false, |
| 351 | bazel_module: { bp2build_available: false }, |
| 352 | } |
| 353 | |
| 354 | cc_object { |
| 355 | name: "arm_obj", |
| 356 | system_shared_libs: [], |
| 357 | srcs: ["arm.cpp"], |
| 358 | include_build_directory: false, |
| 359 | bazel_module: { bp2build_available: false }, |
| 360 | } |
| 361 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 362 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 363 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 364 | "copts": `["-fno-addrsig"]`, |
| 365 | "deps": `select({ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 366 | "//build/bazel/platforms/arch:arm": [":arm_obj"], |
| 367 | "//build/bazel/platforms/arch:x86": [":x86_obj"], |
| 368 | "//build/bazel/platforms/arch:x86_64": [":x86_64_obj"], |
| 369 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 370 | })`, |
| 371 | "linker_script": `select({ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 372 | "//build/bazel/platforms/arch:arm": "arm.lds", |
| 373 | "//build/bazel/platforms/arch:x86": "x86.lds", |
| 374 | "//build/bazel/platforms/arch:x86_64": "x86_64.lds", |
| 375 | "//conditions:default": None, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 376 | })`, |
| 377 | "srcs": `["base.cpp"]`, |
| 378 | }), |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 379 | }, |
| 380 | }) |
| 381 | } |
| 382 | |
| 383 | func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 384 | runCcObjectTestCase(t, Bp2buildTestCase{ |
| 385 | Description: "cc_object setting srcs based on linux and bionic archs", |
| 386 | Blueprint: `cc_object { |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 387 | name: "foo", |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 388 | srcs: ["base.cpp"], |
| 389 | target: { |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 390 | linux_arm64: { |
| 391 | srcs: ["linux_arm64.cpp",] |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 392 | }, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 393 | linux_x86: { |
| 394 | srcs: ["linux_x86.cpp",] |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 395 | }, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 396 | bionic_arm64: { |
| 397 | srcs: ["bionic_arm64.cpp",] |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 398 | }, |
| 399 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 400 | include_build_directory: false, |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 401 | } |
| 402 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 403 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 404 | MakeBazelTarget("cc_object", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 405 | "copts": `["-fno-addrsig"]`, |
| 406 | "srcs": `["base.cpp"] + select({ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 407 | "//build/bazel/platforms/os_arch:android_arm64": [ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 408 | "linux_arm64.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 409 | "bionic_arm64.cpp", |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 410 | ], |
| 411 | "//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"], |
| 412 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": [ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 413 | "linux_arm64.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 414 | "bionic_arm64.cpp", |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 415 | ], |
| 416 | "//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"], |
Colin Cross | a9b2aac | 2022-06-15 17:25:51 -0700 | [diff] [blame] | 417 | "//build/bazel/platforms/os_arch:linux_musl_arm64": ["linux_arm64.cpp"], |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 418 | "//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"], |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 419 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 420 | })`, |
| 421 | }), |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 422 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 423 | }) |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 424 | } |