Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [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 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 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 | |
| 15 | package android |
| 16 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 17 | import ( |
| 18 | "fmt" |
| 19 | "io/ioutil" |
| 20 | "path/filepath" |
| 21 | "strings" |
| 22 | |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
Jingwen Chen | 0181202 | 2021-11-19 14:29:43 +0000 | [diff] [blame] | 27 | type bazelModuleProperties struct { |
| 28 | // The label of the Bazel target replacing this Soong module. When run in conversion mode, this |
| 29 | // will import the handcrafted build target into the autogenerated file. Note: this may result in |
| 30 | // a conflict due to duplicate targets if bp2build_available is also set. |
| 31 | Label *string |
| 32 | |
| 33 | // If true, bp2build will generate the converted Bazel target for this module. Note: this may |
| 34 | // cause a conflict due to the duplicate targets if label is also set. |
| 35 | // |
| 36 | // This is a bool pointer to support tristates: true, false, not set. |
| 37 | // |
| 38 | // To opt-in a module, set bazel_module: { bp2build_available: true } |
| 39 | // To opt-out a module, set bazel_module: { bp2build_available: false } |
| 40 | // To defer the default setting for the directory, do not set the value. |
| 41 | Bp2build_available *bool |
| 42 | } |
| 43 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 44 | // Properties contains common module properties for Bazel migration purposes. |
| 45 | type properties struct { |
| 46 | // In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing |
| 47 | // this Soong module. |
Jingwen Chen | 0181202 | 2021-11-19 14:29:43 +0000 | [diff] [blame] | 48 | Bazel_module bazelModuleProperties |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 49 | } |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 50 | |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 51 | // namespacedVariableProperties is a map from a string representing a Soong |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 52 | // config variable namespace, like "android" or "vendor_name" to a slice of |
| 53 | // pointer to a struct containing a single field called Soong_config_variables |
| 54 | // whose value mirrors the structure in the Blueprint file. |
| 55 | type namespacedVariableProperties map[string][]interface{} |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 56 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 57 | // BazelModuleBase contains the property structs with metadata for modules which can be converted to |
| 58 | // Bazel. |
| 59 | type BazelModuleBase struct { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 60 | bazelProperties properties |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 61 | |
| 62 | // namespacedVariableProperties is used for soong_config_module_type support |
| 63 | // in bp2build. Soong config modules allow users to set module properties |
| 64 | // based on custom product variables defined in Android.bp files. These |
| 65 | // variables are namespaced to prevent clobbering, especially when set from |
| 66 | // Makefiles. |
| 67 | namespacedVariableProperties namespacedVariableProperties |
| 68 | |
| 69 | // baseModuleType is set when this module was created from a module type |
| 70 | // defined by a soong_config_module_type. Every soong_config_module_type |
| 71 | // "wraps" another module type, e.g. a soong_config_module_type can wrap a |
| 72 | // cc_defaults to a custom_cc_defaults, or cc_binary to a custom_cc_binary. |
| 73 | // This baseModuleType is set to the wrapped module type. |
| 74 | baseModuleType string |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // Bazelable is specifies the interface for modules that can be converted to Bazel. |
| 78 | type Bazelable interface { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 79 | bazelProps() *properties |
| 80 | HasHandcraftedLabel() bool |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 81 | HandcraftedLabel() string |
| 82 | GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 83 | ConvertWithBp2build(ctx BazelConversionContext) bool |
| 84 | convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 85 | GetBazelBuildFileContents(c Config, path, name string) (string, error) |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 86 | |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 87 | // namespacedVariableProps is a map from a soong config variable namespace |
| 88 | // (e.g. acme, android) to a map of interfaces{}, which are really |
| 89 | // reflect.Struct pointers, representing the value of the |
| 90 | // soong_config_variables property of a module. The struct pointer is the |
| 91 | // one with the single member called Soong_config_variables, which itself is |
| 92 | // a struct containing fields for each supported feature in that namespace. |
| 93 | // |
| 94 | // The reason for using an slice of interface{} is to support defaults |
| 95 | // propagation of the struct pointers. |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 96 | namespacedVariableProps() namespacedVariableProperties |
| 97 | setNamespacedVariableProps(props namespacedVariableProperties) |
| 98 | BaseModuleType() string |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 99 | SetBaseModuleType(baseModuleType string) |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. |
| 103 | type BazelModule interface { |
| 104 | Module |
| 105 | Bazelable |
| 106 | } |
| 107 | |
| 108 | // InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion |
| 109 | // properties. |
| 110 | func InitBazelModule(module BazelModule) { |
| 111 | module.AddProperties(module.bazelProps()) |
| 112 | } |
| 113 | |
| 114 | // bazelProps returns the Bazel properties for the given BazelModuleBase. |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 115 | func (b *BazelModuleBase) bazelProps() *properties { |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 116 | return &b.bazelProperties |
| 117 | } |
| 118 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 119 | func (b *BazelModuleBase) namespacedVariableProps() namespacedVariableProperties { |
| 120 | return b.namespacedVariableProperties |
| 121 | } |
| 122 | |
| 123 | func (b *BazelModuleBase) setNamespacedVariableProps(props namespacedVariableProperties) { |
| 124 | b.namespacedVariableProperties = props |
| 125 | } |
| 126 | |
| 127 | func (b *BazelModuleBase) BaseModuleType() string { |
| 128 | return b.baseModuleType |
| 129 | } |
| 130 | |
| 131 | func (b *BazelModuleBase) SetBaseModuleType(baseModuleType string) { |
| 132 | b.baseModuleType = baseModuleType |
| 133 | } |
| 134 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 135 | // HasHandcraftedLabel returns whether this module has a handcrafted Bazel label. |
| 136 | func (b *BazelModuleBase) HasHandcraftedLabel() bool { |
| 137 | return b.bazelProperties.Bazel_module.Label != nil |
| 138 | } |
| 139 | |
| 140 | // HandcraftedLabel returns the handcrafted label for this module, or empty string if there is none |
| 141 | func (b *BazelModuleBase) HandcraftedLabel() string { |
| 142 | return proptools.String(b.bazelProperties.Bazel_module.Label) |
| 143 | } |
| 144 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 145 | // GetBazelLabel returns the Bazel label for the given BazelModuleBase. |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 146 | func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string { |
| 147 | if b.HasHandcraftedLabel() { |
| 148 | return b.HandcraftedLabel() |
| 149 | } |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 150 | if b.ConvertWithBp2build(ctx) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 151 | return bp2buildModuleLabel(ctx, module) |
| 152 | } |
| 153 | return "" // no label for unconverted module |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 154 | } |
| 155 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 156 | // Configuration to decide if modules in a directory should default to true/false for bp2build_available |
| 157 | type Bp2BuildConfig map[string]BazelConversionConfigEntry |
| 158 | type BazelConversionConfigEntry int |
| 159 | |
| 160 | const ( |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 161 | // A sentinel value to be used as a key in Bp2BuildConfig for modules with |
| 162 | // no package path. This is also the module dir for top level Android.bp |
| 163 | // modules. |
| 164 | BP2BUILD_TOPLEVEL = "." |
| 165 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 166 | // iota + 1 ensures that the int value is not 0 when used in the Bp2buildAllowlist map, |
| 167 | // which can also mean that the key doesn't exist in a lookup. |
| 168 | |
| 169 | // all modules in this package and subpackages default to bp2build_available: true. |
| 170 | // allows modules to opt-out. |
| 171 | Bp2BuildDefaultTrueRecursively BazelConversionConfigEntry = iota + 1 |
| 172 | |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 173 | // all modules in this package (not recursively) default to bp2build_available: true. |
| 174 | // allows modules to opt-out. |
| 175 | Bp2BuildDefaultTrue |
| 176 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 177 | // all modules in this package (not recursively) default to bp2build_available: false. |
| 178 | // allows modules to opt-in. |
| 179 | Bp2BuildDefaultFalse |
| 180 | ) |
| 181 | |
| 182 | var ( |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 183 | // Keep any existing BUILD files (and do not generate new BUILD files) for these directories |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 184 | // in the synthetic Bazel workspace. |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 185 | bp2buildKeepExistingBuildFile = map[string]bool{ |
| 186 | // This is actually build/bazel/build.BAZEL symlinked to ./BUILD |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 187 | ".":/*recursive = */ false, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 188 | |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 189 | // build/bazel/examples/apex/... BUILD files should be generated, so |
| 190 | // build/bazel is not recursive. Instead list each subdirectory under |
| 191 | // build/bazel explicitly. |
| 192 | "build/bazel":/* recursive = */ false, |
| 193 | "build/bazel/examples/android_app":/* recursive = */ true, |
Romain Jobredeaux | 5cc9c9d | 2021-08-26 15:07:48 +0000 | [diff] [blame] | 194 | "build/bazel/examples/java":/* recursive = */ true, |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 195 | "build/bazel/bazel_skylib":/* recursive = */ true, |
| 196 | "build/bazel/rules":/* recursive = */ true, |
| 197 | "build/bazel/rules_cc":/* recursive = */ true, |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 198 | "build/bazel/scripts":/* recursive = */ true, |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 199 | "build/bazel/tests":/* recursive = */ true, |
| 200 | "build/bazel/platforms":/* recursive = */ true, |
| 201 | "build/bazel/product_variables":/* recursive = */ true, |
Jingwen Chen | 5e49b82 | 2021-08-24 05:14:22 +0000 | [diff] [blame] | 202 | "build/bazel_common_rules":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 203 | "build/make/tools":/* recursive = */ true, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 204 | "build/pesto":/* recursive = */ true, |
| 205 | |
| 206 | // external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails |
| 207 | // e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed |
| 208 | "external/bazelbuild-rules_android":/* recursive = */ true, |
Jingwen Chen | 9163225 | 2021-08-10 13:00:33 +0000 | [diff] [blame] | 209 | "external/bazel-skylib":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 210 | "external/guava":/* recursive = */ true, |
| 211 | "external/error_prone":/* recursive = */ true, |
| 212 | "external/jsr305":/* recursive = */ true, |
| 213 | "frameworks/ex/common":/* recursive = */ true, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 214 | |
Romain Jobredeaux | f1b0ac8 | 2021-08-12 14:39:00 +0000 | [diff] [blame] | 215 | "packages/apps/Music":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 216 | "packages/apps/QuickSearchBox":/* recursive = */ true, |
Romain Jobredeaux | a2c0814 | 2021-09-22 14:43:43 -0400 | [diff] [blame] | 217 | "packages/apps/WallpaperPicker":/* recursive = */ false, |
| 218 | |
Chris Parsons | 494eef3 | 2021-11-09 10:29:52 -0500 | [diff] [blame] | 219 | "prebuilts/gcc":/* recursive = */ true, |
Romain Jobredeaux | a2c0814 | 2021-09-22 14:43:43 -0400 | [diff] [blame] | 220 | "prebuilts/sdk":/* recursive = */ false, |
| 221 | "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false, |
| 222 | "prebuilts/sdk/current/support":/* recursive = */ false, |
| 223 | "prebuilts/sdk/tools":/* recursive = */ false, |
| 224 | "prebuilts/r8":/* recursive = */ false, |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 227 | // Configure modules in these directories to enable bp2build_available: true or false by default. |
| 228 | bp2buildDefaultConfig = Bp2BuildConfig{ |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 229 | "art/libdexfile": Bp2BuildDefaultTrueRecursively, |
| 230 | "bionic": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 0a9d09f | 2021-11-24 07:00:11 +0000 | [diff] [blame] | 231 | "build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 232 | "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 233 | "build/soong": Bp2BuildDefaultTrue, |
Rupert Shuttleworth | 2ac9c48 | 2021-11-10 10:37:05 -0500 | [diff] [blame] | 234 | "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 235 | "cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 236 | "development/sdk": Bp2BuildDefaultTrueRecursively, |
| 237 | "external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively, |
| 238 | "external/boringssl": Bp2BuildDefaultTrueRecursively, |
| 239 | "external/brotli": Bp2BuildDefaultTrue, |
| 240 | "external/fmtlib": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 241 | "external/google-benchmark": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 242 | "external/googletest": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 243 | "external/gwp_asan": Bp2BuildDefaultTrueRecursively, |
| 244 | "external/jemalloc_new": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 245 | "external/jsoncpp": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 246 | "external/libcap": Bp2BuildDefaultTrueRecursively, |
| 247 | "external/libcxx": Bp2BuildDefaultTrueRecursively, |
| 248 | "external/libcxxabi": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 249 | "external/libevent": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 250 | "external/lz4/lib": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 251 | "external/lzma/C": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 252 | "external/mdnsresponder": Bp2BuildDefaultTrueRecursively, |
| 253 | "external/minijail": Bp2BuildDefaultTrueRecursively, |
| 254 | "external/pcre": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 255 | "external/protobuf": Bp2BuildDefaultTrueRecursively, |
| 256 | "external/python/six": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 257 | "external/selinux/libsepol": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 258 | "external/scudo": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 259 | "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 260 | "external/zlib": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 261 | "external/zstd": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 262 | "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 263 | "frameworks/proto_logging/stats/stats_log_api_gen": Bp2BuildDefaultTrueRecursively, |
| 264 | "libnativehelper": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 265 | "packages/modules/adb": Bp2BuildDefaultTrue, |
| 266 | "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively, |
| 267 | "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively, |
| 268 | "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively, |
| 269 | "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively, |
| 270 | "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively, |
| 271 | "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively, |
| 272 | "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | d43d4a4 | 2021-11-23 12:40:11 +0000 | [diff] [blame] | 273 | "system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 274 | "system/core/debuggerd": Bp2BuildDefaultTrue, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 275 | "system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively, |
| 276 | "system/core/libasyncio": Bp2BuildDefaultTrue, |
| 277 | "system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively, |
| 278 | "system/core/libcutils": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 279 | "system/core/libpackagelistparser": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 280 | "system/core/libprocessgroup": Bp2BuildDefaultTrue, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 281 | "system/core/libprocessgroup/cgrouprc": Bp2BuildDefaultTrue, |
| 282 | "system/core/libprocessgroup/cgrouprc_format": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 283 | "system/core/libsystem": Bp2BuildDefaultTrueRecursively, |
| 284 | "system/core/libutils": Bp2BuildDefaultTrueRecursively, |
| 285 | "system/core/libvndksupport": Bp2BuildDefaultTrueRecursively, |
Lukacs T. Berki | 497f17d | 2021-04-26 12:15:57 +0200 | [diff] [blame] | 286 | "system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 287 | "system/libbase": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 288 | "system/libprocinfo": Bp2BuildDefaultTrue, |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 289 | "system/libziparchive": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 290 | "system/logging/liblog": Bp2BuildDefaultTrueRecursively, |
| 291 | "system/sepolicy/apex": Bp2BuildDefaultTrueRecursively, |
| 292 | "system/timezone/apex": Bp2BuildDefaultTrueRecursively, |
| 293 | "system/timezone/output_data": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 294 | "system/unwinding/libbacktrace": Bp2BuildDefaultTrueRecursively, |
| 295 | "system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 296 | } |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 297 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 298 | // Per-module denylist to always opt modules out of both bp2build and mixed builds. |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 299 | bp2buildModuleDoNotConvertList = []string{ |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 300 | "libnativehelper_compat_libc++", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 |
| 301 | "art_libdexfile_dex_instruction_list_header", // breaks libart_mterp.armng, header not found |
| 302 | |
| 303 | "libandroid_runtime_lazy", // depends on unconverted modules: libbinder_headers |
| 304 | "libcmd", // depends on unconverted modules: libbinder |
| 305 | |
| 306 | "chkcon", "sefcontext_compile", // depends on unconverted modules: libsepol |
| 307 | |
| 308 | "libsepol", // TODO(b/207408632): Unsupported case of .l sources in cc library rules |
| 309 | |
| 310 | "get_clang_version_test", // depends on unconverted module: get_clang_version |
| 311 | |
| 312 | "libbinder", // TODO(b/188503688): Disabled for some archs, |
| 313 | "libactivitymanager_aidl", // TODO(b/207426160): Depends on activity_manager_procstate_aidl, which is an aidl filegroup. |
| 314 | |
| 315 | "libnativehelper_lazy_mts_jni", // depends on unconverted modules: libgmock_ndk |
| 316 | "libnativehelper_mts_jni", // depends on unconverted modules: libgmock_ndk |
| 317 | "libnativetesthelper_jni", // depends on unconverted modules: libgtest_ndk_c++ |
| 318 | |
| 319 | "statslog-framework-java-gen", "statslog.cpp", "statslog.h", "statslog.rs", "statslog_header.rs", // depends on unconverted modules: stats-log-api-gen |
| 320 | |
| 321 | "stats-log-api-gen", // depends on unconverted modules: libstats_proto_host, libprotobuf-cpp-full |
| 322 | |
| 323 | "libstatslog", // depends on unconverted modules: statslog.cpp, statslog.h, ... |
| 324 | |
| 325 | "libgmock_main_ndk", "libgmock_ndk", // depends on unconverted module: libgtest_ndk_c++ |
| 326 | |
| 327 | "cmd", // depends on unconverted module packagemanager_aidl-cpp, of unsupported type aidl_interface |
| 328 | "servicedispatcher", // depends on unconverted module android.debug_aidl, of unsupported type aidl_interface |
| 329 | "libutilscallstack", // depends on unconverted module libbacktrace |
| 330 | "libbacktrace", // depends on unconverted module libunwindstack |
| 331 | "libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core |
| 332 | "libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd |
| 333 | "unwind_for_offline", // depends on unconverted module libunwindstack_utils |
| 334 | "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite |
| 335 | "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library. |
| 336 | "host_bionic_linker_asm", // depends on extract_linker, a go binary. |
| 337 | "host_bionic_linker_script", // depends on extract_linker, a go binary. |
| 338 | |
| 339 | "pbtombstone", // depends on libprotobuf-cpp-lite, libtombstone_proto |
| 340 | "crash_dump", // depends on unconverted module libprotobuf-cpp-lite |
Chris Parsons | 494eef3 | 2021-11-09 10:29:52 -0500 | [diff] [blame] | 341 | "libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610. |
| 342 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 343 | "libunwindstack_local", "libunwindstack_utils", // depends on unconverted module libunwindstack |
| 344 | "libunwindstack", // depends on libdexfile_support, of unsupported module type art_cc_library_static |
| 345 | "libc_malloc_debug", // depends on unconverted module libunwindstack |
Rupert Shuttleworth | 47aa584 | 2021-04-30 04:04:15 -0400 | [diff] [blame] | 346 | |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 347 | "libbase_ndk", // http://b/186826477, fails to link libctscamera2_jni for device (required for CtsCameraTestCases) |
Alex Márquez Pérez MuñÃz DÃaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 348 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 349 | "lib_linker_config_proto_lite", // contains .proto sources |
| 350 | |
Liz Kammer | 0f3b7d2 | 2021-09-28 13:48:21 -0400 | [diff] [blame] | 351 | "libprotobuf-python", // contains .proto sources |
| 352 | "libprotobuf-internal-protos", // we don't handle path property for fileegroups |
| 353 | "libprotobuf-internal-python-srcs", // we don't handle path property for fileegroups |
| 354 | |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 355 | "libseccomp_policy", // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds. |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 356 | "libfdtrack", // depends on unconverted module libunwindstack |
Lukacs T. Berki | b5ac5af | 2021-04-27 11:02:11 +0200 | [diff] [blame] | 357 | |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 358 | "gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset |
| 359 | |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 360 | "brotli-fuzzer-corpus", // b/202015218: outputs are in location incompatible with bazel genrule handling. |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 361 | |
Jingwen Chen | df27b7a | 2021-10-18 06:33:16 +0000 | [diff] [blame] | 362 | // b/203369847: multiple genrules in the same package creating the same file |
| 363 | // //development/sdk/... |
| 364 | "platform_tools_properties", |
| 365 | "build_tools_source_properties", |
| 366 | |
Chris Parsons | 393002a | 2021-11-11 13:39:20 -0500 | [diff] [blame] | 367 | "libminijail", // b/202491296: Uses unsupported c_std property. |
| 368 | "minijail0", // depends on unconverted modules: libminijail |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 369 | "drop_privs", // depends on unconverted modules: libminijail |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 370 | |
Jingwen Chen | 790324e | 2021-04-30 08:20:01 +0000 | [diff] [blame] | 371 | // Tests. Handle later. |
| 372 | "libbionic_tests_headers_posix", // http://b/186024507, cc_library_static, sched.h, time.h not found |
| 373 | "libjemalloc5_integrationtest", |
| 374 | "libjemalloc5_stresstestlib", |
| 375 | "libjemalloc5_unittest", |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 376 | |
| 377 | // APEX support |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 378 | "com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 379 | |
| 380 | "libadb_crypto", // Depends on libadb_protos |
| 381 | "libadb_crypto_static", // Depends on libadb_protos_static |
| 382 | "libadb_pairing_connection", // Depends on libadb_protos |
| 383 | "libadb_pairing_connection_static", // Depends on libadb_protos_static |
| 384 | "libadb_pairing_server", // Depends on libadb_protos |
| 385 | "libadb_pairing_server_static", // Depends on libadb_protos_static |
| 386 | "libadbd", // Depends on libadbd_core |
| 387 | "libadbd_core", // Depends on libadb_protos |
| 388 | "libadbd_services", // Depends on libadb_protos |
| 389 | |
| 390 | "libadb_protos_static", // b/200601772: Requires cc_library proto support |
| 391 | "libadb_protos", // b/200601772: Requires cc_library proto support |
| 392 | "libapp_processes_protos_lite", // b/200601772: Requires cc_library proto support |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 393 | |
| 394 | "libgtest_ndk_c++", // b/201816222: Requires sdk_version support. |
| 395 | "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support. |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 396 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 397 | "abb", // depends on unconverted modules: libadbd_core, libadbd_services, |
| 398 | "adb", // depends on unconverted modules: bin2c_fastdeployagent, libadb_crypto, libadb_host, libadb_pairing_connection, libadb_protos, libandroidfw, libapp_processes_protos_full, libfastdeploy_host, libopenscreen-discovery, libopenscreen-platform-impl, libusb, libzstd, AdbWinApi |
| 399 | "adbd", // depends on unconverted modules: libadb_crypto, libadb_pairing_connection, libadb_protos, libadbd, libadbd_core, libapp_processes_protos_lite, libzstd, libadbd_services, libcap, libminijail |
| 400 | "linker", // depends on unconverted modules: libdebuggerd_handler_fallback |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 401 | "linker_reloc_bench_main", // depends on unconverted modules: liblinker_reloc_bench_* |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame^] | 402 | "versioner", // depends on unconverted modules: libclang_cxx_host, libLLVM_host, of unsupported type llvm_host_prebuilt_library_shared |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 403 | |
| 404 | "linkerconfig", // http://b/202876379 has arch-variant static_executable |
| 405 | "mdnsd", // http://b/202876379 has arch-variant static_executable |
| 406 | |
| 407 | "acvp_modulewrapper", // disabled for android x86/x86_64 |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 408 | } |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 409 | |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 410 | // Per-module denylist of cc_library modules to only generate the static |
| 411 | // variant if their shared variant isn't ready or buildable by Bazel. |
| 412 | bp2buildCcLibraryStaticOnlyList = []string{ |
Jingwen Chen | 5354292 | 2021-05-18 09:01:49 +0000 | [diff] [blame] | 413 | "libjemalloc5", // http://b/188503688, cc_library, `target: { android: { enabled: false } }` for android targets. |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 416 | // Per-module denylist to opt modules out of mixed builds. Such modules will |
| 417 | // still be generated via bp2build. |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 418 | mixedBuildsDisabledList = []string{ |
Wei Li | 455ba83 | 2021-11-04 22:58:12 +0000 | [diff] [blame] | 419 | "libbrotli", // http://b/198585397, ld.lld: error: bionic/libc/arch-arm64/generic/bionic/memmove.S:95:(.text+0x10): relocation R_AARCH64_CONDBR19 out of range: -1404176 is not in [-1048576, 1048575]; references __memcpy |
| 420 | "minijail_constants_json", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. |
Liz Kammer | c319299 | 2021-11-16 17:01:11 -0500 | [diff] [blame] | 421 | |
| 422 | "cap_names.h", // TODO(b/204913827) runfiles need to be handled in mixed builds |
| 423 | "libcap", // TODO(b/204913827) runfiles need to be handled in mixed builds |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 424 | } |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 425 | |
| 426 | // Used for quicker lookups |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 427 | bp2buildModuleDoNotConvert = map[string]bool{} |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 428 | bp2buildCcLibraryStaticOnly = map[string]bool{} |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 429 | mixedBuildsDisabled = map[string]bool{} |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 430 | ) |
| 431 | |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 432 | func init() { |
| 433 | for _, moduleName := range bp2buildModuleDoNotConvertList { |
| 434 | bp2buildModuleDoNotConvert[moduleName] = true |
| 435 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 436 | |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 437 | for _, moduleName := range bp2buildCcLibraryStaticOnlyList { |
| 438 | bp2buildCcLibraryStaticOnly[moduleName] = true |
| 439 | } |
| 440 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 441 | for _, moduleName := range mixedBuildsDisabledList { |
| 442 | mixedBuildsDisabled[moduleName] = true |
| 443 | } |
| 444 | } |
| 445 | |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 446 | func GenerateCcLibraryStaticOnly(moduleName string) bool { |
| 447 | return bp2buildCcLibraryStaticOnly[moduleName] |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 450 | func ShouldKeepExistingBuildFileForDir(dir string) bool { |
| 451 | if _, ok := bp2buildKeepExistingBuildFile[dir]; ok { |
| 452 | // Exact dir match |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 453 | return true |
| 454 | } |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 455 | // Check if subtree match |
| 456 | for prefix, recursive := range bp2buildKeepExistingBuildFile { |
| 457 | if recursive { |
| 458 | if strings.HasPrefix(dir, prefix+"/") { |
| 459 | return true |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | // Default |
| 464 | return false |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 467 | // MixedBuildsEnabled checks that a module is ready to be replaced by a |
| 468 | // converted or handcrafted Bazel target. |
Chris Parsons | 494eef3 | 2021-11-09 10:29:52 -0500 | [diff] [blame] | 469 | func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool { |
| 470 | if ctx.Os() == Windows { |
| 471 | // Windows toolchains are not currently supported. |
| 472 | return false |
| 473 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 474 | if !ctx.Config().BazelContext.BazelEnabled() { |
| 475 | return false |
| 476 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 477 | if !convertedToBazel(ctx, ctx.Module()) { |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 478 | return false |
| 479 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 480 | |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 481 | if GenerateCcLibraryStaticOnly(ctx.Module().Name()) { |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 482 | // Don't use partially-converted cc_library targets in mixed builds, |
| 483 | // since mixed builds would generally rely on both static and shared |
| 484 | // variants of a cc_library. |
| 485 | return false |
| 486 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 487 | return !mixedBuildsDisabled[ctx.Module().Name()] |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 490 | // ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 491 | func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 492 | b, ok := module.(Bazelable) |
| 493 | if !ok { |
| 494 | return false |
| 495 | } |
| 496 | return b.convertWithBp2build(ctx, module) || b.HasHandcraftedLabel() |
| 497 | } |
| 498 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 499 | // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 500 | func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionContext) bool { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 501 | return b.convertWithBp2build(ctx, ctx.Module()) |
| 502 | } |
| 503 | |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 504 | func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 505 | if bp2buildModuleDoNotConvert[module.Name()] { |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 506 | return false |
| 507 | } |
| 508 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 509 | // Ensure that the module type of this module has a bp2build converter. This |
| 510 | // prevents mixed builds from using auto-converted modules just by matching |
| 511 | // the package dir; it also has to have a bp2build mutator as well. |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 512 | if ctx.Config().bp2buildModuleTypeConfig[ctx.OtherModuleType(module)] == false { |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 513 | if b, ok := module.(Bazelable); ok && b.BaseModuleType() != "" { |
| 514 | // For modules with custom types from soong_config_module_types, |
| 515 | // check that their _base module type_ has a bp2build mutator. |
| 516 | if ctx.Config().bp2buildModuleTypeConfig[b.BaseModuleType()] == false { |
| 517 | return false |
| 518 | } |
| 519 | } else { |
| 520 | return false |
| 521 | } |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 524 | packagePath := ctx.OtherModuleDir(module) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 525 | config := ctx.Config().bp2buildPackageConfig |
| 526 | |
| 527 | // This is a tristate value: true, false, or unset. |
| 528 | propValue := b.bazelProperties.Bazel_module.Bp2build_available |
| 529 | if bp2buildDefaultTrueRecursively(packagePath, config) { |
| 530 | // Allow modules to explicitly opt-out. |
| 531 | return proptools.BoolDefault(propValue, true) |
| 532 | } |
| 533 | |
| 534 | // Allow modules to explicitly opt-in. |
| 535 | return proptools.BoolDefault(propValue, false) |
| 536 | } |
| 537 | |
| 538 | // bp2buildDefaultTrueRecursively checks that the package contains a prefix from the |
| 539 | // set of package prefixes where all modules must be converted. That is, if the |
| 540 | // package is x/y/z, and the list contains either x, x/y, or x/y/z, this function will |
| 541 | // return true. |
| 542 | // |
| 543 | // However, if the package is x/y, and it matches a Bp2BuildDefaultFalse "x/y" entry |
| 544 | // exactly, this module will return false early. |
| 545 | // |
| 546 | // This function will also return false if the package doesn't match anything in |
| 547 | // the config. |
| 548 | func bp2buildDefaultTrueRecursively(packagePath string, config Bp2BuildConfig) bool { |
| 549 | ret := false |
| 550 | |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 551 | // Check if the package path has an exact match in the config. |
| 552 | if config[packagePath] == Bp2BuildDefaultTrue || config[packagePath] == Bp2BuildDefaultTrueRecursively { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 553 | return true |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 554 | } else if config[packagePath] == Bp2BuildDefaultFalse { |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 555 | return false |
| 556 | } |
| 557 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 558 | // If not, check for the config recursively. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 559 | packagePrefix := "" |
| 560 | // e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist. |
| 561 | for _, part := range strings.Split(packagePath, "/") { |
| 562 | packagePrefix += part |
| 563 | if config[packagePrefix] == Bp2BuildDefaultTrueRecursively { |
| 564 | // package contains this prefix and this prefix should convert all modules |
| 565 | return true |
| 566 | } |
| 567 | // Continue to the next part of the package dir. |
| 568 | packagePrefix += "/" |
| 569 | } |
| 570 | |
| 571 | return ret |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 572 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 573 | |
| 574 | // GetBazelBuildFileContents returns the file contents of a hand-crafted BUILD file if available or |
| 575 | // an error if there are errors reading the file. |
| 576 | // TODO(b/181575318): currently we append the whole BUILD file, let's change that to do |
| 577 | // something more targeted based on the rule type and target. |
| 578 | func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) (string, error) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 579 | if !strings.Contains(b.HandcraftedLabel(), path) { |
| 580 | return "", fmt.Errorf("%q not found in bazel_module.label %q", path, b.HandcraftedLabel()) |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 581 | } |
| 582 | name = filepath.Join(path, name) |
| 583 | f, err := c.fs.Open(name) |
| 584 | if err != nil { |
| 585 | return "", err |
| 586 | } |
| 587 | defer f.Close() |
| 588 | |
| 589 | data, err := ioutil.ReadAll(f) |
| 590 | if err != nil { |
| 591 | return "", err |
| 592 | } |
| 593 | return string(data[:]), nil |
| 594 | } |