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