Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 19 | |
| 20 | "android/soong/android" |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 21 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // This file contains support for using cc library modules within an sdk. |
| 27 | |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 28 | var sharedLibrarySdkMemberType = &librarySdkMemberType{ |
| 29 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 30 | PropertyName: "native_shared_libs", |
| 31 | SupportsSdk: true, |
| 32 | HostOsDependent: true, |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 33 | }, |
| 34 | prebuiltModuleType: "cc_prebuilt_library_shared", |
| 35 | linkTypes: []string{"shared"}, |
| 36 | } |
| 37 | |
| 38 | var staticLibrarySdkMemberType = &librarySdkMemberType{ |
| 39 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 40 | PropertyName: "native_static_libs", |
| 41 | SupportsSdk: true, |
| 42 | HostOsDependent: true, |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 43 | }, |
| 44 | prebuiltModuleType: "cc_prebuilt_library_static", |
| 45 | linkTypes: []string{"static"}, |
| 46 | } |
| 47 | |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 48 | var staticAndSharedLibrarySdkMemberType = &librarySdkMemberType{ |
| 49 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 50 | PropertyName: "native_libs", |
| 51 | SupportsSdk: true, |
| 52 | HostOsDependent: true, |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 53 | }, |
| 54 | prebuiltModuleType: "cc_prebuilt_library", |
| 55 | linkTypes: []string{"static", "shared"}, |
| 56 | } |
| 57 | |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 58 | func init() { |
| 59 | // Register sdk member types. |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 60 | android.RegisterSdkMemberType(sharedLibrarySdkMemberType) |
| 61 | android.RegisterSdkMemberType(staticLibrarySdkMemberType) |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 62 | android.RegisterSdkMemberType(staticAndSharedLibrarySdkMemberType) |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | type librarySdkMemberType struct { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 66 | android.SdkMemberTypeBase |
| 67 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 68 | prebuiltModuleType string |
| 69 | |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 70 | noOutputFiles bool // True if there are no srcs files. |
| 71 | |
| 72 | // The set of link types supported. A set of "static", "shared", or nil to |
| 73 | // skip link type variations. |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 74 | linkTypes []string |
| 75 | } |
| 76 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 77 | func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
Paul Duffin | 93b750e | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 78 | // The base set of targets which does not include native bridge targets. |
| 79 | defaultTargets := ctx.MultiTargets() |
| 80 | |
| 81 | // The lazily created list of native bridge targets. |
| 82 | var includeNativeBridgeTargets []android.Target |
| 83 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 84 | for _, lib := range names { |
Paul Duffin | 93b750e | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 85 | targets := defaultTargets |
| 86 | |
| 87 | // If native bridge support is required in the sdk snapshot then add native bridge targets to |
| 88 | // the basic list of targets that are required. |
| 89 | nativeBridgeSupport := ctx.RequiresTrait(lib, nativeBridgeSdkTrait) |
| 90 | if nativeBridgeSupport && ctx.Device() { |
| 91 | // If not already computed then compute the list of native bridge targets. |
| 92 | if includeNativeBridgeTargets == nil { |
| 93 | includeNativeBridgeTargets = append([]android.Target{}, defaultTargets...) |
| 94 | allAndroidTargets := ctx.Config().Targets[android.Android] |
| 95 | for _, possibleNativeBridgeTarget := range allAndroidTargets { |
| 96 | if possibleNativeBridgeTarget.NativeBridge == android.NativeBridgeEnabled { |
| 97 | includeNativeBridgeTargets = append(includeNativeBridgeTargets, possibleNativeBridgeTarget) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Include the native bridge targets as well. |
| 103 | targets = includeNativeBridgeTargets |
| 104 | } |
Paul Duffin | b1f0f2a | 2021-09-09 17:06:07 +0100 | [diff] [blame] | 105 | |
| 106 | // memberDependency encapsulates information about the dependencies to add for this member. |
| 107 | type memberDependency struct { |
| 108 | // The targets to depend upon. |
| 109 | targets []android.Target |
| 110 | |
| 111 | // Additional image variations to depend upon, is either nil for no image variation or |
| 112 | // contains a single image variation. |
| 113 | imageVariations []blueprint.Variation |
| 114 | } |
| 115 | |
| 116 | // Extract the name and version from the module name. |
| 117 | name, version := StubsLibNameAndVersion(lib) |
| 118 | if version == "" { |
| 119 | version = "latest" |
| 120 | } |
| 121 | |
| 122 | // Compute the set of dependencies to add. |
| 123 | var memberDependencies []memberDependency |
| 124 | if ctx.Host() { |
| 125 | // Host does not support image variations so add a dependency without any. |
| 126 | memberDependencies = append(memberDependencies, memberDependency{ |
| 127 | targets: targets, |
| 128 | }) |
| 129 | } else { |
| 130 | // Otherwise, this is targeting the device so add a dependency on the core image variation |
| 131 | // (image:""). |
| 132 | memberDependencies = append(memberDependencies, memberDependency{ |
| 133 | imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.CoreVariation}}, |
| 134 | targets: targets, |
| 135 | }) |
Paul Duffin | 6369622 | 2021-09-06 10:28:34 +0100 | [diff] [blame] | 136 | |
Paul Duffin | 12a0a31 | 2021-09-15 17:25:10 +0100 | [diff] [blame^] | 137 | // If required add additional dependencies on the image:ramdisk variants. |
| 138 | if ctx.RequiresTrait(lib, ramdiskImageRequiredSdkTrait) { |
| 139 | memberDependencies = append(memberDependencies, memberDependency{ |
| 140 | imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.RamdiskVariation}}, |
| 141 | // Only add a dependency on the first target as that is the only one which will have an |
| 142 | // image:ramdisk variant. |
| 143 | targets: targets[:1], |
| 144 | }) |
| 145 | } |
| 146 | |
Paul Duffin | 6369622 | 2021-09-06 10:28:34 +0100 | [diff] [blame] | 147 | // If required add additional dependencies on the image:recovery variants. |
| 148 | if ctx.RequiresTrait(lib, recoveryImageRequiredSdkTrait) { |
| 149 | memberDependencies = append(memberDependencies, memberDependency{ |
| 150 | imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.RecoveryVariation}}, |
| 151 | // Only add a dependency on the first target as that is the only one which will have an |
| 152 | // image:recovery variant. |
| 153 | targets: targets[:1], |
| 154 | }) |
| 155 | } |
Paul Duffin | b1f0f2a | 2021-09-09 17:06:07 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // For each dependency in the list add dependencies on the targets with the correct variations. |
| 159 | for _, dependency := range memberDependencies { |
| 160 | // For each target add a dependency on the target with any additional dependencies. |
| 161 | for _, target := range dependency.targets { |
| 162 | // Get the variations for the target. |
| 163 | variations := target.Variations() |
| 164 | |
| 165 | // Add any additional dependencies needed. |
| 166 | variations = append(variations, dependency.imageVariations...) |
| 167 | |
| 168 | if mt.linkTypes == nil { |
| 169 | // No link types are supported so add a dependency directly. |
| 170 | ctx.AddFarVariationDependencies(variations, dependencyTag, name) |
| 171 | } else { |
| 172 | // Otherwise, add a dependency on each supported link type in turn. |
| 173 | for _, linkType := range mt.linkTypes { |
| 174 | libVariations := append(variations, |
| 175 | blueprint.Variation{Mutator: "link", Variation: linkType}) |
| 176 | // If this is for the device and a shared link type then add a dependency onto the |
| 177 | // appropriate version specific variant of the module. |
| 178 | if ctx.Device() && linkType == "shared" { |
| 179 | libVariations = append(libVariations, |
| 180 | blueprint.Variation{Mutator: "version", Variation: version}) |
| 181 | } |
| 182 | ctx.AddFarVariationDependencies(libVariations, dependencyTag, name) |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 183 | } |
Paul Duffin | 91756d2 | 2020-02-21 16:29:57 +0000 | [diff] [blame] | 184 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 191 | // Check the module to see if it can be used with this module type. |
| 192 | if m, ok := module.(*Module); ok { |
| 193 | for _, allowableMemberType := range m.sdkMemberTypes { |
| 194 | if allowableMemberType == mt { |
| 195 | return true |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return false |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 203 | func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 204 | pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType) |
Paul Duffin | 0c394f3 | 2020-03-05 14:09:58 +0000 | [diff] [blame] | 205 | |
| 206 | ccModule := member.Variants()[0].(*Module) |
| 207 | |
Paul Duffin | 93b750e | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 208 | if ctx.RequiresTrait(nativeBridgeSdkTrait) { |
| 209 | pbm.AddProperty("native_bridge_supported", true) |
| 210 | } |
| 211 | |
Paul Duffin | 12a0a31 | 2021-09-15 17:25:10 +0100 | [diff] [blame^] | 212 | if ctx.RequiresTrait(ramdiskImageRequiredSdkTrait) { |
| 213 | pbm.AddProperty("ramdisk_available", true) |
| 214 | } |
| 215 | |
Paul Duffin | 6369622 | 2021-09-06 10:28:34 +0100 | [diff] [blame] | 216 | if ctx.RequiresTrait(recoveryImageRequiredSdkTrait) { |
Paul Duffin | d6abaa7 | 2020-09-07 16:39:22 +0100 | [diff] [blame] | 217 | pbm.AddProperty("recovery_available", true) |
| 218 | } |
| 219 | |
Paul Duffin | d1edbd4 | 2020-08-13 19:45:31 +0100 | [diff] [blame] | 220 | if proptools.Bool(ccModule.VendorProperties.Vendor_available) { |
| 221 | pbm.AddProperty("vendor_available", true) |
| 222 | } |
| 223 | |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 224 | if proptools.Bool(ccModule.VendorProperties.Odm_available) { |
| 225 | pbm.AddProperty("odm_available", true) |
| 226 | } |
| 227 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 228 | if proptools.Bool(ccModule.VendorProperties.Product_available) { |
| 229 | pbm.AddProperty("product_available", true) |
| 230 | } |
| 231 | |
Paul Duffin | 0c394f3 | 2020-03-05 14:09:58 +0000 | [diff] [blame] | 232 | sdkVersion := ccModule.SdkVersion() |
| 233 | if sdkVersion != "" { |
| 234 | pbm.AddProperty("sdk_version", sdkVersion) |
| 235 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 236 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 237 | stl := ccModule.stl.Properties.Stl |
| 238 | if stl != nil { |
Paul Duffin | 0174d8d | 2020-03-11 18:42:08 +0000 | [diff] [blame] | 239 | pbm.AddProperty("stl", proptools.String(stl)) |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 240 | } |
Martin Stjernholm | 47ed352 | 2020-06-17 22:52:25 +0100 | [diff] [blame] | 241 | |
| 242 | if lib, ok := ccModule.linker.(*libraryDecorator); ok { |
| 243 | uhs := lib.Properties.Unique_host_soname |
| 244 | if uhs != nil { |
| 245 | pbm.AddProperty("unique_host_soname", proptools.Bool(uhs)) |
| 246 | } |
| 247 | } |
| 248 | |
Paul Duffin | 0174d8d | 2020-03-11 18:42:08 +0000 | [diff] [blame] | 249 | return pbm |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 250 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 251 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 252 | func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 253 | return &nativeLibInfoProperties{memberType: mt} |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Liz Kammer | b6a55bf | 2021-04-12 15:42:51 -0400 | [diff] [blame] | 256 | func isBazelOutDirectory(p android.Path) bool { |
| 257 | _, bazel := p.(android.BazelOutPath) |
| 258 | return bazel |
| 259 | } |
| 260 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 261 | func isGeneratedHeaderDirectory(p android.Path) bool { |
| 262 | _, gen := p.(android.WritablePath) |
Liz Kammer | b6a55bf | 2021-04-12 15:42:51 -0400 | [diff] [blame] | 263 | // TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need |
| 264 | // to support generated headers in mixed builds. |
| 265 | return gen && !isBazelOutDirectory(p) |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 268 | type includeDirsProperty struct { |
| 269 | // Accessor to retrieve the paths |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 270 | pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 271 | |
| 272 | // The name of the property in the prebuilt library, "" means there is no property. |
| 273 | propertyName string |
| 274 | |
| 275 | // The directory within the snapshot directory into which items should be copied. |
| 276 | snapshotDir string |
| 277 | |
| 278 | // True if the items on the path should be copied. |
| 279 | copy bool |
| 280 | |
| 281 | // True if the paths represent directories, files if they represent files. |
| 282 | dirs bool |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 285 | var includeDirProperties = []includeDirsProperty{ |
| 286 | { |
| 287 | // ExportedIncludeDirs lists directories that contains some header files to be |
| 288 | // copied into a directory in the snapshot. The snapshot directories must be added to |
| 289 | // the export_include_dirs property in the prebuilt module in the snapshot. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 290 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 291 | propertyName: "export_include_dirs", |
| 292 | snapshotDir: nativeIncludeDir, |
| 293 | copy: true, |
| 294 | dirs: true, |
| 295 | }, |
| 296 | { |
| 297 | // ExportedSystemIncludeDirs lists directories that contains some system header files to |
| 298 | // be copied into a directory in the snapshot. The snapshot directories must be added to |
| 299 | // the export_system_include_dirs property in the prebuilt module in the snapshot. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 300 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 301 | propertyName: "export_system_include_dirs", |
| 302 | snapshotDir: nativeIncludeDir, |
| 303 | copy: true, |
| 304 | dirs: true, |
| 305 | }, |
| 306 | { |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 307 | // ExportedGeneratedIncludeDirs lists directories that contains some header files |
| 308 | // that are explicitly listed in the ExportedGeneratedHeaders property. So, the contents |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 309 | // of these directories do not need to be copied, but these directories do need adding to |
| 310 | // the export_include_dirs property in the prebuilt module in the snapshot. |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 311 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 312 | propertyName: "export_include_dirs", |
| 313 | snapshotDir: nativeGeneratedIncludeDir, |
| 314 | copy: false, |
| 315 | dirs: true, |
| 316 | }, |
| 317 | { |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 318 | // ExportedGeneratedHeaders lists header files that are in one of the directories |
| 319 | // specified in ExportedGeneratedIncludeDirs must be copied into the snapshot. |
| 320 | // As they are in a directory in ExportedGeneratedIncludeDirs they do not need adding to a |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 321 | // property in the prebuilt module in the snapshot. |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 322 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedHeaders }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 323 | propertyName: "", |
| 324 | snapshotDir: nativeGeneratedIncludeDir, |
| 325 | copy: true, |
| 326 | dirs: false, |
| 327 | }, |
| 328 | } |
| 329 | |
| 330 | // Add properties that may, or may not, be arch specific. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 331 | func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) { |
| 332 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 333 | outputProperties.AddProperty("sanitize", &libInfo.Sanitize) |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 334 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 335 | // Copy the generated library to the snapshot and add a reference to it in the .bp module. |
| 336 | if libInfo.outputFile != nil { |
| 337 | nativeLibraryPath := nativeLibraryPathFor(libInfo) |
| 338 | builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath) |
| 339 | outputProperties.AddProperty("srcs", []string{nativeLibraryPath}) |
| 340 | } |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 341 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 342 | if len(libInfo.SharedLibs) > 0 { |
| 343 | outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false)) |
| 344 | } |
| 345 | |
Martin Stjernholm | 10566a0 | 2020-03-24 01:19:52 +0000 | [diff] [blame] | 346 | // SystemSharedLibs needs to be propagated if it's a list, even if it's empty, |
| 347 | // so check for non-nil instead of nonzero length. |
| 348 | if libInfo.SystemSharedLibs != nil { |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 349 | outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false)) |
| 350 | } |
| 351 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 352 | // Map from property name to the include dirs to add to the prebuilt module in the snapshot. |
| 353 | includeDirs := make(map[string][]string) |
| 354 | |
| 355 | // Iterate over each include directory property, copying files and collating property |
| 356 | // values where necessary. |
| 357 | for _, propertyInfo := range includeDirProperties { |
| 358 | // Calculate the base directory in the snapshot into which the files will be copied. |
Paul Duffin | 96f1832 | 2021-09-03 17:53:38 +0100 | [diff] [blame] | 359 | // lib.archSubDir is "" for common properties. |
| 360 | targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archSubDir, propertyInfo.snapshotDir) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 361 | |
| 362 | propertyName := propertyInfo.propertyName |
| 363 | |
| 364 | // Iterate over each path in one of the include directory properties. |
| 365 | for _, path := range propertyInfo.pathsGetter(libInfo) { |
Paul Duffin | 42dd4e6 | 2021-02-22 11:35:24 +0000 | [diff] [blame] | 366 | inputPath := path.String() |
| 367 | |
| 368 | // Map the input path to a snapshot relative path. The mapping is independent of the module |
| 369 | // that references them so that if multiple modules within the same snapshot export the same |
| 370 | // header files they end up in the same place in the snapshot and so do not get duplicated. |
| 371 | targetRelativePath := inputPath |
| 372 | if isGeneratedHeaderDirectory(path) { |
| 373 | // Remove everything up to the .intermediates/ from the generated output directory to |
| 374 | // leave a module relative path. |
| 375 | base := android.PathForIntermediates(sdkModuleContext, "") |
| 376 | targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath) |
| 377 | } |
| 378 | |
| 379 | snapshotRelativePath := filepath.Join(targetDir, targetRelativePath) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 380 | |
| 381 | // Copy the files/directories when necessary. |
| 382 | if propertyInfo.copy { |
| 383 | if propertyInfo.dirs { |
| 384 | // When copying a directory glob and copy all the headers within it. |
| 385 | // TODO(jiyong) copy headers having other suffixes |
Paul Duffin | 42dd4e6 | 2021-02-22 11:35:24 +0000 | [diff] [blame] | 386 | headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 387 | for _, file := range headers { |
| 388 | src := android.PathForSource(sdkModuleContext, file) |
Paul Duffin | 42dd4e6 | 2021-02-22 11:35:24 +0000 | [diff] [blame] | 389 | |
| 390 | // The destination path in the snapshot is constructed from the snapshot relative path |
| 391 | // of the input directory and the input directory relative path of the header file. |
| 392 | inputRelativePath := android.Rel(sdkModuleContext, inputPath, file) |
| 393 | dest := filepath.Join(snapshotRelativePath, inputRelativePath) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 394 | builder.CopyToSnapshot(src, dest) |
| 395 | } |
| 396 | } else { |
Paul Duffin | 42dd4e6 | 2021-02-22 11:35:24 +0000 | [diff] [blame] | 397 | // Otherwise, just copy the file to its snapshot relative path. |
| 398 | builder.CopyToSnapshot(path, snapshotRelativePath) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | // Only directories are added to a property. |
| 403 | if propertyInfo.dirs { |
Paul Duffin | 42dd4e6 | 2021-02-22 11:35:24 +0000 | [diff] [blame] | 404 | includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 405 | } |
| 406 | } |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 407 | } |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 408 | |
| 409 | // Add the collated include dir properties to the output. |
Colin Cross | 2c03361 | 2020-09-11 15:44:31 -0700 | [diff] [blame] | 410 | for _, property := range android.SortedStringKeys(includeDirs) { |
| 411 | outputProperties.AddProperty(property, includeDirs[property]) |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 412 | } |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 413 | |
Martin Stjernholm | 618b671 | 2020-09-24 16:53:04 +0100 | [diff] [blame] | 414 | if len(libInfo.StubsVersions) > 0 { |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 415 | stubsSet := outputProperties.AddPropertySet("stubs") |
Martin Stjernholm | 618b671 | 2020-09-24 16:53:04 +0100 | [diff] [blame] | 416 | stubsSet.AddProperty("versions", libInfo.StubsVersions) |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 417 | } |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 420 | const ( |
| 421 | nativeIncludeDir = "include" |
| 422 | nativeGeneratedIncludeDir = "include_gen" |
| 423 | nativeStubDir = "lib" |
| 424 | ) |
| 425 | |
| 426 | // path to the native library. Relative to <sdk_root>/<api_dir> |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 427 | func nativeLibraryPathFor(lib *nativeLibInfoProperties) string { |
Paul Duffin | 96f1832 | 2021-09-03 17:53:38 +0100 | [diff] [blame] | 428 | return filepath.Join(lib.OsPrefix(), lib.archSubDir, |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 429 | nativeStubDir, lib.outputFile.Base()) |
| 430 | } |
| 431 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 432 | // nativeLibInfoProperties represents properties of a native lib |
| 433 | // |
| 434 | // The exported (capitalized) fields will be examined and may be changed during common value extraction. |
| 435 | // The unexported fields will be left untouched. |
| 436 | type nativeLibInfoProperties struct { |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 437 | android.SdkMemberPropertiesBase |
| 438 | |
| 439 | memberType *librarySdkMemberType |
| 440 | |
Paul Duffin | 96f1832 | 2021-09-03 17:53:38 +0100 | [diff] [blame] | 441 | // archSubDir is the subdirectory within the OS directory in the sdk snapshot into which arch |
| 442 | // specific files will be copied. |
| 443 | // |
| 444 | // It is not exported since any value other than "" is always going to be arch specific. |
| 445 | // This is "" for non-arch specific common properties. |
| 446 | archSubDir string |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 447 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 448 | // The list of possibly common exported include dirs. |
| 449 | // |
| 450 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 451 | ExportedIncludeDirs android.Paths `android:"arch_variant"` |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 452 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 453 | // The list of arch specific exported generated include dirs. |
| 454 | // |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 455 | // This field is exported as its contents may not be arch specific, e.g. protos. |
| 456 | ExportedGeneratedIncludeDirs android.Paths `android:"arch_variant"` |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 457 | |
| 458 | // The list of arch specific exported generated header files. |
| 459 | // |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 460 | // This field is exported as its contents may not be arch specific, e.g. protos. |
| 461 | ExportedGeneratedHeaders android.Paths `android:"arch_variant"` |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 462 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 463 | // The list of possibly common exported system include dirs. |
| 464 | // |
| 465 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 466 | ExportedSystemIncludeDirs android.Paths `android:"arch_variant"` |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 467 | |
| 468 | // The list of possibly common exported flags. |
| 469 | // |
| 470 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 471 | ExportedFlags []string `android:"arch_variant"` |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 472 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 473 | // The set of shared libraries |
| 474 | // |
| 475 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 476 | SharedLibs []string `android:"arch_variant"` |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 477 | |
Martin Stjernholm | 10566a0 | 2020-03-24 01:19:52 +0000 | [diff] [blame] | 478 | // The set of system shared libraries. Note nil and [] are semantically |
| 479 | // distinct - see BaseLinkerProperties.System_shared_libs. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 480 | // |
| 481 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 482 | SystemSharedLibs []string `android:"arch_variant"` |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 483 | |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 484 | // The specific stubs version for the lib variant, or empty string if stubs |
| 485 | // are not in use. |
Paul Duffin | 7a1f7f3 | 2020-05-04 15:32:08 +0100 | [diff] [blame] | 486 | // |
Martin Stjernholm | 618b671 | 2020-09-24 16:53:04 +0100 | [diff] [blame] | 487 | // Marked 'ignored-on-host' as the AllStubsVersions() from which this is |
| 488 | // initialized is not set on host and the stubs.versions property which this |
| 489 | // is written to does not vary by arch so cannot be android specific. |
| 490 | StubsVersions []string `sdk:"ignored-on-host"` |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 491 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 492 | // Value of SanitizeProperties.Sanitize. Several - but not all - of these |
| 493 | // affect the expanded variants. All are propagated to avoid entangling the |
| 494 | // sanitizer logic with the snapshot generation. |
| 495 | Sanitize SanitizeUserProps `android:"arch_variant"` |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 496 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 497 | // outputFile is not exported as it is always arch specific. |
| 498 | outputFile android.Path |
| 499 | } |
| 500 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 501 | func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Martin Stjernholm | 59e0c7a | 2020-10-28 23:38:33 +0000 | [diff] [blame] | 502 | addOutputFile := true |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 503 | ccModule := variant.(*Module) |
| 504 | |
Martin Stjernholm | 59e0c7a | 2020-10-28 23:38:33 +0000 | [diff] [blame] | 505 | if s := ccModule.sanitize; s != nil { |
| 506 | // We currently do not capture sanitizer flags for libs with sanitizers |
| 507 | // enabled, because they may vary among variants that cannot be represented |
| 508 | // in the input blueprint files. In particular, sanitizerDepsMutator enables |
| 509 | // various sanitizers on dependencies, but in many cases only on static |
| 510 | // ones, and we cannot specify sanitizer flags at the link type level (i.e. |
| 511 | // in StaticOrSharedProperties). |
| 512 | if s.isUnsanitizedVariant() { |
| 513 | // This still captures explicitly disabled sanitizers, which may be |
| 514 | // necessary to avoid cyclic dependencies. |
| 515 | p.Sanitize = s.Properties.Sanitize |
| 516 | } else { |
| 517 | // Do not add the output file to the snapshot if we don't represent it |
| 518 | // properly. |
| 519 | addOutputFile = false |
| 520 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 523 | exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo) |
| 524 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 525 | // Separate out the generated include dirs (which are arch specific) from the |
| 526 | // include dirs (which may not be). |
| 527 | exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate( |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 528 | exportedInfo.IncludeDirs, isGeneratedHeaderDirectory) |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 529 | |
Paul Duffin | 93b750e | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 530 | target := ccModule.Target() |
| 531 | p.archSubDir = target.Arch.ArchType.String() |
| 532 | if target.NativeBridge == android.NativeBridgeEnabled { |
| 533 | p.archSubDir += "_native_bridge" |
| 534 | } |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 535 | |
| 536 | // Make sure that the include directories are unique. |
| 537 | p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs) |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 538 | p.ExportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs) |
Paul Duffin | ab5467d | 2020-06-18 16:31:04 +0100 | [diff] [blame] | 539 | |
| 540 | // Take a copy before filtering out duplicates to avoid changing the slice owned by the |
| 541 | // ccModule. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 542 | dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...) |
Paul Duffin | ab5467d | 2020-06-18 16:31:04 +0100 | [diff] [blame] | 543 | p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs) |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 544 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 545 | p.ExportedFlags = exportedInfo.Flags |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 546 | if ccModule.linker != nil { |
| 547 | specifiedDeps := specifiedDeps{} |
| 548 | specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps) |
| 549 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 550 | if lib := ccModule.library; lib != nil { |
| 551 | if !lib.hasStubsVariants() { |
| 552 | // Propagate dynamic dependencies for implementation libs, but not stubs. |
| 553 | p.SharedLibs = specifiedDeps.sharedLibs |
| 554 | } else { |
| 555 | // TODO(b/169373910): 1. Only output the specific version (from |
| 556 | // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all |
| 557 | // the versioned stub libs are retained in the prebuilt tree; currently only |
| 558 | // the stub corresponding to ccModule.StubsVersion() is. |
| 559 | p.StubsVersions = lib.allStubsVersions() |
| 560 | } |
Martin Stjernholm | cc330d6 | 2020-04-21 20:45:35 +0100 | [diff] [blame] | 561 | } |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 562 | p.SystemSharedLibs = specifiedDeps.systemSharedLibs |
| 563 | } |
Paul Duffin | 7a7d067 | 2021-02-17 12:17:40 +0000 | [diff] [blame] | 564 | p.ExportedGeneratedHeaders = exportedInfo.GeneratedHeaders |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 565 | |
Martin Stjernholm | 59e0c7a | 2020-10-28 23:38:33 +0000 | [diff] [blame] | 566 | if !p.memberType.noOutputFiles && addOutputFile { |
| 567 | p.outputFile = getRequiredMemberOutputFile(ctx, ccModule) |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 568 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Paul Duffin | 712993c | 2020-05-05 14:11:57 +0100 | [diff] [blame] | 571 | func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path { |
| 572 | var path android.Path |
| 573 | outputFile := ccModule.OutputFile() |
| 574 | if outputFile.Valid() { |
| 575 | path = outputFile.Path() |
| 576 | } else { |
| 577 | ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule) |
| 578 | } |
| 579 | return path |
| 580 | } |
| 581 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 582 | func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
| 583 | addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet) |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 584 | } |