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 | // |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 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 ( |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [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" |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 23 | "android/soong/cc/config" |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 24 | |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 28 | ) |
| 29 | |
Liz Kammer | ae3994e | 2021-10-19 09:45:48 -0400 | [diff] [blame] | 30 | const ( |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 31 | cSrcPartition = "c" |
| 32 | asSrcPartition = "as" |
| 33 | asmSrcPartition = "asm" |
| 34 | lSrcPartition = "l" |
| 35 | llSrcPartition = "ll" |
| 36 | cppSrcPartition = "cpp" |
| 37 | protoSrcPartition = "proto" |
| 38 | aidlSrcPartition = "aidl" |
| 39 | syspropSrcPartition = "sysprop" |
Liz Kammer | 91487d4 | 2022-09-13 11:27:11 -0400 | [diff] [blame] | 40 | |
| 41 | stubsSuffix = "_stub_libs_current" |
Liz Kammer | ae3994e | 2021-10-19 09:45:48 -0400 | [diff] [blame] | 42 | ) |
| 43 | |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 44 | // staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties -- |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 45 | // 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] | 46 | type staticOrSharedAttributes struct { |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 47 | Srcs bazel.LabelListAttribute |
| 48 | Srcs_c bazel.LabelListAttribute |
| 49 | Srcs_as bazel.LabelListAttribute |
| 50 | Srcs_aidl bazel.LabelListAttribute |
| 51 | Hdrs bazel.LabelListAttribute |
| 52 | Copts bazel.StringListAttribute |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 53 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 54 | Deps bazel.LabelListAttribute |
| 55 | Implementation_deps bazel.LabelListAttribute |
| 56 | Dynamic_deps bazel.LabelListAttribute |
| 57 | Implementation_dynamic_deps bazel.LabelListAttribute |
| 58 | Whole_archive_deps bazel.LabelListAttribute |
| 59 | Implementation_whole_archive_deps bazel.LabelListAttribute |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 60 | Runtime_deps bazel.LabelListAttribute |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 61 | |
| 62 | System_dynamic_deps bazel.LabelListAttribute |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 63 | |
| 64 | Enabled bazel.BoolAttribute |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 65 | |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 66 | Native_coverage *bool |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 67 | |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 68 | Apex_available []string |
| 69 | |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 70 | Features bazel.StringListAttribute |
| 71 | |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 72 | sdkAttributes |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 73 | |
| 74 | tidyAttributes |
| 75 | } |
| 76 | |
| 77 | type tidyAttributes struct { |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame] | 78 | Tidy *string |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 79 | Tidy_flags []string |
| 80 | Tidy_checks []string |
| 81 | Tidy_checks_as_errors []string |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 82 | Tidy_disabled_srcs bazel.LabelListAttribute |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 83 | Tidy_timeout_srcs bazel.LabelListAttribute |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 86 | func (m *Module) convertTidyAttributes(ctx android.BaseMutatorContext, moduleAttrs *tidyAttributes) { |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 87 | for _, f := range m.features { |
| 88 | if tidy, ok := f.(*tidyFeature); ok { |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame] | 89 | var tidyAttr *string |
| 90 | if tidy.Properties.Tidy != nil { |
| 91 | if *tidy.Properties.Tidy { |
| 92 | tidyAttr = proptools.StringPtr("local") |
| 93 | } else { |
| 94 | tidyAttr = proptools.StringPtr("never") |
| 95 | } |
| 96 | } |
| 97 | moduleAttrs.Tidy = tidyAttr |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 98 | moduleAttrs.Tidy_flags = tidy.Properties.Tidy_flags |
| 99 | moduleAttrs.Tidy_checks = tidy.Properties.Tidy_checks |
| 100 | moduleAttrs.Tidy_checks_as_errors = tidy.Properties.Tidy_checks_as_errors |
| 101 | } |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 102 | |
| 103 | } |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 104 | archVariantProps := m.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) |
| 105 | for axis, configToProps := range archVariantProps { |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 106 | for cfg, _props := range configToProps { |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 107 | if archProps, ok := _props.(*BaseCompilerProperties); ok { |
| 108 | archDisabledSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_disabled_srcs) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 109 | moduleAttrs.Tidy_disabled_srcs.SetSelectValue(axis, cfg, archDisabledSrcs) |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 110 | archTimeoutSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_timeout_srcs) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 111 | moduleAttrs.Tidy_timeout_srcs.SetSelectValue(axis, cfg, archTimeoutSrcs) |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 112 | } |
| 113 | } |
Sam Delmerico | fb3bb32 | 2022-10-21 10:42:24 -0400 | [diff] [blame] | 114 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 117 | // groupSrcsByExtension partitions `srcs` into groups based on file extension. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 118 | func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute { |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 119 | // Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl |
| 120 | // macro. |
| 121 | addSuffixForFilegroup := func(suffix string) bazel.LabelMapper { |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 122 | return func(otherModuleCtx bazel.OtherModuleContext, label bazel.Label) (string, bool) { |
| 123 | |
| 124 | m, exists := otherModuleCtx.ModuleFromName(label.OriginalModuleName) |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 125 | labelStr := label.Label |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 126 | if !exists || !android.IsFilegroup(otherModuleCtx, m) { |
| 127 | return labelStr, false |
| 128 | } |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 129 | // If the filegroup is already converted to aidl_library or proto_library, |
| 130 | // skip creating _c_srcs, _as_srcs, _cpp_srcs filegroups |
| 131 | fg, _ := m.(android.FileGroupAsLibrary) |
| 132 | if fg.ShouldConvertToAidlLibrary(ctx) || fg.ShouldConvertToProtoLibrary(ctx) { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 133 | return labelStr, false |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 134 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 135 | return labelStr + suffix, true |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 136 | } |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 139 | // TODO(b/190006308): Handle language detection of sources in a Bazel rule. |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 140 | labels := bazel.LabelPartitions{ |
| 141 | protoSrcPartition: android.ProtoSrcLabelPartition, |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 142 | cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")}, |
| 143 | asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")}, |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 144 | asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}}, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 145 | aidlSrcPartition: android.AidlSrcLabelPartition, |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 146 | // TODO(http://b/231968910): If there is ever a filegroup target that |
| 147 | // contains .l or .ll files we will need to find a way to add a |
| 148 | // LabelMapper for these that identifies these filegroups and |
| 149 | // converts them appropriately |
| 150 | lSrcPartition: bazel.LabelPartition{Extensions: []string{".l"}}, |
| 151 | llSrcPartition: bazel.LabelPartition{Extensions: []string{".ll"}}, |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 152 | // C++ is the "catch-all" group, and comprises generated sources because we don't |
| 153 | // know the language of these sources until the genrule is executed. |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 154 | cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true}, |
| 155 | syspropSrcPartition: bazel.LabelPartition{Extensions: []string{".sysprop"}}, |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 156 | } |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 157 | |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 158 | return bazel.PartitionLabelListAttribute(ctx, &srcs, labels) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 161 | // bp2BuildParseLibProps returns the attributes for a variant of a cc_library. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 162 | func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes { |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 163 | lib, ok := module.compiler.(*libraryDecorator) |
| 164 | if !ok { |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 165 | return staticOrSharedAttributes{} |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 166 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 167 | return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic) |
| 168 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 169 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 170 | // bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 171 | func bp2BuildParseSharedProps(ctx android.BazelConversionPathContext, 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] | 172 | return bp2BuildParseLibProps(ctx, module, false) |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 176 | func bp2BuildParseStaticProps(ctx android.BazelConversionPathContext, 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] | 177 | return bp2BuildParseLibProps(ctx, module, true) |
Liz Kammer | 2222c6b | 2021-05-24 15:41:47 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 180 | type depsPartition struct { |
| 181 | export bazel.LabelList |
| 182 | implementation bazel.LabelList |
| 183 | } |
| 184 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 185 | type bazelLabelForDepsFn func(android.BazelConversionPathContext, []string) bazel.LabelList |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 186 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 187 | func maybePartitionExportedAndImplementationsDeps(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 188 | if !exportsDeps { |
| 189 | return depsPartition{ |
| 190 | implementation: fn(ctx, allDeps), |
| 191 | } |
| 192 | } |
| 193 | |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 194 | implementation, export := android.FilterList(allDeps, exportedDeps) |
| 195 | |
| 196 | return depsPartition{ |
| 197 | export: fn(ctx, export), |
| 198 | implementation: fn(ctx, implementation), |
| 199 | } |
| 200 | } |
| 201 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 202 | type bazelLabelForDepsExcludesFn func(android.BazelConversionPathContext, []string, []string) bazel.LabelList |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 203 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 204 | func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 205 | if !exportsDeps { |
| 206 | return depsPartition{ |
| 207 | implementation: fn(ctx, allDeps, excludes), |
| 208 | } |
| 209 | } |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 210 | implementation, export := android.FilterList(allDeps, exportedDeps) |
| 211 | |
| 212 | return depsPartition{ |
| 213 | export: fn(ctx, export, excludes), |
| 214 | implementation: fn(ctx, implementation, excludes), |
| 215 | } |
| 216 | } |
| 217 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 218 | func bp2BuildPropParseHelper(ctx android.ArchVariantContext, module *Module, propsType interface{}, parseFunc func(axis bazel.ConfigurationAxis, config string, props interface{})) { |
| 219 | for axis, configToProps := range module.GetArchVariantProperties(ctx, propsType) { |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 220 | for cfg, props := range configToProps { |
| 221 | parseFunc(axis, cfg, props) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 226 | // Parses properties common to static and shared libraries. Also used for prebuilt libraries. |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 227 | func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes { |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 228 | attrs := staticOrSharedAttributes{} |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 229 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 230 | setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 231 | attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutHiddenVisibility)) |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 232 | attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs)) |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 233 | attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs)) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 234 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 235 | staticDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 236 | attrs.Deps.SetSelectValue(axis, config, staticDeps.export) |
| 237 | attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation) |
| 238 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 239 | sharedDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 240 | attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export) |
| 241 | attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation) |
| 242 | |
| 243 | attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs)) |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 244 | attrs.Enabled.SetSelectValue(axis, config, props.Enabled) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 245 | } |
Liz Kammer | 135bf55 | 2021-08-11 10:46:06 -0400 | [diff] [blame] | 246 | // system_dynamic_deps distinguishes between nil/empty list behavior: |
| 247 | // nil -> use default values |
| 248 | // empty list -> no values specified |
| 249 | attrs.System_dynamic_deps.ForceSpecifyEmptyList = true |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 250 | |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 251 | var apexAvailable []string |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 252 | if isStatic { |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 253 | apexAvailable = lib.StaticProperties.Static.Apex_available |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 254 | bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 255 | if staticOrSharedProps, ok := props.(*StaticProperties); ok { |
| 256 | setAttrs(axis, config, staticOrSharedProps.Static) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 257 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 258 | }) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 259 | } else { |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 260 | apexAvailable = lib.SharedProperties.Shared.Apex_available |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 261 | bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 262 | if staticOrSharedProps, ok := props.(*SharedProperties); ok { |
| 263 | setAttrs(axis, config, staticOrSharedProps.Shared) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 264 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 265 | }) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Liz Kammer | ae3994e | 2021-10-19 09:45:48 -0400 | [diff] [blame] | 268 | partitionedSrcs := groupSrcsByExtension(ctx, attrs.Srcs) |
| 269 | attrs.Srcs = partitionedSrcs[cppSrcPartition] |
| 270 | attrs.Srcs_c = partitionedSrcs[cSrcPartition] |
| 271 | attrs.Srcs_as = partitionedSrcs[asSrcPartition] |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 272 | |
Liz Kammer | aceec25 | 2023-03-24 09:46:36 -0400 | [diff] [blame] | 273 | attrs.Apex_available = android.ConvertApexAvailableToTags(apexAvailable) |
| 274 | |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 275 | attrs.Features.Append(convertHiddenVisibilityToFeatureStaticOrShared(ctx, module, isStatic)) |
| 276 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 277 | if !partitionedSrcs[protoSrcPartition].IsEmpty() { |
| 278 | // TODO(b/208815215): determine whether this is used and add support if necessary |
| 279 | ctx.ModuleErrorf("Migrating static/shared only proto srcs is not currently supported") |
| 280 | } |
| 281 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 282 | return attrs |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 285 | // Convenience struct to hold all attributes parsed from prebuilt properties. |
| 286 | type prebuiltAttributes struct { |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 287 | Src bazel.LabelAttribute |
| 288 | Enabled bazel.BoolAttribute |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 291 | func parseSrc(ctx android.BazelConversionPathContext, srcLabelAttribute *bazel.LabelAttribute, axis bazel.ConfigurationAxis, config string, srcs []string) { |
| 292 | srcFileError := func() { |
| 293 | ctx.ModuleErrorf("parseSrc: Expected at most one source file for %s %s\n", axis, config) |
| 294 | } |
| 295 | if len(srcs) > 1 { |
| 296 | srcFileError() |
| 297 | return |
| 298 | } else if len(srcs) == 0 { |
| 299 | return |
| 300 | } |
| 301 | if srcLabelAttribute.SelectValue(axis, config) != nil { |
| 302 | srcFileError() |
| 303 | return |
| 304 | } |
| 305 | srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, srcs[0])) |
| 306 | } |
| 307 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 308 | // NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 309 | func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) prebuiltAttributes { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 310 | |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 311 | var srcLabelAttribute bazel.LabelAttribute |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 312 | bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 313 | if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 314 | parseSrc(ctx, &srcLabelAttribute, axis, config, prebuiltLinkerProperties.Srcs) |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 315 | } |
| 316 | }) |
| 317 | |
| 318 | var enabledLabelAttribute bazel.BoolAttribute |
| 319 | parseAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { |
| 320 | if props.Enabled != nil { |
| 321 | enabledLabelAttribute.SetSelectValue(axis, config, props.Enabled) |
| 322 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 323 | parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs) |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if isStatic { |
| 327 | bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 328 | if staticProperties, ok := props.(*StaticProperties); ok { |
| 329 | parseAttrs(axis, config, staticProperties.Static) |
| 330 | } |
| 331 | }) |
| 332 | } else { |
| 333 | bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 334 | if sharedProperties, ok := props.(*SharedProperties); ok { |
| 335 | parseAttrs(axis, config, sharedProperties.Shared) |
| 336 | } |
| 337 | }) |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 340 | return prebuiltAttributes{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 341 | Src: srcLabelAttribute, |
| 342 | Enabled: enabledLabelAttribute, |
| 343 | } |
| 344 | } |
| 345 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 346 | func bp2BuildParsePrebuiltBinaryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes { |
| 347 | var srcLabelAttribute bazel.LabelAttribute |
| 348 | bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 349 | if props, ok := props.(*prebuiltLinkerProperties); ok { |
| 350 | parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs) |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 351 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b12ff59 | 2022-09-01 15:04:04 +0000 | [diff] [blame] | 352 | }) |
| 353 | |
| 354 | return prebuiltAttributes{ |
| 355 | Src: srcLabelAttribute, |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Colin Cross | c5075e9 | 2022-12-05 16:46:39 -0800 | [diff] [blame] | 359 | func bp2BuildParsePrebuiltObjectProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes { |
| 360 | var srcLabelAttribute bazel.LabelAttribute |
| 361 | bp2BuildPropParseHelper(ctx, module, &prebuiltObjectProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 362 | if props, ok := props.(*prebuiltObjectProperties); ok { |
| 363 | parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs) |
| 364 | } |
| 365 | }) |
| 366 | |
| 367 | return prebuiltAttributes{ |
| 368 | Src: srcLabelAttribute, |
| 369 | } |
| 370 | } |
| 371 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 372 | type baseAttributes struct { |
| 373 | compilerAttributes |
| 374 | linkerAttributes |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 375 | |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 376 | // A combination of compilerAttributes.features and linkerAttributes.features, as well as sanitizer features |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 377 | features bazel.StringListAttribute |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 378 | protoDependency *bazel.LabelAttribute |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 379 | aidlDependency *bazel.LabelAttribute |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 380 | Native_coverage *bool |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 383 | // Convenience struct to hold all attributes parsed from compiler properties. |
| 384 | type compilerAttributes struct { |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 385 | // Options for all languages |
| 386 | copts bazel.StringListAttribute |
| 387 | // Assembly options and sources |
| 388 | asFlags bazel.StringListAttribute |
| 389 | asSrcs bazel.LabelListAttribute |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 390 | asmSrcs bazel.LabelListAttribute |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 391 | // C options and sources |
| 392 | conlyFlags bazel.StringListAttribute |
| 393 | cSrcs bazel.LabelListAttribute |
| 394 | // C++ options and sources |
| 395 | cppFlags bazel.StringListAttribute |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 396 | srcs bazel.LabelListAttribute |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 397 | |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 398 | // Lex sources and options |
| 399 | lSrcs bazel.LabelListAttribute |
| 400 | llSrcs bazel.LabelListAttribute |
| 401 | lexopts bazel.StringListAttribute |
| 402 | |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 403 | // Sysprop sources |
| 404 | syspropSrcs bazel.LabelListAttribute |
| 405 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 406 | hdrs bazel.LabelListAttribute |
| 407 | |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 408 | rtti bazel.BoolAttribute |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 409 | |
| 410 | // Not affected by arch variants |
| 411 | stl *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 412 | cStd *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 413 | cppStd *string |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 414 | |
| 415 | localIncludes bazel.StringListAttribute |
| 416 | absoluteIncludes bazel.StringListAttribute |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 417 | |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 418 | includes BazelIncludes |
| 419 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 420 | protoSrcs bazel.LabelListAttribute |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 421 | aidlSrcs bazel.LabelListAttribute |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 422 | |
| 423 | stubsSymbolFile *string |
| 424 | stubsVersions bazel.StringListAttribute |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 425 | |
| 426 | features bazel.StringListAttribute |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 427 | |
| 428 | suffix bazel.StringAttribute |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 429 | |
| 430 | fdoProfile bazel.LabelAttribute |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Liz Kammer | cac7f69 | 2021-12-16 14:19:32 -0500 | [diff] [blame] | 433 | type filterOutFn func(string) bool |
| 434 | |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 435 | // filterOutHiddenVisibility removes the flag specifying hidden visibility as |
| 436 | // this flag is converted to a toolchain feature |
| 437 | func filterOutHiddenVisibility(flag string) bool { |
| 438 | return flag == config.VisibilityHiddenFlag |
| 439 | } |
| 440 | |
Liz Kammer | cac7f69 | 2021-12-16 14:19:32 -0500 | [diff] [blame] | 441 | func filterOutStdFlag(flag string) bool { |
| 442 | return strings.HasPrefix(flag, "-std=") |
| 443 | } |
| 444 | |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 445 | func filterOutClangUnknownCflags(flag string) bool { |
| 446 | for _, f := range config.ClangUnknownCflags { |
| 447 | if f == flag { |
| 448 | return true |
| 449 | } |
| 450 | } |
| 451 | return false |
| 452 | } |
| 453 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 454 | func parseCommandLineFlags(soongFlags []string, filterOut ...filterOutFn) []string { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 455 | var result []string |
| 456 | for _, flag := range soongFlags { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 457 | skipFlag := false |
| 458 | for _, filter := range filterOut { |
| 459 | if filter != nil && filter(flag) { |
| 460 | skipFlag = true |
| 461 | } |
| 462 | } |
| 463 | if skipFlag { |
Liz Kammer | cac7f69 | 2021-12-16 14:19:32 -0500 | [diff] [blame] | 464 | continue |
| 465 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 466 | // Soong's cflags can contain spaces, like `-include header.h`. For |
| 467 | // Bazel's copts, split them up to be compatible with the |
| 468 | // no_copts_tokenization feature. |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 469 | result = append(result, strings.Split(flag, " ")...) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 470 | } |
| 471 | return result |
| 472 | } |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 473 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 474 | func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 475 | // If there's arch specific srcs or exclude_srcs, generate a select entry for it. |
| 476 | // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too. |
| 477 | if srcsList, ok := parseSrcs(ctx, props); ok { |
| 478 | ca.srcs.SetSelectValue(axis, config, srcsList) |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 479 | } |
| 480 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 481 | localIncludeDirs := props.Local_include_dirs |
| 482 | if axis == bazel.NoConfigAxis { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 483 | ca.cStd, ca.cppStd = bp2buildResolveCppStdValue(props.C_std, props.Cpp_std, props.Gnu_extensions) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 484 | if includeBuildDirectory(props.Include_build_directory) { |
| 485 | localIncludeDirs = append(localIncludeDirs, ".") |
Liz Kammer | 222bdcf | 2021-10-11 14:15:51 -0400 | [diff] [blame] | 486 | } |
Jingwen Chen | e32e9e0 | 2021-04-23 09:17:24 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 489 | ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs) |
| 490 | ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs) |
| 491 | |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 492 | instructionSet := proptools.StringDefault(props.Instruction_set, "") |
| 493 | if instructionSet == "arm" { |
| 494 | ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"}) |
| 495 | } else if instructionSet != "" && instructionSet != "thumb" { |
| 496 | ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet) |
| 497 | } |
| 498 | |
Liz Kammer | cac7f69 | 2021-12-16 14:19:32 -0500 | [diff] [blame] | 499 | // In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being |
| 500 | // overridden. In Bazel we always allow overriding, via flags; however, this can cause |
| 501 | // incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other |
| 502 | // cases. |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 503 | ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutClangUnknownCflags, filterOutHiddenVisibility)) |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 504 | ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil)) |
| 505 | ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, filterOutClangUnknownCflags)) |
| 506 | ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, filterOutClangUnknownCflags)) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 507 | ca.rtti.SetSelectValue(axis, config, props.Rtti) |
| 508 | } |
| 509 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 510 | func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, module *Module) { |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 511 | bp2BuildPropParseHelper(ctx, module, &StlProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 512 | if stlProps, ok := props.(*StlProperties); ok { |
| 513 | if stlProps.Stl == nil { |
| 514 | return |
| 515 | } |
| 516 | if ca.stl == nil { |
Liz Kammer | 7128d38 | 2022-05-12 11:42:33 -0400 | [diff] [blame] | 517 | stl := deduplicateStlInput(*stlProps.Stl) |
| 518 | ca.stl = &stl |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 519 | } else if ca.stl != stlProps.Stl { |
| 520 | ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *ca.stl, stlProps.Stl) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 521 | } |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 522 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 523 | }) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 524 | } |
Jingwen Chen | c1c2650 | 2021-04-05 10:35:13 +0000 | [diff] [blame] | 525 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 526 | func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) { |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 527 | productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 528 | "Cflags": &ca.copts, |
| 529 | "Asflags": &ca.asFlags, |
| 530 | "CppFlags": &ca.cppFlags, |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 531 | } |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 532 | for propName, attr := range productVarPropNameToAttribute { |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 533 | if productConfigProps, exists := productVariableProps[propName]; exists { |
| 534 | for productConfigProp, prop := range productConfigProps { |
| 535 | flags, ok := prop.([]string) |
Liz Kammer | ba7a9c5 | 2021-05-26 08:45:30 -0400 | [diff] [blame] | 536 | if !ok { |
| 537 | ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName)) |
| 538 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 539 | newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name) |
| 540 | attr.SetSelectValue(productConfigProp.ConfigurationAxis(), productConfigProp.SelectKey(), newFlags) |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 541 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 542 | } |
| 543 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 544 | } |
Liz Kammer | 6fd7b3f | 2021-05-06 13:54:29 -0400 | [diff] [blame] | 545 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 546 | func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 547 | ca.srcs.ResolveExcludes() |
| 548 | partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs) |
| 549 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 550 | ca.protoSrcs = partitionedSrcs[protoSrcPartition] |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 551 | ca.aidlSrcs = partitionedSrcs[aidlSrcPartition] |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 552 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 553 | for p, lla := range partitionedSrcs { |
| 554 | // if there are no sources, there is no need for headers |
| 555 | if lla.IsEmpty() { |
| 556 | continue |
| 557 | } |
| 558 | lla.Append(implementationHdrs) |
| 559 | partitionedSrcs[p] = lla |
| 560 | } |
| 561 | |
| 562 | ca.srcs = partitionedSrcs[cppSrcPartition] |
| 563 | ca.cSrcs = partitionedSrcs[cSrcPartition] |
| 564 | ca.asSrcs = partitionedSrcs[asSrcPartition] |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 565 | ca.asmSrcs = partitionedSrcs[asmSrcPartition] |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 566 | ca.lSrcs = partitionedSrcs[lSrcPartition] |
| 567 | ca.llSrcs = partitionedSrcs[llSrcPartition] |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 568 | ca.syspropSrcs = partitionedSrcs[syspropSrcPartition] |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 569 | |
| 570 | ca.absoluteIncludes.DeduplicateAxesFromBase() |
| 571 | ca.localIncludes.DeduplicateAxesFromBase() |
| 572 | } |
| 573 | |
| 574 | // Parse srcs from an arch or OS's props value. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 575 | func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, bool) { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 576 | anySrcs := false |
| 577 | // Add srcs-like dependencies such as generated files. |
| 578 | // First create a LabelList containing these dependencies, then merge the values with srcs. |
| 579 | generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, props.Generated_sources, props.Exclude_generated_sources) |
| 580 | if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 { |
| 581 | anySrcs = true |
| 582 | } |
| 583 | |
| 584 | allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs) |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 585 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 586 | if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 { |
| 587 | anySrcs = true |
| 588 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 589 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 590 | return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs |
| 591 | } |
| 592 | |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 593 | func bp2buildStdVal(std *string, prefix string, useGnu bool) *string { |
| 594 | defaultVal := prefix + "_std_default" |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 595 | // If c{,pp}std properties are not specified, don't generate them in the BUILD file. |
| 596 | // Defaults are handled by the toolchain definition. |
| 597 | // However, if gnu_extensions is false, then the default gnu-to-c version must be specified. |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 598 | stdVal := proptools.StringDefault(std, defaultVal) |
| 599 | if stdVal == "experimental" || stdVal == defaultVal { |
| 600 | if stdVal == "experimental" { |
| 601 | stdVal = prefix + "_std_experimental" |
| 602 | } |
| 603 | if !useGnu { |
| 604 | stdVal += "_no_gnu" |
| 605 | } |
| 606 | } else if !useGnu { |
| 607 | stdVal = gnuToCReplacer.Replace(stdVal) |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 608 | } |
| 609 | |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 610 | if stdVal == defaultVal { |
| 611 | return nil |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 612 | } |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 613 | return &stdVal |
| 614 | } |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 615 | |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 616 | func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) { |
| 617 | useGnu := useGnuExtensions(gnu_extensions) |
| 618 | |
| 619 | return bp2buildStdVal(c_std, "c", useGnu), bp2buildStdVal(cpp_std, "cpp", useGnu) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 622 | // packageFromLabel extracts package from a fully-qualified or relative Label and whether the label |
| 623 | // is fully-qualified. |
| 624 | // e.g. fully-qualified "//a/b:foo" -> "a/b", true, relative: ":bar" -> ".", false |
| 625 | func packageFromLabel(label string) (string, bool) { |
| 626 | split := strings.Split(label, ":") |
| 627 | if len(split) != 2 { |
| 628 | return "", false |
| 629 | } |
| 630 | if split[0] == "" { |
| 631 | return ".", false |
| 632 | } |
| 633 | // remove leading "//" |
| 634 | return split[0][2:], true |
| 635 | } |
| 636 | |
| 637 | // includesFromLabelList extracts relative/absolute includes from a bazel.LabelList> |
| 638 | func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []string) { |
| 639 | for _, hdr := range labelList.Includes { |
| 640 | if pkg, hasPkg := packageFromLabel(hdr.Label); hasPkg { |
| 641 | absolute = append(absolute, pkg) |
| 642 | } else if pkg != "" { |
| 643 | relative = append(relative, pkg) |
| 644 | } |
| 645 | } |
| 646 | return relative, absolute |
| 647 | } |
| 648 | |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 649 | type YasmAttributes struct { |
| 650 | Srcs bazel.LabelListAttribute |
| 651 | Flags bazel.StringListAttribute |
| 652 | Include_dirs bazel.StringListAttribute |
| 653 | } |
| 654 | |
| 655 | func bp2BuildYasm(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) *bazel.LabelAttribute { |
| 656 | if ca.asmSrcs.IsEmpty() { |
| 657 | return nil |
| 658 | } |
| 659 | |
| 660 | // Yasm needs the include directories from both local_includes and |
| 661 | // export_include_dirs. We don't care about actually exporting them from the |
| 662 | // yasm rule though, because they will also be present on the cc_ rule that |
| 663 | // wraps this yasm rule. |
| 664 | includes := ca.localIncludes.Clone() |
| 665 | bp2BuildPropParseHelper(ctx, m, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 666 | if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { |
| 667 | if len(flagExporterProperties.Export_include_dirs) > 0 { |
| 668 | x := bazel.StringListAttribute{} |
| 669 | x.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs) |
| 670 | includes.Append(x) |
| 671 | } |
| 672 | } |
| 673 | }) |
| 674 | |
| 675 | ctx.CreateBazelTargetModule( |
| 676 | bazel.BazelTargetModuleProperties{ |
| 677 | Rule_class: "yasm", |
| 678 | Bzl_load_location: "//build/bazel/rules/cc:yasm.bzl", |
| 679 | }, |
| 680 | android.CommonAttributes{Name: m.Name() + "_yasm"}, |
| 681 | &YasmAttributes{ |
| 682 | Srcs: ca.asmSrcs, |
| 683 | Flags: ca.asFlags, |
| 684 | Include_dirs: *includes, |
| 685 | }) |
| 686 | |
| 687 | // We only want to add a dependency on the _yasm target if there are asm |
| 688 | // sources in the current configuration. If there are unconfigured asm |
| 689 | // sources, always add the dependency. Otherwise, add the dependency only |
| 690 | // on the configuration axes and values that had asm sources. |
| 691 | if len(ca.asmSrcs.Value.Includes) > 0 { |
| 692 | return bazel.MakeLabelAttribute(":" + m.Name() + "_yasm") |
| 693 | } |
| 694 | |
| 695 | ret := &bazel.LabelAttribute{} |
| 696 | for _, axis := range ca.asmSrcs.SortedConfigurationAxes() { |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 697 | for cfg := range ca.asmSrcs.ConfigurableValues[axis] { |
| 698 | ret.SetSelectValue(axis, cfg, bazel.Label{Label: ":" + m.Name() + "_yasm"}) |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | return ret |
| 702 | } |
| 703 | |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 704 | // bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module.. |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 705 | func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 706 | archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) |
| 707 | archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 708 | archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{}) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 709 | |
| 710 | var implementationHdrs bazel.LabelListAttribute |
| 711 | |
| 712 | axisToConfigs := map[bazel.ConfigurationAxis]map[string]bool{} |
| 713 | allAxesAndConfigs := func(cp android.ConfigurationAxisToArchVariantProperties) { |
| 714 | for axis, configMap := range cp { |
| 715 | if _, ok := axisToConfigs[axis]; !ok { |
| 716 | axisToConfigs[axis] = map[string]bool{} |
| 717 | } |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 718 | for cfg := range configMap { |
| 719 | axisToConfigs[axis][cfg] = true |
Chris Parsons | a967f25 | 2021-09-23 16:34:35 -0400 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 723 | allAxesAndConfigs(archVariantCompilerProps) |
| 724 | allAxesAndConfigs(archVariantLinkerProps) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 725 | allAxesAndConfigs(archVariantLibraryProperties) |
Chris Parsons | a967f25 | 2021-09-23 16:34:35 -0400 | [diff] [blame] | 726 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 727 | compilerAttrs := compilerAttributes{} |
| 728 | linkerAttrs := linkerAttributes{} |
| 729 | |
Chris Parsons | 7b3289b | 2023-01-26 17:30:44 -0500 | [diff] [blame] | 730 | // Iterate through these axes in a deterministic order. This is required |
| 731 | // because processing certain dependencies may result in concatenating |
| 732 | // elements along other axes. (For example, processing NoConfig may result |
| 733 | // in elements being added to InApex). This is thus the only way to ensure |
| 734 | // that the order of entries in each list is in a predictable order. |
| 735 | for _, axis := range bazel.SortedConfigurationAxes(axisToConfigs) { |
| 736 | configs := axisToConfigs[axis] |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 737 | for cfg := range configs { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 738 | var allHdrs []string |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 739 | if baseCompilerProps, ok := archVariantCompilerProps[axis][cfg].(*BaseCompilerProperties); ok { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 740 | allHdrs = baseCompilerProps.Generated_headers |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 741 | if baseCompilerProps.Lex != nil { |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 742 | compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags) |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 743 | } |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 744 | (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | var exportHdrs []string |
| 748 | |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 749 | if baseLinkerProps, ok := archVariantLinkerProps[axis][cfg].(*BaseLinkerProperties); ok { |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 750 | exportHdrs = baseLinkerProps.Export_generated_headers |
| 751 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 752 | (&linkerAttrs).bp2buildForAxisAndConfig(ctx, module, axis, cfg, baseLinkerProps) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 753 | } |
| 754 | headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 755 | implementationHdrs.SetSelectValue(axis, cfg, headers.implementation) |
| 756 | compilerAttrs.hdrs.SetSelectValue(axis, cfg, headers.export) |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 757 | |
| 758 | exportIncludes, exportAbsoluteIncludes := includesFromLabelList(headers.export) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 759 | compilerAttrs.includes.Includes.SetSelectValue(axis, cfg, exportIncludes) |
| 760 | compilerAttrs.includes.AbsoluteIncludes.SetSelectValue(axis, cfg, exportAbsoluteIncludes) |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 761 | |
| 762 | includes, absoluteIncludes := includesFromLabelList(headers.implementation) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 763 | currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, cfg) |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 764 | currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...)) |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 765 | |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 766 | compilerAttrs.absoluteIncludes.SetSelectValue(axis, cfg, currAbsoluteIncludes) |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 767 | |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 768 | currIncludes := compilerAttrs.localIncludes.SelectValue(axis, cfg) |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 769 | currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...)) |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 770 | |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 771 | compilerAttrs.localIncludes.SetSelectValue(axis, cfg, currIncludes) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 772 | |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 773 | if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok { |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 774 | if axis == bazel.NoConfigAxis { |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 775 | if libraryProps.Stubs.Symbol_file != nil { |
| 776 | compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file |
| 777 | versions := android.CopyOf(libraryProps.Stubs.Versions) |
| 778 | normalizeVersions(ctx, versions) |
| 779 | versions = addCurrentVersionIfNotPresent(versions) |
| 780 | compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions) |
| 781 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 782 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 783 | if suffix := libraryProps.Suffix; suffix != nil { |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 784 | compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 785 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 786 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 787 | } |
| 788 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 789 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 790 | compilerAttrs.convertStlProps(ctx, module) |
| 791 | (&linkerAttrs).convertStripProps(ctx, module) |
| 792 | |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 793 | var nativeCoverage *bool |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 794 | if module.coverage != nil && module.coverage.Properties.Native_coverage != nil && |
| 795 | !Bool(module.coverage.Properties.Native_coverage) { |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 796 | nativeCoverage = BoolPtr(false) |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 799 | productVariableProps := android.ProductVariableProperties(ctx, ctx.Module()) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 800 | |
| 801 | (&compilerAttrs).convertProductVariables(ctx, productVariableProps) |
| 802 | (&linkerAttrs).convertProductVariables(ctx, productVariableProps) |
| 803 | |
| 804 | (&compilerAttrs).finalize(ctx, implementationHdrs) |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 805 | (&linkerAttrs).finalize(ctx) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 806 | |
Cole Faust | 7071a05 | 2022-07-29 15:58:33 -0700 | [diff] [blame] | 807 | (&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs)) |
| 808 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 809 | protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs) |
| 810 | |
| 811 | // bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know |
| 812 | // which. This will add the newly generated proto library to the appropriate attribute and nothing |
| 813 | // to the other |
| 814 | (&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib) |
| 815 | (&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib) |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 816 | |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 817 | aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs, linkerAttrs) |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 818 | if aidlDep != nil { |
| 819 | if lib, ok := module.linker.(*libraryDecorator); ok { |
| 820 | if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) { |
| 821 | (&linkerAttrs).wholeArchiveDeps.Add(aidlDep) |
| 822 | } else { |
| 823 | (&linkerAttrs).implementationWholeArchiveDeps.Add(aidlDep) |
| 824 | } |
| 825 | } |
| 826 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 827 | |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 828 | convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs) |
| 829 | (&compilerAttrs).srcs.Add(&convertedLSrcs.srcName) |
| 830 | (&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName) |
| 831 | |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 832 | if module.afdo != nil && module.afdo.Properties.Afdo { |
| 833 | fdoProfileDep := bp2buildFdoProfile(ctx, module) |
| 834 | if fdoProfileDep != nil { |
| 835 | (&compilerAttrs).fdoProfile.SetValue(*fdoProfileDep) |
| 836 | } |
| 837 | } |
| 838 | |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 839 | if !compilerAttrs.syspropSrcs.IsEmpty() { |
| 840 | (&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs)) |
| 841 | } |
| 842 | |
Zi Wang | 9f609db | 2023-01-04 11:06:54 -0800 | [diff] [blame] | 843 | linkerAttrs.wholeArchiveDeps.Prepend = true |
| 844 | linkerAttrs.deps.Prepend = true |
| 845 | compilerAttrs.localIncludes.Prepend = true |
| 846 | compilerAttrs.absoluteIncludes.Prepend = true |
| 847 | compilerAttrs.hdrs.Prepend = true |
| 848 | |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 849 | features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module)) |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 850 | features = features.Append(bp2buildLtoFeatures(ctx, module)) |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 851 | features = features.Append(convertHiddenVisibilityToFeatureBase(ctx, module)) |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 852 | features.DeduplicateAxesFromBase() |
| 853 | |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 854 | addMuslSystemDynamicDeps(ctx, linkerAttrs) |
| 855 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 856 | return baseAttributes{ |
| 857 | compilerAttrs, |
| 858 | linkerAttrs, |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 859 | *features, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 860 | protoDep.protoDep, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 861 | aidlDep, |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 862 | nativeCoverage, |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 866 | // As a workaround for b/261657184, we are manually adding the default value |
| 867 | // of system_dynamic_deps for the linux_musl os. |
| 868 | // TODO: Solve this properly |
| 869 | func addMuslSystemDynamicDeps(ctx android.Bp2buildMutatorContext, attrs linkerAttributes) { |
| 870 | systemDynamicDeps := attrs.systemDynamicDeps.SelectValue(bazel.OsConfigurationAxis, "linux_musl") |
| 871 | if attrs.systemDynamicDeps.HasAxisSpecificValues(bazel.OsConfigurationAxis) && systemDynamicDeps.IsNil() { |
| 872 | attrs.systemDynamicDeps.SetSelectValue(bazel.OsConfigurationAxis, "linux_musl", android.BazelLabelForModuleDeps(ctx, config.MuslDefaultSharedLibraries)) |
| 873 | } |
| 874 | } |
| 875 | |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 876 | type fdoProfileAttributes struct { |
| 877 | Absolute_path_profile string |
| 878 | } |
| 879 | |
| 880 | func bp2buildFdoProfile( |
| 881 | ctx android.Bp2buildMutatorContext, |
| 882 | m *Module, |
| 883 | ) *bazel.Label { |
| 884 | for _, project := range globalAfdoProfileProjects { |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 885 | // Ensure handcrafted BUILD file exists in the project |
| 886 | BUILDPath := android.ExistentPathForSource(ctx, project, "BUILD") |
| 887 | if BUILDPath.Valid() { |
| 888 | // We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project |
| 889 | // This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has |
| 890 | // an associated fdo_profile target declared in the same package. |
| 891 | // TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `<module-name>-arm<64>.afdo`) |
| 892 | path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo") |
| 893 | if path.Valid() { |
| 894 | // FIXME: Some profiles only exist internally and are not released to AOSP. |
| 895 | // When generated BUILD files are checked in, we'll run into merge conflict. |
| 896 | // The cc_library_shared target in AOSP won't have reference to an fdo_profile target because |
| 897 | // the profile doesn't exist. Internally, the same cc_library_shared target will |
| 898 | // have reference to the fdo_profile. |
| 899 | // For more context, see b/258682955#comment2 |
| 900 | fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name() |
| 901 | return &bazel.Label{ |
| 902 | Label: fdoProfileLabel, |
| 903 | } |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | return nil |
| 909 | } |
| 910 | |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 911 | func bp2buildCcAidlLibrary( |
| 912 | ctx android.Bp2buildMutatorContext, |
| 913 | m *Module, |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 914 | aidlLabelList bazel.LabelListAttribute, |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 915 | linkerAttrs linkerAttributes, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 916 | ) *bazel.LabelAttribute { |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 917 | if !aidlLabelList.IsEmpty() { |
| 918 | aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool { |
| 919 | if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok && |
| 920 | fg.ShouldConvertToAidlLibrary(ctx) { |
| 921 | return true |
| 922 | } |
| 923 | return false |
| 924 | }) |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 925 | |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 926 | apexAvailableTags := android.ApexAvailableTags(ctx.Module()) |
| 927 | sdkAttrs := bp2BuildParseSdkAttributes(m) |
| 928 | |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 929 | if !aidlSrcs.IsEmpty() { |
| 930 | aidlLibName := m.Name() + "_aidl_library" |
| 931 | ctx.CreateBazelTargetModule( |
| 932 | bazel.BazelTargetModuleProperties{ |
| 933 | Rule_class: "aidl_library", |
Sam Delmerico | e55bf08 | 2023-03-31 09:47:28 -0400 | [diff] [blame] | 934 | Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 935 | }, |
| 936 | android.CommonAttributes{Name: aidlLibName}, |
| 937 | &aidlLibraryAttributes{ |
| 938 | Srcs: aidlSrcs, |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 939 | Tags: apexAvailableTags, |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 940 | }, |
| 941 | ) |
| 942 | aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) |
| 943 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 944 | |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 945 | if !aidlLibs.IsEmpty() { |
| 946 | ccAidlLibrarylabel := m.Name() + "_cc_aidl_library" |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 947 | // Since parent cc_library already has these dependencies, we can add them as implementation |
| 948 | // deps so that they don't re-export |
| 949 | implementationDeps := linkerAttrs.deps.Clone() |
| 950 | implementationDeps.Append(linkerAttrs.implementationDeps) |
| 951 | implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone() |
| 952 | implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps) |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 953 | |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 954 | ctx.CreateBazelTargetModule( |
| 955 | bazel.BazelTargetModuleProperties{ |
| 956 | Rule_class: "cc_aidl_library", |
| 957 | Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl", |
| 958 | }, |
| 959 | android.CommonAttributes{Name: ccAidlLibrarylabel}, |
| 960 | &ccAidlLibraryAttributes{ |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 961 | Deps: aidlLibs, |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 962 | Implementation_deps: *implementationDeps, |
| 963 | Implementation_dynamic_deps: *implementationDynamicDeps, |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 964 | Tags: apexAvailableTags, |
| 965 | sdkAttributes: sdkAttrs, |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 966 | }, |
| 967 | ) |
| 968 | label := &bazel.LabelAttribute{ |
| 969 | Value: &bazel.Label{ |
| 970 | Label: ":" + ccAidlLibrarylabel, |
| 971 | }, |
| 972 | } |
| 973 | return label |
| 974 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 975 | } |
| 976 | |
Vinh Tran | a3b8b78 | 2022-09-14 11:40:24 -0400 | [diff] [blame] | 977 | return nil |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 978 | } |
| 979 | |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 980 | func bp2BuildParseSdkAttributes(module *Module) sdkAttributes { |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 981 | return sdkAttributes{ |
| 982 | Sdk_version: module.Properties.Sdk_version, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 983 | Min_sdk_version: module.Properties.Min_sdk_version, |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | type sdkAttributes struct { |
| 988 | Sdk_version *string |
| 989 | Min_sdk_version *string |
| 990 | } |
| 991 | |
Jingwen Chen | 107c0de | 2021-04-09 10:43:12 +0000 | [diff] [blame] | 992 | // Convenience struct to hold all attributes parsed from linker properties. |
| 993 | type linkerAttributes struct { |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 994 | deps bazel.LabelListAttribute |
| 995 | implementationDeps bazel.LabelListAttribute |
| 996 | dynamicDeps bazel.LabelListAttribute |
| 997 | implementationDynamicDeps bazel.LabelListAttribute |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 998 | runtimeDeps bazel.LabelListAttribute |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 999 | wholeArchiveDeps bazel.LabelListAttribute |
| 1000 | implementationWholeArchiveDeps bazel.LabelListAttribute |
| 1001 | systemDynamicDeps bazel.LabelListAttribute |
| 1002 | usedSystemDynamicDepAsDynamicDep map[string]bool |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1003 | |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 1004 | useVersionLib bazel.BoolAttribute |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1005 | linkopts bazel.StringListAttribute |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 1006 | additionalLinkerInputs bazel.LabelListAttribute |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1007 | stripKeepSymbols bazel.BoolAttribute |
| 1008 | stripKeepSymbolsAndDebugFrame bazel.BoolAttribute |
| 1009 | stripKeepSymbolsList bazel.StringListAttribute |
| 1010 | stripAll bazel.BoolAttribute |
| 1011 | stripNone bazel.BoolAttribute |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1012 | features bazel.StringListAttribute |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1015 | var ( |
| 1016 | soongSystemSharedLibs = []string{"libc", "libm", "libdl"} |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1017 | versionLib = "libbuildversion" |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1018 | ) |
| 1019 | |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1020 | // resolveTargetApex re-adds the shared and static libs in target.apex.exclude_shared|static_libs props to non-apex variant |
| 1021 | // since all libs are already excluded by default |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 1022 | func (la *linkerAttributes) resolveTargetApexProp(ctx android.BazelConversionPathContext, props *BaseLinkerProperties) { |
| 1023 | excludeSharedLibs := bazelLabelForSharedDeps(ctx, props.Target.Apex.Exclude_shared_libs) |
| 1024 | sharedExcludes := bazel.LabelList{Excludes: excludeSharedLibs.Includes} |
| 1025 | sharedExcludesLabelList := bazel.LabelListAttribute{} |
| 1026 | sharedExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, sharedExcludes) |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1027 | |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 1028 | la.dynamicDeps.Append(sharedExcludesLabelList) |
| 1029 | la.implementationDynamicDeps.Append(sharedExcludesLabelList) |
| 1030 | |
| 1031 | excludeStaticLibs := bazelLabelForStaticDeps(ctx, props.Target.Apex.Exclude_static_libs) |
| 1032 | staticExcludes := bazel.LabelList{Excludes: excludeStaticLibs.Includes} |
| 1033 | staticExcludesLabelList := bazel.LabelListAttribute{} |
| 1034 | staticExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, staticExcludes) |
| 1035 | |
| 1036 | la.deps.Append(staticExcludesLabelList) |
| 1037 | la.implementationDeps.Append(staticExcludesLabelList) |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1040 | func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, module *Module, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) { |
| 1041 | isBinary := module.Binary() |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1042 | // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module |
| 1043 | var axisFeatures []string |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1044 | |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 1045 | wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs) |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1046 | staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs)) |
| 1047 | if axis == bazel.NoConfigAxis { |
| 1048 | la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib) |
| 1049 | if proptools.Bool(props.Use_version_lib) { |
| 1050 | versionLibAlreadyInDeps := android.InList(versionLib, wholeStaticLibs) |
| 1051 | // remove from static libs so there is no duplicate dependency |
| 1052 | _, staticLibs = android.RemoveFromList(versionLib, staticLibs) |
| 1053 | // only add the dep if it is not in progress |
| 1054 | if !versionLibAlreadyInDeps { |
| 1055 | if isBinary { |
| 1056 | wholeStaticLibs = append(wholeStaticLibs, versionLib) |
| 1057 | } else { |
| 1058 | la.implementationWholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, []string{versionLib}, props.Exclude_static_libs)) |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1064 | // Excludes to parallel Soong: |
| 1065 | // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0 |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1066 | la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs)) |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 1067 | |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1068 | staticDeps := maybePartitionExportedAndImplementationsDepsExcludes( |
| 1069 | ctx, |
| 1070 | !isBinary, |
| 1071 | staticLibs, |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 1072 | props.Exclude_static_libs, |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1073 | props.Export_static_lib_headers, |
| 1074 | bazelLabelForStaticDepsExcludes, |
| 1075 | ) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1076 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1077 | headerLibs := android.FirstUniqueStrings(props.Header_libs) |
| 1078 | hDeps := maybePartitionExportedAndImplementationsDeps(ctx, !isBinary, headerLibs, props.Export_header_lib_headers, bazelLabelForHeaderDeps) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1079 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1080 | (&hDeps.export).Append(staticDeps.export) |
| 1081 | la.deps.SetSelectValue(axis, config, hDeps.export) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1082 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1083 | (&hDeps.implementation).Append(staticDeps.implementation) |
| 1084 | la.implementationDeps.SetSelectValue(axis, config, hDeps.implementation) |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1085 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1086 | systemSharedLibs := props.System_shared_libs |
| 1087 | // systemSharedLibs distinguishes between nil/empty list behavior: |
| 1088 | // nil -> use default values |
| 1089 | // empty list -> no values specified |
| 1090 | if len(systemSharedLibs) > 0 { |
| 1091 | systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs) |
| 1092 | } |
| 1093 | la.systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs)) |
| 1094 | |
| 1095 | sharedLibs := android.FirstUniqueStrings(props.Shared_libs) |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1096 | excludeSharedLibs := props.Exclude_shared_libs |
| 1097 | usedSystem := android.FilterListPred(sharedLibs, func(s string) bool { |
| 1098 | return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs) |
| 1099 | }) |
| 1100 | for _, el := range usedSystem { |
| 1101 | if la.usedSystemDynamicDepAsDynamicDep == nil { |
| 1102 | la.usedSystemDynamicDepAsDynamicDep = map[string]bool{} |
| 1103 | } |
| 1104 | la.usedSystemDynamicDepAsDynamicDep[el] = true |
| 1105 | } |
| 1106 | |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1107 | sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes( |
| 1108 | ctx, |
| 1109 | !isBinary, |
| 1110 | sharedLibs, |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 1111 | props.Exclude_shared_libs, |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1112 | props.Export_shared_lib_headers, |
| 1113 | bazelLabelForSharedDepsExcludes, |
| 1114 | ) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1115 | la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export) |
| 1116 | la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation) |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 1117 | la.resolveTargetApexProp(ctx, props) |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 1118 | |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1119 | if axis == bazel.NoConfigAxis || (axis == bazel.OsConfigurationAxis && config == bazel.OsAndroid) { |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1120 | // If a dependency in la.implementationDynamicDeps or la.dynamicDeps has stubs, its |
| 1121 | // stub variant should be used when the dependency is linked in a APEX. The |
| 1122 | // dependencies in NoConfigAxis and OsConfigurationAxis/OsAndroid are grouped by |
| 1123 | // having stubs or not, so Bazel select() statement can be used to choose |
| 1124 | // source/stub variants of them. |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1125 | apexAvailable := module.ApexAvailable() |
Spandan Das | ac693b2 | 2023-04-24 00:07:38 +0000 | [diff] [blame] | 1126 | setStubsForDynamicDeps(ctx, axis, config, apexAvailable, sharedDeps.export, &la.dynamicDeps, 0, false) |
| 1127 | setStubsForDynamicDeps(ctx, axis, config, apexAvailable, sharedDeps.implementation, &la.implementationDynamicDeps, 1, false) |
| 1128 | if len(systemSharedLibs) > 0 { |
| 1129 | setStubsForDynamicDeps(ctx, axis, config, apexAvailable, bazelLabelForSharedDeps(ctx, systemSharedLibs), &la.systemDynamicDeps, 2, true) |
| 1130 | } |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1131 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1132 | |
| 1133 | if !BoolDefault(props.Pack_relocations, packRelocationsDefault) { |
| 1134 | axisFeatures = append(axisFeatures, "disable_pack_relocations") |
| 1135 | } |
| 1136 | |
| 1137 | if Bool(props.Allow_undefined_symbols) { |
| 1138 | axisFeatures = append(axisFeatures, "-no_undefined_symbols") |
| 1139 | } |
| 1140 | |
| 1141 | var linkerFlags []string |
| 1142 | if len(props.Ldflags) > 0 { |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 1143 | linkerFlags = append(linkerFlags, proptools.NinjaEscapeList(props.Ldflags)...) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1144 | // binaries remove static flag if -shared is in the linker flags |
| 1145 | if isBinary && android.InList("-shared", linkerFlags) { |
| 1146 | axisFeatures = append(axisFeatures, "-static_flag") |
| 1147 | } |
| 1148 | } |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 1149 | |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1150 | if !props.libCrt() { |
| 1151 | axisFeatures = append(axisFeatures, "-use_libcrt") |
| 1152 | } |
| 1153 | if !props.crt() { |
| 1154 | axisFeatures = append(axisFeatures, "-link_crt") |
| 1155 | } |
| 1156 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 1157 | // This must happen before the addition of flags for Version Script and |
| 1158 | // Dynamic List, as these flags must be split on spaces and those must not |
| 1159 | linkerFlags = parseCommandLineFlags(linkerFlags, filterOutClangUnknownCflags) |
| 1160 | |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 1161 | additionalLinkerInputs := bazel.LabelList{} |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1162 | if props.Version_script != nil { |
| 1163 | label := android.BazelLabelForModuleSrcSingle(ctx, *props.Version_script) |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 1164 | additionalLinkerInputs.Add(&label) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1165 | linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label)) |
| 1166 | } |
Alix | 773adaa | 2022-04-27 17:49:34 +0000 | [diff] [blame] | 1167 | |
| 1168 | if props.Dynamic_list != nil { |
| 1169 | label := android.BazelLabelForModuleSrcSingle(ctx, *props.Dynamic_list) |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 1170 | additionalLinkerInputs.Add(&label) |
Alix | 773adaa | 2022-04-27 17:49:34 +0000 | [diff] [blame] | 1171 | linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--dynamic-list,$(location %s)", label.Label)) |
| 1172 | } |
| 1173 | |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 1174 | la.additionalLinkerInputs.SetSelectValue(axis, config, additionalLinkerInputs) |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 1175 | la.linkopts.SetSelectValue(axis, config, linkerFlags) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1176 | |
| 1177 | if axisFeatures != nil { |
| 1178 | la.features.SetSelectValue(axis, config, axisFeatures) |
| 1179 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 1180 | |
| 1181 | runtimeDeps := android.BazelLabelForModuleDepsExcludes(ctx, props.Runtime_libs, props.Exclude_runtime_libs) |
| 1182 | if !runtimeDeps.IsEmpty() { |
| 1183 | la.runtimeDeps.SetSelectValue(axis, config, runtimeDeps) |
| 1184 | } |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
Spandan Das | 2518c02 | 2023-03-17 03:02:32 +0000 | [diff] [blame] | 1187 | var ( |
| 1188 | apiSurfaceModuleLibCurrentPackage = "@api_surfaces//" + android.ModuleLibApi.String() + "/current:" |
| 1189 | ) |
| 1190 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1191 | func availableToSameApexes(a, b []string) bool { |
| 1192 | if len(a) == 0 && len(b) == 0 { |
| 1193 | return true |
| 1194 | } |
| 1195 | differ, _, _ := android.ListSetDifference(a, b) |
| 1196 | return !differ |
| 1197 | } |
| 1198 | |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1199 | func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, |
Spandan Das | ac693b2 | 2023-04-24 00:07:38 +0000 | [diff] [blame] | 1200 | config string, apexAvailable []string, dynamicLibs bazel.LabelList, dynamicDeps *bazel.LabelListAttribute, ind int, buildNonApexWithStubs bool) { |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1201 | |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1202 | depsWithStubs := []bazel.Label{} |
| 1203 | for _, l := range dynamicLibs.Includes { |
| 1204 | dep, _ := ctx.ModuleFromName(l.OriginalModuleName) |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1205 | if d, ok := dep.(*Module); ok && d.HasStubsVariants() { |
| 1206 | depApexAvailable := d.ApexAvailable() |
| 1207 | if !availableToSameApexes(apexAvailable, depApexAvailable) { |
| 1208 | depsWithStubs = append(depsWithStubs, l) |
| 1209 | } |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | if len(depsWithStubs) > 0 { |
| 1213 | implDynamicDeps := bazel.SubtractBazelLabelList(dynamicLibs, bazel.MakeLabelList(depsWithStubs)) |
| 1214 | dynamicDeps.SetSelectValue(axis, config, implDynamicDeps) |
| 1215 | |
| 1216 | stubLibLabels := []bazel.Label{} |
| 1217 | for _, l := range depsWithStubs { |
Spandan Das | 2518c02 | 2023-03-17 03:02:32 +0000 | [diff] [blame] | 1218 | stubLabelInApiSurfaces := bazel.Label{ |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 1219 | Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(l.OriginalModuleName, ":"), |
Spandan Das | 2518c02 | 2023-03-17 03:02:32 +0000 | [diff] [blame] | 1220 | } |
| 1221 | stubLibLabels = append(stubLibLabels, stubLabelInApiSurfaces) |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1222 | } |
| 1223 | inApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex) |
| 1224 | nonApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex) |
| 1225 | defaultSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey) |
Spandan Das | ac693b2 | 2023-04-24 00:07:38 +0000 | [diff] [blame] | 1226 | nonApexDeps := depsWithStubs |
| 1227 | if buildNonApexWithStubs { |
| 1228 | nonApexDeps = stubLibLabels |
| 1229 | } |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1230 | if axis == bazel.NoConfigAxis { |
| 1231 | (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels)) |
Spandan Das | ac693b2 | 2023-04-24 00:07:38 +0000 | [diff] [blame] | 1232 | (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps)) |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1233 | (&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs)) |
| 1234 | dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue)) |
| 1235 | dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue)) |
| 1236 | dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue)) |
| 1237 | } else if config == bazel.OsAndroid { |
| 1238 | (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels)) |
Spandan Das | ac693b2 | 2023-04-24 00:07:38 +0000 | [diff] [blame] | 1239 | (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps)) |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 1240 | dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue)) |
| 1241 | dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue)) |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1246 | func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) { |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1247 | bp2BuildPropParseHelper(ctx, module, &StripProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 1248 | if stripProperties, ok := props.(*StripProperties); ok { |
| 1249 | la.stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols) |
| 1250 | la.stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list) |
| 1251 | la.stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame) |
| 1252 | la.stripAll.SetSelectValue(axis, config, stripProperties.Strip.All) |
| 1253 | la.stripNone.SetSelectValue(axis, config, stripProperties.Strip.None) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1254 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1255 | }) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1256 | } |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1257 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1258 | func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) { |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1259 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1260 | type productVarDep struct { |
| 1261 | // the name of the corresponding excludes field, if one exists |
| 1262 | excludesField string |
| 1263 | // reference to the bazel attribute that should be set for the given product variable config |
| 1264 | attribute *bazel.LabelListAttribute |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 1265 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1266 | depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1269 | // an intermediate attribute that holds Header_libs info, and will be appended to |
| 1270 | // implementationDeps at the end, to solve the confliction that both header_libs |
| 1271 | // and static_libs use implementationDeps. |
| 1272 | var headerDeps bazel.LabelListAttribute |
| 1273 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1274 | productVarToDepFields := map[string]productVarDep{ |
| 1275 | // product variables do not support exclude_shared_libs |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1276 | "Shared_libs": {attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes}, |
| 1277 | "Static_libs": {"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes}, |
| 1278 | "Whole_static_libs": {"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes}, |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1279 | "Header_libs": {attribute: &headerDeps, depResolutionFunc: bazelLabelForHeaderDepsExcludes}, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1280 | } |
| 1281 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1282 | for name, dep := range productVarToDepFields { |
| 1283 | props, exists := productVariableProps[name] |
| 1284 | excludeProps, excludesExists := productVariableProps[dep.excludesField] |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 1285 | // if neither an include nor excludes property exists, then skip it |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1286 | if !exists && !excludesExists { |
| 1287 | continue |
| 1288 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1289 | // Collect all the configurations that an include or exclude property exists for. |
| 1290 | // We want to iterate all configurations rather than either the include or exclude because, for a |
| 1291 | // particular configuration, we may have either only an include or an exclude to handle. |
| 1292 | productConfigProps := make(map[android.ProductConfigProperty]bool, len(props)+len(excludeProps)) |
| 1293 | for p := range props { |
| 1294 | productConfigProps[p] = true |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1295 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1296 | for p := range excludeProps { |
| 1297 | productConfigProps[p] = true |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1300 | for productConfigProp := range productConfigProps { |
| 1301 | prop, includesExists := props[productConfigProp] |
| 1302 | excludesProp, excludesExists := excludeProps[productConfigProp] |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1303 | var includes, excludes []string |
| 1304 | var ok bool |
| 1305 | // if there was no includes/excludes property, casting fails and that's expected |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1306 | if includes, ok = prop.([]string); includesExists && !ok { |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1307 | ctx.ModuleErrorf("Could not convert product variable %s property", name) |
| 1308 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1309 | if excludes, ok = excludesProp.([]string); excludesExists && !ok { |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1310 | ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField) |
| 1311 | } |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 1312 | |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 1313 | dep.attribute.EmitEmptyList = productConfigProp.AlwaysEmit() |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 1314 | dep.attribute.SetSelectValue( |
| 1315 | productConfigProp.ConfigurationAxis(), |
| 1316 | productConfigProp.SelectKey(), |
| 1317 | dep.depResolutionFunc(ctx, android.FirstUniqueStrings(includes), excludes), |
| 1318 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1319 | } |
| 1320 | } |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1321 | la.implementationDeps.Append(headerDeps) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1322 | } |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1323 | |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1324 | func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) { |
| 1325 | // if system dynamic deps have the default value, any use of a system dynamic library used will |
| 1326 | // result in duplicate library errors for bionic OSes. Here, we explicitly exclude those libraries |
Liz Kammer | 43345e2 | 2022-08-04 13:57:35 -0400 | [diff] [blame] | 1327 | // from bionic OSes and the no config case as these libraries only build for bionic OSes. |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1328 | if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsDynamicDep) > 0 { |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1329 | toRemove := bazelLabelForSharedDeps(ctx, android.SortedKeys(la.usedSystemDynamicDepAsDynamicDep)) |
Liz Kammer | 43345e2 | 2022-08-04 13:57:35 -0400 | [diff] [blame] | 1330 | la.dynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove) |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1331 | la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove) |
| 1332 | la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove) |
Liz Kammer | 91487d4 | 2022-09-13 11:27:11 -0400 | [diff] [blame] | 1333 | la.implementationDynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove) |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1334 | la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove) |
| 1335 | la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove) |
Liz Kammer | 91487d4 | 2022-09-13 11:27:11 -0400 | [diff] [blame] | 1336 | |
| 1337 | la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, toRemove) |
| 1338 | la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, toRemove) |
| 1339 | stubsToRemove := make([]bazel.Label, 0, len(la.usedSystemDynamicDepAsDynamicDep)) |
| 1340 | for _, lib := range toRemove.Includes { |
Spandan Das | 2518c02 | 2023-03-17 03:02:32 +0000 | [diff] [blame] | 1341 | stubLabelInApiSurfaces := bazel.Label{ |
| 1342 | Label: apiSurfaceModuleLibCurrentPackage + lib.OriginalModuleName, |
| 1343 | } |
| 1344 | stubsToRemove = append(stubsToRemove, stubLabelInApiSurfaces) |
Liz Kammer | 91487d4 | 2022-09-13 11:27:11 -0400 | [diff] [blame] | 1345 | } |
| 1346 | la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.MakeLabelList(stubsToRemove)) |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1347 | } |
| 1348 | |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 1349 | la.deps.ResolveExcludes() |
| 1350 | la.implementationDeps.ResolveExcludes() |
| 1351 | la.dynamicDeps.ResolveExcludes() |
| 1352 | la.implementationDynamicDeps.ResolveExcludes() |
| 1353 | la.wholeArchiveDeps.ResolveExcludes() |
| 1354 | la.systemDynamicDeps.ForceSpecifyEmptyList = true |
Liz Kammer | 5430953 | 2021-12-14 12:21:22 -0500 | [diff] [blame] | 1355 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 1356 | } |
| 1357 | |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 1358 | // Relativize a list of root-relative paths with respect to the module's |
| 1359 | // directory. |
| 1360 | // |
| 1361 | // include_dirs Soong prop are root-relative (b/183742505), but |
| 1362 | // local_include_dirs, export_include_dirs and export_system_include_dirs are |
| 1363 | // module dir relative. This function makes a list of paths entirely module dir |
| 1364 | // relative. |
| 1365 | // |
| 1366 | // For the `include` attribute, Bazel wants the paths to be relative to the |
| 1367 | // module. |
| 1368 | func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string { |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 1369 | var relativePaths []string |
| 1370 | for _, path := range paths { |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 1371 | // Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path |
| 1372 | relativePath, err := filepath.Rel(ctx.ModuleDir(), path) |
| 1373 | if err != nil { |
| 1374 | panic(err) |
| 1375 | } |
Rupert Shuttleworth | b815168 | 2021-04-06 20:06:21 +0000 | [diff] [blame] | 1376 | relativePaths = append(relativePaths, relativePath) |
| 1377 | } |
| 1378 | return relativePaths |
| 1379 | } |
| 1380 | |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 1381 | // BazelIncludes contains information about -I and -isystem paths from a module converted to Bazel |
| 1382 | // attributes. |
| 1383 | type BazelIncludes struct { |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 1384 | AbsoluteIncludes bazel.StringListAttribute |
| 1385 | Includes bazel.StringListAttribute |
| 1386 | SystemIncludes bazel.StringListAttribute |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
Liz Kammer | 5454944 | 2022-05-11 13:55:06 -0400 | [diff] [blame] | 1389 | func bp2BuildParseExportedIncludes(ctx android.BazelConversionPathContext, module *Module, includes *BazelIncludes) BazelIncludes { |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 1390 | var exported BazelIncludes |
| 1391 | if includes != nil { |
| 1392 | exported = *includes |
| 1393 | } else { |
| 1394 | exported = BazelIncludes{} |
| 1395 | } |
Zi Wang | 1cb1180 | 2022-12-09 16:08:54 -0800 | [diff] [blame] | 1396 | |
| 1397 | // cc library Export_include_dirs and Export_system_include_dirs are marked |
| 1398 | // "variant_prepend" in struct tag, set their prepend property to true to make |
| 1399 | // sure bp2build generates correct result. |
| 1400 | exported.Includes.Prepend = true |
| 1401 | exported.SystemIncludes.Prepend = true |
| 1402 | |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1403 | bp2BuildPropParseHelper(ctx, module, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 1404 | if flagExporterProperties, ok := props.(*FlagExporterProperties); ok { |
| 1405 | if len(flagExporterProperties.Export_include_dirs) > 0 { |
| 1406 | exported.Includes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.Includes.SelectValue(axis, config), flagExporterProperties.Export_include_dirs...))) |
| 1407 | } |
| 1408 | if len(flagExporterProperties.Export_system_include_dirs) > 0 { |
| 1409 | exported.SystemIncludes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.SystemIncludes.SelectValue(axis, config), flagExporterProperties.Export_system_include_dirs...))) |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 1410 | } |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 1411 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1412 | }) |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 1413 | exported.AbsoluteIncludes.DeduplicateAxesFromBase() |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 1414 | exported.Includes.DeduplicateAxesFromBase() |
| 1415 | exported.SystemIncludes.DeduplicateAxesFromBase() |
Rupert Shuttleworth | 375451e | 2021-04-26 07:49:08 -0400 | [diff] [blame] | 1416 | |
Liz Kammer | 5fad501 | 2021-09-09 14:08:21 -0400 | [diff] [blame] | 1417 | return exported |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 1418 | } |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1419 | |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 1420 | func BazelLabelNameForStaticModule(baseLabel string) string { |
| 1421 | return baseLabel + "_bp2build_cc_library_static" |
| 1422 | } |
| 1423 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1424 | func bazelLabelForStaticModule(ctx android.BazelConversionPathContext, m blueprint.Module) string { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1425 | label := android.BazelModuleLabel(ctx, m) |
Sasha Smundak | 39a301c | 2022-12-29 17:11:49 -0800 | [diff] [blame] | 1426 | if ccModule, ok := m.(*Module); ok && ccModule.typ() == fullLibrary { |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 1427 | return BazelLabelNameForStaticModule(label) |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1428 | } |
| 1429 | return label |
| 1430 | } |
| 1431 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1432 | func bazelLabelForSharedModule(ctx android.BazelConversionPathContext, m blueprint.Module) string { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1433 | // cc_library, at it's root name, propagates the shared library, which depends on the static |
| 1434 | // library. |
| 1435 | return android.BazelModuleLabel(ctx, m) |
| 1436 | } |
| 1437 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1438 | func bazelLabelForStaticWholeModuleDeps(ctx android.BazelConversionPathContext, m blueprint.Module) string { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1439 | label := bazelLabelForStaticModule(ctx, m) |
| 1440 | if aModule, ok := m.(android.Module); ok { |
| 1441 | if android.IsModulePrebuilt(aModule) { |
| 1442 | label += "_alwayslink" |
| 1443 | } |
| 1444 | } |
| 1445 | return label |
| 1446 | } |
| 1447 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1448 | func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1449 | return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps) |
| 1450 | } |
| 1451 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1452 | func bazelLabelForWholeDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1453 | return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps) |
| 1454 | } |
| 1455 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1456 | func bazelLabelForStaticDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1457 | return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule) |
| 1458 | } |
| 1459 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1460 | func bazelLabelForStaticDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1461 | return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule) |
| 1462 | } |
| 1463 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1464 | func bazelLabelForSharedDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1465 | return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule) |
| 1466 | } |
| 1467 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1468 | func bazelLabelForHeaderDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1469 | // This is not elegant, but bp2build's shared library targets only propagate |
| 1470 | // their header information as part of the normal C++ provider. |
| 1471 | return bazelLabelForSharedDeps(ctx, modules) |
| 1472 | } |
| 1473 | |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1474 | func bazelLabelForHeaderDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList { |
| 1475 | // This is only used when product_variable header_libs is processed, to follow |
| 1476 | // the pattern of depResolutionFunc |
| 1477 | return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule) |
| 1478 | } |
| 1479 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1480 | func bazelLabelForSharedDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList { |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1481 | return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule) |
| 1482 | } |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1483 | |
| 1484 | type binaryLinkerAttrs struct { |
| 1485 | Linkshared *bool |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 1486 | Suffix bazel.StringAttribute |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 1489 | func bp2buildBinaryLinkerProps(ctx android.BazelConversionPathContext, m *Module) binaryLinkerAttrs { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1490 | attrs := binaryLinkerAttrs{} |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1491 | bp2BuildPropParseHelper(ctx, m, &BinaryLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 1492 | linkerProps := props.(*BinaryLinkerProperties) |
| 1493 | staticExecutable := linkerProps.Static_executable |
| 1494 | if axis == bazel.NoConfigAxis { |
| 1495 | if linkBinaryShared := !proptools.Bool(staticExecutable); !linkBinaryShared { |
| 1496 | attrs.Linkshared = &linkBinaryShared |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1497 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1498 | } else if staticExecutable != nil { |
| 1499 | // TODO(b/202876379): Static_executable is arch-variant; however, linkshared is a |
| 1500 | // nonconfigurable attribute. Only 4 AOSP modules use this feature, defer handling |
| 1501 | ctx.ModuleErrorf("bp2build cannot migrate a module with arch/target-specific static_executable values") |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1502 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 1503 | if suffix := linkerProps.Suffix; suffix != nil { |
| 1504 | attrs.Suffix.SetSelectValue(axis, config, suffix) |
| 1505 | } |
Trevor Radcliffe | 542954f | 2022-04-21 20:04:42 +0000 | [diff] [blame] | 1506 | }) |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 1507 | |
| 1508 | return attrs |
| 1509 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 1510 | |
| 1511 | func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute { |
| 1512 | sanitizerFeatures := bazel.StringListAttribute{} |
| 1513 | bp2BuildPropParseHelper(ctx, m, &SanitizeProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 1514 | var features []string |
| 1515 | if sanitizerProps, ok := props.(*SanitizeProperties); ok { |
| 1516 | if sanitizerProps.Sanitize.Integer_overflow != nil && *sanitizerProps.Sanitize.Integer_overflow { |
| 1517 | features = append(features, "ubsan_integer_overflow") |
| 1518 | } |
| 1519 | for _, sanitizer := range sanitizerProps.Sanitize.Misc_undefined { |
| 1520 | features = append(features, "ubsan_"+sanitizer) |
| 1521 | } |
| 1522 | sanitizerFeatures.SetSelectValue(axis, config, features) |
| 1523 | } |
| 1524 | }) |
| 1525 | return sanitizerFeatures |
| 1526 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 1527 | |
| 1528 | func bp2buildLtoFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute { |
| 1529 | lto_feature_name := "android_thin_lto" |
| 1530 | ltoBoolFeatures := bazel.BoolAttribute{} |
| 1531 | bp2BuildPropParseHelper(ctx, m, <OProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) { |
| 1532 | if ltoProps, ok := props.(*LTOProperties); ok { |
| 1533 | thinProp := ltoProps.Lto.Thin != nil && *ltoProps.Lto.Thin |
| 1534 | thinPropSetToFalse := ltoProps.Lto.Thin != nil && !*ltoProps.Lto.Thin |
| 1535 | neverProp := ltoProps.Lto.Never != nil && *ltoProps.Lto.Never |
| 1536 | if thinProp { |
| 1537 | ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(true)) |
| 1538 | return |
| 1539 | } |
| 1540 | if neverProp || thinPropSetToFalse { |
| 1541 | if thinProp { |
| 1542 | ctx.ModuleErrorf("lto.thin and lto.never are mutually exclusive but were specified together") |
| 1543 | } else { |
| 1544 | ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(false)) |
| 1545 | } |
| 1546 | return |
| 1547 | } |
| 1548 | } |
| 1549 | ltoBoolFeatures.SetSelectValue(axis, config, nil) |
| 1550 | }) |
| 1551 | |
| 1552 | props := m.GetArchVariantProperties(ctx, <OProperties{}) |
| 1553 | ltoStringFeatures, err := ltoBoolFeatures.ToStringListAttribute(func(boolPtr *bool, axis bazel.ConfigurationAxis, config string) []string { |
| 1554 | if boolPtr == nil { |
| 1555 | return []string{} |
| 1556 | } |
| 1557 | if !*boolPtr { |
| 1558 | return []string{"-" + lto_feature_name} |
| 1559 | } |
| 1560 | features := []string{lto_feature_name} |
| 1561 | if ltoProps, ok := props[axis][config].(*LTOProperties); ok { |
| 1562 | if ltoProps.Whole_program_vtables != nil && *ltoProps.Whole_program_vtables { |
| 1563 | features = append(features, "android_thin_lto_whole_program_vtables") |
| 1564 | } |
| 1565 | } |
| 1566 | return features |
| 1567 | }) |
| 1568 | if err != nil { |
| 1569 | ctx.ModuleErrorf("Error processing LTO attributes: %s", err) |
| 1570 | } |
| 1571 | return ltoStringFeatures |
| 1572 | } |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 1573 | |
| 1574 | func convertHiddenVisibilityToFeatureBase(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute { |
| 1575 | visibilityHiddenFeature := bazel.StringListAttribute{} |
| 1576 | bp2BuildPropParseHelper(ctx, m, &BaseCompilerProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) { |
| 1577 | if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok { |
| 1578 | convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, baseCompilerProps.Cflags) |
| 1579 | } |
| 1580 | }) |
| 1581 | return visibilityHiddenFeature |
| 1582 | } |
| 1583 | |
| 1584 | func convertHiddenVisibilityToFeatureStaticOrShared(ctx android.BazelConversionPathContext, m *Module, isStatic bool) bazel.StringListAttribute { |
| 1585 | visibilityHiddenFeature := bazel.StringListAttribute{} |
| 1586 | if isStatic { |
| 1587 | bp2BuildPropParseHelper(ctx, m, &StaticProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) { |
| 1588 | if staticProps, ok := props.(*StaticProperties); ok { |
| 1589 | convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, staticProps.Static.Cflags) |
| 1590 | } |
| 1591 | }) |
| 1592 | } else { |
| 1593 | bp2BuildPropParseHelper(ctx, m, &SharedProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) { |
| 1594 | if sharedProps, ok := props.(*SharedProperties); ok { |
| 1595 | convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, sharedProps.Shared.Cflags) |
| 1596 | } |
| 1597 | }) |
| 1598 | } |
| 1599 | |
| 1600 | return visibilityHiddenFeature |
| 1601 | } |
| 1602 | |
| 1603 | func convertHiddenVisibilityToFeatureHelper(feature *bazel.StringListAttribute, axis bazel.ConfigurationAxis, configString string, cflags []string) { |
| 1604 | if inList(config.VisibilityHiddenFlag, cflags) { |
| 1605 | feature.SetSelectValue(axis, configString, []string{"visibility_hidden"}) |
| 1606 | } |
| 1607 | } |