blob: 6ed62fc4704c0546a539a4abcb764a5ba611f70c [file] [log] [blame]
Jingwen Chen91220d72021-03-24 02:18:33 -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//
Cole Faust7071a052022-07-29 15:58:33 -07007// http://www.apache.org/licenses/LICENSE-2.0
Jingwen Chen91220d72021-03-24 02:18:33 -04008//
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.
14package cc
15
16import (
Liz Kammerd2871182021-10-04 13:54:37 -040017 "fmt"
Jingwen Chened9c17d2021-04-13 07:14:55 +000018 "path/filepath"
Jingwen Chen3950cd62021-05-12 04:33:00 +000019 "strings"
Chris Parsons484e50a2021-05-13 15:13:04 -040020
21 "android/soong/android"
22 "android/soong/bazel"
Alix1be00d42022-05-16 22:56:04 +000023 "android/soong/cc/config"
Liz Kammer7a210ac2021-09-22 15:52:58 -040024
Chris Parsons953b3562021-09-20 15:14:39 -040025 "github.com/google/blueprint"
Liz Kammerba7a9c52021-05-26 08:45:30 -040026
27 "github.com/google/blueprint/proptools"
Jingwen Chen91220d72021-03-24 02:18:33 -040028)
29
Liz Kammerae3994e2021-10-19 09:45:48 -040030const (
Trevor Radcliffecee4e052022-09-06 19:31:25 +000031 cSrcPartition = "c"
32 asSrcPartition = "as"
33 asmSrcPartition = "asm"
34 lSrcPartition = "l"
35 llSrcPartition = "ll"
36 cppSrcPartition = "cpp"
37 protoSrcPartition = "proto"
38 aidlSrcPartition = "aidl"
39 syspropSrcPartition = "sysprop"
Liz Kammer91487d42022-09-13 11:27:11 -040040
41 stubsSuffix = "_stub_libs_current"
Liz Kammerae3994e2021-10-19 09:45:48 -040042)
43
Liz Kammer2222c6b2021-05-24 15:41:47 -040044// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
Jingwen Chenbcf53042021-05-26 04:42:42 +000045// properties which apply to either the shared or static version of a cc_library module.
Liz Kammer2222c6b2021-05-24 15:41:47 -040046type staticOrSharedAttributes struct {
Vinh Tran9f6796a2022-08-16 13:10:31 -040047 Srcs bazel.LabelListAttribute
48 Srcs_c bazel.LabelListAttribute
49 Srcs_as bazel.LabelListAttribute
50 Srcs_aidl bazel.LabelListAttribute
51 Hdrs bazel.LabelListAttribute
52 Copts bazel.StringListAttribute
Jingwen Chen14a8bda2021-06-02 11:10:02 +000053
Liz Kammer12615db2021-09-28 09:19:17 -040054 Deps bazel.LabelListAttribute
55 Implementation_deps bazel.LabelListAttribute
56 Dynamic_deps bazel.LabelListAttribute
57 Implementation_dynamic_deps bazel.LabelListAttribute
58 Whole_archive_deps bazel.LabelListAttribute
59 Implementation_whole_archive_deps bazel.LabelListAttribute
Cole Faust6b29f592022-08-09 09:50:56 -070060 Runtime_deps bazel.LabelListAttribute
Chris Parsons51f8c392021-08-03 21:01:05 -040061
62 System_dynamic_deps bazel.LabelListAttribute
Chris Parsons58852a02021-12-09 18:10:18 -050063
64 Enabled bazel.BoolAttribute
Yu Liufc603162022-03-01 15:44:08 -080065
Yu Liu8d82ac52022-05-17 15:13:28 -070066 Native_coverage bazel.BoolAttribute
67
Yu Liufc603162022-03-01 15:44:08 -080068 sdkAttributes
Sam Delmericofb3bb322022-10-21 10:42:24 -040069
70 tidyAttributes
71}
72
73type tidyAttributes struct {
74 Tidy *bool
75 Tidy_flags []string
76 Tidy_checks []string
77 Tidy_checks_as_errors []string
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -040078 Tidy_disabled_srcs bazel.LabelListAttribute
Sam Delmerico4c902d62022-11-02 14:17:15 -040079 Tidy_timeout_srcs bazel.LabelListAttribute
Sam Delmericofb3bb322022-10-21 10:42:24 -040080}
81
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -040082func (m *Module) convertTidyAttributes(ctx android.BaseMutatorContext, moduleAttrs *tidyAttributes) {
Sam Delmericofb3bb322022-10-21 10:42:24 -040083 for _, f := range m.features {
84 if tidy, ok := f.(*tidyFeature); ok {
85 moduleAttrs.Tidy = tidy.Properties.Tidy
86 moduleAttrs.Tidy_flags = tidy.Properties.Tidy_flags
87 moduleAttrs.Tidy_checks = tidy.Properties.Tidy_checks
88 moduleAttrs.Tidy_checks_as_errors = tidy.Properties.Tidy_checks_as_errors
89 }
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -040090
91 }
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -040092 archVariantProps := m.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
93 for axis, configToProps := range archVariantProps {
94 for config, _props := range configToProps {
95 if archProps, ok := _props.(*BaseCompilerProperties); ok {
96 archDisabledSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_disabled_srcs)
97 moduleAttrs.Tidy_disabled_srcs.SetSelectValue(axis, config, archDisabledSrcs)
Sam Delmerico4c902d62022-11-02 14:17:15 -040098 archTimeoutSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_timeout_srcs)
99 moduleAttrs.Tidy_timeout_srcs.SetSelectValue(axis, config, archTimeoutSrcs)
Sam Delmericoc9b8fbd2022-10-25 15:47:17 -0400100 }
101 }
Sam Delmericofb3bb322022-10-21 10:42:24 -0400102 }
Jingwen Chen53681ef2021-04-29 08:15:13 +0000103}
104
Sam Delmericoc7681022022-02-04 21:01:20 +0000105// groupSrcsByExtension partitions `srcs` into groups based on file extension.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000106func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
Liz Kammer57e2e7a2021-09-20 12:55:02 -0400107 // Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl
108 // macro.
109 addSuffixForFilegroup := func(suffix string) bazel.LabelMapper {
Vinh Tran9f6796a2022-08-16 13:10:31 -0400110 return func(otherModuleCtx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
111
112 m, exists := otherModuleCtx.ModuleFromName(label.OriginalModuleName)
Liz Kammer12615db2021-09-28 09:19:17 -0400113 labelStr := label.Label
Vinh Tran9f6796a2022-08-16 13:10:31 -0400114 if !exists || !android.IsFilegroup(otherModuleCtx, m) {
115 return labelStr, false
116 }
Yu Liu2aa806b2022-09-01 11:54:47 -0700117 // If the filegroup is already converted to aidl_library or proto_library,
118 // skip creating _c_srcs, _as_srcs, _cpp_srcs filegroups
119 fg, _ := m.(android.FileGroupAsLibrary)
120 if fg.ShouldConvertToAidlLibrary(ctx) || fg.ShouldConvertToProtoLibrary(ctx) {
Liz Kammer12615db2021-09-28 09:19:17 -0400121 return labelStr, false
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000122 }
Liz Kammer12615db2021-09-28 09:19:17 -0400123 return labelStr + suffix, true
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400124 }
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000125 }
126
Liz Kammer57e2e7a2021-09-20 12:55:02 -0400127 // TODO(b/190006308): Handle language detection of sources in a Bazel rule.
Sam Delmericoc7681022022-02-04 21:01:20 +0000128 labels := bazel.LabelPartitions{
129 protoSrcPartition: android.ProtoSrcLabelPartition,
Liz Kammeraabfb5d2021-12-08 15:25:06 -0500130 cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
131 asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
Cole Faust7071a052022-07-29 15:58:33 -0700132 asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}},
Vinh Tran9f6796a2022-08-16 13:10:31 -0400133 aidlSrcPartition: android.AidlSrcLabelPartition,
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000134 // TODO(http://b/231968910): If there is ever a filegroup target that
135 // contains .l or .ll files we will need to find a way to add a
136 // LabelMapper for these that identifies these filegroups and
137 // converts them appropriately
138 lSrcPartition: bazel.LabelPartition{Extensions: []string{".l"}},
139 llSrcPartition: bazel.LabelPartition{Extensions: []string{".ll"}},
Liz Kammer57e2e7a2021-09-20 12:55:02 -0400140 // C++ is the "catch-all" group, and comprises generated sources because we don't
141 // know the language of these sources until the genrule is executed.
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000142 cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
143 syspropSrcPartition: bazel.LabelPartition{Extensions: []string{".sysprop"}},
Sam Delmericoc7681022022-02-04 21:01:20 +0000144 }
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000145
Sam Delmericoc7681022022-02-04 21:01:20 +0000146 return bazel.PartitionLabelListAttribute(ctx, &srcs, labels)
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000147}
148
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000149// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000150func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes {
Jingwen Chen53681ef2021-04-29 08:15:13 +0000151 lib, ok := module.compiler.(*libraryDecorator)
152 if !ok {
Liz Kammer2222c6b2021-05-24 15:41:47 -0400153 return staticOrSharedAttributes{}
Jingwen Chen53681ef2021-04-29 08:15:13 +0000154 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000155 return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic)
156}
Jingwen Chen53681ef2021-04-29 08:15:13 +0000157
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000158// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000159func bp2BuildParseSharedProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000160 return bp2BuildParseLibProps(ctx, module, false)
Jingwen Chen53681ef2021-04-29 08:15:13 +0000161}
162
163// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000164func bp2BuildParseStaticProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000165 return bp2BuildParseLibProps(ctx, module, true)
Liz Kammer2222c6b2021-05-24 15:41:47 -0400166}
167
Liz Kammer7a210ac2021-09-22 15:52:58 -0400168type depsPartition struct {
169 export bazel.LabelList
170 implementation bazel.LabelList
171}
172
Jingwen Chen55bc8202021-11-02 06:40:51 +0000173type bazelLabelForDepsFn func(android.BazelConversionPathContext, []string) bazel.LabelList
Liz Kammer7a210ac2021-09-22 15:52:58 -0400174
Jingwen Chen55bc8202021-11-02 06:40:51 +0000175func maybePartitionExportedAndImplementationsDeps(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
Liz Kammer2b8004b2021-10-04 13:55:44 -0400176 if !exportsDeps {
177 return depsPartition{
178 implementation: fn(ctx, allDeps),
179 }
180 }
181
Liz Kammer7a210ac2021-09-22 15:52:58 -0400182 implementation, export := android.FilterList(allDeps, exportedDeps)
183
184 return depsPartition{
185 export: fn(ctx, export),
186 implementation: fn(ctx, implementation),
187 }
188}
189
Jingwen Chen55bc8202021-11-02 06:40:51 +0000190type bazelLabelForDepsExcludesFn func(android.BazelConversionPathContext, []string, []string) bazel.LabelList
Liz Kammer7a210ac2021-09-22 15:52:58 -0400191
Jingwen Chen55bc8202021-11-02 06:40:51 +0000192func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
Liz Kammer2b8004b2021-10-04 13:55:44 -0400193 if !exportsDeps {
194 return depsPartition{
195 implementation: fn(ctx, allDeps, excludes),
196 }
197 }
Liz Kammer7a210ac2021-09-22 15:52:58 -0400198 implementation, export := android.FilterList(allDeps, exportedDeps)
199
200 return depsPartition{
201 export: fn(ctx, export, excludes),
202 implementation: fn(ctx, implementation, excludes),
203 }
204}
205
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000206func bp2BuildPropParseHelper(ctx android.ArchVariantContext, module *Module, propsType interface{}, parseFunc func(axis bazel.ConfigurationAxis, config string, props interface{})) {
207 for axis, configToProps := range module.GetArchVariantProperties(ctx, propsType) {
208 for config, props := range configToProps {
209 parseFunc(axis, config, props)
210 }
211 }
212}
213
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000214// Parses properties common to static and shared libraries. Also used for prebuilt libraries.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000215func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
Liz Kammer135bf552021-08-11 10:46:06 -0400216 attrs := staticOrSharedAttributes{}
Jingwen Chenbcf53042021-05-26 04:42:42 +0000217
Liz Kammer9abd62d2021-05-21 08:37:59 -0400218 setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000219 attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag))
Jingwen Chenc4dc9b42021-06-11 12:51:48 +0000220 attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
Chris Parsons953b3562021-09-20 15:14:39 -0400221 attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
Liz Kammer7a210ac2021-09-22 15:52:58 -0400222
Liz Kammer2b8004b2021-10-04 13:55:44 -0400223 staticDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
Liz Kammer7a210ac2021-09-22 15:52:58 -0400224 attrs.Deps.SetSelectValue(axis, config, staticDeps.export)
225 attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation)
226
Liz Kammer2b8004b2021-10-04 13:55:44 -0400227 sharedDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
Liz Kammer7a210ac2021-09-22 15:52:58 -0400228 attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export)
229 attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
230
231 attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
Chris Parsons58852a02021-12-09 18:10:18 -0500232 attrs.Enabled.SetSelectValue(axis, config, props.Enabled)
Jingwen Chenbcf53042021-05-26 04:42:42 +0000233 }
Liz Kammer135bf552021-08-11 10:46:06 -0400234 // system_dynamic_deps distinguishes between nil/empty list behavior:
235 // nil -> use default values
236 // empty list -> no values specified
237 attrs.System_dynamic_deps.ForceSpecifyEmptyList = true
Jingwen Chenbcf53042021-05-26 04:42:42 +0000238
239 if isStatic {
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000240 bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
241 if staticOrSharedProps, ok := props.(*StaticProperties); ok {
242 setAttrs(axis, config, staticOrSharedProps.Static)
Jingwen Chenbcf53042021-05-26 04:42:42 +0000243 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000244 })
Jingwen Chenbcf53042021-05-26 04:42:42 +0000245 } else {
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000246 bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
247 if staticOrSharedProps, ok := props.(*SharedProperties); ok {
248 setAttrs(axis, config, staticOrSharedProps.Shared)
Jingwen Chenbcf53042021-05-26 04:42:42 +0000249 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000250 })
Jingwen Chenbcf53042021-05-26 04:42:42 +0000251 }
252
Liz Kammerae3994e2021-10-19 09:45:48 -0400253 partitionedSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
254 attrs.Srcs = partitionedSrcs[cppSrcPartition]
255 attrs.Srcs_c = partitionedSrcs[cSrcPartition]
256 attrs.Srcs_as = partitionedSrcs[asSrcPartition]
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000257
Liz Kammer12615db2021-09-28 09:19:17 -0400258 if !partitionedSrcs[protoSrcPartition].IsEmpty() {
259 // TODO(b/208815215): determine whether this is used and add support if necessary
260 ctx.ModuleErrorf("Migrating static/shared only proto srcs is not currently supported")
261 }
262
Jingwen Chenbcf53042021-05-26 04:42:42 +0000263 return attrs
Jingwen Chen53681ef2021-04-29 08:15:13 +0000264}
265
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400266// Convenience struct to hold all attributes parsed from prebuilt properties.
267type prebuiltAttributes struct {
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000268 Src bazel.LabelAttribute
269 Enabled bazel.BoolAttribute
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400270}
271
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000272func parseSrc(ctx android.BazelConversionPathContext, srcLabelAttribute *bazel.LabelAttribute, axis bazel.ConfigurationAxis, config string, srcs []string) {
273 srcFileError := func() {
274 ctx.ModuleErrorf("parseSrc: Expected at most one source file for %s %s\n", axis, config)
275 }
276 if len(srcs) > 1 {
277 srcFileError()
278 return
279 } else if len(srcs) == 0 {
280 return
281 }
282 if srcLabelAttribute.SelectValue(axis, config) != nil {
283 srcFileError()
284 return
285 }
286 srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, srcs[0]))
287}
288
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000289// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000290func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) prebuiltAttributes {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000291
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400292 var srcLabelAttribute bazel.LabelAttribute
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000293 bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
294 if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000295 parseSrc(ctx, &srcLabelAttribute, axis, config, prebuiltLinkerProperties.Srcs)
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000296 }
297 })
298
299 var enabledLabelAttribute bazel.BoolAttribute
300 parseAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
301 if props.Enabled != nil {
302 enabledLabelAttribute.SetSelectValue(axis, config, props.Enabled)
303 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000304 parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000305 }
306
307 if isStatic {
308 bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
309 if staticProperties, ok := props.(*StaticProperties); ok {
310 parseAttrs(axis, config, staticProperties.Static)
311 }
312 })
313 } else {
314 bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
315 if sharedProperties, ok := props.(*SharedProperties); ok {
316 parseAttrs(axis, config, sharedProperties.Shared)
317 }
318 })
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400319 }
320
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400321 return prebuiltAttributes{
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000322 Src: srcLabelAttribute,
323 Enabled: enabledLabelAttribute,
324 }
325}
326
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000327func bp2BuildParsePrebuiltBinaryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
328 var srcLabelAttribute bazel.LabelAttribute
329 bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
330 if props, ok := props.(*prebuiltLinkerProperties); ok {
331 parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000332 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxb12ff592022-09-01 15:04:04 +0000333 })
334
335 return prebuiltAttributes{
336 Src: srcLabelAttribute,
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400337 }
338}
339
Colin Crossc5075e92022-12-05 16:46:39 -0800340func bp2BuildParsePrebuiltObjectProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
341 var srcLabelAttribute bazel.LabelAttribute
342 bp2BuildPropParseHelper(ctx, module, &prebuiltObjectProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
343 if props, ok := props.(*prebuiltObjectProperties); ok {
344 parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
345 }
346 })
347
348 return prebuiltAttributes{
349 Src: srcLabelAttribute,
350 }
351}
352
Liz Kammere6583482021-10-19 13:56:10 -0400353type baseAttributes struct {
354 compilerAttributes
355 linkerAttributes
Liz Kammer12615db2021-09-28 09:19:17 -0400356
Jingwen Chen0ead79b2022-11-28 22:44:35 +0000357 // A combination of compilerAttributes.features and linkerAttributes.features
Cole Faust5fa4e962022-08-22 14:31:04 -0700358 features bazel.StringListAttribute
Liz Kammer12615db2021-09-28 09:19:17 -0400359 protoDependency *bazel.LabelAttribute
Vinh Tran9f6796a2022-08-16 13:10:31 -0400360 aidlDependency *bazel.LabelAttribute
Liz Kammere6583482021-10-19 13:56:10 -0400361}
362
Jingwen Chen107c0de2021-04-09 10:43:12 +0000363// Convenience struct to hold all attributes parsed from compiler properties.
364type compilerAttributes struct {
Chris Parsons990c4f42021-05-25 12:10:58 -0400365 // Options for all languages
366 copts bazel.StringListAttribute
367 // Assembly options and sources
368 asFlags bazel.StringListAttribute
369 asSrcs bazel.LabelListAttribute
Cole Faust7071a052022-07-29 15:58:33 -0700370 asmSrcs bazel.LabelListAttribute
Chris Parsons990c4f42021-05-25 12:10:58 -0400371 // C options and sources
372 conlyFlags bazel.StringListAttribute
373 cSrcs bazel.LabelListAttribute
374 // C++ options and sources
375 cppFlags bazel.StringListAttribute
Jingwen Chened9c17d2021-04-13 07:14:55 +0000376 srcs bazel.LabelListAttribute
Chris Parsons2c788392021-08-10 11:58:07 -0400377
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000378 // Lex sources and options
379 lSrcs bazel.LabelListAttribute
380 llSrcs bazel.LabelListAttribute
381 lexopts bazel.StringListAttribute
382
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000383 // Sysprop sources
384 syspropSrcs bazel.LabelListAttribute
385
Liz Kammere6583482021-10-19 13:56:10 -0400386 hdrs bazel.LabelListAttribute
387
Chris Parsons2c788392021-08-10 11:58:07 -0400388 rtti bazel.BoolAttribute
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000389
390 // Not affected by arch variants
391 stl *string
Chris Parsons79bd2b72021-11-29 17:52:41 -0500392 cStd *string
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000393 cppStd *string
Liz Kammer35687bc2021-09-10 10:07:07 -0400394
395 localIncludes bazel.StringListAttribute
396 absoluteIncludes bazel.StringListAttribute
Liz Kammer12615db2021-09-28 09:19:17 -0400397
Liz Kammer1263d9b2021-12-10 14:28:20 -0500398 includes BazelIncludes
399
Liz Kammer12615db2021-09-28 09:19:17 -0400400 protoSrcs bazel.LabelListAttribute
Vinh Tran9f6796a2022-08-16 13:10:31 -0400401 aidlSrcs bazel.LabelListAttribute
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000402
403 stubsSymbolFile *string
404 stubsVersions bazel.StringListAttribute
Cole Faust5fa4e962022-08-22 14:31:04 -0700405
406 features bazel.StringListAttribute
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500407
408 suffix bazel.StringAttribute
Jingwen Chen107c0de2021-04-09 10:43:12 +0000409}
410
Liz Kammercac7f692021-12-16 14:19:32 -0500411type filterOutFn func(string) bool
412
413func filterOutStdFlag(flag string) bool {
414 return strings.HasPrefix(flag, "-std=")
415}
416
Alix1be00d42022-05-16 22:56:04 +0000417func filterOutClangUnknownCflags(flag string) bool {
418 for _, f := range config.ClangUnknownCflags {
419 if f == flag {
420 return true
421 }
422 }
423 return false
424}
425
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000426func parseCommandLineFlags(soongFlags []string, filterOut ...filterOutFn) []string {
Liz Kammere6583482021-10-19 13:56:10 -0400427 var result []string
428 for _, flag := range soongFlags {
Alix1be00d42022-05-16 22:56:04 +0000429 skipFlag := false
430 for _, filter := range filterOut {
431 if filter != nil && filter(flag) {
432 skipFlag = true
433 }
434 }
435 if skipFlag {
Liz Kammercac7f692021-12-16 14:19:32 -0500436 continue
437 }
Liz Kammere6583482021-10-19 13:56:10 -0400438 // Soong's cflags can contain spaces, like `-include header.h`. For
439 // Bazel's copts, split them up to be compatible with the
440 // no_copts_tokenization feature.
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000441 result = append(result, strings.Split(flag, " ")...)
Liz Kammere6583482021-10-19 13:56:10 -0400442 }
443 return result
444}
Jingwen Chened9c17d2021-04-13 07:14:55 +0000445
Jingwen Chen55bc8202021-11-02 06:40:51 +0000446func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) {
Liz Kammere6583482021-10-19 13:56:10 -0400447 // If there's arch specific srcs or exclude_srcs, generate a select entry for it.
448 // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
449 if srcsList, ok := parseSrcs(ctx, props); ok {
450 ca.srcs.SetSelectValue(axis, config, srcsList)
Chris Parsons990c4f42021-05-25 12:10:58 -0400451 }
452
Liz Kammere6583482021-10-19 13:56:10 -0400453 localIncludeDirs := props.Local_include_dirs
454 if axis == bazel.NoConfigAxis {
Chris Parsons79bd2b72021-11-29 17:52:41 -0500455 ca.cStd, ca.cppStd = bp2buildResolveCppStdValue(props.C_std, props.Cpp_std, props.Gnu_extensions)
Liz Kammere6583482021-10-19 13:56:10 -0400456 if includeBuildDirectory(props.Include_build_directory) {
457 localIncludeDirs = append(localIncludeDirs, ".")
Liz Kammer222bdcf2021-10-11 14:15:51 -0400458 }
Jingwen Chene32e9e02021-04-23 09:17:24 +0000459 }
460
Liz Kammere6583482021-10-19 13:56:10 -0400461 ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs)
462 ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs)
463
Cole Faust5fa4e962022-08-22 14:31:04 -0700464 instructionSet := proptools.StringDefault(props.Instruction_set, "")
465 if instructionSet == "arm" {
466 ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"})
467 } else if instructionSet != "" && instructionSet != "thumb" {
468 ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
469 }
470
Liz Kammercac7f692021-12-16 14:19:32 -0500471 // In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being
472 // overridden. In Bazel we always allow overriding, via flags; however, this can cause
473 // incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other
474 // cases.
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +0000475 ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutClangUnknownCflags))
476 ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil))
477 ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, filterOutClangUnknownCflags))
478 ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, filterOutClangUnknownCflags))
Liz Kammere6583482021-10-19 13:56:10 -0400479 ca.rtti.SetSelectValue(axis, config, props.Rtti)
480}
481
Jingwen Chen55bc8202021-11-02 06:40:51 +0000482func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, module *Module) {
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000483 bp2BuildPropParseHelper(ctx, module, &StlProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
484 if stlProps, ok := props.(*StlProperties); ok {
485 if stlProps.Stl == nil {
486 return
487 }
488 if ca.stl == nil {
Liz Kammer7128d382022-05-12 11:42:33 -0400489 stl := deduplicateStlInput(*stlProps.Stl)
490 ca.stl = &stl
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000491 } else if ca.stl != stlProps.Stl {
492 ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *ca.stl, stlProps.Stl)
Liz Kammer9abd62d2021-05-21 08:37:59 -0400493 }
Jingwen Chenc1c26502021-04-05 10:35:13 +0000494 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +0000495 })
Liz Kammere6583482021-10-19 13:56:10 -0400496}
Jingwen Chenc1c26502021-04-05 10:35:13 +0000497
Jingwen Chen55bc8202021-11-02 06:40:51 +0000498func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
Liz Kammerba7a9c52021-05-26 08:45:30 -0400499 productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
Liz Kammere6583482021-10-19 13:56:10 -0400500 "Cflags": &ca.copts,
501 "Asflags": &ca.asFlags,
502 "CppFlags": &ca.cppFlags,
Liz Kammerba7a9c52021-05-26 08:45:30 -0400503 }
Liz Kammerba7a9c52021-05-26 08:45:30 -0400504 for propName, attr := range productVarPropNameToAttribute {
Jingwen Chen25825ca2021-11-15 12:28:43 +0000505 if productConfigProps, exists := productVariableProps[propName]; exists {
506 for productConfigProp, prop := range productConfigProps {
507 flags, ok := prop.([]string)
Liz Kammerba7a9c52021-05-26 08:45:30 -0400508 if !ok {
509 ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
510 }
Jingwen Chen25825ca2021-11-15 12:28:43 +0000511 newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name)
512 attr.SetSelectValue(productConfigProp.ConfigurationAxis(), productConfigProp.SelectKey(), newFlags)
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400513 }
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400514 }
515 }
Liz Kammere6583482021-10-19 13:56:10 -0400516}
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400517
Jingwen Chen55bc8202021-11-02 06:40:51 +0000518func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) {
Liz Kammere6583482021-10-19 13:56:10 -0400519 ca.srcs.ResolveExcludes()
520 partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs)
521
Liz Kammer12615db2021-09-28 09:19:17 -0400522 ca.protoSrcs = partitionedSrcs[protoSrcPartition]
Vinh Tran9f6796a2022-08-16 13:10:31 -0400523 ca.aidlSrcs = partitionedSrcs[aidlSrcPartition]
Liz Kammer12615db2021-09-28 09:19:17 -0400524
Liz Kammere6583482021-10-19 13:56:10 -0400525 for p, lla := range partitionedSrcs {
526 // if there are no sources, there is no need for headers
527 if lla.IsEmpty() {
528 continue
529 }
530 lla.Append(implementationHdrs)
531 partitionedSrcs[p] = lla
532 }
533
534 ca.srcs = partitionedSrcs[cppSrcPartition]
535 ca.cSrcs = partitionedSrcs[cSrcPartition]
536 ca.asSrcs = partitionedSrcs[asSrcPartition]
Cole Faust7071a052022-07-29 15:58:33 -0700537 ca.asmSrcs = partitionedSrcs[asmSrcPartition]
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000538 ca.lSrcs = partitionedSrcs[lSrcPartition]
539 ca.llSrcs = partitionedSrcs[llSrcPartition]
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000540 ca.syspropSrcs = partitionedSrcs[syspropSrcPartition]
Liz Kammere6583482021-10-19 13:56:10 -0400541
542 ca.absoluteIncludes.DeduplicateAxesFromBase()
543 ca.localIncludes.DeduplicateAxesFromBase()
544}
545
546// Parse srcs from an arch or OS's props value.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000547func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, bool) {
Liz Kammere6583482021-10-19 13:56:10 -0400548 anySrcs := false
549 // Add srcs-like dependencies such as generated files.
550 // First create a LabelList containing these dependencies, then merge the values with srcs.
551 generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, props.Generated_sources, props.Exclude_generated_sources)
552 if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 {
553 anySrcs = true
554 }
555
556 allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
Vinh Tran9f6796a2022-08-16 13:10:31 -0400557
Liz Kammere6583482021-10-19 13:56:10 -0400558 if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
559 anySrcs = true
560 }
Vinh Tran9f6796a2022-08-16 13:10:31 -0400561
Liz Kammere6583482021-10-19 13:56:10 -0400562 return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
563}
564
Liz Kammera5a29de2022-05-25 23:19:37 -0400565func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
566 defaultVal := prefix + "_std_default"
Chris Parsons79bd2b72021-11-29 17:52:41 -0500567 // If c{,pp}std properties are not specified, don't generate them in the BUILD file.
568 // Defaults are handled by the toolchain definition.
569 // However, if gnu_extensions is false, then the default gnu-to-c version must be specified.
Liz Kammera5a29de2022-05-25 23:19:37 -0400570 stdVal := proptools.StringDefault(std, defaultVal)
571 if stdVal == "experimental" || stdVal == defaultVal {
572 if stdVal == "experimental" {
573 stdVal = prefix + "_std_experimental"
574 }
575 if !useGnu {
576 stdVal += "_no_gnu"
577 }
578 } else if !useGnu {
579 stdVal = gnuToCReplacer.Replace(stdVal)
Chris Parsons79bd2b72021-11-29 17:52:41 -0500580 }
581
Liz Kammera5a29de2022-05-25 23:19:37 -0400582 if stdVal == defaultVal {
583 return nil
Liz Kammer46fb7ab2021-12-01 10:09:34 -0500584 }
Liz Kammera5a29de2022-05-25 23:19:37 -0400585 return &stdVal
586}
Liz Kammer46fb7ab2021-12-01 10:09:34 -0500587
Liz Kammera5a29de2022-05-25 23:19:37 -0400588func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
589 useGnu := useGnuExtensions(gnu_extensions)
590
591 return bp2buildStdVal(c_std, "c", useGnu), bp2buildStdVal(cpp_std, "cpp", useGnu)
Liz Kammere6583482021-10-19 13:56:10 -0400592}
593
Liz Kammer1263d9b2021-12-10 14:28:20 -0500594// packageFromLabel extracts package from a fully-qualified or relative Label and whether the label
595// is fully-qualified.
596// e.g. fully-qualified "//a/b:foo" -> "a/b", true, relative: ":bar" -> ".", false
597func packageFromLabel(label string) (string, bool) {
598 split := strings.Split(label, ":")
599 if len(split) != 2 {
600 return "", false
601 }
602 if split[0] == "" {
603 return ".", false
604 }
605 // remove leading "//"
606 return split[0][2:], true
607}
608
609// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList>
610func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []string) {
611 for _, hdr := range labelList.Includes {
612 if pkg, hasPkg := packageFromLabel(hdr.Label); hasPkg {
613 absolute = append(absolute, pkg)
614 } else if pkg != "" {
615 relative = append(relative, pkg)
616 }
617 }
618 return relative, absolute
619}
620
Cole Faust7071a052022-07-29 15:58:33 -0700621type YasmAttributes struct {
622 Srcs bazel.LabelListAttribute
623 Flags bazel.StringListAttribute
624 Include_dirs bazel.StringListAttribute
625}
626
627func bp2BuildYasm(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) *bazel.LabelAttribute {
628 if ca.asmSrcs.IsEmpty() {
629 return nil
630 }
631
632 // Yasm needs the include directories from both local_includes and
633 // export_include_dirs. We don't care about actually exporting them from the
634 // yasm rule though, because they will also be present on the cc_ rule that
635 // wraps this yasm rule.
636 includes := ca.localIncludes.Clone()
637 bp2BuildPropParseHelper(ctx, m, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
638 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
639 if len(flagExporterProperties.Export_include_dirs) > 0 {
640 x := bazel.StringListAttribute{}
641 x.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs)
642 includes.Append(x)
643 }
644 }
645 })
646
647 ctx.CreateBazelTargetModule(
648 bazel.BazelTargetModuleProperties{
649 Rule_class: "yasm",
650 Bzl_load_location: "//build/bazel/rules/cc:yasm.bzl",
651 },
652 android.CommonAttributes{Name: m.Name() + "_yasm"},
653 &YasmAttributes{
654 Srcs: ca.asmSrcs,
655 Flags: ca.asFlags,
656 Include_dirs: *includes,
657 })
658
659 // We only want to add a dependency on the _yasm target if there are asm
660 // sources in the current configuration. If there are unconfigured asm
661 // sources, always add the dependency. Otherwise, add the dependency only
662 // on the configuration axes and values that had asm sources.
663 if len(ca.asmSrcs.Value.Includes) > 0 {
664 return bazel.MakeLabelAttribute(":" + m.Name() + "_yasm")
665 }
666
667 ret := &bazel.LabelAttribute{}
668 for _, axis := range ca.asmSrcs.SortedConfigurationAxes() {
669 for config := range ca.asmSrcs.ConfigurableValues[axis] {
670 ret.SetSelectValue(axis, config, bazel.Label{Label: ":" + m.Name() + "_yasm"})
671 }
672 }
673 return ret
674}
675
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000676// bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module..
Liz Kammer12615db2021-09-28 09:19:17 -0400677func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes {
Liz Kammere6583482021-10-19 13:56:10 -0400678 archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
679 archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{})
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000680 archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{})
Liz Kammere6583482021-10-19 13:56:10 -0400681
682 var implementationHdrs bazel.LabelListAttribute
683
684 axisToConfigs := map[bazel.ConfigurationAxis]map[string]bool{}
685 allAxesAndConfigs := func(cp android.ConfigurationAxisToArchVariantProperties) {
686 for axis, configMap := range cp {
687 if _, ok := axisToConfigs[axis]; !ok {
688 axisToConfigs[axis] = map[string]bool{}
689 }
690 for config, _ := range configMap {
691 axisToConfigs[axis][config] = true
Chris Parsonsa967f252021-09-23 16:34:35 -0400692 }
693 }
694 }
Liz Kammere6583482021-10-19 13:56:10 -0400695 allAxesAndConfigs(archVariantCompilerProps)
696 allAxesAndConfigs(archVariantLinkerProps)
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000697 allAxesAndConfigs(archVariantLibraryProperties)
Chris Parsonsa967f252021-09-23 16:34:35 -0400698
Liz Kammere6583482021-10-19 13:56:10 -0400699 compilerAttrs := compilerAttributes{}
700 linkerAttrs := linkerAttributes{}
701
702 for axis, configs := range axisToConfigs {
703 for config, _ := range configs {
704 var allHdrs []string
705 if baseCompilerProps, ok := archVariantCompilerProps[axis][config].(*BaseCompilerProperties); ok {
706 allHdrs = baseCompilerProps.Generated_headers
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000707 if baseCompilerProps.Lex != nil {
708 compilerAttrs.lexopts.SetSelectValue(axis, config, baseCompilerProps.Lex.Flags)
709 }
Liz Kammere6583482021-10-19 13:56:10 -0400710 (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, config, baseCompilerProps)
711 }
712
713 var exportHdrs []string
714
715 if baseLinkerProps, ok := archVariantLinkerProps[axis][config].(*BaseLinkerProperties); ok {
716 exportHdrs = baseLinkerProps.Export_generated_headers
717
718 (&linkerAttrs).bp2buildForAxisAndConfig(ctx, module.Binary(), axis, config, baseLinkerProps)
719 }
720 headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps)
721 implementationHdrs.SetSelectValue(axis, config, headers.implementation)
722 compilerAttrs.hdrs.SetSelectValue(axis, config, headers.export)
Liz Kammer1263d9b2021-12-10 14:28:20 -0500723
724 exportIncludes, exportAbsoluteIncludes := includesFromLabelList(headers.export)
725 compilerAttrs.includes.Includes.SetSelectValue(axis, config, exportIncludes)
726 compilerAttrs.includes.AbsoluteIncludes.SetSelectValue(axis, config, exportAbsoluteIncludes)
727
728 includes, absoluteIncludes := includesFromLabelList(headers.implementation)
729 currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, config)
730 currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...))
Vinh Tran9f6796a2022-08-16 13:10:31 -0400731
Liz Kammer1263d9b2021-12-10 14:28:20 -0500732 compilerAttrs.absoluteIncludes.SetSelectValue(axis, config, currAbsoluteIncludes)
Vinh Tran9f6796a2022-08-16 13:10:31 -0400733
Liz Kammer1263d9b2021-12-10 14:28:20 -0500734 currIncludes := compilerAttrs.localIncludes.SelectValue(axis, config)
735 currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...))
Vinh Tran9f6796a2022-08-16 13:10:31 -0400736
Liz Kammer1263d9b2021-12-10 14:28:20 -0500737 compilerAttrs.localIncludes.SetSelectValue(axis, config, currIncludes)
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000738
739 if libraryProps, ok := archVariantLibraryProperties[axis][config].(*LibraryProperties); ok {
740 if axis == bazel.NoConfigAxis {
741 compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file
742 compilerAttrs.stubsVersions.SetSelectValue(axis, config, libraryProps.Stubs.Versions)
743 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -0500744 if suffix := libraryProps.Suffix; suffix != nil {
745 compilerAttrs.suffix.SetSelectValue(axis, config, suffix)
746 }
Jingwen Chen0ee88a62022-01-07 14:55:29 +0000747 }
Liz Kammere6583482021-10-19 13:56:10 -0400748 }
749 }
Vinh Tran9f6796a2022-08-16 13:10:31 -0400750
Liz Kammere6583482021-10-19 13:56:10 -0400751 compilerAttrs.convertStlProps(ctx, module)
752 (&linkerAttrs).convertStripProps(ctx, module)
753
Yu Liu8d82ac52022-05-17 15:13:28 -0700754 if module.coverage != nil && module.coverage.Properties.Native_coverage != nil &&
755 !Bool(module.coverage.Properties.Native_coverage) {
756 // Native_coverage is arch neutral
757 (&linkerAttrs).features.Append(bazel.MakeStringListAttribute([]string{"-coverage"}))
758 }
759
Liz Kammere6583482021-10-19 13:56:10 -0400760 productVariableProps := android.ProductVariableProperties(ctx)
761
762 (&compilerAttrs).convertProductVariables(ctx, productVariableProps)
763 (&linkerAttrs).convertProductVariables(ctx, productVariableProps)
764
765 (&compilerAttrs).finalize(ctx, implementationHdrs)
Liz Kammer54309532021-12-14 12:21:22 -0500766 (&linkerAttrs).finalize(ctx)
Liz Kammere6583482021-10-19 13:56:10 -0400767
Cole Faust7071a052022-07-29 15:58:33 -0700768 (&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
769
Liz Kammer12615db2021-09-28 09:19:17 -0400770 protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
771
772 // bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know
773 // which. This will add the newly generated proto library to the appropriate attribute and nothing
774 // to the other
775 (&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib)
776 (&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib)
Vinh Tranfde57eb2022-08-29 17:46:58 -0400777
Vinh Tran395a1e92022-09-16 18:27:29 -0400778 aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs, linkerAttrs)
Vinh Tranfde57eb2022-08-29 17:46:58 -0400779 if aidlDep != nil {
780 if lib, ok := module.linker.(*libraryDecorator); ok {
781 if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) {
782 (&linkerAttrs).wholeArchiveDeps.Add(aidlDep)
783 } else {
784 (&linkerAttrs).implementationWholeArchiveDeps.Add(aidlDep)
785 }
786 }
787 }
Liz Kammer12615db2021-09-28 09:19:17 -0400788
Trevor Radcliffeef9c9002022-05-13 20:55:35 +0000789 convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs)
790 (&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
791 (&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
792
Trevor Radcliffecee4e052022-09-06 19:31:25 +0000793 if !compilerAttrs.syspropSrcs.IsEmpty() {
794 (&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
795 }
796
Jingwen Chen0ead79b2022-11-28 22:44:35 +0000797 features := compilerAttrs.features.Clone().Append(linkerAttrs.features)
Cole Faust5fa4e962022-08-22 14:31:04 -0700798 features.DeduplicateAxesFromBase()
799
Liz Kammere6583482021-10-19 13:56:10 -0400800 return baseAttributes{
801 compilerAttrs,
802 linkerAttrs,
Cole Faust5fa4e962022-08-22 14:31:04 -0700803 *features,
Liz Kammer12615db2021-09-28 09:19:17 -0400804 protoDep.protoDep,
Vinh Tran9f6796a2022-08-16 13:10:31 -0400805 aidlDep,
Jingwen Chen107c0de2021-04-09 10:43:12 +0000806 }
807}
808
Vinh Tran9f6796a2022-08-16 13:10:31 -0400809func bp2buildCcAidlLibrary(
810 ctx android.Bp2buildMutatorContext,
811 m *Module,
Vinh Trana3b8b782022-09-14 11:40:24 -0400812 aidlLabelList bazel.LabelListAttribute,
Vinh Tran395a1e92022-09-16 18:27:29 -0400813 linkerAttrs linkerAttributes,
Vinh Tran9f6796a2022-08-16 13:10:31 -0400814) *bazel.LabelAttribute {
Vinh Trana3b8b782022-09-14 11:40:24 -0400815 if !aidlLabelList.IsEmpty() {
816 aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool {
817 if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok &&
818 fg.ShouldConvertToAidlLibrary(ctx) {
819 return true
820 }
821 return false
822 })
Vinh Tran9f6796a2022-08-16 13:10:31 -0400823
Vinh Trana3b8b782022-09-14 11:40:24 -0400824 if !aidlSrcs.IsEmpty() {
825 aidlLibName := m.Name() + "_aidl_library"
826 ctx.CreateBazelTargetModule(
827 bazel.BazelTargetModuleProperties{
828 Rule_class: "aidl_library",
829 Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
830 },
831 android.CommonAttributes{Name: aidlLibName},
832 &aidlLibraryAttributes{
833 Srcs: aidlSrcs,
834 },
835 )
836 aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
837 }
Vinh Tran9f6796a2022-08-16 13:10:31 -0400838
Vinh Trana3b8b782022-09-14 11:40:24 -0400839 if !aidlLibs.IsEmpty() {
840 ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
Vinh Tran395a1e92022-09-16 18:27:29 -0400841 // Since cc_aidl_library only needs the dynamic deps (aka shared libs) from the parent cc library for compiling,
842 // we err on the side of not re-exporting the headers of the dynamic deps from cc_aidl_lirary
843 // because the parent cc library already has all the dynamic deps
844 implementationDynamicDeps := bazel.MakeLabelListAttribute(
845 bazel.AppendBazelLabelLists(
846 linkerAttrs.dynamicDeps.Value,
847 linkerAttrs.implementationDynamicDeps.Value,
848 ),
849 )
850
Vinh Trana3b8b782022-09-14 11:40:24 -0400851 ctx.CreateBazelTargetModule(
852 bazel.BazelTargetModuleProperties{
853 Rule_class: "cc_aidl_library",
854 Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
855 },
856 android.CommonAttributes{Name: ccAidlLibrarylabel},
857 &ccAidlLibraryAttributes{
Vinh Tran395a1e92022-09-16 18:27:29 -0400858 Deps: aidlLibs,
859 Implementation_dynamic_deps: implementationDynamicDeps,
Vinh Trana3b8b782022-09-14 11:40:24 -0400860 },
861 )
862 label := &bazel.LabelAttribute{
863 Value: &bazel.Label{
864 Label: ":" + ccAidlLibrarylabel,
865 },
866 }
867 return label
868 }
Vinh Tran9f6796a2022-08-16 13:10:31 -0400869 }
870
Vinh Trana3b8b782022-09-14 11:40:24 -0400871 return nil
Vinh Tran9f6796a2022-08-16 13:10:31 -0400872}
873
Yu Liufc603162022-03-01 15:44:08 -0800874func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {
Trevor Radcliffe58ea4512022-04-07 20:36:39 +0000875 return sdkAttributes{
876 Sdk_version: module.Properties.Sdk_version,
Yu Liufc603162022-03-01 15:44:08 -0800877 Min_sdk_version: module.Properties.Min_sdk_version,
878 }
879}
880
881type sdkAttributes struct {
882 Sdk_version *string
883 Min_sdk_version *string
884}
885
Jingwen Chen107c0de2021-04-09 10:43:12 +0000886// Convenience struct to hold all attributes parsed from linker properties.
887type linkerAttributes struct {
Liz Kammer54309532021-12-14 12:21:22 -0500888 deps bazel.LabelListAttribute
889 implementationDeps bazel.LabelListAttribute
890 dynamicDeps bazel.LabelListAttribute
891 implementationDynamicDeps bazel.LabelListAttribute
Cole Faust6b29f592022-08-09 09:50:56 -0700892 runtimeDeps bazel.LabelListAttribute
Liz Kammer54309532021-12-14 12:21:22 -0500893 wholeArchiveDeps bazel.LabelListAttribute
894 implementationWholeArchiveDeps bazel.LabelListAttribute
895 systemDynamicDeps bazel.LabelListAttribute
896 usedSystemDynamicDepAsDynamicDep map[string]bool
Liz Kammer7a210ac2021-09-22 15:52:58 -0400897
Jingwen Chen6ada5892021-09-17 11:38:09 +0000898 linkCrt bazel.BoolAttribute
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000899 useLibcrt bazel.BoolAttribute
Rupert Shuttleworth484aa252021-12-10 07:22:53 -0500900 useVersionLib bazel.BoolAttribute
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000901 linkopts bazel.StringListAttribute
Liz Kammerd2871182021-10-04 13:54:37 -0400902 additionalLinkerInputs bazel.LabelListAttribute
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000903 stripKeepSymbols bazel.BoolAttribute
904 stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
905 stripKeepSymbolsList bazel.StringListAttribute
906 stripAll bazel.BoolAttribute
907 stripNone bazel.BoolAttribute
Liz Kammer0eae52e2021-10-06 10:32:26 -0400908 features bazel.StringListAttribute
Rupert Shuttleworth143be942021-05-09 23:55:51 -0400909}
910
Liz Kammer54309532021-12-14 12:21:22 -0500911var (
912 soongSystemSharedLibs = []string{"libc", "libm", "libdl"}
Liz Kammerbaced712022-09-16 09:01:29 -0400913 versionLib = "libbuildversion"
Liz Kammer54309532021-12-14 12:21:22 -0500914)
915
Vinh Tran85fb07c2022-09-16 16:17:48 -0400916// resolveTargetApex re-adds the shared and static libs in target.apex.exclude_shared|static_libs props to non-apex variant
917// since all libs are already excluded by default
918func (la *linkerAttributes) resolveTargetApexProp(ctx android.BazelConversionPathContext, isBinary bool, props *BaseLinkerProperties) {
919 sharedLibsForNonApex := maybePartitionExportedAndImplementationsDeps(
920 ctx,
921 true,
922 props.Target.Apex.Exclude_shared_libs,
923 props.Export_shared_lib_headers,
924 bazelLabelForSharedDeps,
925 )
926 dynamicDeps := la.dynamicDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
927 implDynamicDeps := la.implementationDynamicDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
928 (&dynamicDeps).Append(sharedLibsForNonApex.export)
929 (&implDynamicDeps).Append(sharedLibsForNonApex.implementation)
930 la.dynamicDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, dynamicDeps)
931 la.implementationDynamicDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, implDynamicDeps)
932
933 staticLibsForNonApex := maybePartitionExportedAndImplementationsDeps(
934 ctx,
935 !isBinary,
936 props.Target.Apex.Exclude_static_libs,
937 props.Export_static_lib_headers,
938 bazelLabelForSharedDeps,
939 )
940 deps := la.deps.SelectValue(bazel.InApexAxis, bazel.NonApex)
941 implDeps := la.implementationDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
942 (&deps).Append(staticLibsForNonApex.export)
943 (&implDeps).Append(staticLibsForNonApex.implementation)
944 la.deps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, deps)
945 la.implementationDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, implDeps)
946}
947
Jingwen Chen55bc8202021-11-02 06:40:51 +0000948func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
Liz Kammere6583482021-10-19 13:56:10 -0400949 // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
950 var axisFeatures []string
Liz Kammer7a210ac2021-09-22 15:52:58 -0400951
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400952 wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs)
Liz Kammerbaced712022-09-16 09:01:29 -0400953 staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs))
954 if axis == bazel.NoConfigAxis {
955 la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib)
956 if proptools.Bool(props.Use_version_lib) {
957 versionLibAlreadyInDeps := android.InList(versionLib, wholeStaticLibs)
958 // remove from static libs so there is no duplicate dependency
959 _, staticLibs = android.RemoveFromList(versionLib, staticLibs)
960 // only add the dep if it is not in progress
961 if !versionLibAlreadyInDeps {
962 if isBinary {
963 wholeStaticLibs = append(wholeStaticLibs, versionLib)
964 } else {
965 la.implementationWholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, []string{versionLib}, props.Exclude_static_libs))
966 }
967 }
968 }
969 }
970
Liz Kammere6583482021-10-19 13:56:10 -0400971 // Excludes to parallel Soong:
972 // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
Liz Kammerbaced712022-09-16 09:01:29 -0400973 la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
Liz Kammercc2c1ef2022-03-21 09:03:29 -0400974
Vinh Tran85fb07c2022-09-16 16:17:48 -0400975 staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(
976 ctx,
977 !isBinary,
978 staticLibs,
979 // Exclude static libs in Exclude_static_libs and Target.Apex.Exclude_static_libs props
980 append(props.Exclude_static_libs, props.Target.Apex.Exclude_static_libs...),
981 props.Export_static_lib_headers,
982 bazelLabelForStaticDepsExcludes,
983 )
Liz Kammer7a210ac2021-09-22 15:52:58 -0400984
Liz Kammere6583482021-10-19 13:56:10 -0400985 headerLibs := android.FirstUniqueStrings(props.Header_libs)
986 hDeps := maybePartitionExportedAndImplementationsDeps(ctx, !isBinary, headerLibs, props.Export_header_lib_headers, bazelLabelForHeaderDeps)
Jingwen Chen63930982021-03-24 10:04:33 -0400987
Liz Kammere6583482021-10-19 13:56:10 -0400988 (&hDeps.export).Append(staticDeps.export)
989 la.deps.SetSelectValue(axis, config, hDeps.export)
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000990
Liz Kammere6583482021-10-19 13:56:10 -0400991 (&hDeps.implementation).Append(staticDeps.implementation)
992 la.implementationDeps.SetSelectValue(axis, config, hDeps.implementation)
Liz Kammer0eae52e2021-10-06 10:32:26 -0400993
Liz Kammere6583482021-10-19 13:56:10 -0400994 systemSharedLibs := props.System_shared_libs
995 // systemSharedLibs distinguishes between nil/empty list behavior:
996 // nil -> use default values
997 // empty list -> no values specified
998 if len(systemSharedLibs) > 0 {
999 systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
1000 }
1001 la.systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
1002
1003 sharedLibs := android.FirstUniqueStrings(props.Shared_libs)
Liz Kammer54309532021-12-14 12:21:22 -05001004 excludeSharedLibs := props.Exclude_shared_libs
1005 usedSystem := android.FilterListPred(sharedLibs, func(s string) bool {
1006 return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs)
1007 })
1008 for _, el := range usedSystem {
1009 if la.usedSystemDynamicDepAsDynamicDep == nil {
1010 la.usedSystemDynamicDepAsDynamicDep = map[string]bool{}
1011 }
1012 la.usedSystemDynamicDepAsDynamicDep[el] = true
1013 }
1014
Vinh Tran85fb07c2022-09-16 16:17:48 -04001015 sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(
1016 ctx,
1017 !isBinary,
1018 sharedLibs,
1019 // Exclude shared libs in Exclude_shared_libs and Target.Apex.Exclude_shared_libs props
1020 append(props.Exclude_shared_libs, props.Target.Apex.Exclude_shared_libs...),
1021 props.Export_shared_lib_headers,
1022 bazelLabelForSharedDepsExcludes,
1023 )
Liz Kammere6583482021-10-19 13:56:10 -04001024 la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
1025 la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
Vinh Tran85fb07c2022-09-16 16:17:48 -04001026 la.resolveTargetApexProp(ctx, isBinary, props)
1027
Wei Li81852ca2022-07-27 00:22:06 -07001028 if axis == bazel.NoConfigAxis || (axis == bazel.OsConfigurationAxis && config == bazel.OsAndroid) {
1029 // If a dependency in la.implementationDynamicDeps has stubs, its stub variant should be
1030 // used when the dependency is linked in a APEX. The dependencies in NoConfigAxis and
1031 // OsConfigurationAxis/OsAndroid are grouped by having stubs or not, so Bazel select()
1032 // statement can be used to choose source/stub variants of them.
1033 depsWithStubs := []bazel.Label{}
1034 for _, l := range sharedDeps.implementation.Includes {
1035 dep, _ := ctx.ModuleFromName(l.OriginalModuleName)
1036 if m, ok := dep.(*Module); ok && m.HasStubsVariants() {
1037 depsWithStubs = append(depsWithStubs, l)
1038 }
1039 }
1040 if len(depsWithStubs) > 0 {
1041 implDynamicDeps := bazel.SubtractBazelLabelList(sharedDeps.implementation, bazel.MakeLabelList(depsWithStubs))
1042 la.implementationDynamicDeps.SetSelectValue(axis, config, implDynamicDeps)
1043
1044 stubLibLabels := []bazel.Label{}
1045 for _, l := range depsWithStubs {
Liz Kammer91487d42022-09-13 11:27:11 -04001046 l.Label = l.Label + stubsSuffix
Wei Li81852ca2022-07-27 00:22:06 -07001047 stubLibLabels = append(stubLibLabels, l)
1048 }
1049 inApexSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex)
1050 nonApexSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex)
1051 defaultSelectValue := la.implementationDynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey)
1052 if axis == bazel.NoConfigAxis {
1053 (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
1054 (&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
1055 (&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
Trevor Radcliffe0ed6b7d2022-09-12 20:19:26 +00001056 la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
1057 la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
1058 la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue))
Wei Li81852ca2022-07-27 00:22:06 -07001059 } else if config == bazel.OsAndroid {
1060 (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
1061 (&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
Trevor Radcliffe0ed6b7d2022-09-12 20:19:26 +00001062 la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
1063 la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
Wei Li81852ca2022-07-27 00:22:06 -07001064 }
1065 }
1066 }
Liz Kammere6583482021-10-19 13:56:10 -04001067
1068 if !BoolDefault(props.Pack_relocations, packRelocationsDefault) {
1069 axisFeatures = append(axisFeatures, "disable_pack_relocations")
1070 }
1071
1072 if Bool(props.Allow_undefined_symbols) {
1073 axisFeatures = append(axisFeatures, "-no_undefined_symbols")
1074 }
1075
1076 var linkerFlags []string
1077 if len(props.Ldflags) > 0 {
Liz Kammerf38a8372022-02-04 15:39:00 -05001078 linkerFlags = append(linkerFlags, proptools.NinjaEscapeList(props.Ldflags)...)
Liz Kammere6583482021-10-19 13:56:10 -04001079 // binaries remove static flag if -shared is in the linker flags
1080 if isBinary && android.InList("-shared", linkerFlags) {
1081 axisFeatures = append(axisFeatures, "-static_flag")
1082 }
1083 }
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +00001084
1085 // This must happen before the addition of flags for Version Script and
1086 // Dynamic List, as these flags must be split on spaces and those must not
1087 linkerFlags = parseCommandLineFlags(linkerFlags, filterOutClangUnknownCflags)
1088
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +00001089 additionalLinkerInputs := bazel.LabelList{}
Liz Kammere6583482021-10-19 13:56:10 -04001090 if props.Version_script != nil {
1091 label := android.BazelLabelForModuleSrcSingle(ctx, *props.Version_script)
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +00001092 additionalLinkerInputs.Add(&label)
Liz Kammere6583482021-10-19 13:56:10 -04001093 linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label))
1094 }
Alix773adaa2022-04-27 17:49:34 +00001095
1096 if props.Dynamic_list != nil {
1097 label := android.BazelLabelForModuleSrcSingle(ctx, *props.Dynamic_list)
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +00001098 additionalLinkerInputs.Add(&label)
Alix773adaa2022-04-27 17:49:34 +00001099 linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--dynamic-list,$(location %s)", label.Label))
1100 }
1101
Trevor Radcliffe37ec2f72022-09-27 01:46:01 +00001102 la.additionalLinkerInputs.SetSelectValue(axis, config, additionalLinkerInputs)
Trevor Radcliffeea6a45d2022-09-20 18:58:01 +00001103 la.linkopts.SetSelectValue(axis, config, linkerFlags)
Liz Kammere6583482021-10-19 13:56:10 -04001104 la.useLibcrt.SetSelectValue(axis, config, props.libCrt())
1105
1106 // it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
1107 if props.crt() != nil {
1108 if axis == bazel.NoConfigAxis {
1109 la.linkCrt.SetSelectValue(axis, config, props.crt())
1110 } else if axis == bazel.ArchConfigurationAxis {
1111 ctx.ModuleErrorf("nocrt is not supported for arch variants")
1112 }
1113 }
1114
1115 if axisFeatures != nil {
1116 la.features.SetSelectValue(axis, config, axisFeatures)
1117 }
Cole Faust6b29f592022-08-09 09:50:56 -07001118
1119 runtimeDeps := android.BazelLabelForModuleDepsExcludes(ctx, props.Runtime_libs, props.Exclude_runtime_libs)
1120 if !runtimeDeps.IsEmpty() {
1121 la.runtimeDeps.SetSelectValue(axis, config, runtimeDeps)
1122 }
Liz Kammere6583482021-10-19 13:56:10 -04001123}
1124
Jingwen Chen55bc8202021-11-02 06:40:51 +00001125func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) {
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001126 bp2BuildPropParseHelper(ctx, module, &StripProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
1127 if stripProperties, ok := props.(*StripProperties); ok {
1128 la.stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols)
1129 la.stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list)
1130 la.stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame)
1131 la.stripAll.SetSelectValue(axis, config, stripProperties.Strip.All)
1132 la.stripNone.SetSelectValue(axis, config, stripProperties.Strip.None)
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001133 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001134 })
Liz Kammere6583482021-10-19 13:56:10 -04001135}
Jingwen Chen3d383bb2021-06-09 07:18:37 +00001136
Jingwen Chen55bc8202021-11-02 06:40:51 +00001137func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
Jingwen Chen6ada5892021-09-17 11:38:09 +00001138
Liz Kammer47535c52021-06-02 16:02:22 -04001139 type productVarDep struct {
1140 // the name of the corresponding excludes field, if one exists
1141 excludesField string
1142 // reference to the bazel attribute that should be set for the given product variable config
1143 attribute *bazel.LabelListAttribute
Liz Kammer2d7bbe32021-06-10 18:20:06 -04001144
Jingwen Chen55bc8202021-11-02 06:40:51 +00001145 depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList
Liz Kammer47535c52021-06-02 16:02:22 -04001146 }
1147
Zi Wang0a8a1292022-08-30 06:27:01 +00001148 // an intermediate attribute that holds Header_libs info, and will be appended to
1149 // implementationDeps at the end, to solve the confliction that both header_libs
1150 // and static_libs use implementationDeps.
1151 var headerDeps bazel.LabelListAttribute
1152
Liz Kammer47535c52021-06-02 16:02:22 -04001153 productVarToDepFields := map[string]productVarDep{
1154 // product variables do not support exclude_shared_libs
Jingwen Chen55bc8202021-11-02 06:40:51 +00001155 "Shared_libs": {attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
1156 "Static_libs": {"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes},
1157 "Whole_static_libs": {"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
Zi Wang0a8a1292022-08-30 06:27:01 +00001158 "Header_libs": {attribute: &headerDeps, depResolutionFunc: bazelLabelForHeaderDepsExcludes},
Liz Kammer47535c52021-06-02 16:02:22 -04001159 }
1160
Liz Kammer47535c52021-06-02 16:02:22 -04001161 for name, dep := range productVarToDepFields {
1162 props, exists := productVariableProps[name]
1163 excludeProps, excludesExists := productVariableProps[dep.excludesField]
1164 // if neither an include or excludes property exists, then skip it
1165 if !exists && !excludesExists {
1166 continue
1167 }
Jingwen Chen25825ca2021-11-15 12:28:43 +00001168 // Collect all the configurations that an include or exclude property exists for.
1169 // We want to iterate all configurations rather than either the include or exclude because, for a
1170 // particular configuration, we may have either only an include or an exclude to handle.
1171 productConfigProps := make(map[android.ProductConfigProperty]bool, len(props)+len(excludeProps))
1172 for p := range props {
1173 productConfigProps[p] = true
Liz Kammer47535c52021-06-02 16:02:22 -04001174 }
Jingwen Chen25825ca2021-11-15 12:28:43 +00001175 for p := range excludeProps {
1176 productConfigProps[p] = true
Liz Kammer47535c52021-06-02 16:02:22 -04001177 }
1178
Jingwen Chen25825ca2021-11-15 12:28:43 +00001179 for productConfigProp := range productConfigProps {
1180 prop, includesExists := props[productConfigProp]
1181 excludesProp, excludesExists := excludeProps[productConfigProp]
Liz Kammer47535c52021-06-02 16:02:22 -04001182 var includes, excludes []string
1183 var ok bool
1184 // if there was no includes/excludes property, casting fails and that's expected
Jingwen Chen25825ca2021-11-15 12:28:43 +00001185 if includes, ok = prop.([]string); includesExists && !ok {
Liz Kammer47535c52021-06-02 16:02:22 -04001186 ctx.ModuleErrorf("Could not convert product variable %s property", name)
1187 }
Jingwen Chen25825ca2021-11-15 12:28:43 +00001188 if excludes, ok = excludesProp.([]string); excludesExists && !ok {
Liz Kammer47535c52021-06-02 16:02:22 -04001189 ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField)
1190 }
Liz Kammer2d7bbe32021-06-10 18:20:06 -04001191
Jingwen Chen58ff6802021-11-17 12:14:41 +00001192 dep.attribute.EmitEmptyList = productConfigProp.AlwaysEmit()
Jingwen Chen25825ca2021-11-15 12:28:43 +00001193 dep.attribute.SetSelectValue(
1194 productConfigProp.ConfigurationAxis(),
1195 productConfigProp.SelectKey(),
1196 dep.depResolutionFunc(ctx, android.FirstUniqueStrings(includes), excludes),
1197 )
Liz Kammer47535c52021-06-02 16:02:22 -04001198 }
1199 }
Zi Wang0a8a1292022-08-30 06:27:01 +00001200 la.implementationDeps.Append(headerDeps)
Liz Kammere6583482021-10-19 13:56:10 -04001201}
Liz Kammer47535c52021-06-02 16:02:22 -04001202
Liz Kammer54309532021-12-14 12:21:22 -05001203func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) {
1204 // if system dynamic deps have the default value, any use of a system dynamic library used will
1205 // result in duplicate library errors for bionic OSes. Here, we explicitly exclude those libraries
Liz Kammer43345e22022-08-04 13:57:35 -04001206 // from bionic OSes and the no config case as these libraries only build for bionic OSes.
Liz Kammer54309532021-12-14 12:21:22 -05001207 if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsDynamicDep) > 0 {
1208 toRemove := bazelLabelForSharedDeps(ctx, android.SortedStringKeys(la.usedSystemDynamicDepAsDynamicDep))
Liz Kammer43345e22022-08-04 13:57:35 -04001209 la.dynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove)
Liz Kammer54309532021-12-14 12:21:22 -05001210 la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
1211 la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
Liz Kammer91487d42022-09-13 11:27:11 -04001212 la.implementationDynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove)
Liz Kammer54309532021-12-14 12:21:22 -05001213 la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
1214 la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
Liz Kammer91487d42022-09-13 11:27:11 -04001215
1216 la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, toRemove)
1217 la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, toRemove)
1218 stubsToRemove := make([]bazel.Label, 0, len(la.usedSystemDynamicDepAsDynamicDep))
1219 for _, lib := range toRemove.Includes {
1220 lib.Label += stubsSuffix
1221 stubsToRemove = append(stubsToRemove, lib)
1222 }
1223 la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.MakeLabelList(stubsToRemove))
Liz Kammer54309532021-12-14 12:21:22 -05001224 }
1225
Liz Kammere6583482021-10-19 13:56:10 -04001226 la.deps.ResolveExcludes()
1227 la.implementationDeps.ResolveExcludes()
1228 la.dynamicDeps.ResolveExcludes()
1229 la.implementationDynamicDeps.ResolveExcludes()
1230 la.wholeArchiveDeps.ResolveExcludes()
1231 la.systemDynamicDeps.ForceSpecifyEmptyList = true
Liz Kammer54309532021-12-14 12:21:22 -05001232
Jingwen Chen91220d72021-03-24 02:18:33 -04001233}
1234
Jingwen Chened9c17d2021-04-13 07:14:55 +00001235// Relativize a list of root-relative paths with respect to the module's
1236// directory.
1237//
1238// include_dirs Soong prop are root-relative (b/183742505), but
1239// local_include_dirs, export_include_dirs and export_system_include_dirs are
1240// module dir relative. This function makes a list of paths entirely module dir
1241// relative.
1242//
1243// For the `include` attribute, Bazel wants the paths to be relative to the
1244// module.
1245func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string {
Rupert Shuttleworthb8151682021-04-06 20:06:21 +00001246 var relativePaths []string
1247 for _, path := range paths {
Jingwen Chened9c17d2021-04-13 07:14:55 +00001248 // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path
1249 relativePath, err := filepath.Rel(ctx.ModuleDir(), path)
1250 if err != nil {
1251 panic(err)
1252 }
Rupert Shuttleworthb8151682021-04-06 20:06:21 +00001253 relativePaths = append(relativePaths, relativePath)
1254 }
1255 return relativePaths
1256}
1257
Liz Kammer5fad5012021-09-09 14:08:21 -04001258// BazelIncludes contains information about -I and -isystem paths from a module converted to Bazel
1259// attributes.
1260type BazelIncludes struct {
Liz Kammer1263d9b2021-12-10 14:28:20 -05001261 AbsoluteIncludes bazel.StringListAttribute
1262 Includes bazel.StringListAttribute
1263 SystemIncludes bazel.StringListAttribute
Liz Kammer5fad5012021-09-09 14:08:21 -04001264}
1265
Liz Kammer54549442022-05-11 13:55:06 -04001266func bp2BuildParseExportedIncludes(ctx android.BazelConversionPathContext, module *Module, includes *BazelIncludes) BazelIncludes {
Liz Kammer1263d9b2021-12-10 14:28:20 -05001267 var exported BazelIncludes
1268 if includes != nil {
1269 exported = *includes
1270 } else {
1271 exported = BazelIncludes{}
1272 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001273 bp2BuildPropParseHelper(ctx, module, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
1274 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
1275 if len(flagExporterProperties.Export_include_dirs) > 0 {
1276 exported.Includes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.Includes.SelectValue(axis, config), flagExporterProperties.Export_include_dirs...)))
1277 }
1278 if len(flagExporterProperties.Export_system_include_dirs) > 0 {
1279 exported.SystemIncludes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.SystemIncludes.SelectValue(axis, config), flagExporterProperties.Export_system_include_dirs...)))
Rupert Shuttleworth375451e2021-04-26 07:49:08 -04001280 }
Rupert Shuttleworth375451e2021-04-26 07:49:08 -04001281 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001282 })
Liz Kammer1263d9b2021-12-10 14:28:20 -05001283 exported.AbsoluteIncludes.DeduplicateAxesFromBase()
Liz Kammer5fad5012021-09-09 14:08:21 -04001284 exported.Includes.DeduplicateAxesFromBase()
1285 exported.SystemIncludes.DeduplicateAxesFromBase()
Rupert Shuttleworth375451e2021-04-26 07:49:08 -04001286
Liz Kammer5fad5012021-09-09 14:08:21 -04001287 return exported
Jingwen Chen91220d72021-03-24 02:18:33 -04001288}
Chris Parsons953b3562021-09-20 15:14:39 -04001289
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001290func BazelLabelNameForStaticModule(baseLabel string) string {
1291 return baseLabel + "_bp2build_cc_library_static"
1292}
1293
Jingwen Chen55bc8202021-11-02 06:40:51 +00001294func bazelLabelForStaticModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
Chris Parsons953b3562021-09-20 15:14:39 -04001295 label := android.BazelModuleLabel(ctx, m)
Chris Parsonsad876012022-08-20 14:48:32 -04001296 if ccModule, ok := m.(*Module); ok && ccModule.typ() == fullLibrary && !android.GetBp2BuildAllowList().GenerateCcLibraryStaticOnly(m.Name()) {
Trevor Radcliffecee4e052022-09-06 19:31:25 +00001297 return BazelLabelNameForStaticModule(label)
Chris Parsons953b3562021-09-20 15:14:39 -04001298 }
1299 return label
1300}
1301
Jingwen Chen55bc8202021-11-02 06:40:51 +00001302func bazelLabelForSharedModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
Chris Parsons953b3562021-09-20 15:14:39 -04001303 // cc_library, at it's root name, propagates the shared library, which depends on the static
1304 // library.
1305 return android.BazelModuleLabel(ctx, m)
1306}
1307
Jingwen Chen55bc8202021-11-02 06:40:51 +00001308func bazelLabelForStaticWholeModuleDeps(ctx android.BazelConversionPathContext, m blueprint.Module) string {
Chris Parsons953b3562021-09-20 15:14:39 -04001309 label := bazelLabelForStaticModule(ctx, m)
1310 if aModule, ok := m.(android.Module); ok {
1311 if android.IsModulePrebuilt(aModule) {
1312 label += "_alwayslink"
1313 }
1314 }
1315 return label
1316}
1317
Jingwen Chen55bc8202021-11-02 06:40:51 +00001318func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001319 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps)
1320}
1321
Jingwen Chen55bc8202021-11-02 06:40:51 +00001322func bazelLabelForWholeDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001323 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps)
1324}
1325
Jingwen Chen55bc8202021-11-02 06:40:51 +00001326func bazelLabelForStaticDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001327 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule)
1328}
1329
Jingwen Chen55bc8202021-11-02 06:40:51 +00001330func bazelLabelForStaticDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001331 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule)
1332}
1333
Jingwen Chen55bc8202021-11-02 06:40:51 +00001334func bazelLabelForSharedDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001335 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule)
1336}
1337
Jingwen Chen55bc8202021-11-02 06:40:51 +00001338func bazelLabelForHeaderDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001339 // This is not elegant, but bp2build's shared library targets only propagate
1340 // their header information as part of the normal C++ provider.
1341 return bazelLabelForSharedDeps(ctx, modules)
1342}
1343
Zi Wang0a8a1292022-08-30 06:27:01 +00001344func bazelLabelForHeaderDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
1345 // This is only used when product_variable header_libs is processed, to follow
1346 // the pattern of depResolutionFunc
1347 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
1348}
1349
Jingwen Chen55bc8202021-11-02 06:40:51 +00001350func bazelLabelForSharedDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
Chris Parsons953b3562021-09-20 15:14:39 -04001351 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
1352}
Liz Kammer2b8004b2021-10-04 13:55:44 -04001353
1354type binaryLinkerAttrs struct {
1355 Linkshared *bool
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001356 Suffix bazel.StringAttribute
Liz Kammer2b8004b2021-10-04 13:55:44 -04001357}
1358
Jingwen Chen55bc8202021-11-02 06:40:51 +00001359func bp2buildBinaryLinkerProps(ctx android.BazelConversionPathContext, m *Module) binaryLinkerAttrs {
Liz Kammer2b8004b2021-10-04 13:55:44 -04001360 attrs := binaryLinkerAttrs{}
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001361 bp2BuildPropParseHelper(ctx, m, &BinaryLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
1362 linkerProps := props.(*BinaryLinkerProperties)
1363 staticExecutable := linkerProps.Static_executable
1364 if axis == bazel.NoConfigAxis {
1365 if linkBinaryShared := !proptools.Bool(staticExecutable); !linkBinaryShared {
1366 attrs.Linkshared = &linkBinaryShared
Liz Kammer2b8004b2021-10-04 13:55:44 -04001367 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001368 } else if staticExecutable != nil {
1369 // TODO(b/202876379): Static_executable is arch-variant; however, linkshared is a
1370 // nonconfigurable attribute. Only 4 AOSP modules use this feature, defer handling
1371 ctx.ModuleErrorf("bp2build cannot migrate a module with arch/target-specific static_executable values")
Liz Kammer2b8004b2021-10-04 13:55:44 -04001372 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa56e9702022-02-23 18:39:59 -05001373 if suffix := linkerProps.Suffix; suffix != nil {
1374 attrs.Suffix.SetSelectValue(axis, config, suffix)
1375 }
Trevor Radcliffe542954f2022-04-21 20:04:42 +00001376 })
Liz Kammer2b8004b2021-10-04 13:55:44 -04001377
1378 return attrs
1379}