2021-02-17 16:17:28 +01:00
// Copyright 2021 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package android
2021-02-17 19:22:03 +01:00
import (
2021-12-10 12:14:59 +01:00
"bufio"
"errors"
2021-02-17 19:22:03 +01:00
"fmt"
"io/ioutil"
"path/filepath"
"strings"
2021-02-24 22:55:11 +01:00
"github.com/google/blueprint"
2021-02-17 19:22:03 +01:00
"github.com/google/blueprint/proptools"
)
2021-11-19 15:29:43 +01:00
type bazelModuleProperties struct {
// The label of the Bazel target replacing this Soong module. When run in conversion mode, this
// will import the handcrafted build target into the autogenerated file. Note: this may result in
// a conflict due to duplicate targets if bp2build_available is also set.
Label * string
// If true, bp2build will generate the converted Bazel target for this module. Note: this may
// cause a conflict due to the duplicate targets if label is also set.
//
// This is a bool pointer to support tristates: true, false, not set.
//
// To opt-in a module, set bazel_module: { bp2build_available: true }
// To opt-out a module, set bazel_module: { bp2build_available: false }
// To defer the default setting for the directory, do not set the value.
Bp2build_available * bool
2021-11-01 20:32:43 +01:00
// CanConvertToBazel is set via InitBazelModule to indicate that a module type can be converted to
// Bazel with Bp2build.
CanConvertToBazel bool ` blueprint:"mutated" `
2021-11-19 15:29:43 +01:00
}
2021-02-17 19:22:03 +01:00
// Properties contains common module properties for Bazel migration purposes.
type properties struct {
// In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing
// this Soong module.
2021-11-19 15:29:43 +01:00
Bazel_module bazelModuleProperties
2021-02-17 19:22:03 +01:00
}
2021-02-17 16:17:28 +01:00
2021-11-15 13:28:43 +01:00
// namespacedVariableProperties is a map from a string representing a Soong
2021-11-17 11:57:35 +01:00
// config variable namespace, like "android" or "vendor_name" to a slice of
// pointer to a struct containing a single field called Soong_config_variables
// whose value mirrors the structure in the Blueprint file.
type namespacedVariableProperties map [ string ] [ ] interface { }
2021-11-02 17:43:57 +01:00
2021-02-17 16:17:28 +01:00
// BazelModuleBase contains the property structs with metadata for modules which can be converted to
// Bazel.
type BazelModuleBase struct {
2021-02-17 19:22:03 +01:00
bazelProperties properties
2021-11-02 17:43:57 +01:00
// namespacedVariableProperties is used for soong_config_module_type support
// in bp2build. Soong config modules allow users to set module properties
// based on custom product variables defined in Android.bp files. These
// variables are namespaced to prevent clobbering, especially when set from
// Makefiles.
namespacedVariableProperties namespacedVariableProperties
// baseModuleType is set when this module was created from a module type
// defined by a soong_config_module_type. Every soong_config_module_type
// "wraps" another module type, e.g. a soong_config_module_type can wrap a
// cc_defaults to a custom_cc_defaults, or cc_binary to a custom_cc_binary.
// This baseModuleType is set to the wrapped module type.
baseModuleType string
2021-02-17 16:17:28 +01:00
}
// Bazelable is specifies the interface for modules that can be converted to Bazel.
type Bazelable interface {
2021-02-17 19:22:03 +01:00
bazelProps ( ) * properties
HasHandcraftedLabel ( ) bool
2021-02-24 22:55:11 +01:00
HandcraftedLabel ( ) string
GetBazelLabel ( ctx BazelConversionPathContext , module blueprint . Module ) string
2021-11-01 20:32:43 +01:00
ShouldConvertWithBp2build ( ctx BazelConversionContext ) bool
shouldConvertWithBp2build ( ctx BazelConversionContext , module blueprint . Module ) bool
2021-02-17 19:22:03 +01:00
GetBazelBuildFileContents ( c Config , path , name string ) ( string , error )
2021-11-01 20:32:43 +01:00
ConvertWithBp2build ( ctx TopDownMutatorContext )
2021-11-02 17:43:57 +01:00
2021-11-17 11:57:35 +01:00
// namespacedVariableProps is a map from a soong config variable namespace
// (e.g. acme, android) to a map of interfaces{}, which are really
// reflect.Struct pointers, representing the value of the
// soong_config_variables property of a module. The struct pointer is the
// one with the single member called Soong_config_variables, which itself is
// a struct containing fields for each supported feature in that namespace.
//
// The reason for using an slice of interface{} is to support defaults
// propagation of the struct pointers.
2021-11-02 17:43:57 +01:00
namespacedVariableProps ( ) namespacedVariableProperties
setNamespacedVariableProps ( props namespacedVariableProperties )
BaseModuleType ( ) string
2021-11-17 11:57:35 +01:00
SetBaseModuleType ( baseModuleType string )
2021-02-17 16:17:28 +01:00
}
// BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules.
type BazelModule interface {
Module
Bazelable
}
// InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion
// properties.
func InitBazelModule ( module BazelModule ) {
module . AddProperties ( module . bazelProps ( ) )
2021-11-01 20:32:43 +01:00
module . bazelProps ( ) . Bazel_module . CanConvertToBazel = true
2021-02-17 16:17:28 +01:00
}
// bazelProps returns the Bazel properties for the given BazelModuleBase.
2021-02-17 19:22:03 +01:00
func ( b * BazelModuleBase ) bazelProps ( ) * properties {
2021-02-17 16:17:28 +01:00
return & b . bazelProperties
}
2021-11-02 17:43:57 +01:00
func ( b * BazelModuleBase ) namespacedVariableProps ( ) namespacedVariableProperties {
return b . namespacedVariableProperties
}
func ( b * BazelModuleBase ) setNamespacedVariableProps ( props namespacedVariableProperties ) {
b . namespacedVariableProperties = props
}
func ( b * BazelModuleBase ) BaseModuleType ( ) string {
return b . baseModuleType
}
func ( b * BazelModuleBase ) SetBaseModuleType ( baseModuleType string ) {
b . baseModuleType = baseModuleType
}
2021-02-17 19:22:03 +01:00
// HasHandcraftedLabel returns whether this module has a handcrafted Bazel label.
func ( b * BazelModuleBase ) HasHandcraftedLabel ( ) bool {
return b . bazelProperties . Bazel_module . Label != nil
}
// HandcraftedLabel returns the handcrafted label for this module, or empty string if there is none
func ( b * BazelModuleBase ) HandcraftedLabel ( ) string {
return proptools . String ( b . bazelProperties . Bazel_module . Label )
}
2021-02-17 16:17:28 +01:00
// GetBazelLabel returns the Bazel label for the given BazelModuleBase.
2021-02-24 22:55:11 +01:00
func ( b * BazelModuleBase ) GetBazelLabel ( ctx BazelConversionPathContext , module blueprint . Module ) string {
if b . HasHandcraftedLabel ( ) {
return b . HandcraftedLabel ( )
}
2021-11-01 20:32:43 +01:00
if b . ShouldConvertWithBp2build ( ctx ) {
2021-02-24 22:55:11 +01:00
return bp2buildModuleLabel ( ctx , module )
}
return "" // no label for unconverted module
2021-02-17 16:17:28 +01:00
}
2021-03-10 08:05:59 +01:00
// Configuration to decide if modules in a directory should default to true/false for bp2build_available
type Bp2BuildConfig map [ string ] BazelConversionConfigEntry
type BazelConversionConfigEntry int
const (
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
// A sentinel value to be used as a key in Bp2BuildConfig for modules with
// no package path. This is also the module dir for top level Android.bp
// modules.
BP2BUILD_TOPLEVEL = "."
2021-03-10 08:05:59 +01:00
// iota + 1 ensures that the int value is not 0 when used in the Bp2buildAllowlist map,
// which can also mean that the key doesn't exist in a lookup.
// all modules in this package and subpackages default to bp2build_available: true.
// allows modules to opt-out.
Bp2BuildDefaultTrueRecursively BazelConversionConfigEntry = iota + 1
2021-08-31 07:58:01 +02:00
// all modules in this package (not recursively) default to bp2build_available: true.
// allows modules to opt-out.
Bp2BuildDefaultTrue
2021-03-10 08:05:59 +01:00
// all modules in this package (not recursively) default to bp2build_available: false.
// allows modules to opt-in.
Bp2BuildDefaultFalse
)
var (
2021-05-13 03:20:13 +02:00
// Keep any existing BUILD files (and do not generate new BUILD files) for these directories
2021-07-26 06:45:48 +02:00
// in the synthetic Bazel workspace.
2021-05-13 03:20:13 +02:00
bp2buildKeepExistingBuildFile = map [ string ] bool {
// This is actually build/bazel/build.BAZEL symlinked to ./BUILD
2021-07-16 11:28:53 +02:00
"." : /*recursive = */ false ,
2021-05-13 03:20:13 +02:00
2021-07-26 06:45:48 +02:00
// build/bazel/examples/apex/... BUILD files should be generated, so
// build/bazel is not recursive. Instead list each subdirectory under
// build/bazel explicitly.
"build/bazel" : /* recursive = */ false ,
"build/bazel/examples/android_app" : /* recursive = */ true ,
2021-08-26 17:07:48 +02:00
"build/bazel/examples/java" : /* recursive = */ true ,
2021-07-26 06:45:48 +02:00
"build/bazel/bazel_skylib" : /* recursive = */ true ,
"build/bazel/rules" : /* recursive = */ true ,
"build/bazel/rules_cc" : /* recursive = */ true ,
2021-08-31 07:58:01 +02:00
"build/bazel/scripts" : /* recursive = */ true ,
2021-07-26 06:45:48 +02:00
"build/bazel/tests" : /* recursive = */ true ,
"build/bazel/platforms" : /* recursive = */ true ,
"build/bazel/product_variables" : /* recursive = */ true ,
2021-08-24 07:14:22 +02:00
"build/bazel_common_rules" : /* recursive = */ true ,
2021-12-10 12:14:59 +01:00
// build/make/tools/signapk BUILD file is generated, so build/make/tools is not recursive.
"build/make/tools" : /* recursive = */ false ,
2021-05-13 03:20:13 +02:00
"build/pesto" : /* recursive = */ true ,
// external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails
// e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed
"external/bazelbuild-rules_android" : /* recursive = */ true ,
2021-08-10 15:00:33 +02:00
"external/bazel-skylib" : /* recursive = */ true ,
2021-09-08 20:09:02 +02:00
"external/guava" : /* recursive = */ true ,
"external/error_prone" : /* recursive = */ true ,
"external/jsr305" : /* recursive = */ true ,
"frameworks/ex/common" : /* recursive = */ true ,
2021-05-13 03:20:13 +02:00
2021-09-22 20:43:43 +02:00
"packages/apps/Music" : /* recursive = */ true ,
"packages/apps/QuickSearchBox" : /* recursive = */ true ,
"packages/apps/WallpaperPicker" : /* recursive = */ false ,
2021-11-09 16:29:52 +01:00
"prebuilts/gcc" : /* recursive = */ true ,
2021-05-13 03:20:13 +02:00
"prebuilts/sdk" : /* recursive = */ false ,
2021-09-22 20:43:43 +02:00
"prebuilts/sdk/current/extras/app-toolkit" : /* recursive = */ false ,
"prebuilts/sdk/current/support" : /* recursive = */ false ,
2021-05-13 03:20:13 +02:00
"prebuilts/sdk/tools" : /* recursive = */ false ,
2021-08-02 19:27:06 +02:00
"prebuilts/r8" : /* recursive = */ false ,
2021-04-21 13:10:09 +02:00
}
2021-03-10 08:05:59 +01:00
// Configure modules in these directories to enable bp2build_available: true or false by default.
bp2buildDefaultConfig = Bp2BuildConfig {
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"art/libdexfile" : Bp2BuildDefaultTrueRecursively ,
"bionic" : Bp2BuildDefaultTrueRecursively ,
"bootable/recovery/tools/recovery_l10n" : Bp2BuildDefaultTrue ,
2021-11-24 08:00:11 +01:00
"build/bazel/examples/soong_config_variables" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"build/bazel/examples/apex/minimal" : Bp2BuildDefaultTrueRecursively ,
2021-12-10 12:14:59 +01:00
"build/make/tools/signapk" : Bp2BuildDefaultTrue ,
2021-11-18 23:19:12 +01:00
"build/soong" : Bp2BuildDefaultTrue ,
2021-11-10 16:37:05 +01:00
"build/soong/cc/libbuildversion" : Bp2BuildDefaultTrue , // Skip tests subdir
2021-11-30 12:16:06 +01:00
"build/soong/cc/ndkstubgen" : Bp2BuildDefaultTrue ,
"build/soong/cc/symbolfile" : Bp2BuildDefaultTrue ,
2021-12-03 21:23:26 +01:00
"build/soong/scripts" : Bp2BuildDefaultTrueRecursively ,
2021-11-18 23:19:12 +01:00
"cts/common/device-side/nativetesthelper/jni" : Bp2BuildDefaultTrueRecursively ,
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"development/apps/DevelopmentSettings" : Bp2BuildDefaultTrue ,
"development/apps/Fallback" : Bp2BuildDefaultTrue ,
"development/apps/WidgetPreview" : Bp2BuildDefaultTrue ,
"development/samples/BasicGLSurfaceView" : Bp2BuildDefaultTrue ,
"development/samples/BluetoothChat" : Bp2BuildDefaultTrue ,
"development/samples/BrokenKeyDerivation" : Bp2BuildDefaultTrue ,
"development/samples/Compass" : Bp2BuildDefaultTrue ,
"development/samples/ContactManager" : Bp2BuildDefaultTrue ,
"development/samples/FixedGridLayout" : Bp2BuildDefaultTrue ,
"development/samples/HelloEffects" : Bp2BuildDefaultTrue ,
"development/samples/Home" : Bp2BuildDefaultTrue ,
"development/samples/HoneycombGallery" : Bp2BuildDefaultTrue ,
"development/samples/JetBoy" : Bp2BuildDefaultTrue ,
"development/samples/KeyChainDemo" : Bp2BuildDefaultTrue ,
"development/samples/LceDemo" : Bp2BuildDefaultTrue ,
"development/samples/LunarLander" : Bp2BuildDefaultTrue ,
"development/samples/MultiResolution" : Bp2BuildDefaultTrue ,
"development/samples/MultiWindow" : Bp2BuildDefaultTrue ,
"development/samples/NotePad" : Bp2BuildDefaultTrue ,
"development/samples/Obb" : Bp2BuildDefaultTrue ,
"development/samples/RSSReader" : Bp2BuildDefaultTrue ,
"development/samples/ReceiveShareDemo" : Bp2BuildDefaultTrue ,
"development/samples/SearchableDictionary" : Bp2BuildDefaultTrue ,
"development/samples/SipDemo" : Bp2BuildDefaultTrue ,
"development/samples/SkeletonApp" : Bp2BuildDefaultTrue ,
"development/samples/Snake" : Bp2BuildDefaultTrue ,
"development/samples/SpellChecker/" : Bp2BuildDefaultTrueRecursively ,
"development/samples/ThemedNavBarKeyboard" : Bp2BuildDefaultTrue ,
"development/samples/ToyVpn" : Bp2BuildDefaultTrue ,
"development/samples/TtsEngine" : Bp2BuildDefaultTrue ,
"development/samples/USB/AdbTest" : Bp2BuildDefaultTrue ,
"development/samples/USB/MissileLauncher" : Bp2BuildDefaultTrue ,
"development/samples/VoiceRecognitionService" : Bp2BuildDefaultTrue ,
"development/samples/VoicemailProviderDemo" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"development/sdk" : Bp2BuildDefaultTrueRecursively ,
"external/arm-optimized-routines" : Bp2BuildDefaultTrueRecursively ,
"external/boringssl" : Bp2BuildDefaultTrueRecursively ,
2021-12-10 12:14:59 +01:00
"external/bouncycastle" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"external/brotli" : Bp2BuildDefaultTrue ,
2021-12-10 12:14:59 +01:00
"external/conscrypt" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"external/fmtlib" : Bp2BuildDefaultTrueRecursively ,
2021-10-04 18:48:29 +02:00
"external/google-benchmark" : Bp2BuildDefaultTrueRecursively ,
2021-11-18 23:19:12 +01:00
"external/googletest" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"external/gwp_asan" : Bp2BuildDefaultTrueRecursively ,
"external/jemalloc_new" : Bp2BuildDefaultTrueRecursively ,
2021-10-04 18:48:29 +02:00
"external/jsoncpp" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"external/libcap" : Bp2BuildDefaultTrueRecursively ,
"external/libcxx" : Bp2BuildDefaultTrueRecursively ,
"external/libcxxabi" : Bp2BuildDefaultTrueRecursively ,
2021-11-18 23:19:12 +01:00
"external/libevent" : Bp2BuildDefaultTrueRecursively ,
2021-12-15 19:00:21 +01:00
"external/libpng" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"external/lz4/lib" : Bp2BuildDefaultTrue ,
2021-11-18 23:19:12 +01:00
"external/lzma/C" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"external/mdnsresponder" : Bp2BuildDefaultTrueRecursively ,
"external/minijail" : Bp2BuildDefaultTrueRecursively ,
"external/pcre" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"external/protobuf" : Bp2BuildDefaultTrueRecursively ,
"external/python/six" : Bp2BuildDefaultTrueRecursively ,
"external/scudo" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"external/selinux/libselinux" : Bp2BuildDefaultTrueRecursively ,
2021-12-15 19:00:21 +01:00
"external/selinux/libsepol" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"external/zlib" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"external/zstd" : Bp2BuildDefaultTrueRecursively ,
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"frameworks/base/media/tests/MediaDump" : Bp2BuildDefaultTrue ,
"frameworks/base/startop/apps/test" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"frameworks/native/libs/adbd_auth" : Bp2BuildDefaultTrueRecursively ,
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"frameworks/native/opengl/tests/gl2_cameraeye" : Bp2BuildDefaultTrue ,
"frameworks/native/opengl/tests/gl2_java" : Bp2BuildDefaultTrue ,
"frameworks/native/opengl/tests/testLatency" : Bp2BuildDefaultTrue ,
"frameworks/native/opengl/tests/testPauseResume" : Bp2BuildDefaultTrue ,
"frameworks/native/opengl/tests/testViewport" : Bp2BuildDefaultTrue ,
2021-11-18 23:19:12 +01:00
"frameworks/proto_logging/stats/stats_log_api_gen" : Bp2BuildDefaultTrueRecursively ,
"libnativehelper" : Bp2BuildDefaultTrueRecursively ,
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"packages/apps/DevCamera" : Bp2BuildDefaultTrue ,
"packages/apps/HTMLViewer" : Bp2BuildDefaultTrue ,
"packages/apps/Protips" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"packages/modules/adb" : Bp2BuildDefaultTrue ,
2021-12-14 08:50:18 +01:00
"packages/modules/adb/apex" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"packages/modules/adb/crypto" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb/libs" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb/pairing_auth" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb/pairing_connection" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb/proto" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb/tls" : Bp2BuildDefaultTrueRecursively ,
Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.
Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-10-29 16:52:59 +02:00
"packages/providers/MediaProvider/tools/dialogs" : Bp2BuildDefaultTrue ,
"packages/screensavers/Basic" : Bp2BuildDefaultTrue ,
"packages/services/Car/tests/SampleRearViewCamera" : Bp2BuildDefaultTrue ,
2021-09-28 22:47:36 +02:00
"prebuilts/clang/host/linux-x86" : Bp2BuildDefaultTrueRecursively ,
2021-11-23 13:40:11 +01:00
"system/apex" : Bp2BuildDefaultFalse , // TODO(b/207466993): flaky failures
2021-12-08 21:25:06 +01:00
"system/core/debuggerd" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"system/core/diagnose_usb" : Bp2BuildDefaultTrueRecursively ,
"system/core/libasyncio" : Bp2BuildDefaultTrue ,
"system/core/libcrypto_utils" : Bp2BuildDefaultTrueRecursively ,
"system/core/libcutils" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"system/core/libpackagelistparser" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"system/core/libprocessgroup" : Bp2BuildDefaultTrue ,
2021-10-04 18:48:29 +02:00
"system/core/libprocessgroup/cgrouprc" : Bp2BuildDefaultTrue ,
"system/core/libprocessgroup/cgrouprc_format" : Bp2BuildDefaultTrue ,
2021-11-18 23:19:12 +01:00
"system/core/libsystem" : Bp2BuildDefaultTrueRecursively ,
"system/core/libutils" : Bp2BuildDefaultTrueRecursively ,
"system/core/libvndksupport" : Bp2BuildDefaultTrueRecursively ,
2021-04-26 12:15:57 +02:00
"system/core/property_service/libpropertyinfoparser" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"system/libbase" : Bp2BuildDefaultTrueRecursively ,
2021-11-18 23:19:12 +01:00
"system/libprocinfo" : Bp2BuildDefaultTrue ,
2021-10-02 00:00:31 +02:00
"system/libziparchive" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"system/logging/liblog" : Bp2BuildDefaultTrueRecursively ,
"system/sepolicy/apex" : Bp2BuildDefaultTrueRecursively ,
"system/timezone/apex" : Bp2BuildDefaultTrueRecursively ,
"system/timezone/output_data" : Bp2BuildDefaultTrueRecursively ,
2021-11-18 23:19:12 +01:00
"system/unwinding/libbacktrace" : Bp2BuildDefaultTrueRecursively ,
"system/unwinding/libunwindstack" : Bp2BuildDefaultTrueRecursively ,
2021-12-10 12:14:59 +01:00
"tools/apksig" : Bp2BuildDefaultTrue ,
"tools/platform-compat/java/android/compat" : Bp2BuildDefaultTrueRecursively ,
2021-03-10 08:05:59 +01:00
}
2021-03-25 10:28:38 +01:00
2021-04-15 23:27:08 +02:00
// Per-module denylist to always opt modules out of both bp2build and mixed builds.
2021-03-30 16:13:16 +02:00
bp2buildModuleDoNotConvertList = [ ] string {
2021-11-18 23:19:12 +01:00
"libandroid_runtime_lazy" , // depends on unconverted modules: libbinder_headers
"libcmd" , // depends on unconverted modules: libbinder
2021-12-10 00:10:18 +01:00
"libdexfile_support_static" , // Depends on unconverted module: libdexfile_external_headers
"libunwindstack_local" , "libunwindstack_utils" , "libc_malloc_debug" , "libfdtrack" , // Depends on unconverted module: libunwindstack
"libdexfile_support" , // TODO(b/210546943): Enabled based on product variables.
"libdexfile_external_headers" , // TODO(b/210546943): Enabled based on product variables.
"libunwindstack" , // Depends on unconverted module libdexfile_support.
"libnativehelper_compat_libc++" , // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99
2021-11-18 23:19:12 +01:00
"chkcon" , "sefcontext_compile" , // depends on unconverted modules: libsepol
"libsepol" , // TODO(b/207408632): Unsupported case of .l sources in cc library rules
2021-12-03 21:23:26 +01:00
"gen-kotlin-build-file.py" , // module has same name as source
2021-11-18 23:19:12 +01:00
"libactivitymanager_aidl" , // TODO(b/207426160): Depends on activity_manager_procstate_aidl, which is an aidl filegroup.
2021-12-03 21:23:26 +01:00
"libnativehelper_lazy_mts_jni" , "libnativehelper_mts_jni" , // depends on unconverted modules: libgmock_ndk
"libnativetesthelper_jni" , "libgmock_main_ndk" , "libgmock_ndk" , // depends on unconverted module: libgtest_ndk_c++
2021-11-18 23:19:12 +01:00
"statslog-framework-java-gen" , "statslog.cpp" , "statslog.h" , "statslog.rs" , "statslog_header.rs" , // depends on unconverted modules: stats-log-api-gen
"stats-log-api-gen" , // depends on unconverted modules: libstats_proto_host, libprotobuf-cpp-full
"libstatslog" , // depends on unconverted modules: statslog.cpp, statslog.h, ...
"cmd" , // depends on unconverted module packagemanager_aidl-cpp, of unsupported type aidl_interface
"servicedispatcher" , // depends on unconverted module android.debug_aidl, of unsupported type aidl_interface
"libutilscallstack" , // depends on unconverted module libbacktrace
"libbacktrace" , // depends on unconverted module libunwindstack
"libdebuggerd_handler" , // depends on unconverted module libdebuggerd_handler_core
"libdebuggerd_handler_core" , "libdebuggerd_handler_fallback" , // depends on unconverted module libdebuggerd
2021-12-08 21:25:06 +01:00
"unwind_for_offline" , // depends on unconverted module libunwindstack_utils
"libdebuggerd" , // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite
"libdexfile_static" , // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library.
2021-11-18 23:19:12 +01:00
"host_bionic_linker_asm" , // depends on extract_linker, a go binary.
"host_bionic_linker_script" , // depends on extract_linker, a go binary.
2021-12-03 21:23:26 +01:00
"static_crasher" , // depends on unconverted modules: libdebuggerd_handler
2021-11-18 23:19:12 +01:00
2021-12-03 21:23:26 +01:00
"pbtombstone" , "crash_dump" , // depends on libdebuggerd, libunwindstack
2021-10-02 00:00:31 +02:00
"libbase_ndk" , // http://b/186826477, fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
2021-09-01 23:22:09 +02:00
2021-09-28 19:48:21 +02:00
"libprotobuf-python" , // contains .proto sources
2021-12-10 12:14:59 +01:00
"libprotobuf-internal-protos" , // b/210751803, we don't handle path property for filegroups
"libprotobuf-internal-python-srcs" , // b/210751803, we don't handle path property for filegroups
"libprotobuf-java-full" , // b/210751803, we don't handle path property for filegroups
"libprotobuf-java-util-full" , // b/210751803, we don't handle path property for filegroups
"conscrypt" , // b/210751803, we don't handle path property for filegroups
2021-09-28 19:48:21 +02:00
2021-12-03 21:23:26 +01:00
"conv_linker_config" , // depends on linker_config_proto, a python lib with proto sources
2021-05-13 03:20:13 +02:00
2021-10-04 18:48:29 +02:00
"brotli-fuzzer-corpus" , // b/202015218: outputs are in location incompatible with bazel genrule handling.
2021-08-31 07:58:01 +02:00
2021-10-18 08:33:16 +02:00
// b/203369847: multiple genrules in the same package creating the same file
// //development/sdk/...
"platform_tools_properties" ,
"build_tools_source_properties" ,
2021-07-27 07:34:59 +02:00
// APEX support
2021-12-03 21:23:26 +01:00
"com.android.runtime" , // depends on unconverted modules: bionic-linker-config, linkerconfig
2021-09-28 22:47:36 +02:00
2021-10-02 00:00:31 +02:00
"libgtest_ndk_c++" , // b/201816222: Requires sdk_version support.
"libgtest_main_ndk_c++" , // b/201816222: Requires sdk_version support.
2021-10-04 19:55:44 +02:00
2021-12-10 20:28:20 +01:00
"abb" , // depends on unconverted modules: libcmd, libbinder
"adb" , // depends on unconverted modules: AdbWinApi, libadb_host, libandroidfw, libapp_processes_protos_full, libfastdeploy_host, libopenscreen-discovery, libopenscreen-platform-impl, libusb, bin2c_fastdeployagent, AdbWinUsbApi
2021-12-15 20:48:35 +01:00
"libadb_host" , // depends on unconverted modules: libopenscreen-discovery, libopenscreen-platform-impl, libusb, AdbWinApi
"libfastdeploy_host" , // depends on unconverted modules: libandroidfw, libusb, AdbWinApi
2021-11-18 23:19:12 +01:00
"linker" , // depends on unconverted modules: libdebuggerd_handler_fallback
2021-10-04 19:55:44 +02:00
"linker_reloc_bench_main" , // depends on unconverted modules: liblinker_reloc_bench_*
2021-11-18 23:19:12 +01:00
"versioner" , // depends on unconverted modules: libclang_cxx_host, libLLVM_host, of unsupported type llvm_host_prebuilt_library_shared
2021-10-04 19:55:44 +02:00
"linkerconfig" , // http://b/202876379 has arch-variant static_executable
"mdnsd" , // http://b/202876379 has arch-variant static_executable
2021-12-10 00:10:18 +01:00
"CarHTMLViewer" , // depends on unconverted modules android.car-stubs, car-ui-lib
2021-11-01 20:32:43 +01:00
"libdexfile" , // depends on unconverted modules: dexfile_operator_srcs, libartbase, libartpalette,
"libdexfiled" , // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette
2021-04-15 23:27:08 +02:00
}
2021-04-13 19:08:04 +02:00
2021-05-03 11:15:48 +02:00
// Per-module denylist of cc_library modules to only generate the static
// variant if their shared variant isn't ready or buildable by Bazel.
2021-12-10 00:10:18 +01:00
bp2buildCcLibraryStaticOnlyList = [ ] string { }
2021-05-03 11:15:48 +02:00
2021-04-15 23:27:08 +02:00
// Per-module denylist to opt modules out of mixed builds. Such modules will
// still be generated via bp2build.
2021-08-10 17:58:07 +02:00
mixedBuildsDisabledList = [ ] string {
2021-12-03 21:23:26 +01:00
"art_libdexfile_dex_instruction_list_header" , // breaks libart_mterp.armng, header not found
2021-11-04 23:58:12 +01:00
"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
"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.
2021-11-16 23:01:11 +01:00
2021-11-26 06:39:07 +01:00
"cap_names.h" , // TODO(b/204913827) runfiles need to be handled in mixed builds
"libcap" , // TODO(b/204913827) runfiles need to be handled in mixed builds
"libprotobuf-cpp-full" , "libprotobuf-cpp-lite" , // Unsupported product&vendor suffix. b/204811222 and b/204810610.
2021-09-28 15:19:17 +02:00
// Depends on libprotobuf-cpp-*
2021-12-06 20:56:25 +01:00
"libadb_pairing_connection" ,
2021-09-28 15:19:17 +02:00
"libadb_pairing_connection_static" ,
"libadb_pairing_server" , "libadb_pairing_server_static" ,
2021-08-10 17:58:07 +02:00
}
2021-03-30 16:13:16 +02:00
// Used for quicker lookups
2021-04-21 13:10:09 +02:00
bp2buildModuleDoNotConvert = map [ string ] bool { }
2021-05-03 11:15:48 +02:00
bp2buildCcLibraryStaticOnly = map [ string ] bool { }
2021-04-21 13:10:09 +02:00
mixedBuildsDisabled = map [ string ] bool { }
2021-03-10 08:05:59 +01:00
)
2021-03-30 16:13:16 +02:00
func init ( ) {
for _ , moduleName := range bp2buildModuleDoNotConvertList {
bp2buildModuleDoNotConvert [ moduleName ] = true
}
2021-04-15 23:27:08 +02:00
2021-05-03 11:15:48 +02:00
for _ , moduleName := range bp2buildCcLibraryStaticOnlyList {
bp2buildCcLibraryStaticOnly [ moduleName ] = true
}
2021-04-15 23:27:08 +02:00
for _ , moduleName := range mixedBuildsDisabledList {
mixedBuildsDisabled [ moduleName ] = true
}
}
2021-09-20 21:14:39 +02:00
func GenerateCcLibraryStaticOnly ( moduleName string ) bool {
return bp2buildCcLibraryStaticOnly [ moduleName ]
2021-05-03 11:15:48 +02:00
}
2021-05-13 03:20:13 +02:00
func ShouldKeepExistingBuildFileForDir ( dir string ) bool {
if _ , ok := bp2buildKeepExistingBuildFile [ dir ] ; ok {
// Exact dir match
2021-04-21 13:10:09 +02:00
return true
}
2021-05-13 03:20:13 +02:00
// Check if subtree match
for prefix , recursive := range bp2buildKeepExistingBuildFile {
if recursive {
if strings . HasPrefix ( dir , prefix + "/" ) {
return true
}
}
}
// Default
return false
2021-04-21 13:10:09 +02:00
}
2021-04-15 23:27:08 +02:00
// MixedBuildsEnabled checks that a module is ready to be replaced by a
// converted or handcrafted Bazel target.
2021-11-09 16:29:52 +01:00
func ( b * BazelModuleBase ) MixedBuildsEnabled ( ctx ModuleContext ) bool {
if ctx . Os ( ) == Windows {
// Windows toolchains are not currently supported.
return false
}
2021-12-10 00:10:18 +01:00
if ! ctx . Module ( ) . Enabled ( ) {
return false
}
2021-04-15 23:27:08 +02:00
if ! ctx . Config ( ) . BazelContext . BazelEnabled ( ) {
return false
}
2021-08-26 14:37:59 +02:00
if ! convertedToBazel ( ctx , ctx . Module ( ) ) {
2021-04-15 23:27:08 +02:00
return false
}
2021-08-26 14:37:59 +02:00
2021-09-20 21:14:39 +02:00
if GenerateCcLibraryStaticOnly ( ctx . Module ( ) . Name ( ) ) {
2021-05-03 11:15:48 +02:00
// Don't use partially-converted cc_library targets in mixed builds,
// since mixed builds would generally rely on both static and shared
// variants of a cc_library.
return false
}
2021-04-15 23:27:08 +02:00
return ! mixedBuildsDisabled [ ctx . Module ( ) . Name ( ) ]
2021-03-30 16:13:16 +02:00
}
2021-08-26 14:37:59 +02:00
// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.
2021-11-02 07:40:51 +01:00
func convertedToBazel ( ctx BazelConversionContext , module blueprint . Module ) bool {
2021-08-26 14:37:59 +02:00
b , ok := module . ( Bazelable )
if ! ok {
return false
}
2021-11-01 20:32:43 +01:00
return b . shouldConvertWithBp2build ( ctx , module ) || b . HasHandcraftedLabel ( )
2021-08-26 14:37:59 +02:00
}
2021-11-01 20:32:43 +01:00
// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
func ( b * BazelModuleBase ) ShouldConvertWithBp2build ( ctx BazelConversionContext ) bool {
return b . shouldConvertWithBp2build ( ctx , ctx . Module ( ) )
2021-08-26 14:37:59 +02:00
}
2021-11-01 20:32:43 +01:00
func ( b * BazelModuleBase ) shouldConvertWithBp2build ( ctx BazelConversionContext , module blueprint . Module ) bool {
2021-08-26 14:37:59 +02:00
if bp2buildModuleDoNotConvert [ module . Name ( ) ] {
2021-03-25 10:28:38 +01:00
return false
}
2021-11-01 20:32:43 +01:00
if ! b . bazelProps ( ) . Bazel_module . CanConvertToBazel {
return false
2021-03-10 08:05:59 +01:00
}
2021-08-26 14:37:59 +02:00
packagePath := ctx . OtherModuleDir ( module )
2021-03-10 08:05:59 +01:00
config := ctx . Config ( ) . bp2buildPackageConfig
// This is a tristate value: true, false, or unset.
propValue := b . bazelProperties . Bazel_module . Bp2build_available
if bp2buildDefaultTrueRecursively ( packagePath , config ) {
// Allow modules to explicitly opt-out.
return proptools . BoolDefault ( propValue , true )
}
// Allow modules to explicitly opt-in.
return proptools . BoolDefault ( propValue , false )
}
// bp2buildDefaultTrueRecursively checks that the package contains a prefix from the
// set of package prefixes where all modules must be converted. That is, if the
// package is x/y/z, and the list contains either x, x/y, or x/y/z, this function will
// return true.
//
// However, if the package is x/y, and it matches a Bp2BuildDefaultFalse "x/y" entry
// exactly, this module will return false early.
//
// This function will also return false if the package doesn't match anything in
// the config.
func bp2buildDefaultTrueRecursively ( packagePath string , config Bp2BuildConfig ) bool {
ret := false
2021-08-31 07:58:01 +02:00
// Check if the package path has an exact match in the config.
if config [ packagePath ] == Bp2BuildDefaultTrue || config [ packagePath ] == Bp2BuildDefaultTrueRecursively {
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
return true
2021-08-31 07:58:01 +02:00
} else if config [ packagePath ] == Bp2BuildDefaultFalse {
2021-03-10 08:05:59 +01:00
return false
}
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
// If not, check for the config recursively.
2021-03-10 08:05:59 +01:00
packagePrefix := ""
// e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist.
for _ , part := range strings . Split ( packagePath , "/" ) {
packagePrefix += part
if config [ packagePrefix ] == Bp2BuildDefaultTrueRecursively {
// package contains this prefix and this prefix should convert all modules
return true
}
// Continue to the next part of the package dir.
packagePrefix += "/"
}
return ret
2021-02-17 16:17:28 +01:00
}
2021-02-17 19:22:03 +01:00
// GetBazelBuildFileContents returns the file contents of a hand-crafted BUILD file if available or
// an error if there are errors reading the file.
// TODO(b/181575318): currently we append the whole BUILD file, let's change that to do
// something more targeted based on the rule type and target.
func ( b * BazelModuleBase ) GetBazelBuildFileContents ( c Config , path , name string ) ( string , error ) {
2021-02-24 22:55:11 +01:00
if ! strings . Contains ( b . HandcraftedLabel ( ) , path ) {
return "" , fmt . Errorf ( "%q not found in bazel_module.label %q" , path , b . HandcraftedLabel ( ) )
2021-02-17 19:22:03 +01:00
}
name = filepath . Join ( path , name )
f , err := c . fs . Open ( name )
if err != nil {
return "" , err
}
defer f . Close ( )
data , err := ioutil . ReadAll ( f )
if err != nil {
return "" , err
}
return string ( data [ : ] ) , nil
}
2021-11-01 20:32:43 +01:00
func registerBp2buildConversionMutator ( ctx RegisterMutatorsContext ) {
ctx . TopDown ( "bp2build_conversion" , convertWithBp2build ) . Parallel ( )
}
func convertWithBp2build ( ctx TopDownMutatorContext ) {
bModule , ok := ctx . Module ( ) . ( Bazelable )
if ! ok || ! bModule . shouldConvertWithBp2build ( ctx , ctx . Module ( ) ) {
return
}
bModule . ConvertWithBp2build ( ctx )
}
2021-12-10 12:14:59 +01:00
// GetMainClassInManifest scans the manifest file specified in filepath and returns
// the value of attribute Main-Class in the manifest file if it exists, or returns error.
// WARNING: this is for bp2build converters of java_* modules only.
func GetMainClassInManifest ( c Config , filepath string ) ( string , error ) {
file , err := c . fs . Open ( filepath )
if err != nil {
return "" , err
}
scanner := bufio . NewScanner ( file )
for scanner . Scan ( ) {
line := scanner . Text ( )
if strings . HasPrefix ( line , "Main-Class:" ) {
return strings . TrimSpace ( line [ len ( "Main-Class:" ) : ] ) , nil
}
}
return "" , errors . New ( "Main-Class is not found." )
}