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 | |
| 77 | func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 78 | targets := mctx.MultiTargets() |
| 79 | for _, lib := range names { |
| 80 | for _, target := range targets { |
| 81 | name, version := StubsLibNameAndVersion(lib) |
| 82 | if version == "" { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 83 | version = "latest" |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 84 | } |
Colin Cross | 4250733 | 2020-08-21 16:15:23 -0700 | [diff] [blame] | 85 | variations := target.Variations() |
| 86 | if mctx.Device() { |
| 87 | variations = append(variations, |
| 88 | blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}, |
| 89 | blueprint.Variation{Mutator: "version", Variation: version}) |
| 90 | } |
Paul Duffin | 91756d2 | 2020-02-21 16:29:57 +0000 | [diff] [blame] | 91 | if mt.linkTypes == nil { |
Colin Cross | 4250733 | 2020-08-21 16:15:23 -0700 | [diff] [blame] | 92 | mctx.AddFarVariationDependencies(variations, dependencyTag, name) |
Paul Duffin | 91756d2 | 2020-02-21 16:29:57 +0000 | [diff] [blame] | 93 | } else { |
| 94 | for _, linkType := range mt.linkTypes { |
Colin Cross | 4250733 | 2020-08-21 16:15:23 -0700 | [diff] [blame] | 95 | libVariations := append(variations, |
| 96 | blueprint.Variation{Mutator: "link", Variation: linkType}) |
| 97 | mctx.AddFarVariationDependencies(libVariations, dependencyTag, name) |
Paul Duffin | 91756d2 | 2020-02-21 16:29:57 +0000 | [diff] [blame] | 98 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 105 | // Check the module to see if it can be used with this module type. |
| 106 | if m, ok := module.(*Module); ok { |
| 107 | for _, allowableMemberType := range m.sdkMemberTypes { |
| 108 | if allowableMemberType == mt { |
| 109 | return true |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return false |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 117 | func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 118 | pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType) |
Paul Duffin | 0c394f3 | 2020-03-05 14:09:58 +0000 | [diff] [blame] | 119 | |
| 120 | ccModule := member.Variants()[0].(*Module) |
| 121 | |
Paul Duffin | d6abaa7 | 2020-09-07 16:39:22 +0100 | [diff] [blame] | 122 | if proptools.Bool(ccModule.Properties.Recovery_available) { |
| 123 | pbm.AddProperty("recovery_available", true) |
| 124 | } |
| 125 | |
Paul Duffin | d1edbd4 | 2020-08-13 19:45:31 +0100 | [diff] [blame] | 126 | if proptools.Bool(ccModule.VendorProperties.Vendor_available) { |
| 127 | pbm.AddProperty("vendor_available", true) |
| 128 | } |
| 129 | |
Paul Duffin | 0c394f3 | 2020-03-05 14:09:58 +0000 | [diff] [blame] | 130 | sdkVersion := ccModule.SdkVersion() |
| 131 | if sdkVersion != "" { |
| 132 | pbm.AddProperty("sdk_version", sdkVersion) |
| 133 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 134 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 135 | stl := ccModule.stl.Properties.Stl |
| 136 | if stl != nil { |
Paul Duffin | 0174d8d | 2020-03-11 18:42:08 +0000 | [diff] [blame] | 137 | pbm.AddProperty("stl", proptools.String(stl)) |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 138 | } |
Martin Stjernholm | 47ed352 | 2020-06-17 22:52:25 +0100 | [diff] [blame] | 139 | |
| 140 | if lib, ok := ccModule.linker.(*libraryDecorator); ok { |
| 141 | uhs := lib.Properties.Unique_host_soname |
| 142 | if uhs != nil { |
| 143 | pbm.AddProperty("unique_host_soname", proptools.Bool(uhs)) |
| 144 | } |
| 145 | } |
| 146 | |
Paul Duffin | 0174d8d | 2020-03-11 18:42:08 +0000 | [diff] [blame] | 147 | return pbm |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 148 | } |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 149 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 150 | func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 151 | return &nativeLibInfoProperties{memberType: mt} |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | func isGeneratedHeaderDirectory(p android.Path) bool { |
| 155 | _, gen := p.(android.WritablePath) |
| 156 | return gen |
| 157 | } |
| 158 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 159 | type includeDirsProperty struct { |
| 160 | // Accessor to retrieve the paths |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 161 | pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 162 | |
| 163 | // The name of the property in the prebuilt library, "" means there is no property. |
| 164 | propertyName string |
| 165 | |
| 166 | // The directory within the snapshot directory into which items should be copied. |
| 167 | snapshotDir string |
| 168 | |
| 169 | // True if the items on the path should be copied. |
| 170 | copy bool |
| 171 | |
| 172 | // True if the paths represent directories, files if they represent files. |
| 173 | dirs bool |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 176 | var includeDirProperties = []includeDirsProperty{ |
| 177 | { |
| 178 | // ExportedIncludeDirs lists directories that contains some header files to be |
| 179 | // copied into a directory in the snapshot. The snapshot directories must be added to |
| 180 | // the export_include_dirs property in the prebuilt module in the snapshot. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 181 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 182 | propertyName: "export_include_dirs", |
| 183 | snapshotDir: nativeIncludeDir, |
| 184 | copy: true, |
| 185 | dirs: true, |
| 186 | }, |
| 187 | { |
| 188 | // ExportedSystemIncludeDirs lists directories that contains some system header files to |
| 189 | // be copied into a directory in the snapshot. The snapshot directories must be added to |
| 190 | // 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] | 191 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 192 | propertyName: "export_system_include_dirs", |
| 193 | snapshotDir: nativeIncludeDir, |
| 194 | copy: true, |
| 195 | dirs: true, |
| 196 | }, |
| 197 | { |
| 198 | // exportedGeneratedIncludeDirs lists directories that contains some header files |
| 199 | // that are explicitly listed in the exportedGeneratedHeaders property. So, the contents |
| 200 | // of these directories do not need to be copied, but these directories do need adding to |
| 201 | // the export_include_dirs property in the prebuilt module in the snapshot. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 202 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.exportedGeneratedIncludeDirs }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 203 | propertyName: "export_include_dirs", |
| 204 | snapshotDir: nativeGeneratedIncludeDir, |
| 205 | copy: false, |
| 206 | dirs: true, |
| 207 | }, |
| 208 | { |
| 209 | // exportedGeneratedHeaders lists header files that are in one of the directories |
| 210 | // specified in exportedGeneratedIncludeDirs must be copied into the snapshot. |
| 211 | // As they are in a directory in exportedGeneratedIncludeDirs they do not need adding to a |
| 212 | // property in the prebuilt module in the snapshot. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 213 | pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.exportedGeneratedHeaders }, |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 214 | propertyName: "", |
| 215 | snapshotDir: nativeGeneratedIncludeDir, |
| 216 | copy: true, |
| 217 | dirs: false, |
| 218 | }, |
| 219 | } |
| 220 | |
| 221 | // Add properties that may, or may not, be arch specific. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 222 | func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) { |
| 223 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame^] | 224 | outputProperties.AddProperty("sanitize", &libInfo.Sanitize) |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 225 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 226 | // Copy the generated library to the snapshot and add a reference to it in the .bp module. |
| 227 | if libInfo.outputFile != nil { |
| 228 | nativeLibraryPath := nativeLibraryPathFor(libInfo) |
| 229 | builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath) |
| 230 | outputProperties.AddProperty("srcs", []string{nativeLibraryPath}) |
| 231 | } |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 232 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 233 | if len(libInfo.SharedLibs) > 0 { |
| 234 | outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false)) |
| 235 | } |
| 236 | |
Martin Stjernholm | 10566a0 | 2020-03-24 01:19:52 +0000 | [diff] [blame] | 237 | // SystemSharedLibs needs to be propagated if it's a list, even if it's empty, |
| 238 | // so check for non-nil instead of nonzero length. |
| 239 | if libInfo.SystemSharedLibs != nil { |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 240 | outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false)) |
| 241 | } |
| 242 | |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 243 | // Map from property name to the include dirs to add to the prebuilt module in the snapshot. |
| 244 | includeDirs := make(map[string][]string) |
| 245 | |
| 246 | // Iterate over each include directory property, copying files and collating property |
| 247 | // values where necessary. |
| 248 | for _, propertyInfo := range includeDirProperties { |
| 249 | // Calculate the base directory in the snapshot into which the files will be copied. |
| 250 | // lib.ArchType is "" for common properties. |
Paul Duffin | ed62b9c | 2020-06-16 16:12:50 +0100 | [diff] [blame] | 251 | targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archType, propertyInfo.snapshotDir) |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 252 | |
| 253 | propertyName := propertyInfo.propertyName |
| 254 | |
| 255 | // Iterate over each path in one of the include directory properties. |
| 256 | for _, path := range propertyInfo.pathsGetter(libInfo) { |
| 257 | |
| 258 | // Copy the files/directories when necessary. |
| 259 | if propertyInfo.copy { |
| 260 | if propertyInfo.dirs { |
| 261 | // When copying a directory glob and copy all the headers within it. |
| 262 | // TODO(jiyong) copy headers having other suffixes |
| 263 | headers, _ := sdkModuleContext.GlobWithDeps(path.String()+"/**/*.h", nil) |
| 264 | for _, file := range headers { |
| 265 | src := android.PathForSource(sdkModuleContext, file) |
| 266 | dest := filepath.Join(targetDir, file) |
| 267 | builder.CopyToSnapshot(src, dest) |
| 268 | } |
| 269 | } else { |
| 270 | // Otherwise, just copy the files. |
| 271 | dest := filepath.Join(targetDir, libInfo.name, path.Rel()) |
| 272 | builder.CopyToSnapshot(path, dest) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // Only directories are added to a property. |
| 277 | if propertyInfo.dirs { |
| 278 | var snapshotPath string |
| 279 | if isGeneratedHeaderDirectory(path) { |
| 280 | snapshotPath = filepath.Join(targetDir, libInfo.name) |
| 281 | } else { |
| 282 | snapshotPath = filepath.Join(targetDir, path.String()) |
| 283 | } |
| 284 | |
| 285 | includeDirs[propertyName] = append(includeDirs[propertyName], snapshotPath) |
| 286 | } |
| 287 | } |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 288 | } |
Paul Duffin | 64f54b0 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 289 | |
| 290 | // Add the collated include dir properties to the output. |
Colin Cross | 2c03361 | 2020-09-11 15:44:31 -0700 | [diff] [blame] | 291 | for _, property := range android.SortedStringKeys(includeDirs) { |
| 292 | outputProperties.AddProperty(property, includeDirs[property]) |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 293 | } |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 294 | |
| 295 | if len(libInfo.StubsVersion) > 0 { |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 296 | stubsSet := outputProperties.AddPropertySet("stubs") |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 297 | stubsSet.AddProperty("versions", []string{libInfo.StubsVersion}) |
| 298 | } |
Paul Duffin | 74fc190 | 2020-01-23 11:45:03 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 301 | const ( |
| 302 | nativeIncludeDir = "include" |
| 303 | nativeGeneratedIncludeDir = "include_gen" |
| 304 | nativeStubDir = "lib" |
| 305 | ) |
| 306 | |
| 307 | // path to the native library. Relative to <sdk_root>/<api_dir> |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 308 | func nativeLibraryPathFor(lib *nativeLibInfoProperties) string { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 309 | return filepath.Join(lib.OsPrefix(), lib.archType, |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 310 | nativeStubDir, lib.outputFile.Base()) |
| 311 | } |
| 312 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 313 | // nativeLibInfoProperties represents properties of a native lib |
| 314 | // |
| 315 | // The exported (capitalized) fields will be examined and may be changed during common value extraction. |
| 316 | // The unexported fields will be left untouched. |
| 317 | type nativeLibInfoProperties struct { |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 318 | android.SdkMemberPropertiesBase |
| 319 | |
| 320 | memberType *librarySdkMemberType |
| 321 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 322 | // The name of the library, is not exported as this must not be changed during optimization. |
| 323 | name string |
| 324 | |
| 325 | // archType is not exported as if set (to a non default value) it is always arch specific. |
| 326 | // This is "" for common properties. |
| 327 | archType string |
| 328 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 329 | // The list of possibly common exported include dirs. |
| 330 | // |
| 331 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 332 | ExportedIncludeDirs android.Paths `android:"arch_variant"` |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 333 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 334 | // The list of arch specific exported generated include dirs. |
| 335 | // |
| 336 | // This field is not exported as its contents are always arch specific. |
| 337 | exportedGeneratedIncludeDirs android.Paths |
| 338 | |
| 339 | // The list of arch specific exported generated header files. |
| 340 | // |
| 341 | // This field is not exported as its contents are is always arch specific. |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 342 | exportedGeneratedHeaders android.Paths |
| 343 | |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 344 | // The list of possibly common exported system include dirs. |
| 345 | // |
| 346 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 347 | ExportedSystemIncludeDirs android.Paths `android:"arch_variant"` |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 348 | |
| 349 | // The list of possibly common exported flags. |
| 350 | // |
| 351 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 352 | ExportedFlags []string `android:"arch_variant"` |
Paul Duffin | 5efd198 | 2020-02-20 14:33:54 +0000 | [diff] [blame] | 353 | |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 354 | // The set of shared libraries |
| 355 | // |
| 356 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 357 | SharedLibs []string `android:"arch_variant"` |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 358 | |
Martin Stjernholm | 10566a0 | 2020-03-24 01:19:52 +0000 | [diff] [blame] | 359 | // The set of system shared libraries. Note nil and [] are semantically |
| 360 | // distinct - see BaseLinkerProperties.System_shared_libs. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 361 | // |
| 362 | // This field is exported as its contents may not be arch specific. |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 363 | SystemSharedLibs []string `android:"arch_variant"` |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 364 | |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 365 | // The specific stubs version for the lib variant, or empty string if stubs |
| 366 | // are not in use. |
Paul Duffin | 7a1f7f3 | 2020-05-04 15:32:08 +0100 | [diff] [blame] | 367 | // |
| 368 | // Marked 'ignored-on-host' as the StubsVersion() from which this is initialized is |
| 369 | // not set on host and the stubs.versions property which this is written to is does |
| 370 | // not vary by arch so cannot be android specific. |
| 371 | StubsVersion string `sdk:"ignored-on-host"` |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 372 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame^] | 373 | // Value of SanitizeProperties.Sanitize. Several - but not all - of these |
| 374 | // affect the expanded variants. All are propagated to avoid entangling the |
| 375 | // sanitizer logic with the snapshot generation. |
| 376 | Sanitize SanitizeUserProps `android:"arch_variant"` |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 377 | |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 378 | // outputFile is not exported as it is always arch specific. |
| 379 | outputFile android.Path |
| 380 | } |
| 381 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 382 | func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 383 | ccModule := variant.(*Module) |
| 384 | |
| 385 | // If the library has some link types then it produces an output binary file, otherwise it |
| 386 | // is header only. |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 387 | if !p.memberType.noOutputFiles { |
Paul Duffin | 712993c | 2020-05-05 14:11:57 +0100 | [diff] [blame] | 388 | p.outputFile = getRequiredMemberOutputFile(ctx, ccModule) |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | // Separate out the generated include dirs (which are arch specific) from the |
| 392 | // include dirs (which may not be). |
| 393 | exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate( |
| 394 | ccModule.ExportedIncludeDirs(), isGeneratedHeaderDirectory) |
| 395 | |
| 396 | p.name = variant.Name() |
| 397 | p.archType = ccModule.Target().Arch.ArchType.String() |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 398 | |
| 399 | // Make sure that the include directories are unique. |
| 400 | p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs) |
| 401 | p.exportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs) |
Paul Duffin | ab5467d | 2020-06-18 16:31:04 +0100 | [diff] [blame] | 402 | |
| 403 | // Take a copy before filtering out duplicates to avoid changing the slice owned by the |
| 404 | // ccModule. |
| 405 | dirs := append(android.Paths(nil), ccModule.ExportedSystemIncludeDirs()...) |
| 406 | p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs) |
Paul Duffin | 9b76c0b | 2020-03-12 10:24:35 +0000 | [diff] [blame] | 407 | |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 408 | p.ExportedFlags = ccModule.ExportedFlags() |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 409 | if ccModule.linker != nil { |
| 410 | specifiedDeps := specifiedDeps{} |
| 411 | specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps) |
| 412 | |
Martin Stjernholm | cc330d6 | 2020-04-21 20:45:35 +0100 | [diff] [blame] | 413 | if !ccModule.HasStubsVariants() { |
| 414 | // Propagate dynamic dependencies for implementation libs, but not stubs. |
| 415 | p.SharedLibs = specifiedDeps.sharedLibs |
| 416 | } |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 417 | p.SystemSharedLibs = specifiedDeps.systemSharedLibs |
| 418 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 419 | p.exportedGeneratedHeaders = ccModule.ExportedGeneratedHeaders() |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 420 | |
| 421 | if ccModule.HasStubsVariants() { |
| 422 | p.StubsVersion = ccModule.StubsVersion() |
Martin Stjernholm | c5dd4f7 | 2020-04-01 20:38:01 +0100 | [diff] [blame] | 423 | } |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 424 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame^] | 425 | if ccModule.sanitize != nil { |
| 426 | p.Sanitize = ccModule.sanitize.Properties.Sanitize |
Martin Stjernholm | fbb486f | 2020-08-21 18:43:51 +0100 | [diff] [blame] | 427 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Paul Duffin | 712993c | 2020-05-05 14:11:57 +0100 | [diff] [blame] | 430 | func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path { |
| 431 | var path android.Path |
| 432 | outputFile := ccModule.OutputFile() |
| 433 | if outputFile.Valid() { |
| 434 | path = outputFile.Path() |
| 435 | } else { |
| 436 | ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule) |
| 437 | } |
| 438 | return path |
| 439 | } |
| 440 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 441 | func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
| 442 | addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet) |
Paul Duffin | 2f6bc09 | 2019-12-13 10:40:56 +0000 | [diff] [blame] | 443 | } |