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