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 | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 17 | "fmt" |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 18 | "path/filepath" |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 19 | "strings" |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/bazel" |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint/proptools" |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 25 | ) |
| 26 | |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 27 | // staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties -- |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 28 | // properties which apply to either the shared or static version of a cc_library module. |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 29 | type staticOrSharedAttributes struct { |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 30 | Srcs bazel.LabelListAttribute |
| 31 | Srcs_c bazel.LabelListAttribute |
| 32 | Srcs_as bazel.LabelListAttribute |
| 33 | Copts bazel.StringListAttribute |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 34 | |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 35 | Static_deps bazel.LabelListAttribute |
| 36 | Dynamic_deps bazel.LabelListAttribute |
| 37 | Whole_archive_deps bazel.LabelListAttribute |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 38 | |
| 39 | System_dynamic_deps bazel.LabelListAttribute |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 42 | func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) { |
| 43 | // Branch srcs into three language-specific groups. |
| 44 | // C++ is the "catch-all" group, and comprises generated sources because we don't |
| 45 | // know the language of these sources until the genrule is executed. |
| 46 | // TODO(b/190006308): Handle language detection of sources in a Bazel rule. |
| 47 | isCSrcOrFilegroup := func(s string) bool { |
| 48 | return strings.HasSuffix(s, ".c") || strings.HasSuffix(s, "_c_srcs") |
| 49 | } |
| 50 | |
| 51 | isAsmSrcOrFilegroup := func(s string) bool { |
| 52 | return strings.HasSuffix(s, ".S") || strings.HasSuffix(s, ".s") || strings.HasSuffix(s, "_as_srcs") |
| 53 | } |
| 54 | |
| 55 | // Check that a module is a filegroup type named <label>. |
| 56 | isFilegroupNamed := func(m android.Module, fullLabel string) bool { |
| 57 | if ctx.OtherModuleType(m) != "filegroup" { |
| 58 | return false |
| 59 | } |
| 60 | labelParts := strings.Split(fullLabel, ":") |
| 61 | if len(labelParts) > 2 { |
| 62 | // There should not be more than one colon in a label. |
| 63 | panic(fmt.Errorf("%s is not a valid Bazel label for a filegroup", fullLabel)) |
| 64 | } else { |
| 65 | return m.Name() == labelParts[len(labelParts)-1] |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Convert the filegroup dependencies into the extension-specific filegroups |
| 70 | // filtered in the filegroup.bzl macro. |
| 71 | cppFilegroup := func(label string) string { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 72 | m, exists := ctx.ModuleFromName(label) |
| 73 | if exists { |
| 74 | aModule, _ := m.(android.Module) |
| 75 | if isFilegroupNamed(aModule, label) { |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 76 | label = label + "_cpp_srcs" |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 77 | } |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 78 | } |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 79 | return label |
| 80 | } |
| 81 | cFilegroup := func(label string) string { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 82 | m, exists := ctx.ModuleFromName(label) |
| 83 | if exists { |
| 84 | aModule, _ := m.(android.Module) |
| 85 | if isFilegroupNamed(aModule, label) { |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 86 | label = label + "_c_srcs" |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 87 | } |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 88 | } |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 89 | return label |
| 90 | } |
| 91 | asFilegroup := func(label string) string { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 92 | m, exists := ctx.ModuleFromName(label) |
| 93 | if exists { |
| 94 | aModule, _ := m.(android.Module) |
| 95 | if isFilegroupNamed(aModule, label) { |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 96 | label = label + "_as_srcs" |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 97 | } |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 98 | } |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 99 | return label |
| 100 | } |
| 101 | |
| 102 | cSrcs = bazel.MapLabelListAttribute(srcs, cFilegroup) |
| 103 | cSrcs = bazel.FilterLabelListAttribute(cSrcs, isCSrcOrFilegroup) |
| 104 | |
| 105 | asSrcs = bazel.MapLabelListAttribute(srcs, asFilegroup) |
| 106 | asSrcs = bazel.FilterLabelListAttribute(asSrcs, isAsmSrcOrFilegroup) |
| 107 | |
| 108 | cppSrcs = bazel.MapLabelListAttribute(srcs, cppFilegroup) |
| 109 | cppSrcs = bazel.SubtractBazelLabelListAttribute(cppSrcs, cSrcs) |
| 110 | cppSrcs = bazel.SubtractBazelLabelListAttribute(cppSrcs, asSrcs) |
| 111 | return |
| 112 | } |
| 113 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame^] | 114 | // bp2BuildParseLibProps returns the attributes for a variant of a cc_library. |
| 115 | func bp2BuildParseLibProps(ctx android.TopDownMutatorContext, module *Module, isStatic bool) staticOrSharedAttributes { |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 116 | lib, ok := module.compiler.(*libraryDecorator) |
| 117 | if !ok { |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 118 | return staticOrSharedAttributes{} |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 119 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame^] | 120 | return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic) |
| 121 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 122 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame^] | 123 | // bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. |
| 124 | func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { |
| 125 | return bp2BuildParseLibProps(ctx, module, false) |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 129 | func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame^] | 130 | return bp2BuildParseLibProps(ctx, module, true) |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 133 | func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes { |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 134 | attrs := staticOrSharedAttributes{} |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 135 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 136 | setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 137 | attrs.Copts.SetSelectValue(axis, config, props.Cflags) |
| 138 | attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs)) |
| 139 | attrs.Static_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs)) |
| 140 | attrs.Dynamic_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs)) |
| 141 | attrs.Whole_archive_deps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 142 | attrs.System_dynamic_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.System_shared_libs)) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 143 | } |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 144 | // system_dynamic_deps distinguishes between nil/empty list behavior: |
| 145 | // nil -> use default values |
| 146 | // empty list -> no values specified |
| 147 | attrs.System_dynamic_deps.ForceSpecifyEmptyList = true |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 148 | |
| 149 | if isStatic { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 150 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &StaticProperties{}) { |
| 151 | for config, props := range configToProps { |
| 152 | if staticOrSharedProps, ok := props.(*StaticProperties); ok { |
| 153 | setAttrs(axis, config, staticOrSharedProps.Static) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | } |
| 157 | } else { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 158 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &SharedProperties{}) { |
| 159 | for config, props := range configToProps { |
| 160 | if staticOrSharedProps, ok := props.(*SharedProperties); ok { |
| 161 | setAttrs(axis, config, staticOrSharedProps.Shared) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 167 | cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs) |
| 168 | attrs.Srcs = cppSrcs |
| 169 | attrs.Srcs_c = cSrcs |
| 170 | attrs.Srcs_as = asSrcs |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 171 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 172 | return attrs |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 175 | // Convenience struct to hold all attributes parsed from prebuilt properties. |
| 176 | type prebuiltAttributes struct { |
| 177 | Src bazel.LabelAttribute |
| 178 | } |
| 179 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame^] | 180 | // NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 181 | func Bp2BuildParsePrebuiltLibraryProps(ctx android.TopDownMutatorContext, module *Module) prebuiltAttributes { |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 182 | var srcLabelAttribute bazel.LabelAttribute |
| 183 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 184 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltLinkerProperties{}) { |
| 185 | for config, props := range configToProps { |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 186 | if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok { |
| 187 | if len(prebuiltLinkerProperties.Srcs) > 1 { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 188 | ctx.ModuleErrorf("Bp2BuildParsePrebuiltLibraryProps: Expected at most once source file for %s %s\n", axis, config) |
| 189 | continue |
| 190 | } else if len(prebuiltLinkerProperties.Srcs) == 0 { |
| 191 | continue |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 192 | } |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 193 | src := android.BazelLabelForModuleSrcSingle(ctx, prebuiltLinkerProperties.Srcs[0]) |
| 194 | srcLabelAttribute.SetSelectValue(axis, config, src) |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 199 | return prebuiltAttributes{ |
| 200 | Src: srcLabelAttribute, |
| 201 | } |
| 202 | } |
| 203 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 204 | // Convenience struct to hold all attributes parsed from compiler properties. |
| 205 | type compilerAttributes struct { |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 206 | // Options for all languages |
| 207 | copts bazel.StringListAttribute |
| 208 | // Assembly options and sources |
| 209 | asFlags bazel.StringListAttribute |
| 210 | asSrcs bazel.LabelListAttribute |
| 211 | // C options and sources |
| 212 | conlyFlags bazel.StringListAttribute |
| 213 | cSrcs bazel.LabelListAttribute |
| 214 | // C++ options and sources |
| 215 | cppFlags bazel.StringListAttribute |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 216 | srcs bazel.LabelListAttribute |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 217 | |
| 218 | rtti bazel.BoolAttribute |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 219 | |
| 220 | localIncludes bazel.StringListAttribute |
| 221 | absoluteIncludes bazel.StringListAttribute |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 224 | // bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes. |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 225 | func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes { |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 226 | var srcs bazel.LabelListAttribute |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 227 | var copts bazel.StringListAttribute |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 228 | var asFlags bazel.StringListAttribute |
| 229 | var conlyFlags bazel.StringListAttribute |
| 230 | var cppFlags bazel.StringListAttribute |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 231 | var rtti bazel.BoolAttribute |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 232 | var localIncludes bazel.StringListAttribute |
| 233 | var absoluteIncludes bazel.StringListAttribute |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 234 | |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 235 | parseCommandLineFlags := func(soongFlags []string) []string { |
| 236 | var result []string |
| 237 | for _, flag := range soongFlags { |
Colin Cross | 52aa4e1 | 2021-05-25 15:20:39 +0000 | [diff] [blame] | 238 | // Soong's cflags can contain spaces, like `-include header.h`. For |
| 239 | // Bazel's copts, split them up to be compatible with the |
| 240 | // no_copts_tokenization feature. |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 241 | result = append(result, strings.Split(flag, " ")...) |
Colin Cross | 52aa4e1 | 2021-05-25 15:20:39 +0000 | [diff] [blame] | 242 | } |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 243 | return result |
| 244 | } |
| 245 | |
Liz Kammer | 74deed4 | 2021-06-02 13:02:03 -0400 | [diff] [blame] | 246 | // Parse srcs from an arch or OS's props value. |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 247 | parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList { |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 248 | // Add srcs-like dependencies such as generated files. |
| 249 | // First create a LabelList containing these dependencies, then merge the values with srcs. |
| 250 | generatedHdrsAndSrcs := baseCompilerProps.Generated_headers |
| 251 | generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, baseCompilerProps.Generated_sources...) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 252 | generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDeps(ctx, generatedHdrsAndSrcs) |
| 253 | |
Liz Kammer | 74deed4 | 2021-06-02 13:02:03 -0400 | [diff] [blame] | 254 | allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, baseCompilerProps.Srcs, baseCompilerProps.Exclude_srcs) |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 255 | return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList) |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 258 | archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 259 | for axis, configToProps := range archVariantCompilerProps { |
| 260 | for config, props := range configToProps { |
| 261 | if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { |
| 262 | // If there's arch specific srcs or exclude_srcs, generate a select entry for it. |
| 263 | // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too. |
| 264 | if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 { |
| 265 | srcsList := parseSrcs(baseCompilerProps) |
| 266 | srcs.SetSelectValue(axis, config, srcsList) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 269 | archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags) |
| 270 | archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags) |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 271 | |
| 272 | localIncludeDirs := baseCompilerProps.Local_include_dirs |
| 273 | if axis == bazel.NoConfigAxis && includeBuildDirectory(baseCompilerProps.Include_build_directory) { |
| 274 | localIncludeDirs = append(localIncludeDirs, ".") |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 275 | } |
| 276 | |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 277 | absoluteIncludes.SetSelectValue(axis, config, baseCompilerProps.Include_dirs) |
| 278 | localIncludes.SetSelectValue(axis, config, localIncludeDirs) |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 279 | |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 280 | copts.SetSelectValue(axis, config, archVariantCopts) |
| 281 | asFlags.SetSelectValue(axis, config, archVariantAsflags) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 282 | conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Conlyflags)) |
| 283 | cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Cppflags)) |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 284 | rtti.SetSelectValue(axis, config, baseCompilerProps.Rtti) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 285 | } |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Liz Kammer | 74deed4 | 2021-06-02 13:02:03 -0400 | [diff] [blame] | 289 | srcs.ResolveExcludes() |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 290 | absoluteIncludes.DeduplicateAxesFromBase() |
| 291 | localIncludes.DeduplicateAxesFromBase() |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 292 | |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 293 | productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ |
| 294 | "Cflags": &copts, |
| 295 | "Asflags": &asFlags, |
| 296 | "CppFlags": &cppFlags, |
| 297 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 298 | productVariableProps := android.ProductVariableProperties(ctx) |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 299 | for propName, attr := range productVarPropNameToAttribute { |
| 300 | if props, exists := productVariableProps[propName]; exists { |
| 301 | for _, prop := range props { |
| 302 | flags, ok := prop.Property.([]string) |
| 303 | if !ok { |
| 304 | ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName)) |
| 305 | } |
| 306 | newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 307 | attr.SetSelectValue(bazel.ProductVariableConfigurationAxis(prop.FullConfig), prop.FullConfig, newFlags) |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 308 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 312 | srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs) |
| 313 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 314 | return compilerAttributes{ |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 315 | copts: copts, |
| 316 | srcs: srcs, |
| 317 | asFlags: asFlags, |
| 318 | asSrcs: asSrcs, |
| 319 | cSrcs: cSrcs, |
| 320 | conlyFlags: conlyFlags, |
| 321 | cppFlags: cppFlags, |
| 322 | rtti: rtti, |
| 323 | localIncludes: localIncludes, |
| 324 | absoluteIncludes: absoluteIncludes, |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | // Convenience struct to hold all attributes parsed from linker properties. |
| 329 | type linkerAttributes struct { |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 330 | deps bazel.LabelListAttribute |
| 331 | dynamicDeps bazel.LabelListAttribute |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 332 | systemDynamicDeps bazel.LabelListAttribute |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 333 | wholeArchiveDeps bazel.LabelListAttribute |
| 334 | exportedDeps bazel.LabelListAttribute |
| 335 | useLibcrt bazel.BoolAttribute |
| 336 | linkopts bazel.StringListAttribute |
| 337 | versionScript bazel.LabelAttribute |
| 338 | stripKeepSymbols bazel.BoolAttribute |
| 339 | stripKeepSymbolsAndDebugFrame bazel.BoolAttribute |
| 340 | stripKeepSymbolsList bazel.StringListAttribute |
| 341 | stripAll bazel.BoolAttribute |
| 342 | stripNone bazel.BoolAttribute |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 345 | // FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here |
| 346 | func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string { |
| 347 | flags := linkerProperties.Ldflags |
| 348 | if !BoolDefault(linkerProperties.Pack_relocations, true) { |
| 349 | flags = append(flags, "-Wl,--pack-dyn-relocs=none") |
| 350 | } |
| 351 | return flags |
| 352 | } |
| 353 | |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 354 | // bp2BuildParseLinkerProps parses the linker properties of a module, including |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 355 | // configurable attribute values. |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 356 | func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 357 | var headerDeps bazel.LabelListAttribute |
| 358 | var staticDeps bazel.LabelListAttribute |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 359 | var exportedDeps bazel.LabelListAttribute |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 360 | var dynamicDeps bazel.LabelListAttribute |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 361 | var wholeArchiveDeps bazel.LabelListAttribute |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 362 | systemSharedDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true} |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 363 | var linkopts bazel.StringListAttribute |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 364 | var versionScript bazel.LabelAttribute |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 365 | var useLibcrt bazel.BoolAttribute |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 366 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 367 | var stripKeepSymbols bazel.BoolAttribute |
| 368 | var stripKeepSymbolsAndDebugFrame bazel.BoolAttribute |
| 369 | var stripKeepSymbolsList bazel.StringListAttribute |
| 370 | var stripAll bazel.BoolAttribute |
| 371 | var stripNone bazel.BoolAttribute |
| 372 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 373 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) { |
| 374 | for config, props := range configToProps { |
| 375 | if stripProperties, ok := props.(*StripProperties); ok { |
| 376 | stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols) |
| 377 | stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list) |
| 378 | stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame) |
| 379 | stripAll.SetSelectValue(axis, config, stripProperties.Strip.All) |
| 380 | stripNone.SetSelectValue(axis, config, stripProperties.Strip.None) |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 385 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) { |
| 386 | for config, props := range configToProps { |
| 387 | if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok { |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 388 | // Excludes to parallel Soong: |
| 389 | // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0 |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 390 | staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs) |
| 391 | staticDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs)) |
| 392 | wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 393 | wholeArchiveDeps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs)) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 394 | |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 395 | systemSharedLibs := baseLinkerProps.System_shared_libs |
| 396 | // systemSharedLibs distinguishes between nil/empty list behavior: |
| 397 | // nil -> use default values |
| 398 | // empty list -> no values specified |
| 399 | if len(systemSharedLibs) > 0 { |
| 400 | systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 401 | } |
| 402 | systemSharedDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, systemSharedLibs)) |
| 403 | |
| 404 | sharedLibs := android.FirstUniqueStrings(baseLinkerProps.Shared_libs) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 405 | dynamicDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs)) |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 406 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 407 | headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs) |
| 408 | headerDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, headerLibs)) |
| 409 | exportedLibs := android.FirstUniqueStrings(baseLinkerProps.Export_header_lib_headers) |
| 410 | exportedDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, exportedLibs)) |
| 411 | |
| 412 | linkopts.SetSelectValue(axis, config, getBp2BuildLinkerFlags(baseLinkerProps)) |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 413 | if baseLinkerProps.Version_script != nil { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 414 | versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)) |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 415 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 416 | useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt()) |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 417 | } |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 421 | type productVarDep struct { |
| 422 | // the name of the corresponding excludes field, if one exists |
| 423 | excludesField string |
| 424 | // reference to the bazel attribute that should be set for the given product variable config |
| 425 | attribute *bazel.LabelListAttribute |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 426 | |
| 427 | depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | productVarToDepFields := map[string]productVarDep{ |
| 431 | // product variables do not support exclude_shared_libs |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 432 | "Shared_libs": productVarDep{attribute: &dynamicDeps, depResolutionFunc: android.BazelLabelForModuleDepsExcludes}, |
| 433 | "Static_libs": productVarDep{"Exclude_static_libs", &staticDeps, android.BazelLabelForModuleDepsExcludes}, |
| 434 | "Whole_static_libs": productVarDep{"Exclude_static_libs", &wholeArchiveDeps, android.BazelLabelForModuleWholeDepsExcludes}, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | productVariableProps := android.ProductVariableProperties(ctx) |
| 438 | for name, dep := range productVarToDepFields { |
| 439 | props, exists := productVariableProps[name] |
| 440 | excludeProps, excludesExists := productVariableProps[dep.excludesField] |
| 441 | // if neither an include or excludes property exists, then skip it |
| 442 | if !exists && !excludesExists { |
| 443 | continue |
| 444 | } |
| 445 | // collect all the configurations that an include or exclude property exists for. |
| 446 | // we want to iterate all configurations rather than either the include or exclude because for a |
| 447 | // particular configuration we may have only and include or only an exclude to handle |
| 448 | configs := make(map[string]bool, len(props)+len(excludeProps)) |
| 449 | for config := range props { |
| 450 | configs[config] = true |
| 451 | } |
| 452 | for config := range excludeProps { |
| 453 | configs[config] = true |
| 454 | } |
| 455 | |
| 456 | for config := range configs { |
| 457 | prop, includesExists := props[config] |
| 458 | excludesProp, excludesExists := excludeProps[config] |
| 459 | var includes, excludes []string |
| 460 | var ok bool |
| 461 | // if there was no includes/excludes property, casting fails and that's expected |
| 462 | if includes, ok = prop.Property.([]string); includesExists && !ok { |
| 463 | ctx.ModuleErrorf("Could not convert product variable %s property", name) |
| 464 | } |
| 465 | if excludes, ok = excludesProp.Property.([]string); excludesExists && !ok { |
| 466 | ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField) |
| 467 | } |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 468 | |
| 469 | dep.attribute.SetSelectValue(bazel.ProductVariableConfigurationAxis(config), config, dep.depResolutionFunc(ctx, android.FirstUniqueStrings(includes), excludes)) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | staticDeps.ResolveExcludes() |
| 474 | dynamicDeps.ResolveExcludes() |
| 475 | wholeArchiveDeps.ResolveExcludes() |
| 476 | |
| 477 | headerDeps.Append(staticDeps) |
| 478 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 479 | return linkerAttributes{ |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 480 | deps: headerDeps, |
| 481 | exportedDeps: exportedDeps, |
| 482 | dynamicDeps: dynamicDeps, |
| 483 | systemDynamicDeps: systemSharedDeps, |
| 484 | wholeArchiveDeps: wholeArchiveDeps, |
| 485 | linkopts: linkopts, |
| 486 | useLibcrt: useLibcrt, |
| 487 | versionScript: versionScript, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 488 | |
| 489 | // Strip properties |
| 490 | stripKeepSymbols: stripKeepSymbols, |
| 491 | stripKeepSymbolsAndDebugFrame: stripKeepSymbolsAndDebugFrame, |
| 492 | stripKeepSymbolsList: stripKeepSymbolsList, |
| 493 | stripAll: stripAll, |
| 494 | stripNone: stripNone, |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 495 | } |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 498 | // Relativize a list of root-relative paths with respect to the module's |
| 499 | // directory. |
| 500 | // |
| 501 | // include_dirs Soong prop are root-relative (b/183742505), but |
| 502 | // local_include_dirs, export_include_dirs and export_system_include_dirs are |
| 503 | // module dir relative. This function makes a list of paths entirely module dir |
| 504 | // relative. |
| 505 | // |
| 506 | // For the `include` attribute, Bazel wants the paths to be relative to the |
| 507 | // module. |
| 508 | func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string { |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 509 | var relativePaths []string |
| 510 | for _, path := range paths { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 511 | // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path |
| 512 | relativePath, err := filepath.Rel(ctx.ModuleDir(), path) |
| 513 | if err != nil { |
| 514 | panic(err) |
| 515 | } |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 516 | relativePaths = append(relativePaths, relativePath) |
| 517 | } |
| 518 | return relativePaths |
| 519 | } |
| 520 | |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 521 | // BazelIncludes contains information about -I and -isystem paths from a module converted to Bazel |
| 522 | // attributes. |
| 523 | type BazelIncludes struct { |
| 524 | Includes bazel.StringListAttribute |
| 525 | SystemIncludes bazel.StringListAttribute |
| 526 | } |
| 527 | |
| 528 | func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) BazelIncludes { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 529 | libraryDecorator := module.linker.(*libraryDecorator) |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 530 | return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator) |
| 531 | } |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 532 | |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 533 | // Bp2buildParseExportedIncludesForPrebuiltLibrary returns a BazelIncludes with Bazel-ified values |
| 534 | // to export includes from the underlying module's properties. |
| 535 | func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.TopDownMutatorContext, module *Module) BazelIncludes { |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 536 | prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker) |
| 537 | libraryDecorator := prebuiltLibraryLinker.libraryDecorator |
| 538 | return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator) |
| 539 | } |
| 540 | |
| 541 | // bp2BuildParseExportedIncludes creates a string list attribute contains the |
| 542 | // exported included directories of a module. |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 543 | func bp2BuildParseExportedIncludesHelper(ctx android.TopDownMutatorContext, module *Module, libraryDecorator *libraryDecorator) BazelIncludes { |
| 544 | exported := BazelIncludes{} |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 545 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &FlagExporterProperties{}) { |
| 546 | for config, props := range configToProps { |
| 547 | if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 548 | if len(flagExporterProperties.Export_include_dirs) > 0 { |
| 549 | exported.Includes.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs) |
| 550 | } |
| 551 | if len(flagExporterProperties.Export_system_include_dirs) > 0 { |
| 552 | exported.SystemIncludes.SetSelectValue(axis, config, flagExporterProperties.Export_system_include_dirs) |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 553 | } |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 554 | } |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 555 | } |
| 556 | } |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 557 | exported.Includes.DeduplicateAxesFromBase() |
| 558 | exported.SystemIncludes.DeduplicateAxesFromBase() |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 559 | |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 560 | return exported |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 561 | } |