Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package cc |
| 15 | |
| 16 | import ( |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 17 | "path/filepath" |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 18 | "strings" |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/bazel" |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | // bp2build functions and helpers for converting cc_* modules to Bazel. |
| 25 | |
| 26 | func init() { |
| 27 | android.DepsBp2BuildMutators(RegisterDepsBp2Build) |
| 28 | } |
| 29 | |
| 30 | func RegisterDepsBp2Build(ctx android.RegisterMutatorsContext) { |
| 31 | ctx.BottomUp("cc_bp2build_deps", depsBp2BuildMutator) |
| 32 | } |
| 33 | |
| 34 | // A naive deps mutator to add deps on all modules across all combinations of |
| 35 | // target props for cc modules. This is needed to make module -> bazel label |
| 36 | // resolution work in the bp2build mutator later. This is probably |
| 37 | // the wrong way to do it, but it works. |
| 38 | // |
| 39 | // TODO(jingwen): can we create a custom os mutator in depsBp2BuildMutator to do this? |
| 40 | func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) { |
| 41 | module, ok := ctx.Module().(*Module) |
| 42 | if !ok { |
| 43 | // Not a cc module |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if !module.ConvertWithBp2build(ctx) { |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | var allDeps []string |
| 52 | |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 53 | for _, p := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) { |
| 54 | // base compiler props |
| 55 | if baseCompilerProps, ok := p.(*BaseCompilerProperties); ok { |
| 56 | allDeps = append(allDeps, baseCompilerProps.Generated_headers...) |
| 57 | allDeps = append(allDeps, baseCompilerProps.Generated_sources...) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | for _, p := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) { |
| 62 | // arch specific compiler props |
| 63 | if baseCompilerProps, ok := p.(*BaseCompilerProperties); ok { |
| 64 | allDeps = append(allDeps, baseCompilerProps.Generated_headers...) |
| 65 | allDeps = append(allDeps, baseCompilerProps.Generated_sources...) |
| 66 | } |
| 67 | } |
| 68 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 69 | for _, p := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 70 | // arch specific linker props |
| 71 | if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok { |
| 72 | allDeps = append(allDeps, baseLinkerProps.Header_libs...) |
| 73 | allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 74 | allDeps = append(allDeps, baseLinkerProps.Static_libs...) |
| 75 | allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...) |
| 76 | } |
| 77 | } |
| 78 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 79 | for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 80 | // arch specific linker props |
| 81 | if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok { |
| 82 | allDeps = append(allDeps, baseLinkerProps.Header_libs...) |
| 83 | allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...) |
| 84 | allDeps = append(allDeps, baseLinkerProps.Static_libs...) |
| 85 | allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...) |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 89 | // Deps in the static: { .. } and shared: { .. } props of a cc_library. |
| 90 | if lib, ok := module.compiler.(*libraryDecorator); ok { |
| 91 | allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...) |
| 92 | allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...) |
| 93 | allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...) |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 94 | |
| 95 | allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...) |
| 96 | allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...) |
| 97 | allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...) |
Jingwen Chen | 45dec10 | 2021-05-19 10:30:29 +0000 | [diff] [blame] | 98 | |
| 99 | // TODO(b/186024507, b/186489250): Temporarily exclude adding |
| 100 | // system_shared_libs deps until libc and libm builds. |
| 101 | // allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...) |
| 102 | // allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...) |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 105 | ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...) |
| 106 | } |
| 107 | |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 108 | type sharedAttributes struct { |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 109 | copts bazel.StringListAttribute |
| 110 | srcs bazel.LabelListAttribute |
| 111 | staticDeps bazel.LabelListAttribute |
| 112 | dynamicDeps bazel.LabelListAttribute |
| 113 | wholeArchiveDeps bazel.LabelListAttribute |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. |
| 117 | func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes { |
| 118 | lib, ok := module.compiler.(*libraryDecorator) |
| 119 | if !ok { |
| 120 | return sharedAttributes{} |
| 121 | } |
| 122 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 123 | copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags} |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 124 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 125 | srcs := bazel.LabelListAttribute{ |
| 126 | Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)} |
| 127 | |
| 128 | staticDeps := bazel.LabelListAttribute{ |
| 129 | Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)} |
| 130 | |
| 131 | dynamicDeps := bazel.LabelListAttribute{ |
| 132 | Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)} |
| 133 | |
| 134 | wholeArchiveDeps := bazel.LabelListAttribute{ |
| 135 | Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)} |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 136 | |
| 137 | return sharedAttributes{ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 138 | copts: copts, |
| 139 | srcs: srcs, |
| 140 | staticDeps: staticDeps, |
| 141 | dynamicDeps: dynamicDeps, |
| 142 | wholeArchiveDeps: wholeArchiveDeps, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | type staticAttributes struct { |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 147 | copts bazel.StringListAttribute |
| 148 | srcs bazel.LabelListAttribute |
| 149 | staticDeps bazel.LabelListAttribute |
| 150 | dynamicDeps bazel.LabelListAttribute |
| 151 | wholeArchiveDeps bazel.LabelListAttribute |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. |
| 155 | func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes { |
| 156 | lib, ok := module.compiler.(*libraryDecorator) |
| 157 | if !ok { |
| 158 | return staticAttributes{} |
| 159 | } |
| 160 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 161 | copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags} |
| 162 | |
| 163 | srcs := bazel.LabelListAttribute{ |
| 164 | Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)} |
| 165 | |
| 166 | staticDeps := bazel.LabelListAttribute{ |
| 167 | Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)} |
| 168 | |
| 169 | dynamicDeps := bazel.LabelListAttribute{ |
| 170 | Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)} |
| 171 | |
| 172 | wholeArchiveDeps := bazel.LabelListAttribute{ |
| 173 | Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)} |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 174 | |
| 175 | return staticAttributes{ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 176 | copts: copts, |
| 177 | srcs: srcs, |
| 178 | staticDeps: staticDeps, |
| 179 | dynamicDeps: dynamicDeps, |
| 180 | wholeArchiveDeps: wholeArchiveDeps, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 184 | // Convenience struct to hold all attributes parsed from compiler properties. |
| 185 | type compilerAttributes struct { |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 186 | // Options for all languages |
| 187 | copts bazel.StringListAttribute |
| 188 | // Assembly options and sources |
| 189 | asFlags bazel.StringListAttribute |
| 190 | asSrcs bazel.LabelListAttribute |
| 191 | // C options and sources |
| 192 | conlyFlags bazel.StringListAttribute |
| 193 | cSrcs bazel.LabelListAttribute |
| 194 | // C++ options and sources |
| 195 | cppFlags bazel.StringListAttribute |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 196 | srcs bazel.LabelListAttribute |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 199 | // bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes. |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 200 | func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes { |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 201 | var srcs bazel.LabelListAttribute |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 202 | var copts bazel.StringListAttribute |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 203 | var asFlags bazel.StringListAttribute |
| 204 | var conlyFlags bazel.StringListAttribute |
| 205 | var cppFlags bazel.StringListAttribute |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 206 | |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 207 | // Creates the -I flags for a directory, while making the directory relative |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 208 | // to the exec root for Bazel to work. |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 209 | includeFlags := func(dir string) []string { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 210 | // filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements. |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 211 | moduleDirRootedPath := filepath.Join(ctx.ModuleDir(), dir) |
| 212 | return []string{ |
| 213 | "-I" + moduleDirRootedPath, |
| 214 | // Include the bindir-rooted path (using make variable substitution). This most |
| 215 | // closely matches Bazel's native include path handling, which allows for dependency |
| 216 | // on generated headers in these directories. |
| 217 | // TODO(b/188084383): Handle local include directories in Bazel. |
| 218 | "-I$(BINDIR)/" + moduleDirRootedPath, |
| 219 | } |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 222 | // Parse the list of module-relative include directories (-I). |
| 223 | parseLocalIncludeDirs := func(baseCompilerProps *BaseCompilerProperties) []string { |
| 224 | // include_dirs are root-relative, not module-relative. |
| 225 | includeDirs := bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs) |
| 226 | return append(includeDirs, baseCompilerProps.Local_include_dirs...) |
| 227 | } |
| 228 | |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 229 | parseCommandLineFlags := func(soongFlags []string) []string { |
| 230 | var result []string |
| 231 | for _, flag := range soongFlags { |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 232 | // Soong's cflags can contain spaces, like `-include header.h`. For |
| 233 | // Bazel's copts, split them up to be compatible with the |
| 234 | // no_copts_tokenization feature. |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 235 | result = append(result, strings.Split(flag, " ")...) |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 236 | } |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 237 | return result |
| 238 | } |
| 239 | |
| 240 | // Parse the list of copts. |
| 241 | parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string { |
| 242 | var copts []string |
| 243 | copts = append(copts, parseCommandLineFlags(baseCompilerProps.Cflags)...) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 244 | for _, dir := range parseLocalIncludeDirs(baseCompilerProps) { |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 245 | copts = append(copts, includeFlags(dir)...) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 246 | } |
| 247 | return copts |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 248 | } |
| 249 | |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 250 | // baseSrcs contain the list of src files that are used for every configuration. |
| 251 | var baseSrcs []string |
| 252 | // baseExcludeSrcs contain the list of src files that are excluded for every configuration. |
| 253 | var baseExcludeSrcs []string |
| 254 | // baseSrcsLabelList is a clone of the base srcs LabelList, used for computing the |
| 255 | // arch or os specific srcs later. |
| 256 | var baseSrcsLabelList bazel.LabelList |
| 257 | |
| 258 | // Parse srcs from an arch or OS's props value, taking the base srcs and |
| 259 | // exclude srcs into account. |
| 260 | parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList { |
| 261 | // Combine the base srcs and arch-specific srcs |
| 262 | allSrcs := append(baseSrcs, baseCompilerProps.Srcs...) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 263 | // Add srcs-like dependencies such as generated files. |
| 264 | // First create a LabelList containing these dependencies, then merge the values with srcs. |
| 265 | generatedHdrsAndSrcs := baseCompilerProps.Generated_headers |
| 266 | generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, baseCompilerProps.Generated_sources...) |
| 267 | |
| 268 | generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDeps(ctx, generatedHdrsAndSrcs) |
| 269 | |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 270 | // Combine the base exclude_srcs and configuration-specific exclude_srcs |
| 271 | allExcludeSrcs := append(baseExcludeSrcs, baseCompilerProps.Exclude_srcs...) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 272 | allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, allSrcs, allExcludeSrcs) |
| 273 | return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList) |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 276 | for _, props := range module.compiler.compilerProps() { |
| 277 | if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 278 | srcs.Value = parseSrcs(baseCompilerProps) |
| 279 | copts.Value = parseCopts(baseCompilerProps) |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 280 | asFlags.Value = parseCommandLineFlags(baseCompilerProps.Asflags) |
| 281 | conlyFlags.Value = parseCommandLineFlags(baseCompilerProps.Conlyflags) |
| 282 | cppFlags.Value = parseCommandLineFlags(baseCompilerProps.Cppflags) |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 283 | |
| 284 | // Used for arch-specific srcs later. |
| 285 | baseSrcs = baseCompilerProps.Srcs |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 286 | baseSrcsLabelList = parseSrcs(baseCompilerProps) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 287 | baseExcludeSrcs = baseCompilerProps.Exclude_srcs |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 288 | break |
| 289 | } |
| 290 | } |
| 291 | |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 292 | // Handle include_build_directory prop. If the property is true, then the |
| 293 | // target has access to all headers recursively in the package, and has |
| 294 | // "-I<module-dir>" in its copts. |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 295 | if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() { |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 296 | copts.Value = append(copts.Value, includeFlags(".")...) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 297 | } else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() { |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 298 | copts.Value = append(copts.Value, includeFlags(".")...) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 301 | for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) { |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 302 | if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 303 | // If there's arch specific srcs or exclude_srcs, generate a select entry for it. |
| 304 | // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too. |
| 305 | if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 { |
| 306 | srcsList := parseSrcs(baseCompilerProps) |
| 307 | srcs.SetValueForArch(arch.Name, srcsList) |
| 308 | // The base srcs value should not contain any arch-specific excludes. |
| 309 | srcs.Value = bazel.SubtractBazelLabelList(srcs.Value, bazel.LabelList{Includes: srcsList.Excludes}) |
| 310 | } |
| 311 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 312 | copts.SetValueForArch(arch.Name, parseCopts(baseCompilerProps)) |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 313 | asFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Asflags)) |
| 314 | conlyFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags)) |
| 315 | cppFlags.SetValueForArch(arch.Name, parseCommandLineFlags(baseCompilerProps.Cppflags)) |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 319 | // After going through all archs, delete the duplicate files in the arch |
| 320 | // values that are already in the base srcs.Value. |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 321 | for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) { |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 322 | if _, ok := props.(*BaseCompilerProperties); ok { |
| 323 | srcs.SetValueForArch(arch.Name, bazel.SubtractBazelLabelList(srcs.GetValueForArch(arch.Name), srcs.Value)) |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Now that the srcs.Value list is finalized, compare it with the original |
| 328 | // list, and put the difference into the default condition for the arch |
| 329 | // select. |
| 330 | defaultsSrcs := bazel.SubtractBazelLabelList(baseSrcsLabelList, srcs.Value) |
| 331 | // TODO(b/186153868): handle the case with multiple variant types, e.g. when arch and os are both used. |
| 332 | srcs.SetValueForArch(bazel.CONDITIONS_DEFAULT, defaultsSrcs) |
| 333 | |
| 334 | // Handle OS specific props. |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 335 | for os, props := range module.GetTargetProperties(ctx, &BaseCompilerProperties{}) { |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 336 | if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 337 | srcsList := parseSrcs(baseCompilerProps) |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 338 | // TODO(b/186153868): add support for os-specific srcs and exclude_srcs |
| 339 | srcs.SetValueForOS(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList)) |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 340 | copts.SetValueForOS(os.Name, parseCopts(baseCompilerProps)) |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 341 | asFlags.SetValueForOS(os.Name, parseCommandLineFlags(baseCompilerProps.Asflags)) |
| 342 | conlyFlags.SetValueForOS(os.Name, parseCommandLineFlags(baseCompilerProps.Conlyflags)) |
| 343 | cppFlags.SetValueForOS(os.Name, parseCommandLineFlags(baseCompilerProps.Cppflags)) |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 347 | productVariableProps := android.ProductVariableProperties(ctx) |
| 348 | if props, exists := productVariableProps["Cflags"]; exists { |
| 349 | for _, prop := range props { |
| 350 | flags, ok := prop.Property.([]string) |
| 351 | if !ok { |
| 352 | ctx.ModuleErrorf("Could not convert product variable cflag property") |
| 353 | } |
| 354 | newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) |
| 355 | copts.ProductValues = append(copts.ProductValues, bazel.ProductVariableValues{ |
| 356 | ProductVariable: prop.ProductConfigVariable, |
| 357 | Values: newFlags, |
| 358 | }) |
| 359 | } |
| 360 | } |
| 361 | |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 362 | // Branch srcs into three language-specific groups. |
| 363 | // C++ is the "catch-all" group, and comprises generated sources because we don't |
| 364 | // know the language of these sources until the genrule is executed. |
| 365 | // TODO(b/): Handle language detection of sources in a Bazel rule. |
| 366 | isCSrc := func(s string) bool { |
| 367 | return strings.HasSuffix(s, ".c") |
| 368 | } |
| 369 | isAsmSrc := func(s string) bool { |
| 370 | return strings.HasSuffix(s, ".S") || strings.HasSuffix(s, ".s") |
| 371 | } |
| 372 | cSrcs := bazel.FilterLabelListAttribute(srcs, isCSrc) |
| 373 | asSrcs := bazel.FilterLabelListAttribute(srcs, isAsmSrc) |
| 374 | srcs = bazel.SubtractBazelLabelListAttribute(srcs, cSrcs) |
| 375 | srcs = bazel.SubtractBazelLabelListAttribute(srcs, asSrcs) |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 376 | return compilerAttributes{ |
Chris Parsons | af24cdd | 2021-05-21 18:50:44 -0400 | [diff] [blame^] | 377 | copts: copts, |
| 378 | srcs: srcs, |
| 379 | asFlags: asFlags, |
| 380 | asSrcs: asSrcs, |
| 381 | cSrcs: cSrcs, |
| 382 | conlyFlags: conlyFlags, |
| 383 | cppFlags: cppFlags, |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
| 387 | // Convenience struct to hold all attributes parsed from linker properties. |
| 388 | type linkerAttributes struct { |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 389 | deps bazel.LabelListAttribute |
| 390 | dynamicDeps bazel.LabelListAttribute |
| 391 | wholeArchiveDeps bazel.LabelListAttribute |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 392 | exportedDeps bazel.LabelListAttribute |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 393 | linkopts bazel.StringListAttribute |
| 394 | versionScript bazel.LabelAttribute |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 397 | // FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here |
| 398 | func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string { |
| 399 | flags := linkerProperties.Ldflags |
| 400 | if !BoolDefault(linkerProperties.Pack_relocations, true) { |
| 401 | flags = append(flags, "-Wl,--pack-dyn-relocs=none") |
| 402 | } |
| 403 | return flags |
| 404 | } |
| 405 | |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 406 | // bp2BuildParseLinkerProps parses the linker properties of a module, including |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 407 | // configurable attribute values. |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 408 | func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 409 | var deps bazel.LabelListAttribute |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 410 | var exportedDeps bazel.LabelListAttribute |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 411 | var dynamicDeps bazel.LabelListAttribute |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 412 | var wholeArchiveDeps bazel.LabelListAttribute |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 413 | var linkopts bazel.StringListAttribute |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 414 | var versionScript bazel.LabelAttribute |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 415 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 416 | for _, linkerProps := range module.linker.linkerProps() { |
| 417 | if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok { |
| 418 | libs := baseLinkerProps.Header_libs |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 419 | libs = append(libs, baseLinkerProps.Static_libs...) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 420 | exportedLibs := baseLinkerProps.Export_header_lib_headers |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 421 | wholeArchiveLibs := baseLinkerProps.Whole_static_libs |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 422 | libs = android.SortedUniqueStrings(libs) |
| 423 | deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 424 | exportedDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, exportedLibs)) |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 425 | linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps) |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 426 | wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 427 | |
| 428 | if baseLinkerProps.Version_script != nil { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 429 | versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script) |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 430 | } |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 431 | |
| 432 | sharedLibs := baseLinkerProps.Shared_libs |
| 433 | dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs)) |
| 434 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 435 | break |
| 436 | } |
| 437 | } |
| 438 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 439 | for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) { |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 440 | if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok { |
| 441 | libs := baseLinkerProps.Header_libs |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 442 | libs = append(libs, baseLinkerProps.Static_libs...) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 443 | exportedLibs := baseLinkerProps.Export_header_lib_headers |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 444 | wholeArchiveLibs := baseLinkerProps.Whole_static_libs |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 445 | libs = android.SortedUniqueStrings(libs) |
| 446 | deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs)) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 447 | exportedDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs)) |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 448 | linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps)) |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 449 | wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 450 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 451 | if baseLinkerProps.Version_script != nil { |
| 452 | versionScript.SetValueForArch(arch.Name, |
| 453 | android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)) |
| 454 | } |
Rupert Shuttleworth | 3b413d3 | 2021-05-10 18:41:51 -0400 | [diff] [blame] | 455 | |
| 456 | sharedLibs := baseLinkerProps.Shared_libs |
| 457 | dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 461 | for os, p := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 462 | if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok { |
| 463 | libs := baseLinkerProps.Header_libs |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 464 | libs = append(libs, baseLinkerProps.Static_libs...) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 465 | exportedLibs := baseLinkerProps.Export_header_lib_headers |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 466 | wholeArchiveLibs := baseLinkerProps.Whole_static_libs |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 467 | libs = android.SortedUniqueStrings(libs) |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 468 | wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 469 | deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs)) |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 470 | exportedDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs)) |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 471 | |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 472 | linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps)) |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 473 | |
| 474 | sharedLibs := baseLinkerProps.Shared_libs |
| 475 | dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 479 | return linkerAttributes{ |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 480 | deps: deps, |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 481 | exportedDeps: exportedDeps, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 482 | dynamicDeps: dynamicDeps, |
| 483 | wholeArchiveDeps: wholeArchiveDeps, |
| 484 | linkopts: linkopts, |
| 485 | versionScript: versionScript, |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 486 | } |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 487 | } |
| 488 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 489 | // Relativize a list of root-relative paths with respect to the module's |
| 490 | // directory. |
| 491 | // |
| 492 | // include_dirs Soong prop are root-relative (b/183742505), but |
| 493 | // local_include_dirs, export_include_dirs and export_system_include_dirs are |
| 494 | // module dir relative. This function makes a list of paths entirely module dir |
| 495 | // relative. |
| 496 | // |
| 497 | // For the `include` attribute, Bazel wants the paths to be relative to the |
| 498 | // module. |
| 499 | func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string { |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 500 | var relativePaths []string |
| 501 | for _, path := range paths { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 502 | // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path |
| 503 | relativePath, err := filepath.Rel(ctx.ModuleDir(), path) |
| 504 | if err != nil { |
| 505 | panic(err) |
| 506 | } |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 507 | relativePaths = append(relativePaths, relativePath) |
| 508 | } |
| 509 | return relativePaths |
| 510 | } |
| 511 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 512 | // bp2BuildParseExportedIncludes creates a string list attribute contains the |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 513 | // exported included directories of a module. |
| 514 | func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 515 | libraryDecorator := module.linker.(*libraryDecorator) |
| 516 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 517 | // Export_system_include_dirs and export_include_dirs are already module dir |
| 518 | // relative, so they don't need to be relativized like include_dirs, which |
| 519 | // are root-relative. |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 520 | includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs |
| 521 | includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...) |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 522 | includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs) |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 523 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 524 | for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) { |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 525 | if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { |
| 526 | archIncludeDirs := flagExporterProperties.Export_system_include_dirs |
| 527 | archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...) |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 528 | |
| 529 | // To avoid duplicate includes when base includes + arch includes are combined |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 530 | // FIXME: This doesn't take conflicts between arch and os includes into account |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 531 | archIncludeDirs = bazel.SubtractStrings(archIncludeDirs, includeDirs) |
| 532 | |
| 533 | if len(archIncludeDirs) > 0 { |
| 534 | includeDirsAttribute.SetValueForArch(arch.Name, archIncludeDirs) |
| 535 | } |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 536 | } |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 539 | for os, props := range module.GetTargetProperties(ctx, &FlagExporterProperties{}) { |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 540 | if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { |
| 541 | osIncludeDirs := flagExporterProperties.Export_system_include_dirs |
| 542 | osIncludeDirs = append(osIncludeDirs, flagExporterProperties.Export_include_dirs...) |
| 543 | |
| 544 | // To avoid duplicate includes when base includes + os includes are combined |
| 545 | // FIXME: This doesn't take conflicts between arch and os includes into account |
| 546 | osIncludeDirs = bazel.SubtractStrings(osIncludeDirs, includeDirs) |
| 547 | |
| 548 | if len(osIncludeDirs) > 0 { |
| 549 | includeDirsAttribute.SetValueForOS(os.Name, osIncludeDirs) |
| 550 | } |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 554 | return includeDirsAttribute |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 555 | } |