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