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