blob: 7f2554fc1acb4526084ac913765d108a82885000 [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 (
17 "android/soong/android"
18 "android/soong/bazel"
Jingwen Chened9c17d2021-04-13 07:14:55 +000019 "path/filepath"
Jingwen Chen91220d72021-03-24 02:18:33 -040020)
21
22// bp2build functions and helpers for converting cc_* modules to Bazel.
23
24func init() {
25 android.DepsBp2BuildMutators(RegisterDepsBp2Build)
26}
27
28func RegisterDepsBp2Build(ctx android.RegisterMutatorsContext) {
29 ctx.BottomUp("cc_bp2build_deps", depsBp2BuildMutator)
30}
31
32// A naive deps mutator to add deps on all modules across all combinations of
33// target props for cc modules. This is needed to make module -> bazel label
34// resolution work in the bp2build mutator later. This is probably
35// the wrong way to do it, but it works.
36//
37// TODO(jingwen): can we create a custom os mutator in depsBp2BuildMutator to do this?
38func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
39 module, ok := ctx.Module().(*Module)
40 if !ok {
41 // Not a cc module
42 return
43 }
44
45 if !module.ConvertWithBp2build(ctx) {
46 return
47 }
48
49 var allDeps []string
50
51 for _, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
52 // arch specific linker props
53 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
54 allDeps = append(allDeps, baseLinkerProps.Header_libs...)
55 allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
Jingwen Chened9c17d2021-04-13 07:14:55 +000056 allDeps = append(allDeps, baseLinkerProps.Static_libs...)
57 allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
58 }
59 }
60
Lukacs T. Berki598dd002021-05-05 09:00:01 +020061 for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
Jingwen Chened9c17d2021-04-13 07:14:55 +000062 // arch specific linker props
63 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
64 allDeps = append(allDeps, baseLinkerProps.Header_libs...)
65 allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
66 allDeps = append(allDeps, baseLinkerProps.Static_libs...)
67 allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
Jingwen Chen91220d72021-03-24 02:18:33 -040068 }
69 }
70
Jingwen Chen53681ef2021-04-29 08:15:13 +000071 // Deps in the static: { .. } and shared: { .. } props of a cc_library.
72 if lib, ok := module.compiler.(*libraryDecorator); ok {
73 allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...)
74 allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...)
75 allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...)
76 allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...)
77
78 allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...)
79 allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...)
80 allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...)
81 allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...)
82 }
83
Jingwen Chen91220d72021-03-24 02:18:33 -040084 ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
85}
86
Jingwen Chen53681ef2021-04-29 08:15:13 +000087type sharedAttributes struct {
88 staticDeps bazel.LabelListAttribute
89}
90
91// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
92func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes {
93 lib, ok := module.compiler.(*libraryDecorator)
94 if !ok {
95 return sharedAttributes{}
96 }
97
98 var staticDeps bazel.LabelListAttribute
99
100 staticDeps.Value = android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)
101
102 return sharedAttributes{
103 staticDeps: staticDeps,
104 }
105}
106
107type staticAttributes struct {
108 srcs bazel.LabelListAttribute
109}
110
111// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
112func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes {
113 lib, ok := module.compiler.(*libraryDecorator)
114 if !ok {
115 return staticAttributes{}
116 }
117
118 var srcs bazel.LabelListAttribute
119 srcs.Value = android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)
120
121 return staticAttributes{
122 srcs: srcs,
123 }
124}
125
Jingwen Chen107c0de2021-04-09 10:43:12 +0000126// Convenience struct to hold all attributes parsed from compiler properties.
127type compilerAttributes struct {
Jingwen Chened9c17d2021-04-13 07:14:55 +0000128 copts bazel.StringListAttribute
129 srcs bazel.LabelListAttribute
130 includes bazel.StringListAttribute
Jingwen Chen107c0de2021-04-09 10:43:12 +0000131}
132
Jingwen Chen63930982021-03-24 10:04:33 -0400133// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
Jingwen Chen107c0de2021-04-09 10:43:12 +0000134func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
Jingwen Chen882bcc12021-04-27 05:54:20 +0000135 var srcs bazel.LabelListAttribute
Jingwen Chen107c0de2021-04-09 10:43:12 +0000136 var copts bazel.StringListAttribute
Jingwen Chen63930982021-03-24 10:04:33 -0400137
Jingwen Chened9c17d2021-04-13 07:14:55 +0000138 // Creates the -I flag for a directory, while making the directory relative
139 // to the exec root for Bazel to work.
140 includeFlag := func(dir string) string {
141 // filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements.
142 return "-I" + filepath.Join(ctx.ModuleDir(), dir)
143 }
144
Jingwen Chened9c17d2021-04-13 07:14:55 +0000145 // Parse the list of module-relative include directories (-I).
146 parseLocalIncludeDirs := func(baseCompilerProps *BaseCompilerProperties) []string {
147 // include_dirs are root-relative, not module-relative.
148 includeDirs := bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
149 return append(includeDirs, baseCompilerProps.Local_include_dirs...)
150 }
151
152 // Parse the list of copts.
153 parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string {
154 copts := append([]string{}, baseCompilerProps.Cflags...)
155 for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
156 copts = append(copts, includeFlag(dir))
157 }
158 return copts
Jingwen Chen63930982021-03-24 10:04:33 -0400159 }
160
Jingwen Chene32e9e02021-04-23 09:17:24 +0000161 // baseSrcs contain the list of src files that are used for every configuration.
162 var baseSrcs []string
163 // baseExcludeSrcs contain the list of src files that are excluded for every configuration.
164 var baseExcludeSrcs []string
165 // baseSrcsLabelList is a clone of the base srcs LabelList, used for computing the
166 // arch or os specific srcs later.
167 var baseSrcsLabelList bazel.LabelList
168
169 // Parse srcs from an arch or OS's props value, taking the base srcs and
170 // exclude srcs into account.
171 parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {
172 // Combine the base srcs and arch-specific srcs
173 allSrcs := append(baseSrcs, baseCompilerProps.Srcs...)
174 // Combine the base exclude_srcs and configuration-specific exclude_srcs
175 allExcludeSrcs := append(baseExcludeSrcs, baseCompilerProps.Exclude_srcs...)
176 return android.BazelLabelForModuleSrcExcludes(ctx, allSrcs, allExcludeSrcs)
177 }
178
Jingwen Chenc1c26502021-04-05 10:35:13 +0000179 for _, props := range module.compiler.compilerProps() {
180 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
Jingwen Chened9c17d2021-04-13 07:14:55 +0000181 srcs.Value = parseSrcs(baseCompilerProps)
182 copts.Value = parseCopts(baseCompilerProps)
Jingwen Chene32e9e02021-04-23 09:17:24 +0000183
184 // Used for arch-specific srcs later.
185 baseSrcs = baseCompilerProps.Srcs
186 baseExcludeSrcs = baseCompilerProps.Exclude_srcs
187 baseSrcsLabelList = parseSrcs(baseCompilerProps)
Jingwen Chenc1c26502021-04-05 10:35:13 +0000188 break
189 }
190 }
191
Jingwen Chene32e9e02021-04-23 09:17:24 +0000192 // Handle include_build_directory prop. If the property is true, then the
193 // target has access to all headers recursively in the package, and has
194 // "-I<module-dir>" in its copts.
Jingwen Chened9c17d2021-04-13 07:14:55 +0000195 if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {
196 copts.Value = append(copts.Value, includeFlag("."))
Jingwen Chened9c17d2021-04-13 07:14:55 +0000197 } else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() {
198 copts.Value = append(copts.Value, includeFlag("."))
Jingwen Chened9c17d2021-04-13 07:14:55 +0000199 }
200
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200201 for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
Jingwen Chenc1c26502021-04-05 10:35:13 +0000202 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
Jingwen Chene32e9e02021-04-23 09:17:24 +0000203 // If there's arch specific srcs or exclude_srcs, generate a select entry for it.
204 // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
205 if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
206 srcsList := parseSrcs(baseCompilerProps)
207 srcs.SetValueForArch(arch.Name, srcsList)
208 // The base srcs value should not contain any arch-specific excludes.
209 srcs.Value = bazel.SubtractBazelLabelList(srcs.Value, bazel.LabelList{Includes: srcsList.Excludes})
210 }
211
Jingwen Chened9c17d2021-04-13 07:14:55 +0000212 copts.SetValueForArch(arch.Name, parseCopts(baseCompilerProps))
Jingwen Chenc1c26502021-04-05 10:35:13 +0000213 }
214 }
215
Jingwen Chene32e9e02021-04-23 09:17:24 +0000216 // After going through all archs, delete the duplicate files in the arch
217 // values that are already in the base srcs.Value.
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200218 for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
Jingwen Chene32e9e02021-04-23 09:17:24 +0000219 if _, ok := props.(*BaseCompilerProperties); ok {
220 srcs.SetValueForArch(arch.Name, bazel.SubtractBazelLabelList(srcs.GetValueForArch(arch.Name), srcs.Value))
221 }
222 }
223
224 // Now that the srcs.Value list is finalized, compare it with the original
225 // list, and put the difference into the default condition for the arch
226 // select.
227 defaultsSrcs := bazel.SubtractBazelLabelList(baseSrcsLabelList, srcs.Value)
228 // TODO(b/186153868): handle the case with multiple variant types, e.g. when arch and os are both used.
229 srcs.SetValueForArch(bazel.CONDITIONS_DEFAULT, defaultsSrcs)
230
231 // Handle OS specific props.
Jingwen Chenc1c26502021-04-05 10:35:13 +0000232 for os, props := range module.GetTargetProperties(&BaseCompilerProperties{}) {
233 if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
Jingwen Chened9c17d2021-04-13 07:14:55 +0000234 srcsList := parseSrcs(baseCompilerProps)
Jingwen Chene32e9e02021-04-23 09:17:24 +0000235 // TODO(b/186153868): add support for os-specific srcs and exclude_srcs
236 srcs.SetValueForOS(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
Jingwen Chened9c17d2021-04-13 07:14:55 +0000237 copts.SetValueForOS(os.Name, parseCopts(baseCompilerProps))
Jingwen Chenc1c26502021-04-05 10:35:13 +0000238 }
239 }
240
Jingwen Chen107c0de2021-04-09 10:43:12 +0000241 return compilerAttributes{
Jingwen Chen107c0de2021-04-09 10:43:12 +0000242 srcs: srcs,
243 copts: copts,
244 }
245}
246
247// Convenience struct to hold all attributes parsed from linker properties.
248type linkerAttributes struct {
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200249 deps bazel.LabelListAttribute
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400250 dynamicDeps bazel.LabelListAttribute
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200251 linkopts bazel.StringListAttribute
252 versionScript bazel.LabelAttribute
Jingwen Chenc1c26502021-04-05 10:35:13 +0000253}
254
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200255// bp2BuildParseLinkerProps parses the linker properties of a module, including
Jingwen Chen91220d72021-03-24 02:18:33 -0400256// configurable attribute values.
Jingwen Chen107c0de2021-04-09 10:43:12 +0000257func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
Jingwen Chen63930982021-03-24 10:04:33 -0400258 var deps bazel.LabelListAttribute
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400259 var dynamicDeps bazel.LabelListAttribute
Jingwen Chen63930982021-03-24 10:04:33 -0400260 var linkopts bazel.StringListAttribute
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200261 var versionScript bazel.LabelAttribute
Jingwen Chen63930982021-03-24 10:04:33 -0400262
Jingwen Chen91220d72021-03-24 02:18:33 -0400263 for _, linkerProps := range module.linker.linkerProps() {
264 if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
265 libs := baseLinkerProps.Header_libs
266 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
Jingwen Chened9c17d2021-04-13 07:14:55 +0000267 libs = append(libs, baseLinkerProps.Static_libs...)
268 libs = append(libs, baseLinkerProps.Whole_static_libs...)
269 libs = android.SortedUniqueStrings(libs)
270 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400271
Jingwen Chen63930982021-03-24 10:04:33 -0400272 linkopts.Value = baseLinkerProps.Ldflags
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200273
274 if baseLinkerProps.Version_script != nil {
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200275 versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200276 }
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400277
278 sharedLibs := baseLinkerProps.Shared_libs
279 dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs))
280
Jingwen Chen91220d72021-03-24 02:18:33 -0400281 break
282 }
283 }
284
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200285 for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
Jingwen Chen63930982021-03-24 10:04:33 -0400286 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
287 libs := baseLinkerProps.Header_libs
288 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
Jingwen Chened9c17d2021-04-13 07:14:55 +0000289 libs = append(libs, baseLinkerProps.Static_libs...)
290 libs = append(libs, baseLinkerProps.Whole_static_libs...)
Jingwen Chen63930982021-03-24 10:04:33 -0400291 libs = android.SortedUniqueStrings(libs)
292 deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400293
Jingwen Chen63930982021-03-24 10:04:33 -0400294 linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags)
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400295
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200296 if baseLinkerProps.Version_script != nil {
297 versionScript.SetValueForArch(arch.Name,
298 android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400299
300 sharedLibs := baseLinkerProps.Shared_libs
301 dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200302 }
Jingwen Chen63930982021-03-24 10:04:33 -0400303 }
304 }
305
Jingwen Chen91220d72021-03-24 02:18:33 -0400306 for os, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
307 if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
308 libs := baseLinkerProps.Header_libs
309 libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
Jingwen Chened9c17d2021-04-13 07:14:55 +0000310 libs = append(libs, baseLinkerProps.Static_libs...)
311 libs = append(libs, baseLinkerProps.Whole_static_libs...)
Jingwen Chen91220d72021-03-24 02:18:33 -0400312 libs = android.SortedUniqueStrings(libs)
Jingwen Chen63930982021-03-24 10:04:33 -0400313 deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400314
Jingwen Chen63930982021-03-24 10:04:33 -0400315 linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags)
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400316
317 sharedLibs := baseLinkerProps.Shared_libs
318 dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
Jingwen Chen91220d72021-03-24 02:18:33 -0400319 }
320 }
321
Jingwen Chen107c0de2021-04-09 10:43:12 +0000322 return linkerAttributes{
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200323 deps: deps,
Rupert Shuttleworthc50fa8d2021-05-06 02:40:33 -0400324 dynamicDeps: dynamicDeps,
Lukacs T. Berki1353e592021-04-30 15:35:09 +0200325 linkopts: linkopts,
326 versionScript: versionScript,
Jingwen Chen107c0de2021-04-09 10:43:12 +0000327 }
Jingwen Chen91220d72021-03-24 02:18:33 -0400328}
329
Jingwen Chened9c17d2021-04-13 07:14:55 +0000330// Relativize a list of root-relative paths with respect to the module's
331// directory.
332//
333// include_dirs Soong prop are root-relative (b/183742505), but
334// local_include_dirs, export_include_dirs and export_system_include_dirs are
335// module dir relative. This function makes a list of paths entirely module dir
336// relative.
337//
338// For the `include` attribute, Bazel wants the paths to be relative to the
339// module.
340func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string {
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000341 var relativePaths []string
342 for _, path := range paths {
Jingwen Chened9c17d2021-04-13 07:14:55 +0000343 // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path
344 relativePath, err := filepath.Rel(ctx.ModuleDir(), path)
345 if err != nil {
346 panic(err)
347 }
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000348 relativePaths = append(relativePaths, relativePath)
349 }
350 return relativePaths
351}
352
Jingwen Chened9c17d2021-04-13 07:14:55 +0000353// bp2BuildParseExportedIncludes creates a string list attribute contains the
Jingwen Chen882bcc12021-04-27 05:54:20 +0000354// exported included directories of a module.
355func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute {
Jingwen Chen91220d72021-03-24 02:18:33 -0400356 libraryDecorator := module.linker.(*libraryDecorator)
357
Jingwen Chened9c17d2021-04-13 07:14:55 +0000358 // Export_system_include_dirs and export_include_dirs are already module dir
359 // relative, so they don't need to be relativized like include_dirs, which
360 // are root-relative.
Jingwen Chen91220d72021-03-24 02:18:33 -0400361 includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs
362 includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000363 includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs)
Jingwen Chen91220d72021-03-24 02:18:33 -0400364
Lukacs T. Berki598dd002021-05-05 09:00:01 +0200365 for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000366 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
367 archIncludeDirs := flagExporterProperties.Export_system_include_dirs
368 archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...)
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000369
370 // To avoid duplicate includes when base includes + arch includes are combined
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400371 // FIXME: This doesn't take conflicts between arch and os includes into account
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000372 archIncludeDirs = bazel.SubtractStrings(archIncludeDirs, includeDirs)
373
374 if len(archIncludeDirs) > 0 {
375 includeDirsAttribute.SetValueForArch(arch.Name, archIncludeDirs)
376 }
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000377 }
Jingwen Chen91220d72021-03-24 02:18:33 -0400378 }
379
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400380 for os, props := range module.GetTargetProperties(&FlagExporterProperties{}) {
381 if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
382 osIncludeDirs := flagExporterProperties.Export_system_include_dirs
383 osIncludeDirs = append(osIncludeDirs, flagExporterProperties.Export_include_dirs...)
384
385 // To avoid duplicate includes when base includes + os includes are combined
386 // FIXME: This doesn't take conflicts between arch and os includes into account
387 osIncludeDirs = bazel.SubtractStrings(osIncludeDirs, includeDirs)
388
389 if len(osIncludeDirs) > 0 {
390 includeDirsAttribute.SetValueForOS(os.Name, osIncludeDirs)
391 }
Rupert Shuttleworth375451e2021-04-26 07:49:08 -0400392 }
393 }
394
Jingwen Chen882bcc12021-04-27 05:54:20 +0000395 return includeDirsAttribute
Jingwen Chen91220d72021-03-24 02:18:33 -0400396}