Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project |
| 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 rust |
| 16 | |
| 17 | import ( |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 18 | "fmt" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 19 | "strings" |
| 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | "github.com/google/blueprint/proptools" |
| 23 | |
| 24 | "android/soong/android" |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame^] | 25 | "android/soong/bloaty" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 26 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 27 | cc_config "android/soong/cc/config" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 28 | "android/soong/rust/config" |
| 29 | ) |
| 30 | |
| 31 | var pctx = android.NewPackageContext("android/soong/rust") |
| 32 | |
| 33 | func init() { |
| 34 | // Only allow rust modules to be defined for certain projects |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | |
| 36 | android.AddNeverAllowRules( |
| 37 | android.NeverAllow(). |
Ivan Lozano | e169ad7 | 2019-09-18 08:42:54 -0700 | [diff] [blame] | 38 | NotIn(config.RustAllowedPaths...). |
| 39 | ModuleType(config.RustModuleTypes...)) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 40 | |
| 41 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 42 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 43 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 44 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 45 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 46 | |
| 47 | }) |
| 48 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 49 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 50 | }) |
| 51 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 52 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 56 | GlobalRustFlags []string // Flags that apply globally to rust |
| 57 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 58 | RustFlags []string // Flags that apply to rust |
| 59 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 60 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 61 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 62 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 63 | Clippy bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | type BaseProperties struct { |
| 67 | AndroidMkRlibs []string |
| 68 | AndroidMkDylibs []string |
| 69 | AndroidMkProcMacroLibs []string |
| 70 | AndroidMkSharedLibs []string |
| 71 | AndroidMkStaticLibs []string |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 72 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 73 | ImageVariationPrefix string `blueprint:"mutated"` |
| 74 | VndkVersion string `blueprint:"mutated"` |
| 75 | SubName string `blueprint:"mutated"` |
| 76 | |
| 77 | // Set by imageMutator |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 78 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 79 | VendorRamdiskVariantNeeded bool `blueprint:"mutated"` |
| 80 | ExtraVariants []string `blueprint:"mutated"` |
| 81 | |
| 82 | // Make this module available when building for vendor ramdisk. |
| 83 | // On device without a dedicated recovery partition, the module is only |
| 84 | // available after switching root into |
| 85 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 86 | // the recovery variant instead (TODO(b/165791368) recovery not yet supported) |
| 87 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 88 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 89 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 90 | Min_sdk_version *string |
| 91 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 92 | PreventInstall bool |
| 93 | HideFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | type Module struct { |
| 97 | android.ModuleBase |
| 98 | android.DefaultableModuleBase |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 99 | android.ApexModuleBase |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 100 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 101 | VendorProperties cc.VendorProperties |
| 102 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 103 | Properties BaseProperties |
| 104 | |
| 105 | hod android.HostOrDeviceSupported |
| 106 | multilib android.Multilib |
| 107 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 108 | makeLinkType string |
| 109 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 110 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 111 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 112 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 113 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 114 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 115 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 116 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 117 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 118 | // Unstripped output. This is usually used when this module is linked to another module |
| 119 | // as a library. The stripped output which is used for installation can be found via |
| 120 | // compiler.strippedOutputFile if it exists. |
| 121 | unstrippedOutputFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 122 | |
| 123 | hideApexVariantFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 126 | func (mod *Module) Header() bool { |
| 127 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 128 | return false |
| 129 | } |
| 130 | |
| 131 | func (mod *Module) SetPreventInstall() { |
| 132 | mod.Properties.PreventInstall = true |
| 133 | } |
| 134 | |
| 135 | // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor |
| 136 | func (mod *Module) InVendor() bool { |
| 137 | return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix |
| 138 | } |
| 139 | |
| 140 | func (mod *Module) SetHideFromMake() { |
| 141 | mod.Properties.HideFromMake = true |
| 142 | } |
| 143 | |
| 144 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 145 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 146 | // nil since we need compiler to actually sanitize. |
| 147 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | func (mod *Module) IsDependencyRoot() bool { |
| 151 | if mod.compiler != nil { |
| 152 | return mod.compiler.isDependencyRoot() |
| 153 | } |
| 154 | panic("IsDependencyRoot called on a non-compiler Rust module") |
| 155 | } |
| 156 | |
| 157 | func (mod *Module) IsPrebuilt() bool { |
| 158 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 159 | return true |
| 160 | } |
| 161 | return false |
| 162 | } |
| 163 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 164 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 165 | switch tag { |
| 166 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 167 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 168 | return mod.sourceProvider.Srcs(), nil |
| 169 | } else { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 170 | if mod.OutputFile().Valid() { |
| 171 | return android.Paths{mod.OutputFile().Path()}, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 172 | } |
| 173 | return android.Paths{}, nil |
| 174 | } |
| 175 | default: |
| 176 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 177 | } |
| 178 | } |
| 179 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 180 | func (mod *Module) SelectedStl() string { |
| 181 | return "" |
| 182 | } |
| 183 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 184 | func (mod *Module) NonCcVariants() bool { |
| 185 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 186 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 187 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 191 | } |
| 192 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 193 | func (mod *Module) Static() bool { |
| 194 | if mod.compiler != nil { |
| 195 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 196 | return library.static() |
| 197 | } |
| 198 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 199 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | func (mod *Module) Shared() bool { |
| 203 | if mod.compiler != nil { |
| 204 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 205 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 208 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | func (mod *Module) Toc() android.OptionalPath { |
| 212 | if mod.compiler != nil { |
| 213 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 214 | return android.OptionalPath{} |
| 215 | } |
| 216 | } |
| 217 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 218 | } |
| 219 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 220 | func (mod *Module) UseSdk() bool { |
| 221 | return false |
| 222 | } |
| 223 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 224 | // Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64. |
| 225 | // "product" and "vendor" variant modules return true for this function. |
| 226 | // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true", |
| 227 | // "soc_specific: true" and more vendor installed modules are included here. |
| 228 | // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or |
| 229 | // "product_specific: true" modules are included here. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 230 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 231 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | func (mod *Module) MustUseVendorVariant() bool { |
| 235 | return false |
| 236 | } |
| 237 | |
| 238 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 239 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 240 | return false |
| 241 | } |
| 242 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 243 | func (mod *Module) IsVndkExt() bool { |
| 244 | return false |
| 245 | } |
| 246 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 247 | func (c *Module) IsVndkPrivate() bool { |
| 248 | return false |
| 249 | } |
| 250 | |
| 251 | func (c *Module) IsLlndk() bool { |
| 252 | return false |
| 253 | } |
| 254 | |
| 255 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 256 | return false |
| 257 | } |
| 258 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 259 | func (mod *Module) SdkVersion() string { |
| 260 | return "" |
| 261 | } |
| 262 | |
Jiyong Park | fdaa5f7 | 2021-03-19 22:18:04 +0900 | [diff] [blame] | 263 | func (mod *Module) MinSdkVersion() string { |
| 264 | return "" |
| 265 | } |
| 266 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 267 | func (mod *Module) AlwaysSdk() bool { |
| 268 | return false |
| 269 | } |
| 270 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 271 | func (mod *Module) IsSdkVariant() bool { |
| 272 | return false |
| 273 | } |
| 274 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 275 | func (mod *Module) SplitPerApiLevel() bool { |
| 276 | return false |
| 277 | } |
| 278 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 279 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 280 | Dylibs []string |
| 281 | Rlibs []string |
| 282 | Rustlibs []string |
| 283 | Stdlibs []string |
| 284 | ProcMacros []string |
| 285 | SharedLibs []string |
| 286 | StaticLibs []string |
| 287 | WholeStaticLibs []string |
| 288 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 289 | |
| 290 | CrtBegin, CrtEnd string |
| 291 | } |
| 292 | |
| 293 | type PathDeps struct { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 294 | DyLibs RustLibraries |
| 295 | RLibs RustLibraries |
| 296 | SharedLibs android.Paths |
| 297 | SharedLibDeps android.Paths |
| 298 | StaticLibs android.Paths |
| 299 | ProcMacros RustLibraries |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 300 | |
| 301 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 302 | depFlags []string |
| 303 | depLinkFlags []string |
| 304 | |
| 305 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. |
| 306 | // Both of these are exported and propagate to dependencies. |
| 307 | linkDirs []string |
| 308 | linkObjects []string |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 309 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 310 | // Used by bindgen modules which call clang |
| 311 | depClangFlags []string |
| 312 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 313 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 314 | depSystemIncludePaths android.Paths |
| 315 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 316 | CrtBegin android.OptionalPath |
| 317 | CrtEnd android.OptionalPath |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 318 | |
| 319 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 320 | SrcDeps android.Paths |
| 321 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | type RustLibraries []RustLibrary |
| 325 | |
| 326 | type RustLibrary struct { |
| 327 | Path android.Path |
| 328 | CrateName string |
| 329 | } |
| 330 | |
| 331 | type compiler interface { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 332 | initialize(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 333 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 334 | compilerProps() []interface{} |
| 335 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 336 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 337 | crateName() string |
| 338 | |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 339 | // Output directory in which source-generated code from dependencies is |
| 340 | // copied. This is equivalent to Cargo's OUT_DIR variable. |
| 341 | CargoOutDir() android.OptionalPath |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 342 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 343 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 344 | relativeInstallPath() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 345 | |
| 346 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 347 | |
| 348 | Disabled() bool |
| 349 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 350 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 351 | stdLinkage(ctx *depsContext) RustLinkage |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 352 | isDependencyRoot() bool |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 353 | |
| 354 | strippedOutputFilePath() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 357 | type exportedFlagsProducer interface { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 358 | exportLinkDirs(...string) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 359 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 363 | linkDirs []string |
| 364 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 367 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 368 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 369 | } |
| 370 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 371 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 372 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
| 373 | } |
| 374 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 375 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 376 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 377 | LinkDirs: flagExporter.linkDirs, |
| 378 | LinkObjects: flagExporter.linkObjects, |
| 379 | }) |
| 380 | } |
| 381 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 382 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 383 | |
| 384 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 385 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 388 | type FlagExporterInfo struct { |
| 389 | Flags []string |
| 390 | LinkDirs []string // TODO: this should be android.Paths |
| 391 | LinkObjects []string // TODO: this should be android.Paths |
| 392 | } |
| 393 | |
| 394 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 395 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 396 | func (mod *Module) isCoverageVariant() bool { |
| 397 | return mod.coverage.Properties.IsCoverageVariant |
| 398 | } |
| 399 | |
| 400 | var _ cc.Coverage = (*Module)(nil) |
| 401 | |
| 402 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 403 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 404 | } |
| 405 | |
| 406 | func (mod *Module) PreventInstall() { |
| 407 | mod.Properties.PreventInstall = true |
| 408 | } |
| 409 | |
| 410 | func (mod *Module) HideFromMake() { |
| 411 | mod.Properties.HideFromMake = true |
| 412 | } |
| 413 | |
| 414 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 415 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 416 | } |
| 417 | |
| 418 | func (mod *Module) EnableCoverageIfNeeded() { |
| 419 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | func defaultsFactory() android.Module { |
| 423 | return DefaultsFactory() |
| 424 | } |
| 425 | |
| 426 | type Defaults struct { |
| 427 | android.ModuleBase |
| 428 | android.DefaultsModuleBase |
| 429 | } |
| 430 | |
| 431 | func DefaultsFactory(props ...interface{}) android.Module { |
| 432 | module := &Defaults{} |
| 433 | |
| 434 | module.AddProperties(props...) |
| 435 | module.AddProperties( |
| 436 | &BaseProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 437 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 438 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 439 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 440 | &BaseCompilerProperties{}, |
| 441 | &BinaryCompilerProperties{}, |
| 442 | &LibraryCompilerProperties{}, |
| 443 | &ProcMacroCompilerProperties{}, |
| 444 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 445 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 446 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 447 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 448 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 449 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 450 | &SanitizeProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 451 | ) |
| 452 | |
| 453 | android.InitDefaultsModule(module) |
| 454 | return module |
| 455 | } |
| 456 | |
| 457 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 458 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 461 | func (mod *Module) CcLibrary() bool { |
| 462 | if mod.compiler != nil { |
| 463 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 464 | return true |
| 465 | } |
| 466 | } |
| 467 | return false |
| 468 | } |
| 469 | |
| 470 | func (mod *Module) CcLibraryInterface() bool { |
| 471 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 472 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 473 | // VariantIs{Static,Shared} is set. |
| 474 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 475 | return true |
| 476 | } |
| 477 | } |
| 478 | return false |
| 479 | } |
| 480 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 481 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 482 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 483 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 484 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 488 | } |
| 489 | |
| 490 | func (mod *Module) SetStatic() { |
| 491 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 492 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 493 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 494 | return |
| 495 | } |
| 496 | } |
| 497 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 498 | } |
| 499 | |
| 500 | func (mod *Module) SetShared() { |
| 501 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 502 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 503 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 504 | return |
| 505 | } |
| 506 | } |
| 507 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 508 | } |
| 509 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 510 | func (mod *Module) BuildStaticVariant() bool { |
| 511 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 512 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 513 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 517 | } |
| 518 | |
| 519 | func (mod *Module) BuildSharedVariant() bool { |
| 520 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 521 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 522 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 526 | } |
| 527 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 528 | func (mod *Module) Module() android.Module { |
| 529 | return mod |
| 530 | } |
| 531 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 532 | func (mod *Module) OutputFile() android.OptionalPath { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 533 | if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() { |
| 534 | return mod.compiler.strippedOutputFilePath() |
| 535 | } |
| 536 | return mod.unstrippedOutputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 539 | func (mod *Module) CoverageFiles() android.Paths { |
| 540 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 541 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 542 | } |
| 543 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 544 | } |
| 545 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 546 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
| 547 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 548 | // in the system partition as a standalone file. |
| 549 | if !apexInfo.IsForPlatform() { |
| 550 | return false |
| 551 | } |
| 552 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 553 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 554 | } |
| 555 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 556 | var _ cc.LinkableInterface = (*Module)(nil) |
| 557 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 558 | func (mod *Module) Init() android.Module { |
| 559 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 560 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 561 | |
| 562 | if mod.compiler != nil { |
| 563 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 564 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 565 | if mod.coverage != nil { |
| 566 | mod.AddProperties(mod.coverage.props()...) |
| 567 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 568 | if mod.clippy != nil { |
| 569 | mod.AddProperties(mod.clippy.props()...) |
| 570 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 571 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 572 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 573 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 574 | if mod.sanitize != nil { |
| 575 | mod.AddProperties(mod.sanitize.props()...) |
| 576 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 577 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 578 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 579 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 580 | |
| 581 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 582 | return mod |
| 583 | } |
| 584 | |
| 585 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 586 | return &Module{ |
| 587 | hod: hod, |
| 588 | multilib: multilib, |
| 589 | } |
| 590 | } |
| 591 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 592 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 593 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 594 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 595 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 596 | return module |
| 597 | } |
| 598 | |
| 599 | type ModuleContext interface { |
| 600 | android.ModuleContext |
| 601 | ModuleContextIntf |
| 602 | } |
| 603 | |
| 604 | type BaseModuleContext interface { |
| 605 | android.BaseModuleContext |
| 606 | ModuleContextIntf |
| 607 | } |
| 608 | |
| 609 | type DepsContext interface { |
| 610 | android.BottomUpMutatorContext |
| 611 | ModuleContextIntf |
| 612 | } |
| 613 | |
| 614 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 615 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 616 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | type depsContext struct { |
| 620 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | type moduleContext struct { |
| 624 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 627 | type baseModuleContext struct { |
| 628 | android.BaseModuleContext |
| 629 | } |
| 630 | |
| 631 | func (ctx *moduleContext) RustModule() *Module { |
| 632 | return ctx.Module().(*Module) |
| 633 | } |
| 634 | |
| 635 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 636 | return ctx.RustModule().toolchain(ctx) |
| 637 | } |
| 638 | |
| 639 | func (ctx *depsContext) RustModule() *Module { |
| 640 | return ctx.Module().(*Module) |
| 641 | } |
| 642 | |
| 643 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 644 | return ctx.RustModule().toolchain(ctx) |
| 645 | } |
| 646 | |
| 647 | func (ctx *baseModuleContext) RustModule() *Module { |
| 648 | return ctx.Module().(*Module) |
| 649 | } |
| 650 | |
| 651 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 652 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | func (mod *Module) nativeCoverage() bool { |
| 656 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 657 | } |
| 658 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 659 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 660 | if mod.cachedToolchain == nil { |
| 661 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 662 | } |
| 663 | return mod.cachedToolchain |
| 664 | } |
| 665 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 666 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 667 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 668 | } |
| 669 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 670 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 671 | } |
| 672 | |
| 673 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 674 | ctx := &moduleContext{ |
| 675 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 676 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 677 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 678 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 679 | if !apexInfo.IsForPlatform() { |
| 680 | mod.hideApexVariantFromMake = true |
| 681 | } |
| 682 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 683 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 684 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 685 | |
| 686 | // Differentiate static libraries that are vendor available |
| 687 | if mod.UseVndk() { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 688 | mod.Properties.SubName += cc.VendorSuffix |
| 689 | } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() { |
| 690 | mod.Properties.SubName += cc.VendorRamdiskSuffix |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 691 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 692 | |
| 693 | if !toolchain.Supported() { |
| 694 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 695 | return |
| 696 | } |
| 697 | |
| 698 | deps := mod.depsToPaths(ctx) |
| 699 | flags := Flags{ |
| 700 | Toolchain: toolchain, |
| 701 | } |
| 702 | |
| 703 | if mod.compiler != nil { |
| 704 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 705 | } |
| 706 | if mod.coverage != nil { |
| 707 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 708 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 709 | if mod.clippy != nil { |
| 710 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 711 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 712 | if mod.sanitize != nil { |
| 713 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 714 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 715 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 716 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 717 | // compile() so it can provide the source. A SourceProvider has |
| 718 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 719 | // variant is responsible for effectively generating the source. The |
| 720 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 721 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 722 | if mod.compiler.(libraryInterface).source() { |
| 723 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 724 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 725 | } else { |
| 726 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 727 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 728 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 729 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 733 | mod.compiler.initialize(ctx) |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 734 | unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps) |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 735 | mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile) |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame^] | 736 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), mod.unstrippedOutputFile) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 737 | |
| 738 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 739 | if mod.installable(apexInfo) { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 740 | mod.compiler.install(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 741 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
| 745 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 746 | deps := Deps{} |
| 747 | |
| 748 | if mod.compiler != nil { |
| 749 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 750 | } |
| 751 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 752 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 755 | if mod.coverage != nil { |
| 756 | deps = mod.coverage.deps(ctx, deps) |
| 757 | } |
| 758 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 759 | if mod.sanitize != nil { |
| 760 | deps = mod.sanitize.deps(ctx, deps) |
| 761 | } |
| 762 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 763 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 764 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 765 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 766 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 767 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 768 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 769 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 770 | return deps |
| 771 | |
| 772 | } |
| 773 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 774 | type dependencyTag struct { |
| 775 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 776 | name string |
| 777 | library bool |
| 778 | procMacro bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 781 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 782 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 783 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 784 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 788 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 789 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 790 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 791 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 792 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 793 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 794 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 795 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 796 | ) |
| 797 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 798 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 799 | tag, ok := depTag.(dependencyTag) |
| 800 | return ok && tag == dylibDepTag |
| 801 | } |
| 802 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 803 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 804 | tag, ok := depTag.(dependencyTag) |
| 805 | return ok && tag == rlibDepTag |
| 806 | } |
| 807 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 808 | type autoDep struct { |
| 809 | variation string |
| 810 | depTag dependencyTag |
| 811 | } |
| 812 | |
| 813 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 814 | rlibVariation = "rlib" |
| 815 | dylibVariation = "dylib" |
| 816 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 817 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 818 | ) |
| 819 | |
| 820 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 821 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 824 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 825 | if mod.coverage != nil { |
| 826 | mod.coverage.begin(ctx) |
| 827 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 828 | if mod.sanitize != nil { |
| 829 | mod.sanitize.begin(ctx) |
| 830 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 831 | } |
| 832 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 833 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 834 | var depPaths PathDeps |
| 835 | |
| 836 | directRlibDeps := []*Module{} |
| 837 | directDylibDeps := []*Module{} |
| 838 | directProcMacroDeps := []*Module{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 839 | directSharedLibDeps := [](cc.LinkableInterface){} |
| 840 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 841 | directSrcProvidersDeps := []*Module{} |
| 842 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 843 | |
| 844 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 845 | depName := ctx.OtherModuleName(dep) |
| 846 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 847 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 848 | //Handle Rust Modules |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 849 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 850 | switch depTag { |
| 851 | case dylibDepTag: |
| 852 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 853 | if !ok || !dylib.dylib() { |
| 854 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 855 | return |
| 856 | } |
| 857 | directDylibDeps = append(directDylibDeps, rustDep) |
| 858 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName) |
| 859 | case rlibDepTag: |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 860 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 861 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 862 | if !ok || !rlib.rlib() { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 863 | ctx.ModuleErrorf("mod %q not an rlib library", depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 864 | return |
| 865 | } |
| 866 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 867 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 868 | case procMacroDepTag: |
| 869 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
| 870 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 871 | case android.SourceDepTag: |
| 872 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 873 | // OS/Arch variant is used. |
| 874 | var helper string |
| 875 | if ctx.Host() { |
| 876 | helper = "missing 'host_supported'?" |
| 877 | } else { |
| 878 | helper = "device module defined?" |
| 879 | } |
| 880 | |
| 881 | if dep.Target().Os != ctx.Os() { |
| 882 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 883 | return |
| 884 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 885 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 886 | return |
| 887 | } |
| 888 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 891 | //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 892 | if depTag != procMacroDepTag { |
| 893 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 894 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 895 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 896 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 899 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 900 | linkFile := rustDep.unstrippedOutputFile |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 901 | if !linkFile.Valid() { |
| 902 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", |
| 903 | depName, ctx.ModuleName()) |
| 904 | return |
| 905 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 906 | linkDir := linkPathFromFilePath(linkFile.Path()) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 907 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 908 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 912 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 913 | //Handle C dependencies |
| 914 | if _, ok := ccDep.(*Module); !ok { |
| 915 | if ccDep.Module().Target().Os != ctx.Os() { |
| 916 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 917 | return |
| 918 | } |
| 919 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 920 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 921 | return |
| 922 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 923 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 924 | linkObject := ccDep.OutputFile() |
| 925 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 926 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 927 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 928 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 929 | } |
| 930 | |
| 931 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 932 | switch { |
| 933 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 934 | if cc.IsWholeStaticLib(depTag) { |
| 935 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 936 | // if the library is not prefixed by "lib". |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 937 | if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
| 938 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 939 | } else { |
| 940 | ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName()) |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 941 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 945 | // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant. |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 946 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 947 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 948 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 949 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 950 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 951 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 952 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 953 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 954 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
| 955 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 956 | case cc.IsSharedDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 957 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 958 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 959 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 960 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 961 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 962 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 963 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 964 | directSharedLibDeps = append(directSharedLibDeps, ccDep) |
| 965 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) |
| 966 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 967 | case cc.IsHeaderDepTag(depTag): |
| 968 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 969 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 970 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 971 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 972 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 973 | depPaths.CrtBegin = linkObject |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 974 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 975 | depPaths.CrtEnd = linkObject |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 979 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 980 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 981 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 982 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 983 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 984 | |
| 985 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
| 986 | switch depTag { |
| 987 | case android.SourceDepTag: |
| 988 | // These are usually genrules which don't have per-target variants. |
| 989 | directSrcDeps = append(directSrcDeps, srcDep) |
| 990 | } |
| 991 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 992 | }) |
| 993 | |
| 994 | var rlibDepFiles RustLibraries |
| 995 | for _, dep := range directRlibDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 996 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 997 | } |
| 998 | var dylibDepFiles RustLibraries |
| 999 | for _, dep := range directDylibDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1000 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1001 | } |
| 1002 | var procMacroDepFiles RustLibraries |
| 1003 | for _, dep := range directProcMacroDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1004 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | var staticLibDepFiles android.Paths |
| 1008 | for _, dep := range directStaticLibDeps { |
| 1009 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 1010 | } |
| 1011 | |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1012 | var sharedLibFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1013 | var sharedLibDepFiles android.Paths |
| 1014 | for _, dep := range directSharedLibDeps { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1015 | sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path()) |
| 1016 | if dep.Toc().Valid() { |
| 1017 | sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path()) |
| 1018 | } else { |
| 1019 | sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) |
| 1020 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1023 | var srcProviderDepFiles android.Paths |
| 1024 | for _, dep := range directSrcProvidersDeps { |
| 1025 | srcs, _ := dep.OutputFiles("") |
| 1026 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1027 | } |
| 1028 | for _, dep := range directSrcDeps { |
| 1029 | srcs := dep.Srcs() |
| 1030 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1031 | } |
| 1032 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1033 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1034 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 1035 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1036 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1037 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 1038 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1039 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1040 | |
| 1041 | // Dedup exported flags from dependencies |
| 1042 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1043 | depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1044 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1045 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1046 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1047 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1048 | |
| 1049 | return depPaths |
| 1050 | } |
| 1051 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1052 | func (mod *Module) InstallInData() bool { |
| 1053 | if mod.compiler == nil { |
| 1054 | return false |
| 1055 | } |
| 1056 | return mod.compiler.inData() |
| 1057 | } |
| 1058 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1059 | func linkPathFromFilePath(filepath android.Path) string { |
| 1060 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1061 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 1062 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1063 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1064 | ctx := &depsContext{ |
| 1065 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1066 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1067 | |
| 1068 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1069 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1070 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1071 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1072 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1073 | stdLinkage = "rlib-std" |
| 1074 | } |
| 1075 | |
| 1076 | rlibDepVariations := commonDepVariations |
| 1077 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1078 | rlibDepVariations = append(rlibDepVariations, |
| 1079 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1080 | } |
| 1081 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1082 | actx.AddVariationDependencies( |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1083 | append(rlibDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1084 | {Mutator: "rust_libraries", Variation: rlibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1085 | rlibDepTag, deps.Rlibs...) |
| 1086 | actx.AddVariationDependencies( |
| 1087 | append(commonDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1088 | {Mutator: "rust_libraries", Variation: dylibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1089 | dylibDepTag, deps.Dylibs...) |
| 1090 | |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1091 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1092 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1093 | if autoDep.depTag == rlibDepTag { |
| 1094 | actx.AddVariationDependencies( |
| 1095 | append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1096 | autoDep.depTag, deps.Rustlibs...) |
| 1097 | } else { |
| 1098 | actx.AddVariationDependencies( |
| 1099 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1100 | autoDep.depTag, deps.Rustlibs...) |
| 1101 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1102 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1103 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1104 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1105 | actx.AddVariationDependencies( |
| 1106 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}), |
| 1107 | rlibDepTag, deps.Stdlibs...) |
| 1108 | } else { |
| 1109 | actx.AddVariationDependencies( |
| 1110 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), |
| 1111 | dylibDepTag, deps.Stdlibs...) |
| 1112 | } |
| 1113 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1114 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1115 | blueprint.Variation{Mutator: "link", Variation: "shared"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1116 | cc.SharedDepTag(), deps.SharedLibs...) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1117 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1118 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1119 | cc.StaticDepTag(false), deps.StaticLibs...) |
| 1120 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1121 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
| 1122 | cc.StaticDepTag(true), deps.WholeStaticLibs...) |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1123 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1124 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1125 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1126 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1127 | if deps.CrtBegin != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1128 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1129 | } |
| 1130 | if deps.CrtEnd != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1131 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1134 | if mod.sourceProvider != nil { |
| 1135 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1136 | bindgen.Properties.Custom_bindgen != "" { |
| 1137 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1138 | bindgen.Properties.Custom_bindgen) |
| 1139 | } |
| 1140 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1141 | // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1142 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1145 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1146 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1147 | mod.beginMutator(ctx) |
| 1148 | } |
| 1149 | } |
| 1150 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1151 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1152 | ctx := &baseModuleContext{ |
| 1153 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1154 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1155 | |
| 1156 | mod.begin(ctx) |
| 1157 | } |
| 1158 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1159 | func (mod *Module) Name() string { |
| 1160 | name := mod.ModuleBase.Name() |
| 1161 | if p, ok := mod.compiler.(interface { |
| 1162 | Name(string) string |
| 1163 | }); ok { |
| 1164 | name = p.Name(name) |
| 1165 | } |
| 1166 | return name |
| 1167 | } |
| 1168 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1169 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1170 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1171 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1175 | var _ android.HostToolProvider = (*Module)(nil) |
| 1176 | |
| 1177 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1178 | if !mod.Host() { |
| 1179 | return android.OptionalPath{} |
| 1180 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1181 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1182 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1183 | } |
| 1184 | return android.OptionalPath{} |
| 1185 | } |
| 1186 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1187 | var _ android.ApexModule = (*Module)(nil) |
| 1188 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1189 | func (mod *Module) minSdkVersion() string { |
| 1190 | return String(mod.Properties.Min_sdk_version) |
| 1191 | } |
| 1192 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1193 | var _ android.ApexModule = (*Module)(nil) |
| 1194 | |
| 1195 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1196 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1197 | minSdkVersion := mod.minSdkVersion() |
| 1198 | if minSdkVersion == "apex_inherit" { |
| 1199 | return nil |
| 1200 | } |
| 1201 | if minSdkVersion == "" { |
| 1202 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1203 | } |
| 1204 | |
| 1205 | // Not using nativeApiLevelFromUser because the context here is not |
| 1206 | // necessarily a native context. |
| 1207 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1208 | if err != nil { |
| 1209 | return err |
| 1210 | } |
| 1211 | |
| 1212 | if ver.GreaterThan(sdkVersion) { |
| 1213 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1214 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1215 | return nil |
| 1216 | } |
| 1217 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1218 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1219 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1220 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1221 | |
| 1222 | if ccm, ok := dep.(*cc.Module); ok { |
| 1223 | if ccm.HasStubsVariants() { |
| 1224 | if cc.IsSharedDepTag(depTag) { |
| 1225 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1226 | return false |
| 1227 | } |
| 1228 | if cc.IsRuntimeDepTag(depTag) { |
| 1229 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1230 | return false |
| 1231 | } |
| 1232 | |
| 1233 | if cc.IsHeaderDepTag(depTag) { |
| 1234 | return false |
| 1235 | } |
| 1236 | } |
| 1237 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1238 | // shared_lib dependency from a static lib is considered as crossing |
| 1239 | // the APEX boundary because the dependency doesn't actually is |
| 1240 | // linked; the dependency is used only during the compilation phase. |
| 1241 | return false |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if depTag == procMacroDepTag { |
| 1246 | return false |
| 1247 | } |
| 1248 | |
| 1249 | return true |
| 1250 | } |
| 1251 | |
| 1252 | // Overrides ApexModule.IsInstallabeToApex() |
| 1253 | func (mod *Module) IsInstallableToApex() bool { |
| 1254 | if mod.compiler != nil { |
| 1255 | if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) { |
| 1256 | return true |
| 1257 | } |
| 1258 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1259 | return true |
| 1260 | } |
| 1261 | } |
| 1262 | return false |
| 1263 | } |
| 1264 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1265 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1266 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1267 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1268 | if strings.HasPrefix(libName, "lib") { |
| 1269 | libName = libName[3:] |
| 1270 | return libName, true |
| 1271 | } |
| 1272 | return "", false |
| 1273 | } |
| 1274 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1275 | var Bool = proptools.Bool |
| 1276 | var BoolDefault = proptools.BoolDefault |
| 1277 | var String = proptools.String |
| 1278 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1279 | |
| 1280 | var _ android.OutputFileProducer = (*Module)(nil) |