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