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