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 (
"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"
)
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.
2021-03-10 08:05:59 +01:00
//
// 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-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.
Bazel_module bazelModuleProperties
}
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-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-03-10 08:05:59 +01:00
ConvertWithBp2build ( ctx BazelConversionPathContext ) bool
2021-08-26 14:37:59 +02:00
convertWithBp2build ( ctx BazelConversionPathContext , module blueprint . Module ) bool
2021-02-17 19:22:03 +01:00
GetBazelBuildFileContents ( c Config , path , name string ) ( string , error )
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 ( ) )
}
// 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-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-03-10 08:05:59 +01:00
if b . ConvertWithBp2build ( 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-09-08 20:09:02 +02:00
"build/make/tools" : /* recursive = */ true ,
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-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 {
2021-09-28 22:47:36 +02:00
"bionic" : Bp2BuildDefaultTrueRecursively ,
"build/bazel/examples/apex/minimal" : Bp2BuildDefaultTrueRecursively ,
"development/sdk" : Bp2BuildDefaultTrueRecursively ,
"external/arm-optimized-routines" : Bp2BuildDefaultTrueRecursively ,
"external/boringssl" : Bp2BuildDefaultTrueRecursively ,
"external/brotli" : Bp2BuildDefaultTrue ,
"external/fmtlib" : Bp2BuildDefaultTrueRecursively ,
2021-10-04 18:48:29 +02:00
"external/google-benchmark" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"external/googletest/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 ,
"external/lz4/lib" : Bp2BuildDefaultTrue ,
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-09-28 22:47:36 +02:00
"external/zlib" : Bp2BuildDefaultTrueRecursively ,
2021-10-11 18:56:48 +02:00
"external/zstd" : Bp2BuildDefaultTrueRecursively ,
2021-09-28 22:47:36 +02:00
"frameworks/native/libs/adbd_auth" : Bp2BuildDefaultTrueRecursively ,
"packages/modules/adb" : Bp2BuildDefaultTrue ,
"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 ,
"prebuilts/clang/host/linux-x86" : Bp2BuildDefaultTrueRecursively ,
"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-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-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-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-10-02 00:00:31 +02:00
"libc_malloc_debug" , // depends on libunwindstack, which depends on unsupported module art_cc_library_statics
"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
"libprotobuf-internal-protos" , // we don't handle path property for fileegroups
"libprotobuf-internal-python-srcs" , // we don't handle path property for fileegroups
2021-09-28 22:47:36 +02:00
"libseccomp_policy" , // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds.
"libfdtrack" , // depends on libunwindstack, which depends on unsupported module art_cc_library_statics
2021-04-30 10:20:01 +02:00
2021-05-13 03:20:13 +02:00
"gwp_asan_crash_handler" , // cc_library, ld.lld: error: undefined symbol: memset
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" ,
bp2build: allowlist //external/libcap/...
This builds cap_names.list.h, which uses an eponymous filegroup
"generate_cap_names_list.awk" in Soong, but uses the file target
directly in Bazel.
This also improve filegroup support for mixed builds, by issuing a
cquery call _without_ arch. Filegroups in Soong don't have configurable
properties, so don't generate Bazel filegroups into buildroot's
config_nodes (which was x86_64 by default).
The mixed_build_root now looks like this:
```
config_node(...)
config_node(...)
config_node(...)
config_node(...)
...
filegroup(name = "common",
srcs = ["@//bionic/linker:linker_sources_x86",
"@//bionic/libc:kernel_input_headers",
"@//system/timezone/apex:com.android.tzdata-androidManifest",
"@//external/libcap:generate_cap_names_list.awk",
"@//bionic/linker:linker_sources_arm64",
"@//bionic/linker:linker_sources",
"@//bionic/libc:libc_sources_shared_arm",
"@//bionic/linker:linker_sources_x86_64",
"@//bionic/libc:all_kernel_uapi_headers",
"@//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal-file_contexts",
"@//system/core/libcutils:android_filesystem_config_header",
"@//bionic/libc:libc_sources_static",
"@//bionic/linker:linker_sources_arm",
"@//bionic/libc/tools:bionic-gensyscalls",
"@//bionic/tools:bionic-generate-version-script",
"@//bionic/libc:libc_sources_shared"],
)
mixed_build_root(name = "buildroot",
deps = [":x86",
":arm64",
":arm",
":common",
":x86_64"],
)
```
Test: CI
Fixes: 198595323
Fixes: 198235838
Change-Id: I6df9a14da556cf358d96e6a99b514f66a2638295
2021-09-02 14:11:49 +02:00
// //external/libcap/...
"libcap" , // http://b/198595332, depends on _makenames, a cc_binary
"cap_names.h" , // http://b/198596102, depends on _makenames, a cc_binary
2021-10-11 18:56:48 +02:00
"libminijail" , // depends on unconverted modules: libcap
2021-04-30 10:20:01 +02:00
// Tests. Handle later.
"libbionic_tests_headers_posix" , // http://b/186024507, cc_library_static, sched.h, time.h not found
"libjemalloc5_integrationtest" ,
"libjemalloc5_stresstestlib" ,
"libjemalloc5_unittest" ,
2021-07-27 07:34:59 +02:00
// APEX support
2021-10-04 18:48:29 +02:00
"com.android.runtime" , // http://b/194746715, apex, depends on 'libc_malloc_debug'
2021-09-28 22:47:36 +02:00
"libadb_crypto" , // Depends on libadb_protos
"libadb_crypto_static" , // Depends on libadb_protos_static
"libadb_pairing_connection" , // Depends on libadb_protos
"libadb_pairing_connection_static" , // Depends on libadb_protos_static
"libadb_pairing_server" , // Depends on libadb_protos
"libadb_pairing_server_static" , // Depends on libadb_protos_static
"libadbd" , // Depends on libadbd_core
"libadbd_core" , // Depends on libadb_protos
"libadbd_services" , // Depends on libadb_protos
"libadb_protos_static" , // b/200601772: Requires cc_library proto support
"libadb_protos" , // b/200601772: Requires cc_library proto support
"libapp_processes_protos_lite" , // b/200601772: Requires cc_library proto support
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-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.
bp2buildCcLibraryStaticOnlyList = [ ] string {
2021-05-18 11:01:49 +02:00
"libjemalloc5" , // http://b/188503688, cc_library, `target: { android: { enabled: false } }` for android targets.
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-09-17 01:57:28 +02: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
"func_to_syscall_nrs" , // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
"libseccomp_policy_app_zygote_sources" , // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
"libseccomp_policy_app_sources" , // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
"libseccomp_policy_system_sources" , // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
2021-10-11 18:56:48 +02:00
"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-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.
func ( b * BazelModuleBase ) MixedBuildsEnabled ( ctx BazelConversionPathContext ) bool {
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.
func convertedToBazel ( ctx BazelConversionPathContext , module blueprint . Module ) bool {
b , ok := module . ( Bazelable )
if ! ok {
return false
}
return b . convertWithBp2build ( ctx , module ) || b . HasHandcraftedLabel ( )
}
2021-02-17 16:17:28 +01:00
// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
2021-03-10 08:05:59 +01:00
func ( b * BazelModuleBase ) ConvertWithBp2build ( ctx BazelConversionPathContext ) bool {
2021-08-26 14:37:59 +02:00
return b . convertWithBp2build ( ctx , ctx . Module ( ) )
}
func ( b * BazelModuleBase ) convertWithBp2build ( ctx BazelConversionPathContext , module blueprint . Module ) bool {
if bp2buildModuleDoNotConvert [ module . Name ( ) ] {
2021-03-25 10:28:38 +01:00
return false
}
2021-03-10 08:05:59 +01:00
// Ensure that the module type of this module has a bp2build converter. This
// prevents mixed builds from using auto-converted modules just by matching
// the package dir; it also has to have a bp2build mutator as well.
2021-08-26 14:37:59 +02:00
if ctx . Config ( ) . bp2buildModuleTypeConfig [ ctx . OtherModuleType ( module ) ] == false {
2021-03-10 08:05:59 +01:00
return false
}
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
}