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