blob: 9f38c3b63c395d478780efbaaea43df9c4e73aff [file] [log] [blame]
Liz Kammerea6666f2021-02-17 10:17:28 -05001// 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
15package android
16
Liz Kammerba3ea162021-02-17 13:22:03 -050017import (
Wei Libafb6d62021-12-10 03:14:59 -080018 "bufio"
19 "errors"
Liz Kammerba3ea162021-02-17 13:22:03 -050020 "fmt"
21 "io/ioutil"
22 "path/filepath"
23 "strings"
24
Liz Kammerbdc60992021-02-24 16:55:11 -050025 "github.com/google/blueprint"
Liz Kammerba3ea162021-02-17 13:22:03 -050026 "github.com/google/blueprint/proptools"
27)
28
Jingwen Chen01812022021-11-19 14:29:43 +000029type 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 Kammerbe46fcc2021-11-01 15:32:43 -040044
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 Chen01812022021-11-19 14:29:43 +000048}
49
Liz Kammerba3ea162021-02-17 13:22:03 -050050// Properties contains common module properties for Bazel migration purposes.
51type properties struct {
52 // In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing
53 // this Soong module.
Jingwen Chen01812022021-11-19 14:29:43 +000054 Bazel_module bazelModuleProperties
Liz Kammerba3ea162021-02-17 13:22:03 -050055}
Liz Kammerea6666f2021-02-17 10:17:28 -050056
Jingwen Chen25825ca2021-11-15 12:28:43 +000057// namespacedVariableProperties is a map from a string representing a Soong
Jingwen Chen84817de2021-11-17 10:57:35 +000058// 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.
61type namespacedVariableProperties map[string][]interface{}
Jingwen Chena47f28d2021-11-02 16:43:57 +000062
Liz Kammerea6666f2021-02-17 10:17:28 -050063// BazelModuleBase contains the property structs with metadata for modules which can be converted to
64// Bazel.
65type BazelModuleBase struct {
Liz Kammerba3ea162021-02-17 13:22:03 -050066 bazelProperties properties
Jingwen Chena47f28d2021-11-02 16:43:57 +000067
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 Kammerea6666f2021-02-17 10:17:28 -050081}
82
83// Bazelable is specifies the interface for modules that can be converted to Bazel.
84type Bazelable interface {
Liz Kammerba3ea162021-02-17 13:22:03 -050085 bazelProps() *properties
86 HasHandcraftedLabel() bool
Liz Kammerbdc60992021-02-24 16:55:11 -050087 HandcraftedLabel() string
88 GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
Liz Kammerbe46fcc2021-11-01 15:32:43 -040089 ShouldConvertWithBp2build(ctx BazelConversionContext) bool
90 shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool
Liz Kammerba3ea162021-02-17 13:22:03 -050091 GetBazelBuildFileContents(c Config, path, name string) (string, error)
Liz Kammerbe46fcc2021-11-01 15:32:43 -040092 ConvertWithBp2build(ctx TopDownMutatorContext)
Jingwen Chena47f28d2021-11-02 16:43:57 +000093
Jingwen Chen84817de2021-11-17 10:57:35 +000094 // 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 Chena47f28d2021-11-02 16:43:57 +0000103 namespacedVariableProps() namespacedVariableProperties
104 setNamespacedVariableProps(props namespacedVariableProperties)
105 BaseModuleType() string
Jingwen Chen84817de2021-11-17 10:57:35 +0000106 SetBaseModuleType(baseModuleType string)
Liz Kammerea6666f2021-02-17 10:17:28 -0500107}
108
109// BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules.
110type BazelModule interface {
111 Module
112 Bazelable
113}
114
115// InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion
116// properties.
117func InitBazelModule(module BazelModule) {
118 module.AddProperties(module.bazelProps())
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400119 module.bazelProps().Bazel_module.CanConvertToBazel = true
Liz Kammerea6666f2021-02-17 10:17:28 -0500120}
121
122// bazelProps returns the Bazel properties for the given BazelModuleBase.
Liz Kammerba3ea162021-02-17 13:22:03 -0500123func (b *BazelModuleBase) bazelProps() *properties {
Liz Kammerea6666f2021-02-17 10:17:28 -0500124 return &b.bazelProperties
125}
126
Jingwen Chena47f28d2021-11-02 16:43:57 +0000127func (b *BazelModuleBase) namespacedVariableProps() namespacedVariableProperties {
128 return b.namespacedVariableProperties
129}
130
131func (b *BazelModuleBase) setNamespacedVariableProps(props namespacedVariableProperties) {
132 b.namespacedVariableProperties = props
133}
134
135func (b *BazelModuleBase) BaseModuleType() string {
136 return b.baseModuleType
137}
138
139func (b *BazelModuleBase) SetBaseModuleType(baseModuleType string) {
140 b.baseModuleType = baseModuleType
141}
142
Liz Kammerba3ea162021-02-17 13:22:03 -0500143// HasHandcraftedLabel returns whether this module has a handcrafted Bazel label.
144func (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
149func (b *BazelModuleBase) HandcraftedLabel() string {
150 return proptools.String(b.bazelProperties.Bazel_module.Label)
151}
152
Liz Kammerea6666f2021-02-17 10:17:28 -0500153// GetBazelLabel returns the Bazel label for the given BazelModuleBase.
Liz Kammerbdc60992021-02-24 16:55:11 -0500154func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string {
155 if b.HasHandcraftedLabel() {
156 return b.HandcraftedLabel()
157 }
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400158 if b.ShouldConvertWithBp2build(ctx) {
Liz Kammerbdc60992021-02-24 16:55:11 -0500159 return bp2buildModuleLabel(ctx, module)
160 }
161 return "" // no label for unconverted module
Liz Kammerea6666f2021-02-17 10:17:28 -0500162}
163
Jingwen Chen12b4c272021-03-10 02:05:59 -0500164// Configuration to decide if modules in a directory should default to true/false for bp2build_available
165type Bp2BuildConfig map[string]BazelConversionConfigEntry
166type BazelConversionConfigEntry int
167
168const (
Jingwen Chen91220d72021-03-24 02:18:33 -0400169 // 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 Chen12b4c272021-03-10 02:05:59 -0500174 // 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 Chen294e7742021-08-31 05:58:01 +0000181 // all modules in this package (not recursively) default to bp2build_available: true.
182 // allows modules to opt-out.
183 Bp2BuildDefaultTrue
184
Jingwen Chen12b4c272021-03-10 02:05:59 -0500185 // all modules in this package (not recursively) default to bp2build_available: false.
186 // allows modules to opt-in.
187 Bp2BuildDefaultFalse
188)
189
190var (
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400191 // Keep any existing BUILD files (and do not generate new BUILD files) for these directories
Jingwen Chenb643c7a2021-07-26 04:45:48 +0000192 // in the synthetic Bazel workspace.
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400193 bp2buildKeepExistingBuildFile = map[string]bool{
194 // This is actually build/bazel/build.BAZEL symlinked to ./BUILD
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000195 ".":/*recursive = */ false,
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400196
Jingwen Chenb643c7a2021-07-26 04:45:48 +0000197 // 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,
201 "build/bazel/examples/android_app":/* recursive = */ true,
Romain Jobredeaux5cc9c9d2021-08-26 15:07:48 +0000202 "build/bazel/examples/java":/* recursive = */ true,
Jingwen Chenb643c7a2021-07-26 04:45:48 +0000203 "build/bazel/bazel_skylib":/* recursive = */ true,
204 "build/bazel/rules":/* recursive = */ true,
205 "build/bazel/rules_cc":/* recursive = */ true,
Jingwen Chen294e7742021-08-31 05:58:01 +0000206 "build/bazel/scripts":/* recursive = */ true,
Jingwen Chenb643c7a2021-07-26 04:45:48 +0000207 "build/bazel/tests":/* recursive = */ true,
208 "build/bazel/platforms":/* recursive = */ true,
209 "build/bazel/product_variables":/* recursive = */ true,
Jingwen Chen5e49b822021-08-24 05:14:22 +0000210 "build/bazel_common_rules":/* recursive = */ true,
Wei Libafb6d62021-12-10 03:14:59 -0800211 // build/make/tools/signapk BUILD file is generated, so build/make/tools is not recursive.
212 "build/make/tools":/* recursive = */ false,
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400213 "build/pesto":/* recursive = */ true,
214
215 // external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails
216 // e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed
217 "external/bazelbuild-rules_android":/* recursive = */ true,
Jingwen Chen91632252021-08-10 13:00:33 +0000218 "external/bazel-skylib":/* recursive = */ true,
Romain Jobredeaux9e09bba2021-09-08 18:09:02 +0000219 "external/guava":/* recursive = */ true,
220 "external/error_prone":/* recursive = */ true,
221 "external/jsr305":/* recursive = */ true,
222 "frameworks/ex/common":/* recursive = */ true,
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400223
Romain Jobredeauxf1b0ac82021-08-12 14:39:00 +0000224 "packages/apps/Music":/* recursive = */ true,
Romain Jobredeaux9e09bba2021-09-08 18:09:02 +0000225 "packages/apps/QuickSearchBox":/* recursive = */ true,
Romain Jobredeauxa2c08142021-09-22 14:43:43 -0400226 "packages/apps/WallpaperPicker":/* recursive = */ false,
227
Chris Parsons494eef32021-11-09 10:29:52 -0500228 "prebuilts/gcc":/* recursive = */ true,
Romain Jobredeauxa2c08142021-09-22 14:43:43 -0400229 "prebuilts/sdk":/* recursive = */ false,
230 "prebuilts/sdk/current/extras/app-toolkit":/* recursive = */ false,
231 "prebuilts/sdk/current/support":/* recursive = */ false,
232 "prebuilts/sdk/tools":/* recursive = */ false,
233 "prebuilts/r8":/* recursive = */ false,
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400234 }
235
Jingwen Chen12b4c272021-03-10 02:05:59 -0500236 // Configure modules in these directories to enable bp2build_available: true or false by default.
237 bp2buildDefaultConfig = Bp2BuildConfig{
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400238 "art/libdexfile": Bp2BuildDefaultTrueRecursively,
239 "bionic": Bp2BuildDefaultTrueRecursively,
240 "bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
Jingwen Chen0a9d09f2021-11-24 07:00:11 +0000241 "build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400242 "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
Wei Libafb6d62021-12-10 03:14:59 -0800243 "build/make/tools/signapk": Bp2BuildDefaultTrue,
Chris Parsons8a498162021-11-18 17:19:12 -0500244 "build/soong": Bp2BuildDefaultTrue,
Rupert Shuttleworth2ac9c482021-11-10 10:37:05 -0500245 "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir
Jingwen Chen89e21882021-11-30 11:16:06 +0000246 "build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue,
247 "build/soong/cc/symbolfile": Bp2BuildDefaultTrue,
Liz Kammer5c313582021-12-03 15:23:26 -0500248 "build/soong/scripts": Bp2BuildDefaultTrueRecursively,
Chris Parsons8a498162021-11-18 17:19:12 -0500249 "cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively,
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400250 "development/apps/DevelopmentSettings": Bp2BuildDefaultTrue,
251 "development/apps/Fallback": Bp2BuildDefaultTrue,
252 "development/apps/WidgetPreview": Bp2BuildDefaultTrue,
253 "development/samples/BasicGLSurfaceView": Bp2BuildDefaultTrue,
254 "development/samples/BluetoothChat": Bp2BuildDefaultTrue,
255 "development/samples/BrokenKeyDerivation": Bp2BuildDefaultTrue,
256 "development/samples/Compass": Bp2BuildDefaultTrue,
257 "development/samples/ContactManager": Bp2BuildDefaultTrue,
258 "development/samples/FixedGridLayout": Bp2BuildDefaultTrue,
259 "development/samples/HelloEffects": Bp2BuildDefaultTrue,
260 "development/samples/Home": Bp2BuildDefaultTrue,
261 "development/samples/HoneycombGallery": Bp2BuildDefaultTrue,
262 "development/samples/JetBoy": Bp2BuildDefaultTrue,
263 "development/samples/KeyChainDemo": Bp2BuildDefaultTrue,
264 "development/samples/LceDemo": Bp2BuildDefaultTrue,
265 "development/samples/LunarLander": Bp2BuildDefaultTrue,
266 "development/samples/MultiResolution": Bp2BuildDefaultTrue,
267 "development/samples/MultiWindow": Bp2BuildDefaultTrue,
268 "development/samples/NotePad": Bp2BuildDefaultTrue,
269 "development/samples/Obb": Bp2BuildDefaultTrue,
270 "development/samples/RSSReader": Bp2BuildDefaultTrue,
271 "development/samples/ReceiveShareDemo": Bp2BuildDefaultTrue,
272 "development/samples/SearchableDictionary": Bp2BuildDefaultTrue,
273 "development/samples/SipDemo": Bp2BuildDefaultTrue,
274 "development/samples/SkeletonApp": Bp2BuildDefaultTrue,
275 "development/samples/Snake": Bp2BuildDefaultTrue,
276 "development/samples/SpellChecker/": Bp2BuildDefaultTrueRecursively,
277 "development/samples/ThemedNavBarKeyboard": Bp2BuildDefaultTrue,
278 "development/samples/ToyVpn": Bp2BuildDefaultTrue,
279 "development/samples/TtsEngine": Bp2BuildDefaultTrue,
280 "development/samples/USB/AdbTest": Bp2BuildDefaultTrue,
281 "development/samples/USB/MissileLauncher": Bp2BuildDefaultTrue,
282 "development/samples/VoiceRecognitionService": Bp2BuildDefaultTrue,
283 "development/samples/VoicemailProviderDemo": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400284 "development/sdk": Bp2BuildDefaultTrueRecursively,
285 "external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
286 "external/boringssl": Bp2BuildDefaultTrueRecursively,
Wei Libafb6d62021-12-10 03:14:59 -0800287 "external/bouncycastle": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400288 "external/brotli": Bp2BuildDefaultTrue,
Wei Libafb6d62021-12-10 03:14:59 -0800289 "external/conscrypt": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400290 "external/fmtlib": Bp2BuildDefaultTrueRecursively,
Chris Parsonsb97a8172021-10-04 12:48:29 -0400291 "external/google-benchmark": Bp2BuildDefaultTrueRecursively,
Chris Parsons8a498162021-11-18 17:19:12 -0500292 "external/googletest": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400293 "external/gwp_asan": Bp2BuildDefaultTrueRecursively,
294 "external/jemalloc_new": Bp2BuildDefaultTrueRecursively,
Chris Parsonsb97a8172021-10-04 12:48:29 -0400295 "external/jsoncpp": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400296 "external/libcap": Bp2BuildDefaultTrueRecursively,
297 "external/libcxx": Bp2BuildDefaultTrueRecursively,
298 "external/libcxxabi": Bp2BuildDefaultTrueRecursively,
Chris Parsons8a498162021-11-18 17:19:12 -0500299 "external/libevent": Bp2BuildDefaultTrueRecursively,
Liz Kammerb5b478d2021-12-15 13:00:21 -0500300 "external/libpng": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400301 "external/lz4/lib": Bp2BuildDefaultTrue,
Chris Parsons8a498162021-11-18 17:19:12 -0500302 "external/lzma/C": Bp2BuildDefaultTrueRecursively,
Liz Kammer2fc34892021-10-11 12:56:48 -0400303 "external/mdnsresponder": Bp2BuildDefaultTrueRecursively,
304 "external/minijail": Bp2BuildDefaultTrueRecursively,
305 "external/pcre": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400306 "external/protobuf": Bp2BuildDefaultTrueRecursively,
307 "external/python/six": Bp2BuildDefaultTrueRecursively,
308 "external/scudo": Bp2BuildDefaultTrueRecursively,
Liz Kammer2fc34892021-10-11 12:56:48 -0400309 "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively,
Liz Kammerb5b478d2021-12-15 13:00:21 -0500310 "external/selinux/libsepol": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400311 "external/zlib": Bp2BuildDefaultTrueRecursively,
Liz Kammer2fc34892021-10-11 12:56:48 -0400312 "external/zstd": Bp2BuildDefaultTrueRecursively,
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400313 "frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue,
314 "frameworks/base/startop/apps/test": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400315 "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively,
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400316 "frameworks/native/opengl/tests/gl2_cameraeye": Bp2BuildDefaultTrue,
317 "frameworks/native/opengl/tests/gl2_java": Bp2BuildDefaultTrue,
318 "frameworks/native/opengl/tests/testLatency": Bp2BuildDefaultTrue,
319 "frameworks/native/opengl/tests/testPauseResume": Bp2BuildDefaultTrue,
320 "frameworks/native/opengl/tests/testViewport": Bp2BuildDefaultTrue,
Chris Parsons8a498162021-11-18 17:19:12 -0500321 "frameworks/proto_logging/stats/stats_log_api_gen": Bp2BuildDefaultTrueRecursively,
322 "libnativehelper": Bp2BuildDefaultTrueRecursively,
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400323 "packages/apps/DevCamera": Bp2BuildDefaultTrue,
324 "packages/apps/HTMLViewer": Bp2BuildDefaultTrue,
325 "packages/apps/Protips": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400326 "packages/modules/adb": Bp2BuildDefaultTrue,
Jingwen Chend109bd92021-12-14 07:50:18 +0000327 "packages/modules/adb/apex": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400328 "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively,
329 "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively,
330 "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively,
331 "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively,
332 "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively,
333 "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively,
Romain Jobredeaux1282c422021-10-29 10:52:59 -0400334 "packages/providers/MediaProvider/tools/dialogs": Bp2BuildDefaultTrue,
335 "packages/screensavers/Basic": Bp2BuildDefaultTrue,
336 "packages/services/Car/tests/SampleRearViewCamera": Bp2BuildDefaultTrue,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400337 "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
Jingwen Chend43d4a42021-11-23 12:40:11 +0000338 "system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
Liz Kammeraabfb5d2021-12-08 15:25:06 -0500339 "system/core/debuggerd": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400340 "system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively,
341 "system/core/libasyncio": Bp2BuildDefaultTrue,
342 "system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively,
343 "system/core/libcutils": Bp2BuildDefaultTrueRecursively,
Liz Kammer2fc34892021-10-11 12:56:48 -0400344 "system/core/libpackagelistparser": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400345 "system/core/libprocessgroup": Bp2BuildDefaultTrue,
Chris Parsonsb97a8172021-10-04 12:48:29 -0400346 "system/core/libprocessgroup/cgrouprc": Bp2BuildDefaultTrue,
347 "system/core/libprocessgroup/cgrouprc_format": Bp2BuildDefaultTrue,
Chris Parsons8a498162021-11-18 17:19:12 -0500348 "system/core/libsystem": Bp2BuildDefaultTrueRecursively,
349 "system/core/libutils": Bp2BuildDefaultTrueRecursively,
350 "system/core/libvndksupport": Bp2BuildDefaultTrueRecursively,
Lukacs T. Berki497f17d2021-04-26 12:15:57 +0200351 "system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400352 "system/libbase": Bp2BuildDefaultTrueRecursively,
Chris Parsons8a498162021-11-18 17:19:12 -0500353 "system/libprocinfo": Bp2BuildDefaultTrue,
Chris Parsonsc39f6332021-10-01 18:00:31 -0400354 "system/libziparchive": Bp2BuildDefaultTrueRecursively,
Chris Parsonsa37e1952021-09-28 16:47:36 -0400355 "system/logging/liblog": Bp2BuildDefaultTrueRecursively,
356 "system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
357 "system/timezone/apex": Bp2BuildDefaultTrueRecursively,
358 "system/timezone/output_data": Bp2BuildDefaultTrueRecursively,
Chris Parsons8a498162021-11-18 17:19:12 -0500359 "system/unwinding/libbacktrace": Bp2BuildDefaultTrueRecursively,
360 "system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
Wei Libafb6d62021-12-10 03:14:59 -0800361 "tools/apksig": Bp2BuildDefaultTrue,
362 "tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500363 }
Jingwen Chen5d72cba2021-03-25 09:28:38 +0000364
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400365 // Per-module denylist to always opt modules out of both bp2build and mixed builds.
Rupert Shuttleworth4f43fe92021-03-30 14:13:16 +0000366 bp2buildModuleDoNotConvertList = []string{
Chris Parsons8a498162021-11-18 17:19:12 -0500367 "libandroid_runtime_lazy", // depends on unconverted modules: libbinder_headers
368 "libcmd", // depends on unconverted modules: libbinder
369
Chris Parsons58852a02021-12-09 18:10:18 -0500370 "libdexfile_support_static", // Depends on unconverted module: libdexfile_external_headers
371 "libunwindstack_local", "libunwindstack_utils", "libc_malloc_debug", "libfdtrack", // Depends on unconverted module: libunwindstack
372
373 "libdexfile_support", // TODO(b/210546943): Enabled based on product variables.
374 "libdexfile_external_headers", // TODO(b/210546943): Enabled based on product variables.
375
376 "libunwindstack", // Depends on unconverted module libdexfile_support.
377 "libnativehelper_compat_libc++", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99
378
Chris Parsons8a498162021-11-18 17:19:12 -0500379 "chkcon", "sefcontext_compile", // depends on unconverted modules: libsepol
380
381 "libsepol", // TODO(b/207408632): Unsupported case of .l sources in cc library rules
382
Liz Kammer5c313582021-12-03 15:23:26 -0500383 "gen-kotlin-build-file.py", // module has same name as source
Chris Parsons8a498162021-11-18 17:19:12 -0500384
Chris Parsons8a498162021-11-18 17:19:12 -0500385 "libactivitymanager_aidl", // TODO(b/207426160): Depends on activity_manager_procstate_aidl, which is an aidl filegroup.
386
Liz Kammer5c313582021-12-03 15:23:26 -0500387 "libnativehelper_lazy_mts_jni", "libnativehelper_mts_jni", // depends on unconverted modules: libgmock_ndk
388 "libnativetesthelper_jni", "libgmock_main_ndk", "libgmock_ndk", // depends on unconverted module: libgtest_ndk_c++
Chris Parsons8a498162021-11-18 17:19:12 -0500389
390 "statslog-framework-java-gen", "statslog.cpp", "statslog.h", "statslog.rs", "statslog_header.rs", // depends on unconverted modules: stats-log-api-gen
391
392 "stats-log-api-gen", // depends on unconverted modules: libstats_proto_host, libprotobuf-cpp-full
393
394 "libstatslog", // depends on unconverted modules: statslog.cpp, statslog.h, ...
395
Chris Parsons8a498162021-11-18 17:19:12 -0500396 "cmd", // depends on unconverted module packagemanager_aidl-cpp, of unsupported type aidl_interface
397 "servicedispatcher", // depends on unconverted module android.debug_aidl, of unsupported type aidl_interface
398 "libutilscallstack", // depends on unconverted module libbacktrace
399 "libbacktrace", // depends on unconverted module libunwindstack
400 "libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
401 "libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd
Liz Kammeraabfb5d2021-12-08 15:25:06 -0500402 "unwind_for_offline", // depends on unconverted module libunwindstack_utils
403 "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite
404 "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library.
405
Chris Parsons8a498162021-11-18 17:19:12 -0500406 "host_bionic_linker_asm", // depends on extract_linker, a go binary.
407 "host_bionic_linker_script", // depends on extract_linker, a go binary.
Liz Kammer5c313582021-12-03 15:23:26 -0500408 "static_crasher", // depends on unconverted modules: libdebuggerd_handler
Chris Parsons8a498162021-11-18 17:19:12 -0500409
Liz Kammer5c313582021-12-03 15:23:26 -0500410 "pbtombstone", "crash_dump", // depends on libdebuggerd, libunwindstack
Rupert Shuttleworth47aa5842021-04-30 04:04:15 -0400411
Chris Parsonsc39f6332021-10-01 18:00:31 -0400412 "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 Thaureauxac5097f2021-09-01 21:22:09 +0000413
Liz Kammer0f3b7d22021-09-28 13:48:21 -0400414 "libprotobuf-python", // contains .proto sources
Wei Libafb6d62021-12-10 03:14:59 -0800415 "libprotobuf-internal-protos", // b/210751803, we don't handle path property for filegroups
416 "libprotobuf-internal-python-srcs", // b/210751803, we don't handle path property for filegroups
417 "libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups
418 "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups
419 "conscrypt", // b/210751803, we don't handle path property for filegroups
Liz Kammer0f3b7d22021-09-28 13:48:21 -0400420
Liz Kammer5c313582021-12-03 15:23:26 -0500421 "conv_linker_config", // depends on linker_config_proto, a python lib with proto sources
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400422
Chris Parsonsb97a8172021-10-04 12:48:29 -0400423 "brotli-fuzzer-corpus", // b/202015218: outputs are in location incompatible with bazel genrule handling.
Jingwen Chen294e7742021-08-31 05:58:01 +0000424
Jingwen Chendf27b7a2021-10-18 06:33:16 +0000425 // b/203369847: multiple genrules in the same package creating the same file
426 // //development/sdk/...
427 "platform_tools_properties",
428 "build_tools_source_properties",
429
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400430 // APEX support
Liz Kammer5c313582021-12-03 15:23:26 -0500431 "com.android.runtime", // depends on unconverted modules: bionic-linker-config, linkerconfig
Chris Parsonsa37e1952021-09-28 16:47:36 -0400432
Chris Parsonsc39f6332021-10-01 18:00:31 -0400433 "libgtest_ndk_c++", // b/201816222: Requires sdk_version support.
434 "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support.
Liz Kammer2b8004b2021-10-04 13:55:44 -0400435
Liz Kammer1263d9b2021-12-10 14:28:20 -0500436 "abb", // depends on unconverted modules: libcmd, libbinder
437 "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 Kammer3d3b35c2022-01-11 16:02:50 +0000438 "libadb_host", // depends on unconverted modules: libopenscreen-discovery, libopenscreen-platform-impl, libusb, AdbWinApi
439 "libfastdeploy_host", // depends on unconverted modules: libandroidfw, libusb, AdbWinApi
Chris Parsons8a498162021-11-18 17:19:12 -0500440 "linker", // depends on unconverted modules: libdebuggerd_handler_fallback
Liz Kammer2b8004b2021-10-04 13:55:44 -0400441 "linker_reloc_bench_main", // depends on unconverted modules: liblinker_reloc_bench_*
Chris Parsons8a498162021-11-18 17:19:12 -0500442 "versioner", // depends on unconverted modules: libclang_cxx_host, libLLVM_host, of unsupported type llvm_host_prebuilt_library_shared
Liz Kammer2b8004b2021-10-04 13:55:44 -0400443
444 "linkerconfig", // http://b/202876379 has arch-variant static_executable
445 "mdnsd", // http://b/202876379 has arch-variant static_executable
446
Chris Parsons58852a02021-12-09 18:10:18 -0500447 "CarHTMLViewer", // depends on unconverted modules android.car-stubs, car-ui-lib
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400448
449 "libdexfile", // depends on unconverted modules: dexfile_operator_srcs, libartbase, libartpalette,
450 "libdexfiled", // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400451 }
Rupert Shuttleworthc143cc52021-04-13 13:08:04 -0400452
Jingwen Chen179856a2021-05-03 09:15:48 +0000453 // Per-module denylist of cc_library modules to only generate the static
454 // variant if their shared variant isn't ready or buildable by Bazel.
Chris Parsons58852a02021-12-09 18:10:18 -0500455 bp2buildCcLibraryStaticOnlyList = []string{}
Jingwen Chen179856a2021-05-03 09:15:48 +0000456
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400457 // Per-module denylist to opt modules out of mixed builds. Such modules will
458 // still be generated via bp2build.
Chris Parsons2c788392021-08-10 11:58:07 -0400459 mixedBuildsDisabledList = []string{
Liz Kammer5c313582021-12-03 15:23:26 -0500460 "art_libdexfile_dex_instruction_list_header", // breaks libart_mterp.armng, header not found
461
Wei Li455ba832021-11-04 22:58:12 +0000462 "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
463 "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 Kammerc3192992021-11-16 17:01:11 -0500464
Jingwen Chend4808592021-11-26 05:39:07 +0000465 "cap_names.h", // TODO(b/204913827) runfiles need to be handled in mixed builds
466 "libcap", // TODO(b/204913827) runfiles need to be handled in mixed builds
467 "libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610.
Liz Kammer12615db2021-09-28 09:19:17 -0400468
469 // Depends on libprotobuf-cpp-*
Liz Kammereb2d6d12021-12-06 14:56:25 -0500470 "libadb_pairing_connection",
Liz Kammer12615db2021-09-28 09:19:17 -0400471 "libadb_pairing_connection_static",
472 "libadb_pairing_server", "libadb_pairing_server_static",
Chris Parsons2c788392021-08-10 11:58:07 -0400473 }
Rupert Shuttleworth4f43fe92021-03-30 14:13:16 +0000474
475 // Used for quicker lookups
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400476 bp2buildModuleDoNotConvert = map[string]bool{}
Jingwen Chen179856a2021-05-03 09:15:48 +0000477 bp2buildCcLibraryStaticOnly = map[string]bool{}
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400478 mixedBuildsDisabled = map[string]bool{}
Jingwen Chen12b4c272021-03-10 02:05:59 -0500479)
480
Rupert Shuttleworth4f43fe92021-03-30 14:13:16 +0000481func init() {
482 for _, moduleName := range bp2buildModuleDoNotConvertList {
483 bp2buildModuleDoNotConvert[moduleName] = true
484 }
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400485
Jingwen Chen179856a2021-05-03 09:15:48 +0000486 for _, moduleName := range bp2buildCcLibraryStaticOnlyList {
487 bp2buildCcLibraryStaticOnly[moduleName] = true
488 }
489
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400490 for _, moduleName := range mixedBuildsDisabledList {
491 mixedBuildsDisabled[moduleName] = true
492 }
493}
494
Chris Parsons953b3562021-09-20 15:14:39 -0400495func GenerateCcLibraryStaticOnly(moduleName string) bool {
496 return bp2buildCcLibraryStaticOnly[moduleName]
Jingwen Chen179856a2021-05-03 09:15:48 +0000497}
498
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400499func ShouldKeepExistingBuildFileForDir(dir string) bool {
500 if _, ok := bp2buildKeepExistingBuildFile[dir]; ok {
501 // Exact dir match
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400502 return true
503 }
Rupert Shuttleworth00960792021-05-12 21:20:13 -0400504 // Check if subtree match
505 for prefix, recursive := range bp2buildKeepExistingBuildFile {
506 if recursive {
507 if strings.HasPrefix(dir, prefix+"/") {
508 return true
509 }
510 }
511 }
512 // Default
513 return false
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -0400514}
515
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400516// MixedBuildsEnabled checks that a module is ready to be replaced by a
517// converted or handcrafted Bazel target.
Chris Parsons494eef32021-11-09 10:29:52 -0500518func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool {
519 if ctx.Os() == Windows {
520 // Windows toolchains are not currently supported.
521 return false
522 }
Chris Parsons58852a02021-12-09 18:10:18 -0500523 if !ctx.Module().Enabled() {
524 return false
525 }
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400526 if !ctx.Config().BazelContext.BazelEnabled() {
527 return false
528 }
Liz Kammer6eff3232021-08-26 08:37:59 -0400529 if !convertedToBazel(ctx, ctx.Module()) {
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400530 return false
531 }
Liz Kammer6eff3232021-08-26 08:37:59 -0400532
Chris Parsons953b3562021-09-20 15:14:39 -0400533 if GenerateCcLibraryStaticOnly(ctx.Module().Name()) {
Jingwen Chen179856a2021-05-03 09:15:48 +0000534 // Don't use partially-converted cc_library targets in mixed builds,
535 // since mixed builds would generally rely on both static and shared
536 // variants of a cc_library.
537 return false
538 }
Chris Parsonsbab4d7e2021-04-15 17:27:08 -0400539 return !mixedBuildsDisabled[ctx.Module().Name()]
Rupert Shuttleworth4f43fe92021-03-30 14:13:16 +0000540}
541
Liz Kammer6eff3232021-08-26 08:37:59 -0400542// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.
Jingwen Chen55bc8202021-11-02 06:40:51 +0000543func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool {
Liz Kammer6eff3232021-08-26 08:37:59 -0400544 b, ok := module.(Bazelable)
545 if !ok {
546 return false
547 }
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400548 return b.shouldConvertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
Liz Kammer6eff3232021-08-26 08:37:59 -0400549}
550
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400551// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
552func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) bool {
553 return b.shouldConvertWithBp2build(ctx, ctx.Module())
Liz Kammer6eff3232021-08-26 08:37:59 -0400554}
555
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400556func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool {
Liz Kammer6eff3232021-08-26 08:37:59 -0400557 if bp2buildModuleDoNotConvert[module.Name()] {
Jingwen Chen5d72cba2021-03-25 09:28:38 +0000558 return false
559 }
560
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400561 if !b.bazelProps().Bazel_module.CanConvertToBazel {
562 return false
Jingwen Chen12b4c272021-03-10 02:05:59 -0500563 }
564
Liz Kammer6eff3232021-08-26 08:37:59 -0400565 packagePath := ctx.OtherModuleDir(module)
Jingwen Chen12b4c272021-03-10 02:05:59 -0500566 config := ctx.Config().bp2buildPackageConfig
567
568 // This is a tristate value: true, false, or unset.
569 propValue := b.bazelProperties.Bazel_module.Bp2build_available
570 if bp2buildDefaultTrueRecursively(packagePath, config) {
571 // Allow modules to explicitly opt-out.
572 return proptools.BoolDefault(propValue, true)
573 }
574
575 // Allow modules to explicitly opt-in.
576 return proptools.BoolDefault(propValue, false)
577}
578
579// bp2buildDefaultTrueRecursively checks that the package contains a prefix from the
580// set of package prefixes where all modules must be converted. That is, if the
581// package is x/y/z, and the list contains either x, x/y, or x/y/z, this function will
582// return true.
583//
584// However, if the package is x/y, and it matches a Bp2BuildDefaultFalse "x/y" entry
585// exactly, this module will return false early.
586//
587// This function will also return false if the package doesn't match anything in
588// the config.
589func bp2buildDefaultTrueRecursively(packagePath string, config Bp2BuildConfig) bool {
590 ret := false
591
Jingwen Chen294e7742021-08-31 05:58:01 +0000592 // Check if the package path has an exact match in the config.
593 if config[packagePath] == Bp2BuildDefaultTrue || config[packagePath] == Bp2BuildDefaultTrueRecursively {
Jingwen Chen91220d72021-03-24 02:18:33 -0400594 return true
Jingwen Chen294e7742021-08-31 05:58:01 +0000595 } else if config[packagePath] == Bp2BuildDefaultFalse {
Jingwen Chen12b4c272021-03-10 02:05:59 -0500596 return false
597 }
598
Jingwen Chen91220d72021-03-24 02:18:33 -0400599 // If not, check for the config recursively.
Jingwen Chen12b4c272021-03-10 02:05:59 -0500600 packagePrefix := ""
601 // e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist.
602 for _, part := range strings.Split(packagePath, "/") {
603 packagePrefix += part
604 if config[packagePrefix] == Bp2BuildDefaultTrueRecursively {
605 // package contains this prefix and this prefix should convert all modules
606 return true
607 }
608 // Continue to the next part of the package dir.
609 packagePrefix += "/"
610 }
611
612 return ret
Liz Kammerea6666f2021-02-17 10:17:28 -0500613}
Liz Kammerba3ea162021-02-17 13:22:03 -0500614
615// GetBazelBuildFileContents returns the file contents of a hand-crafted BUILD file if available or
616// an error if there are errors reading the file.
617// TODO(b/181575318): currently we append the whole BUILD file, let's change that to do
618// something more targeted based on the rule type and target.
619func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) (string, error) {
Liz Kammerbdc60992021-02-24 16:55:11 -0500620 if !strings.Contains(b.HandcraftedLabel(), path) {
621 return "", fmt.Errorf("%q not found in bazel_module.label %q", path, b.HandcraftedLabel())
Liz Kammerba3ea162021-02-17 13:22:03 -0500622 }
623 name = filepath.Join(path, name)
624 f, err := c.fs.Open(name)
625 if err != nil {
626 return "", err
627 }
628 defer f.Close()
629
630 data, err := ioutil.ReadAll(f)
631 if err != nil {
632 return "", err
633 }
634 return string(data[:]), nil
635}
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400636
637func registerBp2buildConversionMutator(ctx RegisterMutatorsContext) {
638 ctx.TopDown("bp2build_conversion", convertWithBp2build).Parallel()
639}
640
641func convertWithBp2build(ctx TopDownMutatorContext) {
642 bModule, ok := ctx.Module().(Bazelable)
643 if !ok || !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) {
644 return
645 }
646
647 bModule.ConvertWithBp2build(ctx)
648}
Wei Libafb6d62021-12-10 03:14:59 -0800649
650// GetMainClassInManifest scans the manifest file specified in filepath and returns
651// the value of attribute Main-Class in the manifest file if it exists, or returns error.
652// WARNING: this is for bp2build converters of java_* modules only.
653func GetMainClassInManifest(c Config, filepath string) (string, error) {
654 file, err := c.fs.Open(filepath)
655 if err != nil {
656 return "", err
657 }
658 scanner := bufio.NewScanner(file)
659 for scanner.Scan() {
660 line := scanner.Text()
661 if strings.HasPrefix(line, "Main-Class:") {
662 return strings.TrimSpace(line[len("Main-Class:"):]), nil
663 }
664 }
665
666 return "", errors.New("Main-Class is not found.")
667}