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-02-17 19:22:03 +01:00
GetBazelBuildFileContents ( c Config , path , name string ) ( string , error )
2021-03-10 08:05:59 +01:00
ConvertedToBazel ( ctx BazelConversionPathContext ) bool
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
// all modules in this package (not recursively) default to bp2build_available: false.
// allows modules to opt-in.
Bp2BuildDefaultFalse
)
var (
2021-04-21 13:10:09 +02:00
// Do not write BUILD files for these directories
// NOTE: this is not recursive
bp2buildDoNotWriteBuildFileList = [ ] string {
// Don't generate these BUILD files - because external BUILD files already exist
"external/boringssl" ,
"external/brotli" ,
"external/dagger2" ,
"external/flatbuffers" ,
"external/gflags" ,
"external/google-fruit" ,
"external/grpc-grpc" ,
"external/grpc-grpc/test/core/util" ,
"external/grpc-grpc/test/cpp/common" ,
"external/grpc-grpc/third_party/address_sorting" ,
"external/nanopb-c" ,
"external/nos/host/generic" ,
"external/nos/host/generic/libnos" ,
"external/nos/host/generic/libnos/generator" ,
"external/nos/host/generic/libnos_datagram" ,
"external/nos/host/generic/libnos_transport" ,
"external/nos/host/generic/nugget/proto" ,
"external/perfetto" ,
"external/protobuf" ,
"external/rust/cxx" ,
"external/rust/cxx/demo" ,
"external/ruy" ,
"external/tensorflow" ,
"external/tensorflow/tensorflow/lite" ,
"external/tensorflow/tensorflow/lite/java" ,
"external/tensorflow/tensorflow/lite/kernels" ,
"external/tflite-support" ,
"external/tinyalsa_new" ,
"external/wycheproof" ,
"external/libyuv" ,
}
2021-03-10 08:05:59 +01:00
// Configure modules in these directories to enable bp2build_available: true or false by default.
bp2buildDefaultConfig = Bp2BuildConfig {
"bionic" : Bp2BuildDefaultTrueRecursively ,
2021-04-13 19:08:04 +02:00
"external/gwp_asan" : Bp2BuildDefaultTrueRecursively ,
2021-03-10 08:05:59 +01:00
"system/core/libcutils" : Bp2BuildDefaultTrueRecursively ,
2021-04-26 12:15:57 +02:00
"system/core/property_service/libpropertyinfoparser" : Bp2BuildDefaultTrueRecursively ,
2021-04-28 09:19:54 +02:00
"system/libbase" : Bp2BuildDefaultTrueRecursively ,
"system/logging/liblog" : Bp2BuildDefaultTrueRecursively ,
2021-04-30 10:20:01 +02:00
"external/jemalloc_new" : Bp2BuildDefaultTrueRecursively ,
"external/fmtlib" : Bp2BuildDefaultTrueRecursively ,
2021-04-28 09:19:54 +02:00
"external/arm-optimized-routines" : Bp2BuildDefaultTrueRecursively ,
2021-05-12 07:04:58 +02:00
"external/scudo" : 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-04-28 09:19:54 +02:00
// Things that transitively depend on unconverted libc_* modules.
2021-04-30 10:04:15 +02:00
"libc_nopthread" , // http://b/186821550, cc_library_static, depends on //bionic/libc:libc_bionic_ndk (http://b/186822256)
// also depends on //bionic/libc:libc_tzcode (http://b/186822591)
// also depends on //bionic/libc:libstdc++ (http://b/186822597)
"libc_common" , // http://b/186821517, cc_library_static, depends on //bionic/libc:libc_nopthread (http://b/186821550)
"libc_common_static" , // http://b/186824119, cc_library_static, depends on //bionic/libc:libc_common (http://b/186821517)
"libc_common_shared" , // http://b/186824118, cc_library_static, depends on //bionic/libc:libc_common (http://b/186821517)
"libc_nomalloc" , // http://b/186825031, cc_library_static, depends on //bionic/libc:libc_common (http://b/186821517)
"libbionic_spawn_benchmark" , // http://b/186824595, cc_library_static, depends on //external/google-benchmark (http://b/186822740)
// also depends on //system/logging/liblog:liblog (http://b/186822772)
"libc_malloc_debug" , // http://b/186824339, cc_library_static, depends on //system/libbase:libbase (http://b/186823646)
"libc_malloc_debug_backtrace" , // http://b/186824112, cc_library_static, depends on //external/libcxxabi:libc++demangle (http://b/186823773)
"libcutils" , // http://b/186827426, cc_library, depends on //system/core/libprocessgroup:libprocessgroup_headers (http://b/186826841)
"libcutils_sockets" , // http://b/186826853, cc_library, depends on //system/libbase:libbase (http://b/186826479)
"liblinker_debuggerd_stub" , // http://b/186824327, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
// also depends on //system/libziparchive:libziparchive (http://b/186823656)
// also depends on //system/logging/liblog:liblog (http://b/186822772)
"liblinker_main" , // http://b/186825989, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
// also depends on //system/libziparchive:libziparchive (http://b/186823656)
// also depends on//system/logging/liblog:liblog (http://b/186822772)
"liblinker_malloc" , // http://b/186826466, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
// also depends on //system/libziparchive:libziparchive (http://b/186823656)
// also depends on //system/logging/liblog:liblog (http://b/186822772)
2021-05-03 10:32:36 +02:00
"libc_jemalloc_wrapper" , // http://b/187012490, cc_library_static, depends on //external/jemalloc_new:libjemalloc5 (http://b/186828626)
"libc_ndk" , // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661)
"libc" , // http://b/183064430, cc_library, depends on //external/jemalloc_new:libjemalloc5 (http://b/186828626)
2021-05-06 15:31:18 +02:00
"libc_bionic_ndk" , // http://b/186822256, cc_library_static, fatal error: 'generated_android_ids.h' file not found
2021-05-03 10:32:36 +02:00
"libc_malloc_hooks" , // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook
"libm" , // http://b/183064661, cc_library, math.h:25:16: error: unexpected token in argument list
2021-04-30 10:20:01 +02:00
// http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx
// c++_static
2021-05-03 10:32:36 +02:00
"libbase_ndk" , // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added
2021-04-30 10:20:01 +02:00
// libcxx
"libBionicBenchmarksUtils" , // cc_library_static, fatal error: 'map' file not found, from libcxx
"fmtlib" , // cc_library_static, fatal error: 'cassert' file not found, from libcxx
"libbase" , // http://b/186826479, cc_library, fatal error: 'memory' file not found, from libcxx
// http://b/186024507: Includes errors because of the system_shared_libs default value.
// Missing -isystem bionic/libc/include through the libc/libm/libdl
// default dependencies if system_shared_libs is unset.
"liblog" , // http://b/186822772: cc_library, 'sys/cdefs.h' file not found
"libjemalloc5_jet" , // cc_library, 'sys/cdefs.h' file not found
"libseccomp_policy" , // http://b/186476753: cc_library, 'linux/filter.h' not found
"note_memtag_heap_async" , // http://b/185127353: cc_library_static, error: feature.h not found
"note_memtag_heap_sync" , // http://b/185127353: cc_library_static, error: feature.h not found
// 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-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 {
"libstdc++" , // http://b/186822597, cc_library, ld.lld: error: undefined symbol: __errno
}
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.
mixedBuildsDisabledList = [ ] string {
2021-04-28 09:19:54 +02:00
"libc_netbsd" , // lberki@, cc_library_static, version script assignment of 'LIBC_PRIVATE' to symbol 'SHA1Final' failed: symbol not defined
"libc_openbsd" , // ruperts@, cc_library_static, OK for bp2build but error: duplicate symbol: strcpy for mixed builds
"libsystemproperties" , // cparsons@, cc_library_static, wrong include paths
"libpropertyinfoparser" , // cparsons@, cc_library_static, wrong include paths
"libarm-optimized-routines-string" , // jingwen@, cc_library_static, OK for bp2build but b/186615213 (asflags not handled in bp2build), version script assignment of 'LIBC' to symbol 'memcmp' failed: symbol not defined (also for memrchr, strnlen)
2021-05-03 15:59:38 +02:00
"fmtlib_ndk" , // http://b/187040371, cc_library_static, OK for bp2build but format-inl.h:11:10: fatal error: 'cassert' file not found for mixed builds
2021-03-25 10:28:38 +01:00
}
2021-03-30 16:13:16 +02:00
// Used for quicker lookups
2021-04-21 13:10:09 +02:00
bp2buildDoNotWriteBuildFile = map [ string ] bool { }
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 ( ) {
2021-04-21 13:10:09 +02:00
for _ , moduleName := range bp2buildDoNotWriteBuildFileList {
bp2buildDoNotWriteBuildFile [ moduleName ] = true
}
2021-03-30 16:13:16 +02:00
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-05-03 11:15:48 +02:00
func GenerateCcLibraryStaticOnly ( ctx BazelConversionPathContext ) bool {
return bp2buildCcLibraryStaticOnly [ ctx . Module ( ) . Name ( ) ]
}
2021-04-21 13:10:09 +02:00
func ShouldWriteBuildFileForDir ( dir string ) bool {
if _ , ok := bp2buildDoNotWriteBuildFile [ dir ] ; ok {
return false
} else {
return true
}
}
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
}
if len ( b . GetBazelLabel ( ctx , ctx . Module ( ) ) ) == 0 {
return false
}
2021-05-03 11:15:48 +02:00
if GenerateCcLibraryStaticOnly ( ctx ) {
// 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-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-03-25 10:28:38 +01:00
if bp2buildModuleDoNotConvert [ ctx . Module ( ) . Name ( ) ] {
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.
if ctx . Config ( ) . bp2buildModuleTypeConfig [ ctx . ModuleType ( ) ] == false {
return false
}
packagePath := ctx . ModuleDir ( )
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
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 exact matches in the config.
if config [ packagePath ] == Bp2BuildDefaultTrueRecursively {
return true
}
2021-03-10 08:05:59 +01:00
if config [ packagePath ] == Bp2BuildDefaultFalse {
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-02-24 22:55:11 +01:00
// ConvertedToBazel returns whether this module has been converted to Bazel, whether automatically
// or manually
2021-03-10 08:05:59 +01:00
func ( b * BazelModuleBase ) ConvertedToBazel ( ctx BazelConversionPathContext ) bool {
return b . ConvertWithBp2build ( ctx ) || b . HasHandcraftedLabel ( )
2021-02-24 22:55:11 +01:00
}