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