blob: c078096c70ccfedfc57dfa4af3c9dcf697c7149a [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//
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.
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"
Liz Kammer7a210ac2021-09-22 15:52:58 -040023
Chris Parsons953b3562021-09-20 15:14:39 -040024 "github.com/google/blueprint"
Liz Kammerba7a9c52021-05-26 08:45:30 -040025
26 "github.com/google/blueprint/proptools"
Jingwen Chen91220d72021-03-24 02:18:33 -040027)
28
Liz Kammer2222c6b2021-05-24 15:41:47 -040029// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
Jingwen Chenbcf53042021-05-26 04:42:42 +000030// properties which apply to either the shared or static version of a cc_library module.
Liz Kammer2222c6b2021-05-24 15:41:47 -040031type staticOrSharedAttributes struct {
Jingwen Chenc4dc9b42021-06-11 12:51:48 +000032 Srcs bazel.LabelListAttribute
33 Srcs_c bazel.LabelListAttribute
34 Srcs_as bazel.LabelListAttribute
35 Copts bazel.StringListAttribute
Jingwen Chen14a8bda2021-06-02 11:10:02 +000036
Liz Kammer7a210ac2021-09-22 15:52:58 -040037 Deps bazel.LabelListAttribute
38 Implementation_deps bazel.LabelListAttribute
39 Dynamic_deps bazel.LabelListAttribute
40 Implementation_dynamic_deps bazel.LabelListAttribute
41 Whole_archive_deps bazel.LabelListAttribute
Chris Parsons51f8c392021-08-03 21:01:05 -040042
43 System_dynamic_deps bazel.LabelListAttribute
Jingwen Chen53681ef2021-04-29 08:15:13 +000044}
45
Jingwen Chen14a8bda2021-06-02 11:10:02 +000046func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
Jingwen Chen14a8bda2021-06-02 11:10:02 +000047 // Check that a module is a filegroup type named <label>.
48 isFilegroupNamed := func(m android.Module, fullLabel string) bool {
49 if ctx.OtherModuleType(m) != "filegroup" {
50 return false
51 }
52 labelParts := strings.Split(fullLabel, ":")
53 if len(labelParts) > 2 {
54 // There should not be more than one colon in a label.
Liz Kammer57e2e7a2021-09-20 12:55:02 -040055 ctx.ModuleErrorf("%s is not a valid Bazel label for a filegroup", fullLabel)
Jingwen Chen14a8bda2021-06-02 11:10:02 +000056 }
Liz Kammer57e2e7a2021-09-20 12:55:02 -040057 return m.Name() == labelParts[len(labelParts)-1]
Jingwen Chen14a8bda2021-06-02 11:10:02 +000058 }
59
Liz Kammer57e2e7a2021-09-20 12:55:02 -040060 // Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl
61 // macro.
62 addSuffixForFilegroup := func(suffix string) bazel.LabelMapper {
63 return func(ctx bazel.OtherModuleContext, label string) (string, bool) {
64 m, exists := ctx.ModuleFromName(label)
65 if !exists {
66 return label, false
Jingwen Chen14a8bda2021-06-02 11:10:02 +000067 }
Chris Parsons5a34ffb2021-07-21 14:34:58 -040068 aModule, _ := m.(android.Module)
Liz Kammer57e2e7a2021-09-20 12:55:02 -040069 if !isFilegroupNamed(aModule, label) {
70 return label, false
Jingwen Chen14a8bda2021-06-02 11:10:02 +000071 }
Liz Kammer57e2e7a2021-09-20 12:55:02 -040072 return label + suffix, true
Chris Parsons5a34ffb2021-07-21 14:34:58 -040073 }
Jingwen Chen14a8bda2021-06-02 11:10:02 +000074 }
75
Liz Kammer57e2e7a2021-09-20 12:55:02 -040076 // TODO(b/190006308): Handle language detection of sources in a Bazel rule.
77 partitioned := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
78 "c": bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
79 "as": bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
80 // C++ is the "catch-all" group, and comprises generated sources because we don't
81 // know the language of these sources until the genrule is executed.
82 "cpp": bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
83 })
Jingwen Chen14a8bda2021-06-02 11:10:02 +000084
Liz Kammer57e2e7a2021-09-20 12:55:02 -040085 cSrcs = partitioned["c"]
86 asSrcs = partitioned["as"]
87 cppSrcs = partitioned["cpp"]
Jingwen Chen14a8bda2021-06-02 11:10:02 +000088 return
89}
90
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000091// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
92func bp2BuildParseLibProps(ctx android.TopDownMutatorContext, module *Module, isStatic bool) staticOrSharedAttributes {
Jingwen Chen53681ef2021-04-29 08:15:13 +000093 lib, ok := module.compiler.(*libraryDecorator)
94 if !ok {
Liz Kammer2222c6b2021-05-24 15:41:47 -040095 return staticOrSharedAttributes{}
Jingwen Chen53681ef2021-04-29 08:15:13 +000096 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +000097 return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic)
98}
Jingwen Chen53681ef2021-04-29 08:15:13 +000099
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000100// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
101func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes {
102 return bp2BuildParseLibProps(ctx, module, false)
Jingwen Chen53681ef2021-04-29 08:15:13 +0000103}
104
105// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
Liz Kammer2222c6b2021-05-24 15:41:47 -0400106func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000107 return bp2BuildParseLibProps(ctx, module, true)
Liz Kammer2222c6b2021-05-24 15:41:47 -0400108}
109
Liz Kammer7a210ac2021-09-22 15:52:58 -0400110type depsPartition struct {
111 export bazel.LabelList
112 implementation bazel.LabelList
113}
114
115type bazelLabelForDepsFn func(android.TopDownMutatorContext, []string) bazel.LabelList
116
117func partitionExportedAndImplementationsDeps(ctx android.TopDownMutatorContext, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
118 implementation, export := android.FilterList(allDeps, exportedDeps)
119
120 return depsPartition{
121 export: fn(ctx, export),
122 implementation: fn(ctx, implementation),
123 }
124}
125
126type bazelLabelForDepsExcludesFn func(android.TopDownMutatorContext, []string, []string) bazel.LabelList
127
128func partitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMutatorContext, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
129 implementation, export := android.FilterList(allDeps, exportedDeps)
130
131 return depsPartition{
132 export: fn(ctx, export, excludes),
133 implementation: fn(ctx, implementation, excludes),
134 }
135}
136
Jingwen Chenbcf53042021-05-26 04:42:42 +0000137func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
Liz Kammer135bf552021-08-11 10:46:06 -0400138 attrs := staticOrSharedAttributes{}
Jingwen Chenbcf53042021-05-26 04:42:42 +0000139
Liz Kammer9abd62d2021-05-21 08:37:59 -0400140 setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
Jingwen Chenc4dc9b42021-06-11 12:51:48 +0000141 attrs.Copts.SetSelectValue(axis, config, props.Cflags)
142 attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
Chris Parsons953b3562021-09-20 15:14:39 -0400143 attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
Liz Kammer7a210ac2021-09-22 15:52:58 -0400144
145 staticDeps := partitionExportedAndImplementationsDeps(ctx, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
146 attrs.Deps.SetSelectValue(axis, config, staticDeps.export)
147 attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation)
148
149 sharedDeps := partitionExportedAndImplementationsDeps(ctx, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
150 attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export)
151 attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
152
153 attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
Jingwen Chenbcf53042021-05-26 04:42:42 +0000154 }
Liz Kammer135bf552021-08-11 10:46:06 -0400155 // system_dynamic_deps distinguishes between nil/empty list behavior:
156 // nil -> use default values
157 // empty list -> no values specified
158 attrs.System_dynamic_deps.ForceSpecifyEmptyList = true
Jingwen Chenbcf53042021-05-26 04:42:42 +0000159
160 if isStatic {
Liz Kammer9abd62d2021-05-21 08:37:59 -0400161 for axis, configToProps := range module.GetArchVariantProperties(ctx, &StaticProperties{}) {
162 for config, props := range configToProps {
163 if staticOrSharedProps, ok := props.(*StaticProperties); ok {
164 setAttrs(axis, config, staticOrSharedProps.Static)
Jingwen Chenbcf53042021-05-26 04:42:42 +0000165 }
166 }
167 }
168 } else {
Liz Kammer9abd62d2021-05-21 08:37:59 -0400169 for axis, configToProps := range module.GetArchVariantProperties(ctx, &SharedProperties{}) {
170 for config, props := range configToProps {
171 if staticOrSharedProps, ok := props.(*SharedProperties); ok {
172 setAttrs(axis, config, staticOrSharedProps.Shared)
Jingwen Chenbcf53042021-05-26 04:42:42 +0000173 }
174 }
175 }
176 }
177
Jingwen Chenc4dc9b42021-06-11 12:51:48 +0000178 cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
179 attrs.Srcs = cppSrcs
180 attrs.Srcs_c = cSrcs
181 attrs.Srcs_as = asSrcs
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000182
Jingwen Chenbcf53042021-05-26 04:42:42 +0000183 return attrs
Jingwen Chen53681ef2021-04-29 08:15:13 +0000184}
185
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400186// Convenience struct to hold all attributes parsed from prebuilt properties.
187type prebuiltAttributes struct {
188 Src bazel.LabelAttribute
189}
190
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxac5097f2021-09-01 21:22:09 +0000191// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400192func Bp2BuildParsePrebuiltLibraryProps(ctx android.TopDownMutatorContext, module *Module) prebuiltAttributes {
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400193 var srcLabelAttribute bazel.LabelAttribute
194
Liz Kammer9abd62d2021-05-21 08:37:59 -0400195 for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltLinkerProperties{}) {
196 for config, props := range configToProps {
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400197 if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
198 if len(prebuiltLinkerProperties.Srcs) > 1 {
Liz Kammer9abd62d2021-05-21 08:37:59 -0400199 ctx.ModuleErrorf("Bp2BuildParsePrebuiltLibraryProps: Expected at most once source file for %s %s\n", axis, config)
200 continue
201 } else if len(prebuiltLinkerProperties.Srcs) == 0 {
202 continue
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400203 }
Liz Kammer9abd62d2021-05-21 08:37:59 -0400204 src := android.BazelLabelForModuleSrcSingle(ctx, prebuiltLinkerProperties.Srcs[0])
205 srcLabelAttribute.SetSelectValue(axis, config, src)
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400206 }
207 }
208 }
209
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400210 return prebuiltAttributes{
211 Src: srcLabelAttribute,
212 }
213}
214
Jingwen Chen107c0de2021-04-09 10:43:12 +0000215// Convenience struct to hold all attributes parsed from compiler properties.
216type compilerAttributes struct {
Chris Parsons990c4f42021-05-25 12:10:58 -0400217 // Options for all languages
218 copts bazel.StringListAttribute
219 // Assembly options and sources
220 asFlags bazel.StringListAttribute
221 asSrcs bazel.LabelListAttribute
222 // C options and sources
223 conlyFlags bazel.StringListAttribute
224 cSrcs bazel.LabelListAttribute
225 // C++ options and sources
226 cppFlags bazel.StringListAttribute
Jingwen Chened9c17d2021-04-13 07:14:55 +0000227 srcs bazel.LabelListAttribute
Chris Parsons2c788392021-08-10 11:58:07 -0400228
229 rtti bazel.BoolAttribute
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000230
231 // Not affected by arch variants
232 stl *string
233 cppStd *string
Liz Kammer35687bc2021-09-10 10:07:07 -0400234
235 localIncludes bazel.StringListAttribute
236 absoluteIncludes bazel.StringListAttribute
Jingwen Chen107c0de2021-04-09 10:43:12 +0000237}
238
Jingwen Chen63930982021-03-24 10:04:33 -0400239// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
Jingwen Chen107c0de2021-04-09 10:43:12 +0000240func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
Jingwen Chen882bcc12021-04-27 05:54:20 +0000241 var srcs bazel.LabelListAttribute
Jingwen Chen107c0de2021-04-09 10:43:12 +0000242 var copts bazel.StringListAttribute
Chris Parsons990c4f42021-05-25 12:10:58 -0400243 var asFlags bazel.StringListAttribute
244 var conlyFlags bazel.StringListAttribute
245 var cppFlags bazel.StringListAttribute
Chris Parsons2c788392021-08-10 11:58:07 -0400246 var rtti bazel.BoolAttribute
Liz Kammer35687bc2021-09-10 10:07:07 -0400247 var localIncludes bazel.StringListAttribute
248 var absoluteIncludes bazel.StringListAttribute
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000249 var stl *string = nil
250 var cppStd *string = nil
Jingwen Chened9c17d2021-04-13 07:14:55 +0000251
Chris Parsons990c4f42021-05-25 12:10:58 -0400252 parseCommandLineFlags := func(soongFlags []string) []string {
253 var result []string
254 for _, flag := range soongFlags {
Colin Cross52aa4e12021-05-25 15:20:39 +0000255 // Soong's cflags can contain spaces, like `-include header.h`. For
256 // Bazel's copts, split them up to be compatible with the
257 // no_copts_tokenization feature.
Chris Parsons990c4f42021-05-25 12:10:58 -0400258 result = append(result, strings.Split(flag, " ")...)
Colin Cross52aa4e12021-05-25 15:20:39 +0000259 }
Chris Parsons990c4f42021-05-25 12:10:58 -0400260 return result
261 }
262
Liz Kammer74deed42021-06-02 13:02:03 -0400263 // Parse srcs from an arch or OS's props value.
Liz Kammer222bdcf2021-10-11 14:15:51 -0400264 parseSrcs := func(props *BaseCompilerProperties) (bazel.LabelList, bool) {
265 anySrcs := false
Chris Parsons484e50a2021-05-13 15:13:04 -0400266 // Add srcs-like dependencies such as generated files.
267 // First create a LabelList containing these dependencies, then merge the values with srcs.
Liz Kammer222bdcf2021-10-11 14:15:51 -0400268 generatedHdrsAndSrcs := props.Generated_headers
269 generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, props.Generated_sources...)
270 generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, generatedHdrsAndSrcs, props.Exclude_generated_sources)
271 if len(generatedHdrsAndSrcs) > 0 || len(props.Exclude_generated_sources) > 0 {
272 anySrcs = true
273 }
Chris Parsons484e50a2021-05-13 15:13:04 -0400274
Liz Kammer222bdcf2021-10-11 14:15:51 -0400275 allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
276 if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
277 anySrcs = true
278 }
279 return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList), anySrcs
Jingwen Chene32e9e02021-04-23 09:17:24 +0000280 }
281
Liz Kammer9abd62d2021-05-21 08:37:59 -0400282 archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
Liz Kammer9abd62d2021-05-21 08:37:59 -0400283 for axis, configToProps := range archVariantCompilerProps {
284 for config, props := range configToProps {
285 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
286 // If there's arch specific srcs or exclude_srcs, generate a select entry for it.
287 // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
Liz Kammer222bdcf2021-10-11 14:15:51 -0400288 if srcsList, ok := parseSrcs(baseCompilerProps); ok {
Liz Kammer9abd62d2021-05-21 08:37:59 -0400289 srcs.SetSelectValue(axis, config, srcsList)
Liz Kammer9abd62d2021-05-21 08:37:59 -0400290 }
291
Jingwen Chen97b85312021-10-08 10:41:31 +0000292 if axis == bazel.NoConfigAxis {
293 // If cpp_std is not specified, don't generate it in the
294 // BUILD file. For readability purposes, cpp_std and gnu_extensions are
295 // combined into a single -std=<version> copt, except in the
296 // default case where cpp_std is nil and gnu_extensions is true or unspecified,
297 // then the toolchain's default "gnu++17" will be used.
298 if baseCompilerProps.Cpp_std != nil {
299 // TODO(b/202491296): Handle C_std.
300 // These transformations are shared with compiler.go.
301 cppStdVal := parseCppStd(baseCompilerProps.Cpp_std)
302 _, cppStdVal = maybeReplaceGnuToC(baseCompilerProps.Gnu_extensions, "", cppStdVal)
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000303 cppStd = &cppStdVal
Jingwen Chen97b85312021-10-08 10:41:31 +0000304 } else if baseCompilerProps.Gnu_extensions != nil && !*baseCompilerProps.Gnu_extensions {
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000305 cppStdVal := "c++17"
306 cppStd = &cppStdVal
Jingwen Chen97b85312021-10-08 10:41:31 +0000307 }
308 }
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000309
310 var archVariantCopts []string
Jingwen Chen97b85312021-10-08 10:41:31 +0000311 archVariantCopts = append(archVariantCopts, parseCommandLineFlags(baseCompilerProps.Cflags)...)
Chris Parsons69fa9f92021-07-13 11:47:44 -0400312 archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags)
Liz Kammer35687bc2021-09-10 10:07:07 -0400313
314 localIncludeDirs := baseCompilerProps.Local_include_dirs
315 if axis == bazel.NoConfigAxis && includeBuildDirectory(baseCompilerProps.Include_build_directory) {
316 localIncludeDirs = append(localIncludeDirs, ".")
Chris Parsons69fa9f92021-07-13 11:47:44 -0400317 }
318
Liz Kammer35687bc2021-09-10 10:07:07 -0400319 absoluteIncludes.SetSelectValue(axis, config, baseCompilerProps.Include_dirs)
320 localIncludes.SetSelectValue(axis, config, localIncludeDirs)
Liz Kammer135bf552021-08-11 10:46:06 -0400321
Chris Parsons69fa9f92021-07-13 11:47:44 -0400322 copts.SetSelectValue(axis, config, archVariantCopts)
323 asFlags.SetSelectValue(axis, config, archVariantAsflags)
Liz Kammer9abd62d2021-05-21 08:37:59 -0400324 conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Conlyflags))
325 cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Cppflags))
Chris Parsons2c788392021-08-10 11:58:07 -0400326 rtti.SetSelectValue(axis, config, baseCompilerProps.Rtti)
Liz Kammer9abd62d2021-05-21 08:37:59 -0400327 }
Jingwen Chenc1c26502021-04-05 10:35:13 +0000328 }
329 }
330
Liz Kammer74deed42021-06-02 13:02:03 -0400331 srcs.ResolveExcludes()
Liz Kammer35687bc2021-09-10 10:07:07 -0400332 absoluteIncludes.DeduplicateAxesFromBase()
333 localIncludes.DeduplicateAxesFromBase()
Jingwen Chenc1c26502021-04-05 10:35:13 +0000334
Liz Kammerba7a9c52021-05-26 08:45:30 -0400335 productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
336 "Cflags": &copts,
337 "Asflags": &asFlags,
338 "CppFlags": &cppFlags,
339 }
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400340 productVariableProps := android.ProductVariableProperties(ctx)
Liz Kammerba7a9c52021-05-26 08:45:30 -0400341 for propName, attr := range productVarPropNameToAttribute {
342 if props, exists := productVariableProps[propName]; exists {
343 for _, prop := range props {
344 flags, ok := prop.Property.([]string)
345 if !ok {
346 ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
347 }
348 newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
Liz Kammer47535c52021-06-02 16:02:22 -0400349 attr.SetSelectValue(bazel.ProductVariableConfigurationAxis(prop.FullConfig), prop.FullConfig, newFlags)
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400350 }
Liz Kammer6fd7b3f2021-05-06 13:54:29 -0400351 }
352 }
353
Jingwen Chen14a8bda2021-06-02 11:10:02 +0000354 srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs)
355
Chris Parsonsa967f252021-09-23 16:34:35 -0400356 stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{})
357 for _, configToProps := range stlPropsByArch {
358 for _, props := range configToProps {
359 if stlProps, ok := props.(*StlProperties); ok {
360 if stlProps.Stl != nil {
361 if stl == nil {
362 stl = stlProps.Stl
363 } else {
364 if stl != stlProps.Stl {
365 ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *stl, stlProps.Stl)
366 }
367 }
368 }
369 }
370 }
371 }
372
Jingwen Chen107c0de2021-04-09 10:43:12 +0000373 return compilerAttributes{
Liz Kammer35687bc2021-09-10 10:07:07 -0400374 copts: copts,
375 srcs: srcs,
376 asFlags: asFlags,
377 asSrcs: asSrcs,
378 cSrcs: cSrcs,
379 conlyFlags: conlyFlags,
380 cppFlags: cppFlags,
381 rtti: rtti,
Chris Parsonsa967f252021-09-23 16:34:35 -0400382 stl: stl,
Jingwen Chen5b11ab12021-10-11 17:44:33 +0000383 cppStd: cppStd,
Liz Kammer35687bc2021-09-10 10:07:07 -0400384 localIncludes: localIncludes,
385 absoluteIncludes: absoluteIncludes,
Jingwen Chen107c0de2021-04-09 10:43:12 +0000386 }
387}
388
389// Convenience struct to hold all attributes parsed from linker properties.
390type linkerAttributes struct {
Liz Kammer7a210ac2021-09-22 15:52:58 -0400391 deps bazel.LabelListAttribute
392 implementationDeps bazel.LabelListAttribute
393 dynamicDeps bazel.LabelListAttribute
394 implementationDynamicDeps bazel.LabelListAttribute
395 wholeArchiveDeps bazel.LabelListAttribute
396 systemDynamicDeps bazel.LabelListAttribute
397
Jingwen Chen6ada5892021-09-17 11:38:09 +0000398 linkCrt bazel.BoolAttribute
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000399 useLibcrt bazel.BoolAttribute
400 linkopts bazel.StringListAttribute
Liz Kammerd2871182021-10-04 13:54:37 -0400401 additionalLinkerInputs bazel.LabelListAttribute
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000402 stripKeepSymbols bazel.BoolAttribute
403 stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
404 stripKeepSymbolsList bazel.StringListAttribute
405 stripAll bazel.BoolAttribute
406 stripNone bazel.BoolAttribute
Liz Kammer0eae52e2021-10-06 10:32:26 -0400407 features bazel.StringListAttribute
Rupert Shuttleworth143be942021-05-09 23:55:51 -0400408}
409
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200410// bp2BuildParseLinkerProps parses the linker properties of a module, including
Jingwen Chen91220d72021-03-24 02:18:33 -0400411// configurable attribute values.
Jingwen Chen107c0de2021-04-09 10:43:12 +0000412func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
Liz Kammer7a210ac2021-09-22 15:52:58 -0400413
Liz Kammer47535c52021-06-02 16:02:22 -0400414 var headerDeps bazel.LabelListAttribute
Liz Kammer7a210ac2021-09-22 15:52:58 -0400415 var implementationHeaderDeps bazel.LabelListAttribute
416 var deps bazel.LabelListAttribute
417 var implementationDeps bazel.LabelListAttribute
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400418 var dynamicDeps bazel.LabelListAttribute
Liz Kammer7a210ac2021-09-22 15:52:58 -0400419 var implementationDynamicDeps bazel.LabelListAttribute
Chris Parsons08648312021-05-06 16:23:19 -0400420 var wholeArchiveDeps bazel.LabelListAttribute
Liz Kammer135bf552021-08-11 10:46:06 -0400421 systemSharedDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
Liz Kammer7a210ac2021-09-22 15:52:58 -0400422
Jingwen Chen63930982021-03-24 10:04:33 -0400423 var linkopts bazel.StringListAttribute
Jingwen Chen6ada5892021-09-17 11:38:09 +0000424 var linkCrt bazel.BoolAttribute
Liz Kammerd2871182021-10-04 13:54:37 -0400425 var additionalLinkerInputs bazel.LabelListAttribute
Liz Kammerd366c902021-06-03 13:43:01 -0400426 var useLibcrt bazel.BoolAttribute
Jingwen Chen63930982021-03-24 10:04:33 -0400427
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000428 var stripKeepSymbols bazel.BoolAttribute
429 var stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
430 var stripKeepSymbolsList bazel.StringListAttribute
431 var stripAll bazel.BoolAttribute
432 var stripNone bazel.BoolAttribute
433
Liz Kammer0eae52e2021-10-06 10:32:26 -0400434 var features bazel.StringListAttribute
435
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000436 for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
437 for config, props := range configToProps {
438 if stripProperties, ok := props.(*StripProperties); ok {
439 stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols)
440 stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list)
441 stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame)
442 stripAll.SetSelectValue(axis, config, stripProperties.Strip.All)
443 stripNone.SetSelectValue(axis, config, stripProperties.Strip.None)
444 }
445 }
446 }
447
Jingwen Chen6ada5892021-09-17 11:38:09 +0000448 // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
449 var disallowedArchVariantCrt bool
450
Liz Kammer9abd62d2021-05-21 08:37:59 -0400451 for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
452 for config, props := range configToProps {
453 if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
Liz Kammer0eae52e2021-10-06 10:32:26 -0400454 var axisFeatures []string
Liz Kammer7a210ac2021-09-22 15:52:58 -0400455
Liz Kammer135bf552021-08-11 10:46:06 -0400456 // Excludes to parallel Soong:
457 // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
Liz Kammer47535c52021-06-02 16:02:22 -0400458 staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs)
Liz Kammer7a210ac2021-09-22 15:52:58 -0400459 staticDeps := partitionExportedAndImplementationsDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs, baseLinkerProps.Export_static_lib_headers, bazelLabelForStaticDepsExcludes)
460 deps.SetSelectValue(axis, config, staticDeps.export)
461 implementationDeps.SetSelectValue(axis, config, staticDeps.implementation)
462
463 wholeStaticLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs)
464 wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, baseLinkerProps.Exclude_static_libs))
Chris Parsons51f8c392021-08-03 21:01:05 -0400465
Liz Kammer135bf552021-08-11 10:46:06 -0400466 systemSharedLibs := baseLinkerProps.System_shared_libs
467 // systemSharedLibs distinguishes between nil/empty list behavior:
468 // nil -> use default values
469 // empty list -> no values specified
470 if len(systemSharedLibs) > 0 {
471 systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
Chris Parsons51f8c392021-08-03 21:01:05 -0400472 }
Chris Parsons953b3562021-09-20 15:14:39 -0400473 systemSharedDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
Chris Parsons51f8c392021-08-03 21:01:05 -0400474
475 sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs)
Liz Kammer7a210ac2021-09-22 15:52:58 -0400476 sharedDeps := partitionExportedAndImplementationsDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs, baseLinkerProps.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
477 dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
478 implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -0400479
Liz Kammer47535c52021-06-02 16:02:22 -0400480 headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs)
Liz Kammer7a210ac2021-09-22 15:52:58 -0400481 hDeps := partitionExportedAndImplementationsDeps(ctx, headerLibs, baseLinkerProps.Export_header_lib_headers, bazelLabelForHeaderDeps)
482
483 headerDeps.SetSelectValue(axis, config, hDeps.export)
484 implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
Liz Kammer47535c52021-06-02 16:02:22 -0400485
Liz Kammer0eae52e2021-10-06 10:32:26 -0400486 if !BoolDefault(baseLinkerProps.Pack_relocations, packRelocationsDefault) {
487 axisFeatures = append(axisFeatures, "disable_pack_relocations")
488 }
489
490 if Bool(baseLinkerProps.Allow_undefined_symbols) {
491 axisFeatures = append(axisFeatures, "-no_undefined_symbols")
492 }
493
Liz Kammerd2871182021-10-04 13:54:37 -0400494 var linkerFlags []string
495 if len(baseLinkerProps.Ldflags) > 0 {
496 linkerFlags = append(linkerFlags, baseLinkerProps.Ldflags...)
Rupert Shuttleworth22cd2eb2021-05-27 02:15:54 -0400497 }
Liz Kammerd2871182021-10-04 13:54:37 -0400498 if baseLinkerProps.Version_script != nil {
499 label := android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
500 additionalLinkerInputs.SetSelectValue(axis, config, bazel.LabelList{Includes: []bazel.Label{label}})
501 linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label))
502 }
503 linkopts.SetSelectValue(axis, config, linkerFlags)
Liz Kammerd366c902021-06-03 13:43:01 -0400504 useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt())
Jingwen Chen6ada5892021-09-17 11:38:09 +0000505
506 // it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
507 if baseLinkerProps.crt() != nil {
508 if axis == bazel.NoConfigAxis {
509 linkCrt.SetSelectValue(axis, config, baseLinkerProps.crt())
510 } else if axis == bazel.ArchConfigurationAxis {
511 disallowedArchVariantCrt = true
512 }
513 }
Liz Kammer0eae52e2021-10-06 10:32:26 -0400514
515 if axisFeatures != nil {
516 features.SetSelectValue(axis, config, axisFeatures)
517 }
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -0400518 }
Jingwen Chen91220d72021-03-24 02:18:33 -0400519 }
520 }
521
Jingwen Chen6ada5892021-09-17 11:38:09 +0000522 if disallowedArchVariantCrt {
523 ctx.ModuleErrorf("nocrt is not supported for arch variants")
524 }
525
Liz Kammer47535c52021-06-02 16:02:22 -0400526 type productVarDep struct {
527 // the name of the corresponding excludes field, if one exists
528 excludesField string
529 // reference to the bazel attribute that should be set for the given product variable config
530 attribute *bazel.LabelListAttribute
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400531
Chris Parsons953b3562021-09-20 15:14:39 -0400532 depResolutionFunc func(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList
Liz Kammer47535c52021-06-02 16:02:22 -0400533 }
534
535 productVarToDepFields := map[string]productVarDep{
536 // product variables do not support exclude_shared_libs
Liz Kammer7a210ac2021-09-22 15:52:58 -0400537 "Shared_libs": productVarDep{attribute: &implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
538 "Static_libs": productVarDep{"Exclude_static_libs", &implementationDeps, bazelLabelForStaticDepsExcludes},
Chris Parsons953b3562021-09-20 15:14:39 -0400539 "Whole_static_libs": productVarDep{"Exclude_static_libs", &wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
Liz Kammer47535c52021-06-02 16:02:22 -0400540 }
541
542 productVariableProps := android.ProductVariableProperties(ctx)
543 for name, dep := range productVarToDepFields {
544 props, exists := productVariableProps[name]
545 excludeProps, excludesExists := productVariableProps[dep.excludesField]
546 // if neither an include or excludes property exists, then skip it
547 if !exists && !excludesExists {
548 continue
549 }
550 // collect all the configurations that an include or exclude property exists for.
551 // we want to iterate all configurations rather than either the include or exclude because for a
552 // particular configuration we may have only and include or only an exclude to handle
553 configs := make(map[string]bool, len(props)+len(excludeProps))
554 for config := range props {
555 configs[config] = true
556 }
557 for config := range excludeProps {
558 configs[config] = true
559 }
560
561 for config := range configs {
562 prop, includesExists := props[config]
563 excludesProp, excludesExists := excludeProps[config]
564 var includes, excludes []string
565 var ok bool
566 // if there was no includes/excludes property, casting fails and that's expected
567 if includes, ok = prop.Property.([]string); includesExists && !ok {
568 ctx.ModuleErrorf("Could not convert product variable %s property", name)
569 }
570 if excludes, ok = excludesProp.Property.([]string); excludesExists && !ok {
571 ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField)
572 }
Liz Kammer2d7bbe32021-06-10 18:20:06 -0400573
574 dep.attribute.SetSelectValue(bazel.ProductVariableConfigurationAxis(config), config, dep.depResolutionFunc(ctx, android.FirstUniqueStrings(includes), excludes))
Liz Kammer47535c52021-06-02 16:02:22 -0400575 }
576 }
577
Liz Kammer7a210ac2021-09-22 15:52:58 -0400578 headerDeps.Append(deps)
579 implementationHeaderDeps.Append(implementationDeps)
580
581 headerDeps.ResolveExcludes()
582 implementationHeaderDeps.ResolveExcludes()
Liz Kammer47535c52021-06-02 16:02:22 -0400583 dynamicDeps.ResolveExcludes()
Liz Kammer7a210ac2021-09-22 15:52:58 -0400584 implementationDynamicDeps.ResolveExcludes()
Liz Kammer47535c52021-06-02 16:02:22 -0400585 wholeArchiveDeps.ResolveExcludes()
586
Jingwen Chen107c0de2021-04-09 10:43:12 +0000587 return linkerAttributes{
Liz Kammer7a210ac2021-09-22 15:52:58 -0400588 deps: headerDeps,
589 implementationDeps: implementationHeaderDeps,
590 dynamicDeps: dynamicDeps,
591 implementationDynamicDeps: implementationDynamicDeps,
592 wholeArchiveDeps: wholeArchiveDeps,
593 systemDynamicDeps: systemSharedDeps,
594
Liz Kammerd2871182021-10-04 13:54:37 -0400595 linkCrt: linkCrt,
596 linkopts: linkopts,
597 useLibcrt: useLibcrt,
598 additionalLinkerInputs: additionalLinkerInputs,
Jingwen Chen3d383bb2021-06-09 07:18:37 +0000599
600 // Strip properties
601 stripKeepSymbols: stripKeepSymbols,
602 stripKeepSymbolsAndDebugFrame: stripKeepSymbolsAndDebugFrame,
603 stripKeepSymbolsList: stripKeepSymbolsList,
604 stripAll: stripAll,
605 stripNone: stripNone,
Liz Kammer0eae52e2021-10-06 10:32:26 -0400606
607 features: features,
Jingwen Chen107c0de2021-04-09 10:43:12 +0000608 }
Jingwen Chen91220d72021-03-24 02:18:33 -0400609}
610
Jingwen Chened9c17d2021-04-13 07:14:55 +0000611// Relativize a list of root-relative paths with respect to the module's
612// directory.
613//
614// include_dirs Soong prop are root-relative (b/183742505), but
615// local_include_dirs, export_include_dirs and export_system_include_dirs are
616// module dir relative. This function makes a list of paths entirely module dir
617// relative.
618//
619// For the `include` attribute, Bazel wants the paths to be relative to the
620// module.
621func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string {
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000622 var relativePaths []string
623 for _, path := range paths {
Jingwen Chened9c17d2021-04-13 07:14:55 +0000624 // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path
625 relativePath, err := filepath.Rel(ctx.ModuleDir(), path)
626 if err != nil {
627 panic(err)
628 }
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000629 relativePaths = append(relativePaths, relativePath)
630 }
631 return relativePaths
632}
633
Liz Kammer5fad5012021-09-09 14:08:21 -0400634// BazelIncludes contains information about -I and -isystem paths from a module converted to Bazel
635// attributes.
636type BazelIncludes struct {
637 Includes bazel.StringListAttribute
638 SystemIncludes bazel.StringListAttribute
639}
640
641func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) BazelIncludes {
Jingwen Chen91220d72021-03-24 02:18:33 -0400642 libraryDecorator := module.linker.(*libraryDecorator)
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400643 return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
644}
Jingwen Chen91220d72021-03-24 02:18:33 -0400645
Liz Kammer5fad5012021-09-09 14:08:21 -0400646// Bp2buildParseExportedIncludesForPrebuiltLibrary returns a BazelIncludes with Bazel-ified values
647// to export includes from the underlying module's properties.
648func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.TopDownMutatorContext, module *Module) BazelIncludes {
Rupert Shuttleworthffd45822021-05-14 03:02:34 -0400649 prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker)
650 libraryDecorator := prebuiltLibraryLinker.libraryDecorator
651 return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
652}
653
654// bp2BuildParseExportedIncludes creates a string list attribute contains the
655// exported included directories of a module.
Liz Kammer5fad5012021-09-09 14:08:21 -0400656func bp2BuildParseExportedIncludesHelper(ctx android.TopDownMutatorContext, module *Module, libraryDecorator *libraryDecorator) BazelIncludes {
657 exported := BazelIncludes{}
Liz Kammer9abd62d2021-05-21 08:37:59 -0400658 for axis, configToProps := range module.GetArchVariantProperties(ctx, &FlagExporterProperties{}) {
659 for config, props := range configToProps {
660 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
Liz Kammer5fad5012021-09-09 14:08:21 -0400661 if len(flagExporterProperties.Export_include_dirs) > 0 {
662 exported.Includes.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs)
663 }
664 if len(flagExporterProperties.Export_system_include_dirs) > 0 {
665 exported.SystemIncludes.SetSelectValue(axis, config, flagExporterProperties.Export_system_include_dirs)
Rupert Shuttleworthc194ffb2021-05-19 06:49:02 -0400666 }
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400667 }
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400668 }
669 }
Liz Kammer5fad5012021-09-09 14:08:21 -0400670 exported.Includes.DeduplicateAxesFromBase()
671 exported.SystemIncludes.DeduplicateAxesFromBase()
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400672
Liz Kammer5fad5012021-09-09 14:08:21 -0400673 return exported
Jingwen Chen91220d72021-03-24 02:18:33 -0400674}
Chris Parsons953b3562021-09-20 15:14:39 -0400675
676func bazelLabelForStaticModule(ctx android.TopDownMutatorContext, m blueprint.Module) string {
677 label := android.BazelModuleLabel(ctx, m)
678 if aModule, ok := m.(android.Module); ok {
679 if ctx.OtherModuleType(aModule) == "cc_library" && !android.GenerateCcLibraryStaticOnly(m.Name()) {
680 label += "_bp2build_cc_library_static"
681 }
682 }
683 return label
684}
685
686func bazelLabelForSharedModule(ctx android.TopDownMutatorContext, m blueprint.Module) string {
687 // cc_library, at it's root name, propagates the shared library, which depends on the static
688 // library.
689 return android.BazelModuleLabel(ctx, m)
690}
691
692func bazelLabelForStaticWholeModuleDeps(ctx android.TopDownMutatorContext, m blueprint.Module) string {
693 label := bazelLabelForStaticModule(ctx, m)
694 if aModule, ok := m.(android.Module); ok {
695 if android.IsModulePrebuilt(aModule) {
696 label += "_alwayslink"
697 }
698 }
699 return label
700}
701
702func bazelLabelForWholeDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList {
703 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps)
704}
705
706func bazelLabelForWholeDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList {
707 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps)
708}
709
710func bazelLabelForStaticDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList {
711 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule)
712}
713
714func bazelLabelForStaticDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList {
715 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule)
716}
717
718func bazelLabelForSharedDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList {
719 return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule)
720}
721
722func bazelLabelForHeaderDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList {
723 // This is not elegant, but bp2build's shared library targets only propagate
724 // their header information as part of the normal C++ provider.
725 return bazelLabelForSharedDeps(ctx, modules)
726}
727
728func bazelLabelForSharedDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList {
729 return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
730}