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 ( |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 18 | "bufio" |
| 19 | "errors" |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 20 | "fmt" |
| 21 | "io/ioutil" |
| 22 | "path/filepath" |
| 23 | "strings" |
| 24 | |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
| 27 | ) |
| 28 | |
Jingwen Chen | 0181202 | 2021-11-19 14:29:43 +0000 | [diff] [blame] | 29 | type bazelModuleProperties struct { |
| 30 | // The label of the Bazel target replacing this Soong module. When run in conversion mode, this |
| 31 | // will import the handcrafted build target into the autogenerated file. Note: this may result in |
| 32 | // a conflict due to duplicate targets if bp2build_available is also set. |
| 33 | Label *string |
| 34 | |
| 35 | // If true, bp2build will generate the converted Bazel target for this module. Note: this may |
| 36 | // cause a conflict due to the duplicate targets if label is also set. |
| 37 | // |
| 38 | // This is a bool pointer to support tristates: true, false, not set. |
| 39 | // |
| 40 | // To opt-in a module, set bazel_module: { bp2build_available: true } |
| 41 | // To opt-out a module, set bazel_module: { bp2build_available: false } |
| 42 | // To defer the default setting for the directory, do not set the value. |
| 43 | Bp2build_available *bool |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 44 | |
| 45 | // CanConvertToBazel is set via InitBazelModule to indicate that a module type can be converted to |
| 46 | // Bazel with Bp2build. |
| 47 | CanConvertToBazel bool `blueprint:"mutated"` |
Jingwen Chen | 0181202 | 2021-11-19 14:29:43 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 50 | // Properties contains common module properties for Bazel migration purposes. |
| 51 | type properties struct { |
| 52 | // In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing |
| 53 | // this Soong module. |
Jingwen Chen | 0181202 | 2021-11-19 14:29:43 +0000 | [diff] [blame] | 54 | Bazel_module bazelModuleProperties |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 55 | } |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 56 | |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 57 | // namespacedVariableProperties is a map from a string representing a Soong |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 58 | // config variable namespace, like "android" or "vendor_name" to a slice of |
| 59 | // pointer to a struct containing a single field called Soong_config_variables |
| 60 | // whose value mirrors the structure in the Blueprint file. |
| 61 | type namespacedVariableProperties map[string][]interface{} |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 62 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 63 | // BazelModuleBase contains the property structs with metadata for modules which can be converted to |
| 64 | // Bazel. |
| 65 | type BazelModuleBase struct { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 66 | bazelProperties properties |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 67 | |
| 68 | // namespacedVariableProperties is used for soong_config_module_type support |
| 69 | // in bp2build. Soong config modules allow users to set module properties |
| 70 | // based on custom product variables defined in Android.bp files. These |
| 71 | // variables are namespaced to prevent clobbering, especially when set from |
| 72 | // Makefiles. |
| 73 | namespacedVariableProperties namespacedVariableProperties |
| 74 | |
| 75 | // baseModuleType is set when this module was created from a module type |
| 76 | // defined by a soong_config_module_type. Every soong_config_module_type |
| 77 | // "wraps" another module type, e.g. a soong_config_module_type can wrap a |
| 78 | // cc_defaults to a custom_cc_defaults, or cc_binary to a custom_cc_binary. |
| 79 | // This baseModuleType is set to the wrapped module type. |
| 80 | baseModuleType string |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | // Bazelable is specifies the interface for modules that can be converted to Bazel. |
| 84 | type Bazelable interface { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 85 | bazelProps() *properties |
| 86 | HasHandcraftedLabel() bool |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 87 | HandcraftedLabel() string |
| 88 | GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 89 | ShouldConvertWithBp2build(ctx BazelConversionContext) bool |
| 90 | shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 91 | GetBazelBuildFileContents(c Config, path, name string) (string, error) |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 92 | ConvertWithBp2build(ctx TopDownMutatorContext) |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 93 | |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 94 | // namespacedVariableProps is a map from a soong config variable namespace |
| 95 | // (e.g. acme, android) to a map of interfaces{}, which are really |
| 96 | // reflect.Struct pointers, representing the value of the |
| 97 | // soong_config_variables property of a module. The struct pointer is the |
| 98 | // one with the single member called Soong_config_variables, which itself is |
| 99 | // a struct containing fields for each supported feature in that namespace. |
| 100 | // |
| 101 | // The reason for using an slice of interface{} is to support defaults |
| 102 | // propagation of the struct pointers. |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 103 | namespacedVariableProps() namespacedVariableProperties |
| 104 | setNamespacedVariableProps(props namespacedVariableProperties) |
| 105 | BaseModuleType() string |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 106 | SetBaseModuleType(baseModuleType string) |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. |
| 110 | type BazelModule interface { |
| 111 | Module |
| 112 | Bazelable |
| 113 | } |
| 114 | |
| 115 | // InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion |
| 116 | // properties. |
| 117 | func InitBazelModule(module BazelModule) { |
| 118 | module.AddProperties(module.bazelProps()) |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 119 | module.bazelProps().Bazel_module.CanConvertToBazel = true |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // bazelProps returns the Bazel properties for the given BazelModuleBase. |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 123 | func (b *BazelModuleBase) bazelProps() *properties { |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 124 | return &b.bazelProperties |
| 125 | } |
| 126 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 127 | func (b *BazelModuleBase) namespacedVariableProps() namespacedVariableProperties { |
| 128 | return b.namespacedVariableProperties |
| 129 | } |
| 130 | |
| 131 | func (b *BazelModuleBase) setNamespacedVariableProps(props namespacedVariableProperties) { |
| 132 | b.namespacedVariableProperties = props |
| 133 | } |
| 134 | |
| 135 | func (b *BazelModuleBase) BaseModuleType() string { |
| 136 | return b.baseModuleType |
| 137 | } |
| 138 | |
| 139 | func (b *BazelModuleBase) SetBaseModuleType(baseModuleType string) { |
| 140 | b.baseModuleType = baseModuleType |
| 141 | } |
| 142 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 143 | // HasHandcraftedLabel returns whether this module has a handcrafted Bazel label. |
| 144 | func (b *BazelModuleBase) HasHandcraftedLabel() bool { |
| 145 | return b.bazelProperties.Bazel_module.Label != nil |
| 146 | } |
| 147 | |
| 148 | // HandcraftedLabel returns the handcrafted label for this module, or empty string if there is none |
| 149 | func (b *BazelModuleBase) HandcraftedLabel() string { |
| 150 | return proptools.String(b.bazelProperties.Bazel_module.Label) |
| 151 | } |
| 152 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 153 | // GetBazelLabel returns the Bazel label for the given BazelModuleBase. |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 154 | func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string { |
| 155 | if b.HasHandcraftedLabel() { |
| 156 | return b.HandcraftedLabel() |
| 157 | } |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 158 | if b.ShouldConvertWithBp2build(ctx) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 159 | return bp2buildModuleLabel(ctx, module) |
| 160 | } |
| 161 | return "" // no label for unconverted module |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 164 | // Configuration to decide if modules in a directory should default to true/false for bp2build_available |
| 165 | type Bp2BuildConfig map[string]BazelConversionConfigEntry |
| 166 | type BazelConversionConfigEntry int |
| 167 | |
| 168 | const ( |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 169 | // A sentinel value to be used as a key in Bp2BuildConfig for modules with |
| 170 | // no package path. This is also the module dir for top level Android.bp |
| 171 | // modules. |
| 172 | BP2BUILD_TOPLEVEL = "." |
| 173 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 174 | // iota + 1 ensures that the int value is not 0 when used in the Bp2buildAllowlist map, |
| 175 | // which can also mean that the key doesn't exist in a lookup. |
| 176 | |
| 177 | // all modules in this package and subpackages default to bp2build_available: true. |
| 178 | // allows modules to opt-out. |
| 179 | Bp2BuildDefaultTrueRecursively BazelConversionConfigEntry = iota + 1 |
| 180 | |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 181 | // all modules in this package (not recursively) default to bp2build_available: true. |
| 182 | // allows modules to opt-out. |
| 183 | Bp2BuildDefaultTrue |
| 184 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 185 | // all modules in this package (not recursively) default to bp2build_available: false. |
| 186 | // allows modules to opt-in. |
| 187 | Bp2BuildDefaultFalse |
| 188 | ) |
| 189 | |
| 190 | var ( |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 191 | // 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] | 192 | // in the synthetic Bazel workspace. |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 193 | bp2buildKeepExistingBuildFile = map[string]bool{ |
| 194 | // This is actually build/bazel/build.BAZEL symlinked to ./BUILD |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 195 | ".":/*recursive = */ false, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 196 | |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 197 | // build/bazel/examples/apex/... BUILD files should be generated, so |
| 198 | // build/bazel is not recursive. Instead list each subdirectory under |
| 199 | // build/bazel explicitly. |
| 200 | "build/bazel":/* recursive = */ false, |
Jingwen Chen | 941f0ab | 2022-02-09 13:25:30 +0000 | [diff] [blame] | 201 | "build/bazel/ci/dist":/* recursive = */ false, |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 202 | "build/bazel/examples/android_app":/* recursive = */ true, |
Romain Jobredeaux | 5cc9c9d | 2021-08-26 15:07:48 +0000 | [diff] [blame] | 203 | "build/bazel/examples/java":/* recursive = */ true, |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 204 | "build/bazel/bazel_skylib":/* recursive = */ true, |
| 205 | "build/bazel/rules":/* recursive = */ true, |
| 206 | "build/bazel/rules_cc":/* recursive = */ true, |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 207 | "build/bazel/scripts":/* recursive = */ true, |
Jingwen Chen | b643c7a | 2021-07-26 04:45:48 +0000 | [diff] [blame] | 208 | "build/bazel/tests":/* recursive = */ true, |
| 209 | "build/bazel/platforms":/* recursive = */ true, |
| 210 | "build/bazel/product_variables":/* recursive = */ true, |
Wei Li | 1714104 | 2022-02-22 12:36:33 -0800 | [diff] [blame] | 211 | "build/bazel/vendor/google":/* recursive = */ true, |
Jingwen Chen | 5e49b82 | 2021-08-24 05:14:22 +0000 | [diff] [blame] | 212 | "build/bazel_common_rules":/* recursive = */ true, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 213 | // build/make/tools/signapk BUILD file is generated, so build/make/tools is not recursive. |
| 214 | "build/make/tools":/* recursive = */ false, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 215 | "build/pesto":/* recursive = */ true, |
| 216 | |
| 217 | // external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails |
| 218 | // e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed |
| 219 | "external/bazelbuild-rules_android":/* recursive = */ true, |
Jingwen Chen | 9163225 | 2021-08-10 13:00:33 +0000 | [diff] [blame] | 220 | "external/bazel-skylib":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 221 | "external/guava":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 222 | "external/jsr305":/* recursive = */ true, |
| 223 | "frameworks/ex/common":/* recursive = */ true, |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 224 | |
Romain Jobredeaux | f1b0ac8 | 2021-08-12 14:39:00 +0000 | [diff] [blame] | 225 | "packages/apps/Music":/* recursive = */ true, |
Romain Jobredeaux | 9e09bba | 2021-09-08 18:09:02 +0000 | [diff] [blame] | 226 | "packages/apps/QuickSearchBox":/* recursive = */ true, |
Romain Jobredeaux | a2c0814 | 2021-09-22 14:43:43 -0400 | [diff] [blame] | 227 | "packages/apps/WallpaperPicker":/* recursive = */ false, |
| 228 | |
Wei Li | 1714104 | 2022-02-22 12:36:33 -0800 | [diff] [blame] | 229 | "prebuilts/bundletool":/* recursive = */ true, |
Chris Parsons | 494eef3 | 2021-11-09 10:29:52 -0500 | [diff] [blame] | 230 | "prebuilts/gcc":/* recursive = */ true, |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 231 | "prebuilts/build-tools":/* recursive = */ false, |
Sam Delmerico | 9dfb139 | 2022-02-10 21:11:59 +0000 | [diff] [blame] | 232 | "prebuilts/jdk/jdk11":/* recursive = */ false, |
Romain Jobredeaux | a2c0814 | 2021-09-22 14:43:43 -0400 | [diff] [blame] | 233 | "prebuilts/sdk":/* recursive = */ false, |
| 234 | "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false, |
| 235 | "prebuilts/sdk/current/support":/* recursive = */ false, |
| 236 | "prebuilts/sdk/tools":/* recursive = */ false, |
| 237 | "prebuilts/r8":/* recursive = */ false, |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 240 | // Configure modules in these directories to enable bp2build_available: true or false by default. |
| 241 | bp2buildDefaultConfig = Bp2BuildConfig{ |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 242 | "art/libartpalette": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 243 | "art/libdexfile": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 244 | "art/runtime": Bp2BuildDefaultTrueRecursively, |
| 245 | "art/tools": Bp2BuildDefaultTrue, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 246 | "bionic": Bp2BuildDefaultTrueRecursively, |
| 247 | "bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue, |
Jingwen Chen | 0a9d09f | 2021-11-24 07:00:11 +0000 | [diff] [blame] | 248 | "build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 249 | "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 250 | "build/make/tools/signapk": Bp2BuildDefaultTrue, |
Sam Delmerico | 9dfb139 | 2022-02-10 21:11:59 +0000 | [diff] [blame] | 251 | "build/make/target/product/security": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 252 | "build/soong": Bp2BuildDefaultTrue, |
Rupert Shuttleworth | 2ac9c48 | 2021-11-10 10:37:05 -0500 | [diff] [blame] | 253 | "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir |
Jingwen Chen | 89e2188 | 2021-11-30 11:16:06 +0000 | [diff] [blame] | 254 | "build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue, |
| 255 | "build/soong/cc/symbolfile": Bp2BuildDefaultTrue, |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 256 | "build/soong/linkerconfig": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 257 | "build/soong/scripts": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 258 | "cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 259 | "development/apps/DevelopmentSettings": Bp2BuildDefaultTrue, |
| 260 | "development/apps/Fallback": Bp2BuildDefaultTrue, |
| 261 | "development/apps/WidgetPreview": Bp2BuildDefaultTrue, |
| 262 | "development/samples/BasicGLSurfaceView": Bp2BuildDefaultTrue, |
| 263 | "development/samples/BluetoothChat": Bp2BuildDefaultTrue, |
| 264 | "development/samples/BrokenKeyDerivation": Bp2BuildDefaultTrue, |
| 265 | "development/samples/Compass": Bp2BuildDefaultTrue, |
| 266 | "development/samples/ContactManager": Bp2BuildDefaultTrue, |
| 267 | "development/samples/FixedGridLayout": Bp2BuildDefaultTrue, |
| 268 | "development/samples/HelloEffects": Bp2BuildDefaultTrue, |
| 269 | "development/samples/Home": Bp2BuildDefaultTrue, |
| 270 | "development/samples/HoneycombGallery": Bp2BuildDefaultTrue, |
| 271 | "development/samples/JetBoy": Bp2BuildDefaultTrue, |
| 272 | "development/samples/KeyChainDemo": Bp2BuildDefaultTrue, |
| 273 | "development/samples/LceDemo": Bp2BuildDefaultTrue, |
| 274 | "development/samples/LunarLander": Bp2BuildDefaultTrue, |
| 275 | "development/samples/MultiResolution": Bp2BuildDefaultTrue, |
| 276 | "development/samples/MultiWindow": Bp2BuildDefaultTrue, |
| 277 | "development/samples/NotePad": Bp2BuildDefaultTrue, |
| 278 | "development/samples/Obb": Bp2BuildDefaultTrue, |
| 279 | "development/samples/RSSReader": Bp2BuildDefaultTrue, |
| 280 | "development/samples/ReceiveShareDemo": Bp2BuildDefaultTrue, |
| 281 | "development/samples/SearchableDictionary": Bp2BuildDefaultTrue, |
| 282 | "development/samples/SipDemo": Bp2BuildDefaultTrue, |
| 283 | "development/samples/SkeletonApp": Bp2BuildDefaultTrue, |
| 284 | "development/samples/Snake": Bp2BuildDefaultTrue, |
| 285 | "development/samples/SpellChecker/": Bp2BuildDefaultTrueRecursively, |
| 286 | "development/samples/ThemedNavBarKeyboard": Bp2BuildDefaultTrue, |
| 287 | "development/samples/ToyVpn": Bp2BuildDefaultTrue, |
| 288 | "development/samples/TtsEngine": Bp2BuildDefaultTrue, |
| 289 | "development/samples/USB/AdbTest": Bp2BuildDefaultTrue, |
| 290 | "development/samples/USB/MissileLauncher": Bp2BuildDefaultTrue, |
| 291 | "development/samples/VoiceRecognitionService": Bp2BuildDefaultTrue, |
| 292 | "development/samples/VoicemailProviderDemo": Bp2BuildDefaultTrue, |
Romain Jobredeaux | 355851b | 2022-01-13 17:07:01 +0000 | [diff] [blame] | 293 | "development/samples/WiFiDirectDemo": Bp2BuildDefaultTrue, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 294 | "development/sdk": Bp2BuildDefaultTrueRecursively, |
| 295 | "external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 398a32d | 2022-03-08 08:03:28 +0000 | [diff] [blame] | 296 | "external/auto/android-annotation-stubs": Bp2BuildDefaultTrueRecursively, |
Sam Delmerico | 4c7069f | 2022-02-03 17:50:03 +0000 | [diff] [blame] | 297 | "external/auto/common": Bp2BuildDefaultTrueRecursively, |
| 298 | "external/auto/service": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 299 | "external/boringssl": Bp2BuildDefaultTrueRecursively, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 300 | "external/bouncycastle": Bp2BuildDefaultTrue, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 301 | "external/brotli": Bp2BuildDefaultTrue, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 302 | "external/conscrypt": Bp2BuildDefaultTrue, |
Jingwen Chen | f2504b6 | 2022-03-17 14:51:38 +0000 | [diff] [blame] | 303 | "external/e2fsprogs": Bp2BuildDefaultTrueRecursively, |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 304 | "external/error_prone": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 305 | "external/fmtlib": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 306 | "external/google-benchmark": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 307 | "external/googletest": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 308 | "external/gwp_asan": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 309 | "external/icu": Bp2BuildDefaultTrueRecursively, |
| 310 | "external/icu/android_icu4j": Bp2BuildDefaultFalse, // java rules incomplete |
| 311 | "external/icu/icu4j": Bp2BuildDefaultFalse, // java rules incomplete |
Sam Delmerico | 4c7069f | 2022-02-03 17:50:03 +0000 | [diff] [blame] | 312 | "external/javapoet": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 313 | "external/jemalloc_new": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 314 | "external/jsoncpp": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 315 | "external/libcap": Bp2BuildDefaultTrueRecursively, |
| 316 | "external/libcxx": Bp2BuildDefaultTrueRecursively, |
| 317 | "external/libcxxabi": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 318 | "external/libevent": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | b5b478d | 2021-12-15 13:00:21 -0500 | [diff] [blame] | 319 | "external/libpng": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 320 | "external/lz4/lib": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 321 | "external/lzma/C": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 322 | "external/mdnsresponder": Bp2BuildDefaultTrueRecursively, |
| 323 | "external/minijail": Bp2BuildDefaultTrueRecursively, |
| 324 | "external/pcre": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 325 | "external/protobuf": Bp2BuildDefaultTrueRecursively, |
| 326 | "external/python/six": Bp2BuildDefaultTrueRecursively, |
| 327 | "external/scudo": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 328 | "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | b5b478d | 2021-12-15 13:00:21 -0500 | [diff] [blame] | 329 | "external/selinux/libsepol": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 330 | "external/zlib": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 331 | "external/zstd": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 332 | "frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue, |
| 333 | "frameworks/base/startop/apps/test": Bp2BuildDefaultTrue, |
Sam Delmerico | 9dfb139 | 2022-02-10 21:11:59 +0000 | [diff] [blame] | 334 | "frameworks/base/tests/appwidgets/AppWidgetHostTest": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 335 | "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 336 | "frameworks/native/opengl/tests/gl2_cameraeye": Bp2BuildDefaultTrue, |
| 337 | "frameworks/native/opengl/tests/gl2_java": Bp2BuildDefaultTrue, |
| 338 | "frameworks/native/opengl/tests/testLatency": Bp2BuildDefaultTrue, |
| 339 | "frameworks/native/opengl/tests/testPauseResume": Bp2BuildDefaultTrue, |
| 340 | "frameworks/native/opengl/tests/testViewport": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 341 | "frameworks/proto_logging/stats/stats_log_api_gen": Bp2BuildDefaultTrueRecursively, |
| 342 | "libnativehelper": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 343 | "packages/apps/DevCamera": Bp2BuildDefaultTrue, |
| 344 | "packages/apps/HTMLViewer": Bp2BuildDefaultTrue, |
| 345 | "packages/apps/Protips": Bp2BuildDefaultTrue, |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 346 | "packages/modules/StatsD/lib/libstatssocket": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 347 | "packages/modules/adb": Bp2BuildDefaultTrue, |
Jingwen Chen | d109bd9 | 2021-12-14 07:50:18 +0000 | [diff] [blame] | 348 | "packages/modules/adb/apex": Bp2BuildDefaultTrue, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 349 | "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively, |
| 350 | "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively, |
| 351 | "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively, |
| 352 | "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively, |
| 353 | "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively, |
| 354 | "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 355 | "packages/providers/MediaProvider/tools/dialogs": Bp2BuildDefaultTrue, |
| 356 | "packages/screensavers/Basic": Bp2BuildDefaultTrue, |
| 357 | "packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 358 | "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively, |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 359 | "prebuilts/tools/common/m2": Bp2BuildDefaultTrue, |
Jingwen Chen | d43d4a4 | 2021-11-23 12:40:11 +0000 | [diff] [blame] | 360 | "system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 361 | "system/apex/proto": Bp2BuildDefaultTrueRecursively, |
| 362 | "system/apex/libs": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 363 | "system/core/debuggerd": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 364 | "system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively, |
| 365 | "system/core/libasyncio": Bp2BuildDefaultTrue, |
| 366 | "system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively, |
| 367 | "system/core/libcutils": Bp2BuildDefaultTrueRecursively, |
Liz Kammer | 2fc3489 | 2021-10-11 12:56:48 -0400 | [diff] [blame] | 368 | "system/core/libpackagelistparser": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 369 | "system/core/libprocessgroup": Bp2BuildDefaultTrue, |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 370 | "system/core/libprocessgroup/cgrouprc": Bp2BuildDefaultTrue, |
| 371 | "system/core/libprocessgroup/cgrouprc_format": Bp2BuildDefaultTrue, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 372 | "system/core/libsystem": Bp2BuildDefaultTrueRecursively, |
| 373 | "system/core/libutils": Bp2BuildDefaultTrueRecursively, |
| 374 | "system/core/libvndksupport": Bp2BuildDefaultTrueRecursively, |
Lukacs T. Berki | 497f17d | 2021-04-26 12:15:57 +0200 | [diff] [blame] | 375 | "system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 376 | "system/libbase": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 377 | "system/libprocinfo": Bp2BuildDefaultTrue, |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 378 | "system/libziparchive": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 379 | "system/logging/liblog": Bp2BuildDefaultTrueRecursively, |
| 380 | "system/sepolicy/apex": Bp2BuildDefaultTrueRecursively, |
| 381 | "system/timezone/apex": Bp2BuildDefaultTrueRecursively, |
| 382 | "system/timezone/output_data": Bp2BuildDefaultTrueRecursively, |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 383 | "system/unwinding/libbacktrace": Bp2BuildDefaultTrueRecursively, |
| 384 | "system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 385 | "tools/apksig": Bp2BuildDefaultTrue, |
| 386 | "tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 387 | } |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 388 | |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 389 | // Per-module allowlist to always opt modules in of both bp2build and mixed builds. |
Jingwen Chen | 7edadab | 2022-03-04 07:01:29 +0000 | [diff] [blame] | 390 | // These modules are usually in directories with many other modules that are not ready for |
| 391 | // conversion. |
| 392 | // |
| 393 | // A module can either be in this list or its directory allowlisted entirely |
| 394 | // in bp2buildDefaultConfig, but not both at the same time. |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 395 | bp2buildModuleAlwaysConvertList = []string{ |
Jingwen Chen | 7edadab | 2022-03-04 07:01:29 +0000 | [diff] [blame] | 396 | //external/avb |
| 397 | "avbtool", |
| 398 | "libavb", |
| 399 | "avb_headers", |
| 400 | |
| 401 | //external/fec |
| 402 | "libfec_rs", |
| 403 | |
| 404 | //system/core/libsparse |
| 405 | "libsparse", |
| 406 | |
| 407 | //system/extras/ext4_utils |
| 408 | "libext4_utils", |
| 409 | |
| 410 | //system/extras/libfec |
| 411 | "libfec", |
| 412 | |
| 413 | //system/extras/squashfs_utils |
| 414 | "libsquashfs_utils", |
| 415 | |
| 416 | //system/extras/verity/fec |
| 417 | "fec", |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Sam Delmerico | a9b047a | 2022-02-22 19:21:28 +0000 | [diff] [blame^] | 420 | // Per-module-type allowlist to always opt modules in to both bp2build and mixed builds |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 421 | // when they have the same type as one listed. |
Sam Delmerico | a9b047a | 2022-02-22 19:21:28 +0000 | [diff] [blame^] | 422 | bp2buildModuleTypeAlwaysConvertList = []string{ |
| 423 | "java_import", |
| 424 | } |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 425 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 426 | // 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] | 427 | bp2buildModuleDoNotConvertList = []string{ |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 428 | "libnativehelper_compat_libc", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 |
| 429 | |
| 430 | "libart", // depends on unconverted modules: art_operator_srcs, libodrstatslog, libelffile, art_cmdlineparser_headers, cpp-define-generator-definitions, libcpu_features, libdexfile, libartpalette, libbacktrace, libnativebridge, libnativeloader, libsigchain, libunwindstack, libartbase, libprofile, cpp-define-generator-asm-support, apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, libstatssocket, heapprofd_client_api |
| 431 | "libart-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libart-compiler, libdexfile, libprofile, libartbase, libbacktrace, libartbase-art-gtest |
| 432 | "libart_headers", // depends on unconverted modules: art_libartbase_headers |
| 433 | "libartd", // depends on unconverted modules: apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, libstatssocket, heapprofd_client_api, art_operator_srcs, libodrstatslog, libelffiled, art_cmdlineparser_headers, cpp-define-generator-definitions, libcpu_features, libdexfiled, libartpalette, libbacktrace, libnativebridge, libnativeloader, libsigchain, libunwindstack, libartbased, libprofiled, cpp-define-generator-asm-support |
| 434 | "libartd-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libartd-compiler, libdexfiled, libprofiled, libartbased, libbacktrace, libartbased-art-gtest |
| 435 | "libstatslog_art", // depends on unconverted modules: statslog_art.cpp, statslog_art.h |
| 436 | "statslog_art.h", "statslog_art.cpp", // depends on unconverted modules: stats-log-api-gen |
| 437 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 438 | "libandroid_runtime_lazy", // depends on unconverted modules: libbinder_headers |
| 439 | "libcmd", // depends on unconverted modules: libbinder |
| 440 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 441 | "libdexfile_support_static", // Depends on unconverted module: libdexfile_external_headers |
| 442 | "libunwindstack_local", "libunwindstack_utils", "libc_malloc_debug", "libfdtrack", // Depends on unconverted module: libunwindstack |
| 443 | |
| 444 | "libdexfile_support", // TODO(b/210546943): Enabled based on product variables. |
| 445 | "libdexfile_external_headers", // TODO(b/210546943): Enabled based on product variables. |
| 446 | |
| 447 | "libunwindstack", // Depends on unconverted module libdexfile_support. |
| 448 | "libnativehelper_compat_libc++", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 |
| 449 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 450 | "chkcon", "sefcontext_compile", // depends on unconverted modules: libsepol |
| 451 | |
| 452 | "libsepol", // TODO(b/207408632): Unsupported case of .l sources in cc library rules |
| 453 | |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 454 | "gen-kotlin-build-file.py", // module has same name as source |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 455 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 456 | "libactivitymanager_aidl", // TODO(b/207426160): Depends on activity_manager_procstate_aidl, which is an aidl filegroup. |
| 457 | |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 458 | "libnativehelper_lazy_mts_jni", "libnativehelper_mts_jni", // depends on unconverted modules: libgmock_ndk |
| 459 | "libnativetesthelper_jni", "libgmock_main_ndk", "libgmock_ndk", // depends on unconverted module: libgtest_ndk_c++ |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 460 | |
| 461 | "statslog-framework-java-gen", "statslog.cpp", "statslog.h", "statslog.rs", "statslog_header.rs", // depends on unconverted modules: stats-log-api-gen |
| 462 | |
| 463 | "stats-log-api-gen", // depends on unconverted modules: libstats_proto_host, libprotobuf-cpp-full |
| 464 | |
| 465 | "libstatslog", // depends on unconverted modules: statslog.cpp, statslog.h, ... |
| 466 | |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 467 | "cmd", // depends on unconverted module packagemanager_aidl-cpp, of unsupported type aidl_interface |
| 468 | "servicedispatcher", // depends on unconverted module android.debug_aidl, of unsupported type aidl_interface |
| 469 | "libutilscallstack", // depends on unconverted module libbacktrace |
| 470 | "libbacktrace", // depends on unconverted module libunwindstack |
| 471 | "libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core |
| 472 | "libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 473 | "unwind_for_offline", // depends on unconverted module libunwindstack_utils |
| 474 | "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite |
| 475 | "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library. |
| 476 | |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 477 | "static_crasher", // depends on unconverted modules: libdebuggerd_handler |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 478 | |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 479 | "pbtombstone", "crash_dump", // depends on libdebuggerd, libunwindstack |
Rupert Shuttleworth | 47aa584 | 2021-04-30 04:04:15 -0400 | [diff] [blame] | 480 | |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 481 | "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] | 482 | |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 483 | "libprotobuf-internal-protos", // b/210751803, we don't handle path property for filegroups |
| 484 | "libprotobuf-internal-python-srcs", // b/210751803, we don't handle path property for filegroups |
| 485 | "libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 486 | "host-libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 487 | "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 488 | "apex_manifest_proto_java", // b/210751803, depends on libprotobuf-java-full |
| 489 | "conscrypt", // b/210751803, we don't handle path property for filegroups |
| 490 | "conscrypt-for-host", // b/210751803, we don't handle path property for filegroups |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 491 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 492 | "libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK |
| 493 | "host-libprotobuf-java-nano", // b/220869005, depends on libprotobuf-java-nano |
Liz Kammer | 0f3b7d2 | 2021-09-28 13:48:21 -0400 | [diff] [blame] | 494 | |
Jingwen Chen | f6b4cd4 | 2022-02-08 03:23:10 +0000 | [diff] [blame] | 495 | "libc_musl_sysroot_bionic_arch_headers", // b/218405924, depends on soong_zip |
| 496 | "libc_musl_sysroot_bionic_headers", // b/218405924, depends on soong_zip and generates duplicate srcs |
| 497 | |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 498 | // python protos |
| 499 | "libprotobuf-python", // contains .proto sources |
| 500 | "conv_linker_config", // depends on linker_config_proto, a python lib with proto sources |
| 501 | "apex_build_info_proto", "apex_manifest_proto", // a python lib with proto sources |
| 502 | "linker_config_proto", // contains .proto sources |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 503 | |
Chris Parsons | b97a817 | 2021-10-04 12:48:29 -0400 | [diff] [blame] | 504 | "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] | 505 | |
Jingwen Chen | df27b7a | 2021-10-18 06:33:16 +0000 | [diff] [blame] | 506 | // b/203369847: multiple genrules in the same package creating the same file |
| 507 | // //development/sdk/... |
| 508 | "platform_tools_properties", |
| 509 | "build_tools_source_properties", |
| 510 | |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 511 | // APEX support |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 512 | "com.android.runtime", // depends on unconverted modules: bionic-linker-config, linkerconfig |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 513 | |
Chris Parsons | c39f633 | 2021-10-01 18:00:31 -0400 | [diff] [blame] | 514 | "libgtest_ndk_c++", // b/201816222: Requires sdk_version support. |
| 515 | "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support. |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 516 | |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 517 | "abb", // depends on unconverted modules: libcmd, libbinder |
| 518 | "adb", // depends on unconverted modules: AdbWinApi, libadb_host, libandroidfw, libapp_processes_protos_full, libfastdeploy_host, libopenscreen-discovery, libopenscreen-platform-impl, libusb, bin2c_fastdeployagent, AdbWinUsbApi |
Liz Kammer | 3d3b35c | 2022-01-11 16:02:50 +0000 | [diff] [blame] | 519 | "libadb_host", // depends on unconverted modules: libopenscreen-discovery, libopenscreen-platform-impl, libusb, AdbWinApi |
| 520 | "libfastdeploy_host", // depends on unconverted modules: libandroidfw, libusb, AdbWinApi |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 521 | "linker", // depends on unconverted modules: libdebuggerd_handler_fallback |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 522 | "linker_reloc_bench_main", // depends on unconverted modules: liblinker_reloc_bench_* |
Chris Parsons | 8a49816 | 2021-11-18 17:19:12 -0500 | [diff] [blame] | 523 | "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] | 524 | |
| 525 | "linkerconfig", // http://b/202876379 has arch-variant static_executable |
| 526 | "mdnsd", // http://b/202876379 has arch-variant static_executable |
| 527 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 528 | "CarHTMLViewer", // depends on unconverted modules android.car-stubs, car-ui-lib |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 529 | |
| 530 | "libdexfile", // depends on unconverted modules: dexfile_operator_srcs, libartbase, libartpalette, |
| 531 | "libdexfiled", // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 532 | |
| 533 | // go deps: |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 534 | "apex-protos", // depends on soong_zip, a go binary |
| 535 | "generated_android_icu4j_src_files", "generated_android_icu4j_test_files", "icu4c_test_data", // depends on unconverted modules: soong_zip |
Liz Kammer | 878a7f1 | 2022-03-01 08:35:51 -0500 | [diff] [blame] | 536 | "host_bionic_linker_asm", // depends on extract_linker, a go binary. |
| 537 | "host_bionic_linker_script", // depends on extract_linker, a go binary. |
| 538 | "robolectric-sqlite4java-native", // depends on soong_zip, a go binary |
| 539 | "robolectric_tzdata", // depends on soong_zip, a go binary |
| 540 | "libc_musl_sysroot_libc++_headers", "libc_musl_sysroot_libc++abi_headers", // depends on soong_zip, zip2zip |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 541 | |
| 542 | "android_icu4j_srcgen_binary", // Bazel build error: deps not allowed without srcs; move to runtime_deps |
| 543 | "core-icu4j-for-host", // Bazel build error: deps not allowed without srcs; move to runtime_deps |
Sam Delmerico | cd1b80f | 2022-01-11 21:55:46 +0000 | [diff] [blame] | 544 | |
| 545 | // java deps |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 546 | "android_icu4j_srcgen", // depends on unconverted modules: currysrc |
Liz Kammer | a20b7a7 | 2022-02-04 12:59:36 -0500 | [diff] [blame] | 547 | "bin2c_fastdeployagent", // depends on deployagent, a java binary |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 548 | "currysrc", // depends on unconverted modules: currysrc_org.eclipse, guavalib, jopt-simple-4.9 |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 549 | "robolectric-sqlite4java-0.282", // depends on unconverted modules: robolectric-sqlite4java-import, robolectric-sqlite4java-native |
Liz Kammer | a20b7a7 | 2022-02-04 12:59:36 -0500 | [diff] [blame] | 550 | "timezone-host", // depends on unconverted modules: art.module.api.annotations |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 551 | "truth-host-prebuilt", // depends on unconverted modules: truth-prebuilt |
Liz Kammer | a20b7a7 | 2022-02-04 12:59:36 -0500 | [diff] [blame] | 552 | "truth-prebuilt", // depends on unconverted modules: asm-7.0, guava |
Liz Kammer | 35ca77e | 2021-12-22 15:31:40 -0500 | [diff] [blame] | 553 | |
| 554 | "generated_android_icu4j_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip |
| 555 | "generated_android_icu4j_test_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip |
Liz Kammer | a20b7a7 | 2022-02-04 12:59:36 -0500 | [diff] [blame] | 556 | |
| 557 | "art-script", // depends on unconverted modules: dalvikvm, dex2oat |
| 558 | "dex2oat-script", // depends on unconverted modules: dex2oat |
Sam Delmerico | a9b047a | 2022-02-22 19:21:28 +0000 | [diff] [blame^] | 559 | |
| 560 | // TODO(b/221082840) convert java_imports in //packages/apps/Car/libs/car-ui-lib/... |
| 561 | "prebuilt_car-ui-androidx-annotation", |
| 562 | "prebuilt_car-ui-androidx-annotation-nodeps", |
| 563 | "prebuilt_car-ui-androidx-collection", |
| 564 | "prebuilt_car-ui-androidx-collection-nodeps", |
| 565 | "prebuilt_car-ui-androidx-core-common", |
| 566 | "prebuilt_car-ui-androidx-core-common-nodeps", |
| 567 | "prebuilt_car-ui-androidx-lifecycle-common", |
| 568 | "prebuilt_car-ui-androidx-lifecycle-common-nodeps", |
| 569 | "prebuilt_car-ui-androidx-constraintlayout-solver", |
| 570 | "prebuilt_car-ui-androidx-constraintlayout-solver-nodeps", |
| 571 | |
| 572 | "prebuilt_art-module-host-exports_okhttp-norepackage@current", // aosp/1999250, needs Jars (arch variant) |
| 573 | "prebuilt_conscrypt-unbundled", // aosp/1999250, needs Jars (arch variant) |
| 574 | "prebuilt_conscrypt-module-host-exports_conscrypt-unbundled@current", // aosp/1999250, needs Jars (arch variant) |
| 575 | "prebuilt_platform-robolectric-4.4-prebuilt", // aosp/1999250, needs .aar support in Jars |
| 576 | "prebuilt_platform-robolectric-4.5.1-prebuilt", // aosp/1999250, needs .aar support in Jars |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 577 | } |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 578 | |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 579 | // Per-module denylist of cc_library modules to only generate the static |
| 580 | // variant if their shared variant isn't ready or buildable by Bazel. |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 581 | bp2buildCcLibraryStaticOnlyList = []string{} |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 582 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 583 | // Per-module denylist to opt modules out of mixed builds. Such modules will |
| 584 | // still be generated via bp2build. |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 585 | mixedBuildsDisabledList = []string{ |
Liz Kammer | 5c31358 | 2021-12-03 15:23:26 -0500 | [diff] [blame] | 586 | "art_libdexfile_dex_instruction_list_header", // breaks libart_mterp.armng, header not found |
| 587 | |
Wei Li | 455ba83 | 2021-11-04 22:58:12 +0000 | [diff] [blame] | 588 | "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 |
| 589 | "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] | 590 | |
Jingwen Chen | d480859 | 2021-11-26 05:39:07 +0000 | [diff] [blame] | 591 | "cap_names.h", // TODO(b/204913827) runfiles need to be handled in mixed builds |
| 592 | "libcap", // TODO(b/204913827) runfiles need to be handled in mixed builds |
| 593 | "libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610. |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 594 | |
| 595 | // Depends on libprotobuf-cpp-* |
Liz Kammer | eb2d6d1 | 2021-12-06 14:56:25 -0500 | [diff] [blame] | 596 | "libadb_pairing_connection", |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 597 | "libadb_pairing_connection_static", |
| 598 | "libadb_pairing_server", "libadb_pairing_server_static", |
Yu Liu | 7f3605f | 2022-02-08 14:15:12 -0800 | [diff] [blame] | 599 | |
| 600 | // TODO(b/204811222) support suffix in cc_binary |
| 601 | "acvp_modulewrapper", |
| 602 | "android.hardware.media.c2@1.0-service-v4l2", |
| 603 | "app_process", |
| 604 | "bar_test", |
| 605 | "bench_cxa_atexit", |
| 606 | "bench_noop", |
| 607 | "bench_noop_nostl", |
| 608 | "bench_noop_static", |
| 609 | "boringssl_self_test", |
| 610 | "boringssl_self_test_vendor", |
| 611 | "bssl", |
| 612 | "cavp", |
| 613 | "crash_dump", |
| 614 | "crasher", |
| 615 | "libcxx_test_template", |
| 616 | "linker", |
| 617 | "memory_replay", |
| 618 | "native_bridge_guest_linker", |
| 619 | "native_bridge_stub_library_defaults", |
| 620 | "noop", |
| 621 | "simpleperf_ndk", |
| 622 | "toybox-static", |
| 623 | "zlib_bench", |
Chris Parsons | 2c78839 | 2021-08-10 11:58:07 -0400 | [diff] [blame] | 624 | } |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 625 | |
| 626 | // Used for quicker lookups |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 627 | bp2buildModuleDoNotConvert = map[string]bool{} |
| 628 | bp2buildModuleAlwaysConvert = map[string]bool{} |
| 629 | bp2buildModuleTypeAlwaysConvert = map[string]bool{} |
| 630 | bp2buildCcLibraryStaticOnly = map[string]bool{} |
| 631 | mixedBuildsDisabled = map[string]bool{} |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 632 | ) |
| 633 | |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 634 | func init() { |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 635 | for _, moduleName := range bp2buildModuleAlwaysConvertList { |
| 636 | bp2buildModuleAlwaysConvert[moduleName] = true |
| 637 | } |
| 638 | |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 639 | for _, moduleType := range bp2buildModuleTypeAlwaysConvertList { |
| 640 | bp2buildModuleTypeAlwaysConvert[moduleType] = true |
| 641 | } |
| 642 | |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 643 | for _, moduleName := range bp2buildModuleDoNotConvertList { |
| 644 | bp2buildModuleDoNotConvert[moduleName] = true |
| 645 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 646 | |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 647 | for _, moduleName := range bp2buildCcLibraryStaticOnlyList { |
| 648 | bp2buildCcLibraryStaticOnly[moduleName] = true |
| 649 | } |
| 650 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 651 | for _, moduleName := range mixedBuildsDisabledList { |
| 652 | mixedBuildsDisabled[moduleName] = true |
| 653 | } |
| 654 | } |
| 655 | |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 656 | func GenerateCcLibraryStaticOnly(moduleName string) bool { |
| 657 | return bp2buildCcLibraryStaticOnly[moduleName] |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 660 | func ShouldKeepExistingBuildFileForDir(dir string) bool { |
| 661 | if _, ok := bp2buildKeepExistingBuildFile[dir]; ok { |
| 662 | // Exact dir match |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 663 | return true |
| 664 | } |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 665 | // Check if subtree match |
| 666 | for prefix, recursive := range bp2buildKeepExistingBuildFile { |
| 667 | if recursive { |
| 668 | if strings.HasPrefix(dir, prefix+"/") { |
| 669 | return true |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | // Default |
| 674 | return false |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 675 | } |
| 676 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 677 | // MixedBuildsEnabled checks that a module is ready to be replaced by a |
| 678 | // converted or handcrafted Bazel target. |
Chris Parsons | 494eef3 | 2021-11-09 10:29:52 -0500 | [diff] [blame] | 679 | func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool { |
| 680 | if ctx.Os() == Windows { |
| 681 | // Windows toolchains are not currently supported. |
| 682 | return false |
| 683 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 684 | if !ctx.Module().Enabled() { |
| 685 | return false |
| 686 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 687 | if !ctx.Config().BazelContext.BazelEnabled() { |
| 688 | return false |
| 689 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 690 | if !convertedToBazel(ctx, ctx.Module()) { |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 691 | return false |
| 692 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 693 | |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 694 | if GenerateCcLibraryStaticOnly(ctx.Module().Name()) { |
Jingwen Chen | 179856a | 2021-05-03 09:15:48 +0000 | [diff] [blame] | 695 | // Don't use partially-converted cc_library targets in mixed builds, |
| 696 | // since mixed builds would generally rely on both static and shared |
| 697 | // variants of a cc_library. |
| 698 | return false |
| 699 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 700 | return !mixedBuildsDisabled[ctx.Module().Name()] |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 703 | // 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] | 704 | func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 705 | b, ok := module.(Bazelable) |
| 706 | if !ok { |
| 707 | return false |
| 708 | } |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 709 | return b.shouldConvertWithBp2build(ctx, module) || b.HasHandcraftedLabel() |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 712 | // ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. |
| 713 | func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) bool { |
| 714 | return b.shouldConvertWithBp2build(ctx, ctx.Module()) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 717 | func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool { |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 718 | moduleName := module.Name() |
| 719 | moduleNameAllowed := bp2buildModuleAlwaysConvert[moduleName] |
| 720 | moduleTypeAllowed := bp2buildModuleTypeAlwaysConvert[ctx.OtherModuleType(module)] |
| 721 | allowlistConvert := moduleNameAllowed || moduleTypeAllowed |
| 722 | if moduleNameAllowed && moduleTypeAllowed { |
| 723 | ctx.(BaseModuleContext).ModuleErrorf("A module cannot be in bp2buildModuleAlwaysConvert and also be" + |
| 724 | " in bp2buildModuleTypeAlwaysConvert") |
| 725 | } |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 726 | |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 727 | if bp2buildModuleDoNotConvert[moduleName] { |
| 728 | if moduleNameAllowed { |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 729 | ctx.(BaseModuleContext).ModuleErrorf("a module cannot be in bp2buildModuleDoNotConvert" + |
| 730 | " and also be in bp2buildModuleAlwaysConvert") |
| 731 | } |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 732 | return false |
| 733 | } |
| 734 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 735 | if !b.bazelProps().Bazel_module.CanConvertToBazel { |
| 736 | return false |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 737 | } |
| 738 | |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 739 | propValue := b.bazelProperties.Bazel_module.Bp2build_available |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 740 | packagePath := ctx.OtherModuleDir(module) |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 741 | // Modules in unit tests which are enabled in the allowlist by type or name |
| 742 | // trigger this conditional because unit tests run under the "." package path |
| 743 | isTestModule := packagePath == "." && proptools.BoolDefault(propValue, false) |
| 744 | if allowlistConvert && !isTestModule && ShouldKeepExistingBuildFileForDir(packagePath) { |
| 745 | if moduleNameAllowed { |
| 746 | ctx.(BaseModuleContext).ModuleErrorf("A module cannot be in a directory listed in bp2buildKeepExistingBuildFile"+ |
| 747 | " and also be in bp2buildModuleAlwaysConvert. Directory: '%s'", packagePath) |
| 748 | } |
Sam Delmerico | 94d26c2 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 749 | return false |
| 750 | } |
| 751 | |
| 752 | config := ctx.Config().bp2buildPackageConfig |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 753 | // This is a tristate value: true, false, or unset. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 754 | if bp2buildDefaultTrueRecursively(packagePath, config) { |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 755 | if moduleNameAllowed { |
Sam Delmerico | 94d26c2 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 756 | ctx.(BaseModuleContext).ModuleErrorf("A module cannot be in a directory marked Bp2BuildDefaultTrue"+ |
| 757 | " or Bp2BuildDefaultTrueRecursively and also be in bp2buildModuleAlwaysConvert. Directory: '%s'", |
| 758 | packagePath) |
Sam Delmerico | fa1831c | 2022-02-22 18:07:55 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 761 | // Allow modules to explicitly opt-out. |
| 762 | return proptools.BoolDefault(propValue, true) |
| 763 | } |
| 764 | |
| 765 | // Allow modules to explicitly opt-in. |
Sam Delmerico | 85d831a | 2022-03-07 19:12:42 +0000 | [diff] [blame] | 766 | return proptools.BoolDefault(propValue, allowlistConvert) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | // bp2buildDefaultTrueRecursively checks that the package contains a prefix from the |
| 770 | // set of package prefixes where all modules must be converted. That is, if the |
| 771 | // package is x/y/z, and the list contains either x, x/y, or x/y/z, this function will |
| 772 | // return true. |
| 773 | // |
| 774 | // However, if the package is x/y, and it matches a Bp2BuildDefaultFalse "x/y" entry |
| 775 | // exactly, this module will return false early. |
| 776 | // |
| 777 | // This function will also return false if the package doesn't match anything in |
| 778 | // the config. |
| 779 | func bp2buildDefaultTrueRecursively(packagePath string, config Bp2BuildConfig) bool { |
| 780 | ret := false |
| 781 | |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 782 | // Check if the package path has an exact match in the config. |
| 783 | if config[packagePath] == Bp2BuildDefaultTrue || config[packagePath] == Bp2BuildDefaultTrueRecursively { |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 784 | return true |
Jingwen Chen | 294e774 | 2021-08-31 05:58:01 +0000 | [diff] [blame] | 785 | } else if config[packagePath] == Bp2BuildDefaultFalse { |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 786 | return false |
| 787 | } |
| 788 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 789 | // If not, check for the config recursively. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 790 | packagePrefix := "" |
| 791 | // e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist. |
| 792 | for _, part := range strings.Split(packagePath, "/") { |
| 793 | packagePrefix += part |
| 794 | if config[packagePrefix] == Bp2BuildDefaultTrueRecursively { |
| 795 | // package contains this prefix and this prefix should convert all modules |
| 796 | return true |
| 797 | } |
| 798 | // Continue to the next part of the package dir. |
| 799 | packagePrefix += "/" |
| 800 | } |
| 801 | |
| 802 | return ret |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 803 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 804 | |
| 805 | // GetBazelBuildFileContents returns the file contents of a hand-crafted BUILD file if available or |
| 806 | // an error if there are errors reading the file. |
| 807 | // TODO(b/181575318): currently we append the whole BUILD file, let's change that to do |
| 808 | // something more targeted based on the rule type and target. |
| 809 | func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) (string, error) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 810 | if !strings.Contains(b.HandcraftedLabel(), path) { |
| 811 | 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] | 812 | } |
| 813 | name = filepath.Join(path, name) |
| 814 | f, err := c.fs.Open(name) |
| 815 | if err != nil { |
| 816 | return "", err |
| 817 | } |
| 818 | defer f.Close() |
| 819 | |
| 820 | data, err := ioutil.ReadAll(f) |
| 821 | if err != nil { |
| 822 | return "", err |
| 823 | } |
| 824 | return string(data[:]), nil |
| 825 | } |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 826 | |
| 827 | func registerBp2buildConversionMutator(ctx RegisterMutatorsContext) { |
| 828 | ctx.TopDown("bp2build_conversion", convertWithBp2build).Parallel() |
| 829 | } |
| 830 | |
| 831 | func convertWithBp2build(ctx TopDownMutatorContext) { |
| 832 | bModule, ok := ctx.Module().(Bazelable) |
| 833 | if !ok || !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) { |
| 834 | return |
| 835 | } |
| 836 | |
| 837 | bModule.ConvertWithBp2build(ctx) |
| 838 | } |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 839 | |
| 840 | // GetMainClassInManifest scans the manifest file specified in filepath and returns |
| 841 | // the value of attribute Main-Class in the manifest file if it exists, or returns error. |
| 842 | // WARNING: this is for bp2build converters of java_* modules only. |
| 843 | func GetMainClassInManifest(c Config, filepath string) (string, error) { |
| 844 | file, err := c.fs.Open(filepath) |
| 845 | if err != nil { |
| 846 | return "", err |
| 847 | } |
Liz Kammer | 0fe123d | 2022-02-07 10:17:35 -0500 | [diff] [blame] | 848 | defer file.Close() |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 849 | scanner := bufio.NewScanner(file) |
| 850 | for scanner.Scan() { |
| 851 | line := scanner.Text() |
| 852 | if strings.HasPrefix(line, "Main-Class:") { |
| 853 | return strings.TrimSpace(line[len("Main-Class:"):]), nil |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | return "", errors.New("Main-Class is not found.") |
| 858 | } |