blob: 17337f021e982b0e5a62b40cc757af5e3f2d05b4 [file] [log] [blame]
Liz Kammer2b8004b2021-10-04 13:55:44 -04001// 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
15package bp2build
16
17import (
Liz Kammer2b8004b2021-10-04 13:55:44 -040018 "fmt"
19 "strings"
20 "testing"
Yu Liufc603162022-03-01 15:44:08 -080021
22 "android/soong/android"
23 "android/soong/cc"
24 "android/soong/genrule"
Liz Kammer2b8004b2021-10-04 13:55:44 -040025)
26
27const (
Liz Kammer12615db2021-09-28 09:19:17 -040028 ccBinaryTypePlaceHolder = "{rule_name}"
Liz Kammer2b8004b2021-10-04 13:55:44 -040029)
30
Liz Kammer78cfdaa2021-11-08 12:56:31 -050031type testBazelTarget struct {
32 typ string
33 name string
34 attrs attrNameToString
35}
36
37func generateBazelTargetsForTest(targets []testBazelTarget) []string {
38 ret := make([]string, 0, len(targets))
39 for _, t := range targets {
40 ret = append(ret, makeBazelTarget(t.typ, t.name, t.attrs))
41 }
42 return ret
43}
44
45type ccBinaryBp2buildTestCase struct {
46 description string
47 blueprint string
48 targets []testBazelTarget
49}
50
Liz Kammer2b8004b2021-10-04 13:55:44 -040051func registerCcBinaryModuleTypes(ctx android.RegistrationContext) {
52 cc.RegisterCCBuildComponents(ctx)
53 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
54 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
55 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Liz Kammere6583482021-10-19 13:56:10 -040056 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Liz Kammer2b8004b2021-10-04 13:55:44 -040057}
58
Liz Kammer78cfdaa2021-11-08 12:56:31 -050059var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary")
60var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host")
Liz Kammer2b8004b2021-10-04 13:55:44 -040061
Liz Kammer78cfdaa2021-11-08 12:56:31 -050062func runCcBinaryTests(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040063 t.Helper()
64 runCcBinaryTestCase(t, tc)
65 runCcHostBinaryTestCase(t, tc)
66}
67
Liz Kammer78cfdaa2021-11-08 12:56:31 -050068func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040069 t.Helper()
Liz Kammer78cfdaa2021-11-08 12:56:31 -050070 moduleTypeUnderTest := "cc_binary"
71 testCase := bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040072 expectedBazelTargets: generateBazelTargetsForTest(tc.targets),
73 moduleTypeUnderTest: moduleTypeUnderTest,
74 moduleTypeUnderTestFactory: cc.BinaryFactory,
75 description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
76 blueprint: binaryReplacer.Replace(tc.blueprint),
Liz Kammer2b8004b2021-10-04 13:55:44 -040077 }
78 t.Run(testCase.description, func(t *testing.T) {
Liz Kammerbe46fcc2021-11-01 15:32:43 -040079 t.Helper()
Liz Kammer2b8004b2021-10-04 13:55:44 -040080 runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
81 })
82}
83
Liz Kammer78cfdaa2021-11-08 12:56:31 -050084func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040085 t.Helper()
86 testCase := tc
Liz Kammer12615db2021-09-28 09:19:17 -040087 for i, tar := range testCase.targets {
Sam Delmerico75539d62022-01-31 14:37:29 +000088 switch tar.typ {
89 case "cc_binary", "proto_library", "cc_lite_proto_library":
90 tar.attrs["target_compatible_with"] = `select({
Liz Kammer78cfdaa2021-11-08 12:56:31 -050091 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
92 "//conditions:default": [],
93 })`
Sam Delmerico75539d62022-01-31 14:37:29 +000094 }
Liz Kammer12615db2021-09-28 09:19:17 -040095 testCase.targets[i] = tar
Liz Kammer2b8004b2021-10-04 13:55:44 -040096 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -050097 moduleTypeUnderTest := "cc_binary_host"
Liz Kammer2b8004b2021-10-04 13:55:44 -040098 t.Run(testCase.description, func(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -050099 runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400100 expectedBazelTargets: generateBazelTargetsForTest(testCase.targets),
101 moduleTypeUnderTest: moduleTypeUnderTest,
102 moduleTypeUnderTestFactory: cc.BinaryHostFactory,
103 description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
104 blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500105 })
Liz Kammer2b8004b2021-10-04 13:55:44 -0400106 })
107}
108
109func TestBasicCcBinary(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500110 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400111 description: "basic -- properties -> attrs with little/no transformation",
112 blueprint: `
113{rule_name} {
114 name: "foo",
115 srcs: ["a.cc"],
116 local_include_dirs: ["dir"],
117 include_dirs: ["absolute_dir"],
118 cflags: ["-Dcopt"],
119 cppflags: ["-Dcppflag"],
120 conlyflags: ["-Dconlyflag"],
121 asflags: ["-Dasflag"],
122 ldflags: ["ld-flag"],
123 rtti: true,
124 strip: {
125 all: true,
126 keep_symbols: true,
127 keep_symbols_and_debug_frame: true,
128 keep_symbols_list: ["symbol"],
129 none: true,
130 },
Yu Liufc603162022-03-01 15:44:08 -0800131 sdk_version: "current",
132 min_sdk_version: "29",
Liz Kammer2b8004b2021-10-04 13:55:44 -0400133}
134`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500135 targets: []testBazelTarget{
136 {"cc_binary", "foo", attrNameToString{
137 "absolute_includes": `["absolute_dir"]`,
138 "asflags": `["-Dasflag"]`,
139 "conlyflags": `["-Dconlyflag"]`,
140 "copts": `["-Dcopt"]`,
141 "cppflags": `["-Dcppflag"]`,
142 "linkopts": `["ld-flag"]`,
143 "local_includes": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400144 "dir",
145 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500146 ]`,
147 "rtti": `True`,
148 "srcs": `["a.cc"]`,
149 "strip": `{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400150 "all": True,
151 "keep_symbols": True,
152 "keep_symbols_and_debug_frame": True,
153 "keep_symbols_list": ["symbol"],
154 "none": True,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 }`,
Yu Liufc603162022-03-01 15:44:08 -0800156 "sdk_version": `"current"`,
157 "min_sdk_version": `"29"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500158 },
159 },
160 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400161 })
162}
163
164func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500165 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400166 description: `ldflag "-shared" disables static_flag feature`,
167 blueprint: `
168{rule_name} {
169 name: "foo",
170 ldflags: ["-shared"],
171 include_build_directory: false,
172}
173`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500174 targets: []testBazelTarget{
175 {"cc_binary", "foo", attrNameToString{
176 "features": `["-static_flag"]`,
177 "linkopts": `["-shared"]`,
178 },
179 },
180 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400181 })
182}
183
184func TestCcBinaryWithLinkStatic(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500185 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400186 description: "link static",
187 blueprint: `
188{rule_name} {
189 name: "foo",
190 static_executable: true,
191 include_build_directory: false,
192}
193`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500194 targets: []testBazelTarget{
195 {"cc_binary", "foo", attrNameToString{
196 "linkshared": `False`,
197 },
198 },
199 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400200 })
201}
202
203func TestCcBinaryVersionScript(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500204 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400205 description: `version script`,
206 blueprint: `
207{rule_name} {
208 name: "foo",
209 include_build_directory: false,
210 version_script: "vs",
211}
212`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500213 targets: []testBazelTarget{
214 {"cc_binary", "foo", attrNameToString{
215 "additional_linker_inputs": `["vs"]`,
216 "linkopts": `["-Wl,--version-script,$(location vs)"]`,
217 },
218 },
219 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400220 })
221}
222
223func TestCcBinarySplitSrcsByLang(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500224 runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400225 description: "split srcs by lang",
226 blueprint: `
227{rule_name} {
228 name: "foo",
229 srcs: [
230 "asonly.S",
231 "conly.c",
232 "cpponly.cpp",
233 ":fg_foo",
234 ],
235 include_build_directory: false,
236}
237` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500238 targets: []testBazelTarget{
239 {"cc_binary", "foo", attrNameToString{
240 "srcs": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400241 "cpponly.cpp",
242 ":fg_foo_cpp_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500243 ]`,
244 "srcs_as": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400245 "asonly.S",
246 ":fg_foo_as_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500247 ]`,
248 "srcs_c": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400249 "conly.c",
250 ":fg_foo_c_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500251 ]`,
252 },
253 },
254 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400255 })
256}
257
258func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500259 runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400260 description: "no implementation deps",
261 blueprint: `
Liz Kammere6583482021-10-19 13:56:10 -0400262genrule {
263 name: "generated_hdr",
264 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400265 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400266}
267
268genrule {
269 name: "export_generated_hdr",
270 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400271 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400272}
273
Liz Kammer2b8004b2021-10-04 13:55:44 -0400274{rule_name} {
275 name: "foo",
Liz Kammere6583482021-10-19 13:56:10 -0400276 srcs: ["foo.cpp"],
Liz Kammer2b8004b2021-10-04 13:55:44 -0400277 shared_libs: ["implementation_shared_dep", "shared_dep"],
278 export_shared_lib_headers: ["shared_dep"],
279 static_libs: ["implementation_static_dep", "static_dep"],
280 export_static_lib_headers: ["static_dep", "whole_static_dep"],
281 whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"],
282 include_build_directory: false,
Liz Kammere6583482021-10-19 13:56:10 -0400283 generated_headers: ["generated_hdr", "export_generated_hdr"],
284 export_generated_headers: ["export_generated_hdr"],
Liz Kammer2b8004b2021-10-04 13:55:44 -0400285}
286` +
287 simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") +
288 simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") +
289 simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") +
290 simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") +
291 simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") +
292 simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500293 targets: []testBazelTarget{
294 {"cc_binary", "foo", attrNameToString{
295 "deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400296 ":implementation_static_dep",
297 ":static_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500298 ]`,
299 "dynamic_deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400300 ":implementation_shared_dep",
301 ":shared_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500302 ]`,
303 "srcs": `[
Liz Kammere6583482021-10-19 13:56:10 -0400304 "foo.cpp",
305 ":generated_hdr",
306 ":export_generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500307 ]`,
308 "whole_archive_deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400309 ":not_explicitly_exported_whole_static_dep",
310 ":whole_static_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500311 ]`,
Liz Kammer1263d9b2021-12-10 14:28:20 -0500312 "local_includes": `["."]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500313 },
314 },
315 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400316 })
317}
318
319func TestCcBinaryNocrtTests(t *testing.T) {
320 baseTestCases := []struct {
321 description string
322 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500323 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400324 }{
325 {
326 description: "nocrt: true",
327 soongProperty: `nocrt: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500328 bazelAttr: attrNameToString{"link_crt": `False`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400329 },
330 {
331 description: "nocrt: false",
332 soongProperty: `nocrt: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500333 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400334 },
335 {
336 description: "nocrt: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500337 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400338 },
339 }
340
341 baseBlueprint := `{rule_name} {
342 name: "foo",%s
343 include_build_directory: false,
344}
345`
346
Liz Kammer2b8004b2021-10-04 13:55:44 -0400347 for _, btc := range baseTestCases {
348 prop := btc.soongProperty
349 if len(prop) > 0 {
350 prop = "\n" + prop
351 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500352 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400353 description: btc.description,
354 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500355 targets: []testBazelTarget{
356 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400357 },
358 })
359 }
360}
361
362func TestCcBinaryNo_libcrtTests(t *testing.T) {
363 baseTestCases := []struct {
364 description string
365 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500366 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400367 }{
368 {
369 description: "no_libcrt: true",
370 soongProperty: `no_libcrt: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500371 bazelAttr: attrNameToString{"use_libcrt": `False`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400372 },
373 {
374 description: "no_libcrt: false",
375 soongProperty: `no_libcrt: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500376 bazelAttr: attrNameToString{"use_libcrt": `True`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400377 },
378 {
379 description: "no_libcrt: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500380 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400381 },
382 }
383
384 baseBlueprint := `{rule_name} {
385 name: "foo",%s
386 include_build_directory: false,
387}
388`
389
Liz Kammer2b8004b2021-10-04 13:55:44 -0400390 for _, btc := range baseTestCases {
391 prop := btc.soongProperty
392 if len(prop) > 0 {
393 prop = "\n" + prop
394 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500395 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400396 description: btc.description,
397 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500398 targets: []testBazelTarget{
399 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400400 },
401 })
402 }
403}
404
405func TestCcBinaryPropertiesToFeatures(t *testing.T) {
406 baseTestCases := []struct {
407 description string
408 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500409 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400410 }{
411 {
412 description: "pack_relocation: true",
413 soongProperty: `pack_relocations: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500414 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400415 },
416 {
417 description: "pack_relocations: false",
418 soongProperty: `pack_relocations: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500419 bazelAttr: attrNameToString{"features": `["disable_pack_relocations"]`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400420 },
421 {
422 description: "pack_relocations: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500423 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400424 },
425 {
426 description: "pack_relocation: true",
427 soongProperty: `allow_undefined_symbols: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500428 bazelAttr: attrNameToString{"features": `["-no_undefined_symbols"]`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400429 },
430 {
431 description: "allow_undefined_symbols: false",
432 soongProperty: `allow_undefined_symbols: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500433 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400434 },
435 {
436 description: "allow_undefined_symbols: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500437 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400438 },
439 }
440
441 baseBlueprint := `{rule_name} {
442 name: "foo",%s
443 include_build_directory: false,
444}
445`
Liz Kammer2b8004b2021-10-04 13:55:44 -0400446 for _, btc := range baseTestCases {
447 prop := btc.soongProperty
448 if len(prop) > 0 {
449 prop = "\n" + prop
450 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500451 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400452 description: btc.description,
453 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500454 targets: []testBazelTarget{
455 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400456 },
457 })
458 }
459}
Liz Kammer12615db2021-09-28 09:19:17 -0400460
461func TestCcBinarySharedProto(t *testing.T) {
462 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
463 blueprint: soongCcProtoLibraries + `{rule_name} {
464 name: "foo",
465 srcs: ["foo.proto"],
466 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400467 },
468 include_build_directory: false,
469}`,
470 targets: []testBazelTarget{
471 {"proto_library", "foo_proto", attrNameToString{
472 "srcs": `["foo.proto"]`,
473 }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
474 "deps": `[":foo_proto"]`,
475 }}, {"cc_binary", "foo", attrNameToString{
476 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
477 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
478 }},
479 },
480 })
481}
482
483func TestCcBinaryStaticProto(t *testing.T) {
484 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
485 blueprint: soongCcProtoLibraries + `{rule_name} {
486 name: "foo",
487 srcs: ["foo.proto"],
488 static_executable: true,
489 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400490 },
491 include_build_directory: false,
492}`,
493 targets: []testBazelTarget{
494 {"proto_library", "foo_proto", attrNameToString{
495 "srcs": `["foo.proto"]`,
496 }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
497 "deps": `[":foo_proto"]`,
498 }}, {"cc_binary", "foo", attrNameToString{
499 "deps": `[":libprotobuf-cpp-lite"]`,
500 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
501 "linkshared": `False`,
502 }},
503 },
504 })
505}