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