blob: 8d94079acfb189ce372bb37da8be4681fdab84dc [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 (
18 "android/soong/android"
19 "android/soong/cc"
Liz Kammere6583482021-10-19 13:56:10 -040020 "android/soong/genrule"
Liz Kammer2b8004b2021-10-04 13:55:44 -040021 "fmt"
22 "strings"
23 "testing"
24)
25
26const (
Liz Kammer12615db2021-09-28 09:19:17 -040027 ccBinaryTypePlaceHolder = "{rule_name}"
Liz Kammer2b8004b2021-10-04 13:55:44 -040028)
29
Liz Kammer78cfdaa2021-11-08 12:56:31 -050030type testBazelTarget struct {
31 typ string
32 name string
33 attrs attrNameToString
34}
35
36func generateBazelTargetsForTest(targets []testBazelTarget) []string {
37 ret := make([]string, 0, len(targets))
38 for _, t := range targets {
39 ret = append(ret, makeBazelTarget(t.typ, t.name, t.attrs))
40 }
41 return ret
42}
43
44type ccBinaryBp2buildTestCase struct {
45 description string
46 blueprint string
47 targets []testBazelTarget
48}
49
Liz Kammer2b8004b2021-10-04 13:55:44 -040050func registerCcBinaryModuleTypes(ctx android.RegistrationContext) {
51 cc.RegisterCCBuildComponents(ctx)
52 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
53 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
54 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
Liz Kammere6583482021-10-19 13:56:10 -040055 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Liz Kammer2b8004b2021-10-04 13:55:44 -040056}
57
Liz Kammer78cfdaa2021-11-08 12:56:31 -050058var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary")
59var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host")
Liz Kammer2b8004b2021-10-04 13:55:44 -040060
Liz Kammer78cfdaa2021-11-08 12:56:31 -050061func runCcBinaryTests(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040062 t.Helper()
63 runCcBinaryTestCase(t, tc)
64 runCcHostBinaryTestCase(t, tc)
65}
66
Liz Kammer78cfdaa2021-11-08 12:56:31 -050067func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040068 t.Helper()
Liz Kammer78cfdaa2021-11-08 12:56:31 -050069 moduleTypeUnderTest := "cc_binary"
70 testCase := bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040071 expectedBazelTargets: generateBazelTargetsForTest(tc.targets),
72 moduleTypeUnderTest: moduleTypeUnderTest,
73 moduleTypeUnderTestFactory: cc.BinaryFactory,
74 description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
75 blueprint: binaryReplacer.Replace(tc.blueprint),
Liz Kammer2b8004b2021-10-04 13:55:44 -040076 }
77 t.Run(testCase.description, func(t *testing.T) {
Liz Kammerbe46fcc2021-11-01 15:32:43 -040078 t.Helper()
Liz Kammer2b8004b2021-10-04 13:55:44 -040079 runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase)
80 })
81}
82
Liz Kammer78cfdaa2021-11-08 12:56:31 -050083func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
Liz Kammer2b8004b2021-10-04 13:55:44 -040084 t.Helper()
85 testCase := tc
Liz Kammer12615db2021-09-28 09:19:17 -040086 for i, tar := range testCase.targets {
Sam Delmerico75539d62022-01-31 14:37:29 +000087 switch tar.typ {
88 case "cc_binary", "proto_library", "cc_lite_proto_library":
89 tar.attrs["target_compatible_with"] = `select({
Liz Kammer78cfdaa2021-11-08 12:56:31 -050090 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
91 "//conditions:default": [],
92 })`
Sam Delmerico75539d62022-01-31 14:37:29 +000093 }
Liz Kammer12615db2021-09-28 09:19:17 -040094 testCase.targets[i] = tar
Liz Kammer2b8004b2021-10-04 13:55:44 -040095 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -050096 moduleTypeUnderTest := "cc_binary_host"
Liz Kammer2b8004b2021-10-04 13:55:44 -040097 t.Run(testCase.description, func(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -050098 runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040099 expectedBazelTargets: generateBazelTargetsForTest(testCase.targets),
100 moduleTypeUnderTest: moduleTypeUnderTest,
101 moduleTypeUnderTestFactory: cc.BinaryHostFactory,
102 description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description),
103 blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500104 })
Liz Kammer2b8004b2021-10-04 13:55:44 -0400105 })
106}
107
108func TestBasicCcBinary(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500109 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400110 description: "basic -- properties -> attrs with little/no transformation",
111 blueprint: `
112{rule_name} {
113 name: "foo",
114 srcs: ["a.cc"],
115 local_include_dirs: ["dir"],
116 include_dirs: ["absolute_dir"],
117 cflags: ["-Dcopt"],
118 cppflags: ["-Dcppflag"],
119 conlyflags: ["-Dconlyflag"],
120 asflags: ["-Dasflag"],
121 ldflags: ["ld-flag"],
122 rtti: true,
123 strip: {
124 all: true,
125 keep_symbols: true,
126 keep_symbols_and_debug_frame: true,
127 keep_symbols_list: ["symbol"],
128 none: true,
129 },
130}
131`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500132 targets: []testBazelTarget{
133 {"cc_binary", "foo", attrNameToString{
134 "absolute_includes": `["absolute_dir"]`,
135 "asflags": `["-Dasflag"]`,
136 "conlyflags": `["-Dconlyflag"]`,
137 "copts": `["-Dcopt"]`,
138 "cppflags": `["-Dcppflag"]`,
139 "linkopts": `["ld-flag"]`,
140 "local_includes": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400141 "dir",
142 ".",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500143 ]`,
144 "rtti": `True`,
145 "srcs": `["a.cc"]`,
146 "strip": `{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400147 "all": True,
148 "keep_symbols": True,
149 "keep_symbols_and_debug_frame": True,
150 "keep_symbols_list": ["symbol"],
151 "none": True,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500152 }`,
153 },
154 },
155 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400156 })
157}
158
159func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500160 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400161 description: `ldflag "-shared" disables static_flag feature`,
162 blueprint: `
163{rule_name} {
164 name: "foo",
165 ldflags: ["-shared"],
166 include_build_directory: false,
167}
168`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500169 targets: []testBazelTarget{
170 {"cc_binary", "foo", attrNameToString{
171 "features": `["-static_flag"]`,
172 "linkopts": `["-shared"]`,
173 },
174 },
175 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400176 })
177}
178
179func TestCcBinaryWithLinkStatic(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500180 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400181 description: "link static",
182 blueprint: `
183{rule_name} {
184 name: "foo",
185 static_executable: true,
186 include_build_directory: false,
187}
188`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500189 targets: []testBazelTarget{
190 {"cc_binary", "foo", attrNameToString{
191 "linkshared": `False`,
192 },
193 },
194 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400195 })
196}
197
198func TestCcBinaryVersionScript(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500199 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400200 description: `version script`,
201 blueprint: `
202{rule_name} {
203 name: "foo",
204 include_build_directory: false,
205 version_script: "vs",
206}
207`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500208 targets: []testBazelTarget{
209 {"cc_binary", "foo", attrNameToString{
210 "additional_linker_inputs": `["vs"]`,
211 "linkopts": `["-Wl,--version-script,$(location vs)"]`,
212 },
213 },
214 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400215 })
216}
217
218func TestCcBinarySplitSrcsByLang(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500219 runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400220 description: "split srcs by lang",
221 blueprint: `
222{rule_name} {
223 name: "foo",
224 srcs: [
225 "asonly.S",
226 "conly.c",
227 "cpponly.cpp",
228 ":fg_foo",
229 ],
230 include_build_directory: false,
231}
232` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500233 targets: []testBazelTarget{
234 {"cc_binary", "foo", attrNameToString{
235 "srcs": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400236 "cpponly.cpp",
237 ":fg_foo_cpp_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500238 ]`,
239 "srcs_as": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400240 "asonly.S",
241 ":fg_foo_as_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500242 ]`,
243 "srcs_c": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400244 "conly.c",
245 ":fg_foo_c_srcs",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500246 ]`,
247 },
248 },
249 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400250 })
251}
252
253func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) {
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500254 runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400255 description: "no implementation deps",
256 blueprint: `
Liz Kammere6583482021-10-19 13:56:10 -0400257genrule {
258 name: "generated_hdr",
259 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400260 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400261}
262
263genrule {
264 name: "export_generated_hdr",
265 cmd: "nothing to see here",
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400266 bazel_module: { bp2build_available: false },
Liz Kammere6583482021-10-19 13:56:10 -0400267}
268
Liz Kammer2b8004b2021-10-04 13:55:44 -0400269{rule_name} {
270 name: "foo",
Liz Kammere6583482021-10-19 13:56:10 -0400271 srcs: ["foo.cpp"],
Liz Kammer2b8004b2021-10-04 13:55:44 -0400272 shared_libs: ["implementation_shared_dep", "shared_dep"],
273 export_shared_lib_headers: ["shared_dep"],
274 static_libs: ["implementation_static_dep", "static_dep"],
275 export_static_lib_headers: ["static_dep", "whole_static_dep"],
276 whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"],
277 include_build_directory: false,
Liz Kammere6583482021-10-19 13:56:10 -0400278 generated_headers: ["generated_hdr", "export_generated_hdr"],
279 export_generated_headers: ["export_generated_hdr"],
Liz Kammer2b8004b2021-10-04 13:55:44 -0400280}
281` +
282 simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") +
283 simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") +
284 simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") +
285 simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") +
286 simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") +
287 simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500288 targets: []testBazelTarget{
289 {"cc_binary", "foo", attrNameToString{
290 "deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400291 ":implementation_static_dep",
292 ":static_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500293 ]`,
294 "dynamic_deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400295 ":implementation_shared_dep",
296 ":shared_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500297 ]`,
298 "srcs": `[
Liz Kammere6583482021-10-19 13:56:10 -0400299 "foo.cpp",
300 ":generated_hdr",
301 ":export_generated_hdr",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500302 ]`,
303 "whole_archive_deps": `[
Liz Kammer2b8004b2021-10-04 13:55:44 -0400304 ":not_explicitly_exported_whole_static_dep",
305 ":whole_static_dep",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500306 ]`,
Liz Kammer1263d9b2021-12-10 14:28:20 -0500307 "local_includes": `["."]`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500308 },
309 },
310 },
Liz Kammer2b8004b2021-10-04 13:55:44 -0400311 })
312}
313
314func TestCcBinaryNocrtTests(t *testing.T) {
315 baseTestCases := []struct {
316 description string
317 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500318 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400319 }{
320 {
321 description: "nocrt: true",
322 soongProperty: `nocrt: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500323 bazelAttr: attrNameToString{"link_crt": `False`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400324 },
325 {
326 description: "nocrt: false",
327 soongProperty: `nocrt: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500328 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400329 },
330 {
331 description: "nocrt: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500332 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400333 },
334 }
335
336 baseBlueprint := `{rule_name} {
337 name: "foo",%s
338 include_build_directory: false,
339}
340`
341
Liz Kammer2b8004b2021-10-04 13:55:44 -0400342 for _, btc := range baseTestCases {
343 prop := btc.soongProperty
344 if len(prop) > 0 {
345 prop = "\n" + prop
346 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500347 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400348 description: btc.description,
349 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500350 targets: []testBazelTarget{
351 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400352 },
353 })
354 }
355}
356
357func TestCcBinaryNo_libcrtTests(t *testing.T) {
358 baseTestCases := []struct {
359 description string
360 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500361 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400362 }{
363 {
364 description: "no_libcrt: true",
365 soongProperty: `no_libcrt: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500366 bazelAttr: attrNameToString{"use_libcrt": `False`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400367 },
368 {
369 description: "no_libcrt: false",
370 soongProperty: `no_libcrt: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500371 bazelAttr: attrNameToString{"use_libcrt": `True`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400372 },
373 {
374 description: "no_libcrt: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500375 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400376 },
377 }
378
379 baseBlueprint := `{rule_name} {
380 name: "foo",%s
381 include_build_directory: false,
382}
383`
384
Liz Kammer2b8004b2021-10-04 13:55:44 -0400385 for _, btc := range baseTestCases {
386 prop := btc.soongProperty
387 if len(prop) > 0 {
388 prop = "\n" + prop
389 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500390 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400391 description: btc.description,
392 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500393 targets: []testBazelTarget{
394 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400395 },
396 })
397 }
398}
399
400func TestCcBinaryPropertiesToFeatures(t *testing.T) {
401 baseTestCases := []struct {
402 description string
403 soongProperty string
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500404 bazelAttr attrNameToString
Liz Kammer2b8004b2021-10-04 13:55:44 -0400405 }{
406 {
407 description: "pack_relocation: true",
408 soongProperty: `pack_relocations: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500409 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400410 },
411 {
412 description: "pack_relocations: false",
413 soongProperty: `pack_relocations: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500414 bazelAttr: attrNameToString{"features": `["disable_pack_relocations"]`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400415 },
416 {
417 description: "pack_relocations: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500418 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400419 },
420 {
421 description: "pack_relocation: true",
422 soongProperty: `allow_undefined_symbols: true,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500423 bazelAttr: attrNameToString{"features": `["-no_undefined_symbols"]`},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400424 },
425 {
426 description: "allow_undefined_symbols: false",
427 soongProperty: `allow_undefined_symbols: false,`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500428 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400429 },
430 {
431 description: "allow_undefined_symbols: not set",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500432 bazelAttr: attrNameToString{},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400433 },
434 }
435
436 baseBlueprint := `{rule_name} {
437 name: "foo",%s
438 include_build_directory: false,
439}
440`
Liz Kammer2b8004b2021-10-04 13:55:44 -0400441 for _, btc := range baseTestCases {
442 prop := btc.soongProperty
443 if len(prop) > 0 {
444 prop = "\n" + prop
445 }
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500446 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
Liz Kammer2b8004b2021-10-04 13:55:44 -0400447 description: btc.description,
448 blueprint: fmt.Sprintf(baseBlueprint, prop),
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500449 targets: []testBazelTarget{
450 {"cc_binary", "foo", btc.bazelAttr},
Liz Kammer2b8004b2021-10-04 13:55:44 -0400451 },
452 })
453 }
454}
Liz Kammer12615db2021-09-28 09:19:17 -0400455
456func TestCcBinarySharedProto(t *testing.T) {
457 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
458 blueprint: soongCcProtoLibraries + `{rule_name} {
459 name: "foo",
460 srcs: ["foo.proto"],
461 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400462 },
463 include_build_directory: false,
464}`,
465 targets: []testBazelTarget{
466 {"proto_library", "foo_proto", attrNameToString{
467 "srcs": `["foo.proto"]`,
468 }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
469 "deps": `[":foo_proto"]`,
470 }}, {"cc_binary", "foo", attrNameToString{
471 "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
472 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
473 }},
474 },
475 })
476}
477
478func TestCcBinaryStaticProto(t *testing.T) {
479 runCcBinaryTests(t, ccBinaryBp2buildTestCase{
480 blueprint: soongCcProtoLibraries + `{rule_name} {
481 name: "foo",
482 srcs: ["foo.proto"],
483 static_executable: true,
484 proto: {
Liz Kammer12615db2021-09-28 09:19:17 -0400485 },
486 include_build_directory: false,
487}`,
488 targets: []testBazelTarget{
489 {"proto_library", "foo_proto", attrNameToString{
490 "srcs": `["foo.proto"]`,
491 }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
492 "deps": `[":foo_proto"]`,
493 }}, {"cc_binary", "foo", attrNameToString{
494 "deps": `[":libprotobuf-cpp-lite"]`,
495 "whole_archive_deps": `[":foo_cc_proto_lite"]`,
496 "linkshared": `False`,
497 }},
498 },
499 })
500}