Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package android |
| 16 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 17 | import ( |
| 18 | "fmt" |
| 19 | "io/ioutil" |
| 20 | "path/filepath" |
| 21 | "strings" |
| 22 | |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
| 27 | type bazelModuleProperties struct { |
| 28 | // The label of the Bazel target replacing this Soong module. When run in conversion mode, this |
| 29 | // will import the handcrafted build target into the autogenerated file. Note: this may result in |
| 30 | // a conflict due to duplicate targets if bp2build_available is also set. |
| 31 | Label *string |
| 32 | |
| 33 | // If true, bp2build will generate the converted Bazel target for this module. Note: this may |
| 34 | // cause a conflict due to the duplicate targets if label is also set. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 35 | // |
| 36 | // This is a bool pointer to support tristates: true, false, not set. |
| 37 | // |
| 38 | // To opt-in a module, set bazel_module: { bp2build_available: true } |
| 39 | // To opt-out a module, set bazel_module: { bp2build_available: false } |
| 40 | // To defer the default setting for the directory, do not set the value. |
| 41 | Bp2build_available *bool |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Properties contains common module properties for Bazel migration purposes. |
| 45 | type properties struct { |
| 46 | // In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing |
| 47 | // this Soong module. |
| 48 | Bazel_module bazelModuleProperties |
| 49 | } |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 50 | |
| 51 | // BazelModuleBase contains the property structs with metadata for modules which can be converted to |
| 52 | // Bazel. |
| 53 | type BazelModuleBase struct { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 54 | bazelProperties properties |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // Bazelable is specifies the interface for modules that can be converted to Bazel. |
| 58 | type Bazelable interface { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 59 | bazelProps() *properties |
| 60 | HasHandcraftedLabel() bool |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 61 | HandcraftedLabel() string |
| 62 | GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 63 | ConvertWithBp2build(ctx BazelConversionPathContext) bool |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 64 | GetBazelBuildFileContents(c Config, path, name string) (string, error) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 65 | ConvertedToBazel(ctx BazelConversionPathContext) bool |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. |
| 69 | type BazelModule interface { |
| 70 | Module |
| 71 | Bazelable |
| 72 | } |
| 73 | |
| 74 | // InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion |
| 75 | // properties. |
| 76 | func InitBazelModule(module BazelModule) { |
| 77 | module.AddProperties(module.bazelProps()) |
| 78 | } |
| 79 | |
| 80 | // bazelProps returns the Bazel properties for the given BazelModuleBase. |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 81 | func (b *BazelModuleBase) bazelProps() *properties { |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 82 | return &b.bazelProperties |
| 83 | } |
| 84 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 85 | // HasHandcraftedLabel returns whether this module has a handcrafted Bazel label. |
| 86 | func (b *BazelModuleBase) HasHandcraftedLabel() bool { |
| 87 | return b.bazelProperties.Bazel_module.Label != nil |
| 88 | } |
| 89 | |
| 90 | // HandcraftedLabel returns the handcrafted label for this module, or empty string if there is none |
| 91 | func (b *BazelModuleBase) HandcraftedLabel() string { |
| 92 | return proptools.String(b.bazelProperties.Bazel_module.Label) |
| 93 | } |
| 94 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 95 | // GetBazelLabel returns the Bazel label for the given BazelModuleBase. |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 96 | func (b *BazelModuleBase) GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string { |
| 97 | if b.HasHandcraftedLabel() { |
| 98 | return b.HandcraftedLabel() |
| 99 | } |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 100 | if b.ConvertWithBp2build(ctx) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 101 | return bp2buildModuleLabel(ctx, module) |
| 102 | } |
| 103 | return "" // no label for unconverted module |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 106 | // Configuration to decide if modules in a directory should default to true/false for bp2build_available |
| 107 | type Bp2BuildConfig map[string]BazelConversionConfigEntry |
| 108 | type BazelConversionConfigEntry int |
| 109 | |
| 110 | const ( |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 111 | // A sentinel value to be used as a key in Bp2BuildConfig for modules with |
| 112 | // no package path. This is also the module dir for top level Android.bp |
| 113 | // modules. |
| 114 | BP2BUILD_TOPLEVEL = "." |
| 115 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 116 | // iota + 1 ensures that the int value is not 0 when used in the Bp2buildAllowlist map, |
| 117 | // which can also mean that the key doesn't exist in a lookup. |
| 118 | |
| 119 | // all modules in this package and subpackages default to bp2build_available: true. |
| 120 | // allows modules to opt-out. |
| 121 | Bp2BuildDefaultTrueRecursively BazelConversionConfigEntry = iota + 1 |
| 122 | |
| 123 | // all modules in this package (not recursively) default to bp2build_available: false. |
| 124 | // allows modules to opt-in. |
| 125 | Bp2BuildDefaultFalse |
| 126 | ) |
| 127 | |
| 128 | var ( |
| 129 | // Configure modules in these directories to enable bp2build_available: true or false by default. |
| 130 | bp2buildDefaultConfig = Bp2BuildConfig{ |
| 131 | "bionic": Bp2BuildDefaultTrueRecursively, |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 132 | "external/gwp_asan": Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 133 | "system/core/libcutils": Bp2BuildDefaultTrueRecursively, |
| 134 | "system/logging/liblog": Bp2BuildDefaultTrueRecursively, |
| 135 | } |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 136 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 137 | // Per-module denylist to always opt modules out of both bp2build and mixed builds. |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 138 | bp2buildModuleDoNotConvertList = []string{ |
Rupert Shuttleworth | 43b0492 | 2021-04-13 08:54:20 -0400 | [diff] [blame] | 139 | "libBionicBenchmarksUtils", // ruperts@, cc_library_static, 'map' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 140 | "libbionic_spawn_benchmark", // ruperts@, cc_library_static, depends on //system/libbase |
| 141 | "libc_jemalloc_wrapper", // ruperts@, cc_library_static, depends on //external/jemalloc_new |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 142 | "libc_bootstrap", // ruperts@, cc_library_static, 'private/bionic_auxv.h' file not found |
| 143 | "libc_init_static", // ruperts@, cc_library_static, 'private/bionic_elf_tls.h' file not found |
| 144 | "libc_init_dynamic", // ruperts@, cc_library_static, 'private/bionic_defs.h' file not found |
| 145 | "libc_tzcode", // ruperts@, cc_library_static, error: expected expression |
| 146 | "libc_netbsd", // ruperts@, cc_library_static, 'engine.c' file not found |
| 147 | "libc_openbsd_large_stack", // ruperts@, cc_library_static, 'android/log.h' file not found |
| 148 | "libc_openbsd", // ruperts@, cc_library_static, 'android/log.h' file not found |
| 149 | "libc_fortify", // ruperts@, cc_library_static, 'private/bionic_fortify.h' file not found |
| 150 | "libc_bionic", // ruperts@, cc_library_static, 'private/bionic_asm.h' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 151 | "libc_bionic_ndk", // ruperts@, cc_library_static, depends on //bionic/libc/system_properties |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 152 | "libc_bionic_systrace", // ruperts@, cc_library_static, 'private/bionic_systrace.h' file not found |
| 153 | "libc_pthread", // ruperts@, cc_library_static, 'private/bionic_defs.h' file not found |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame^] | 154 | "libc_syscalls", // eakammer@, cc_library_static, 'private/bionic_asm.h' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 155 | "libc_ndk", // ruperts@, cc_library_static, depends on //bionic/libm:libm |
| 156 | "libc_nopthread", // ruperts@, cc_library_static, depends on //external/arm-optimized-routines |
| 157 | "libc_common", // ruperts@, cc_library_static, depends on //bionic/libc:libc_nopthread |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 158 | "libc_common_static", // ruperts@, cc_library_static, depends on //bionic/libc:libc_common |
| 159 | "libc_common_shared", // ruperts@, cc_library_static, depends on //bionic/libc:libc_common |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 160 | "libc_unwind_static", // ruperts@, cc_library_static, 'private/bionic_elf_tls.h' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 161 | "libc_nomalloc", // ruperts@, cc_library_static, depends on //bionic/libc:libc_common |
Rupert Shuttleworth | 43b0492 | 2021-04-13 08:54:20 -0400 | [diff] [blame] | 162 | "libasync_safe", // ruperts@, cc_library_static, 'private/CachedProperty.h' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 163 | "libc_malloc_debug_backtrace", // ruperts@, cc_library_static, depends on //system/libbase |
| 164 | "libsystemproperties", // ruperts@, cc_library_static, depends on //system/core/property_service/libpropertyinfoparser |
Rupert Shuttleworth | 43b0492 | 2021-04-13 08:54:20 -0400 | [diff] [blame] | 165 | "libdl_static", // ruperts@, cc_library_static, 'private/CFIShadow.h' file not found |
Rupert Shuttleworth | 760fb18 | 2021-04-01 04:32:55 +0000 | [diff] [blame] | 166 | "liblinker_main", // ruperts@, cc_library_static, depends on //system/libbase |
| 167 | "liblinker_malloc", // ruperts@, cc_library_static, depends on //system/logging/liblog:liblog |
| 168 | "liblinker_debuggerd_stub", // ruperts@, cc_library_static, depends on //system/libbase |
Rupert Shuttleworth | 43b0492 | 2021-04-13 08:54:20 -0400 | [diff] [blame] | 169 | "libbionic_tests_headers_posix", // ruperts@, cc_library_static, 'complex.h' file not found |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 170 | "libc_dns", // ruperts@, cc_library_static, 'android/log.h' file not found |
Liz Kammer | cefa3c7 | 2021-04-16 11:49:44 -0400 | [diff] [blame] | 171 | "libc_static_dispatch", // eakammer@, cc_library_static, 'private/bionic_asm.h' file not found |
| 172 | "libc_dynamic_dispatch", // eakammer@, cc_library_static, 'private/bionic_ifuncs.h' file not found |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 173 | "note_memtag_heap_async", // jingwen@, cc_library_static, 'private/bionic_asm.h' file not found (arm64) |
| 174 | "note_memtag_heap_sync", // jingwen@, cc_library_static, 'private/bionic_asm.h' file not found (arm64) |
Jingwen Chen | 0a92ed7 | 2021-04-12 05:37:42 +0000 | [diff] [blame] | 175 | |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 176 | // List of all full_cc_libraries in //bionic, with their immediate failures |
| 177 | "libc", // jingwen@, cc_library, depends on //external/gwp_asan |
| 178 | "libc_malloc_debug", // jingwen@, cc_library, fatal error: 'assert.h' file not found |
| 179 | "libc_malloc_hooks", // jingwen@, cc_library, fatal error: 'errno.h' file not found |
| 180 | "libdl", // jingwen@, cc_library, ld.lld: error: no input files |
| 181 | "libm", // jingwen@, cc_library, fatal error: 'freebsd-compat.h' file not found |
| 182 | "libseccomp_policy", // jingwen@, cc_library, fatal error: 'seccomp_policy.h' file not found |
| 183 | "libstdc++", // jingwen@, cc_library, depends on //external/gwp_asan |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 184 | } |
Rupert Shuttleworth | c143cc5 | 2021-04-13 13:08:04 -0400 | [diff] [blame] | 185 | |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 186 | // Per-module denylist to opt modules out of mixed builds. Such modules will |
| 187 | // still be generated via bp2build. |
| 188 | mixedBuildsDisabledList = []string{ |
| 189 | "libc_gdtoa", // ruperts@, cc_library_static, OK for bp2build but undefined symbol: __strtorQ for mixed builds |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 190 | } |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 191 | |
| 192 | // Used for quicker lookups |
| 193 | bp2buildModuleDoNotConvert = map[string]bool{} |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 194 | mixedBuildsDisabled = map[string]bool{} |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 195 | ) |
| 196 | |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 197 | func init() { |
| 198 | for _, moduleName := range bp2buildModuleDoNotConvertList { |
| 199 | bp2buildModuleDoNotConvert[moduleName] = true |
| 200 | } |
Chris Parsons | bab4d7e | 2021-04-15 17:27:08 -0400 | [diff] [blame] | 201 | |
| 202 | for _, moduleName := range mixedBuildsDisabledList { |
| 203 | mixedBuildsDisabled[moduleName] = true |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // MixedBuildsEnabled checks that a module is ready to be replaced by a |
| 208 | // converted or handcrafted Bazel target. |
| 209 | func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) bool { |
| 210 | if !ctx.Config().BazelContext.BazelEnabled() { |
| 211 | return false |
| 212 | } |
| 213 | if len(b.GetBazelLabel(ctx, ctx.Module())) == 0 { |
| 214 | return false |
| 215 | } |
| 216 | return !mixedBuildsDisabled[ctx.Module().Name()] |
Rupert Shuttleworth | 4f43fe9 | 2021-03-30 14:13:16 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 219 | // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 220 | func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionPathContext) bool { |
Jingwen Chen | 5d72cba | 2021-03-25 09:28:38 +0000 | [diff] [blame] | 221 | if bp2buildModuleDoNotConvert[ctx.Module().Name()] { |
| 222 | return false |
| 223 | } |
| 224 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 225 | // Ensure that the module type of this module has a bp2build converter. This |
| 226 | // prevents mixed builds from using auto-converted modules just by matching |
| 227 | // the package dir; it also has to have a bp2build mutator as well. |
| 228 | if ctx.Config().bp2buildModuleTypeConfig[ctx.ModuleType()] == false { |
| 229 | return false |
| 230 | } |
| 231 | |
| 232 | packagePath := ctx.ModuleDir() |
| 233 | config := ctx.Config().bp2buildPackageConfig |
| 234 | |
| 235 | // This is a tristate value: true, false, or unset. |
| 236 | propValue := b.bazelProperties.Bazel_module.Bp2build_available |
| 237 | if bp2buildDefaultTrueRecursively(packagePath, config) { |
| 238 | // Allow modules to explicitly opt-out. |
| 239 | return proptools.BoolDefault(propValue, true) |
| 240 | } |
| 241 | |
| 242 | // Allow modules to explicitly opt-in. |
| 243 | return proptools.BoolDefault(propValue, false) |
| 244 | } |
| 245 | |
| 246 | // bp2buildDefaultTrueRecursively checks that the package contains a prefix from the |
| 247 | // set of package prefixes where all modules must be converted. That is, if the |
| 248 | // package is x/y/z, and the list contains either x, x/y, or x/y/z, this function will |
| 249 | // return true. |
| 250 | // |
| 251 | // However, if the package is x/y, and it matches a Bp2BuildDefaultFalse "x/y" entry |
| 252 | // exactly, this module will return false early. |
| 253 | // |
| 254 | // This function will also return false if the package doesn't match anything in |
| 255 | // the config. |
| 256 | func bp2buildDefaultTrueRecursively(packagePath string, config Bp2BuildConfig) bool { |
| 257 | ret := false |
| 258 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 259 | // Return exact matches in the config. |
| 260 | if config[packagePath] == Bp2BuildDefaultTrueRecursively { |
| 261 | return true |
| 262 | } |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 263 | if config[packagePath] == Bp2BuildDefaultFalse { |
| 264 | return false |
| 265 | } |
| 266 | |
Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 267 | // If not, check for the config recursively. |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 268 | packagePrefix := "" |
| 269 | // e.g. for x/y/z, iterate over x, x/y, then x/y/z, taking the final value from the allowlist. |
| 270 | for _, part := range strings.Split(packagePath, "/") { |
| 271 | packagePrefix += part |
| 272 | if config[packagePrefix] == Bp2BuildDefaultTrueRecursively { |
| 273 | // package contains this prefix and this prefix should convert all modules |
| 274 | return true |
| 275 | } |
| 276 | // Continue to the next part of the package dir. |
| 277 | packagePrefix += "/" |
| 278 | } |
| 279 | |
| 280 | return ret |
Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 281 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 282 | |
| 283 | // GetBazelBuildFileContents returns the file contents of a hand-crafted BUILD file if available or |
| 284 | // an error if there are errors reading the file. |
| 285 | // TODO(b/181575318): currently we append the whole BUILD file, let's change that to do |
| 286 | // something more targeted based on the rule type and target. |
| 287 | func (b *BazelModuleBase) GetBazelBuildFileContents(c Config, path, name string) (string, error) { |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 288 | if !strings.Contains(b.HandcraftedLabel(), path) { |
| 289 | return "", fmt.Errorf("%q not found in bazel_module.label %q", path, b.HandcraftedLabel()) |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 290 | } |
| 291 | name = filepath.Join(path, name) |
| 292 | f, err := c.fs.Open(name) |
| 293 | if err != nil { |
| 294 | return "", err |
| 295 | } |
| 296 | defer f.Close() |
| 297 | |
| 298 | data, err := ioutil.ReadAll(f) |
| 299 | if err != nil { |
| 300 | return "", err |
| 301 | } |
| 302 | return string(data[:]), nil |
| 303 | } |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 304 | |
| 305 | // ConvertedToBazel returns whether this module has been converted to Bazel, whether automatically |
| 306 | // or manually |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 307 | func (b *BazelModuleBase) ConvertedToBazel(ctx BazelConversionPathContext) bool { |
| 308 | return b.ConvertWithBp2build(ctx) || b.HasHandcraftedLabel() |
Liz Kammer | bdc6099 | 2021-02-24 16:55:11 -0500 | [diff] [blame] | 309 | } |