blob: 8988de2e58d4d7773f6734ec5ad0f6f73a7f4877 [file] [log] [blame]
Paul Duffin2f6bc092019-12-13 10:40:56 +00001// 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
15package cc
16
17import (
18 "path/filepath"
Paul Duffin2f6bc092019-12-13 10:40:56 +000019
20 "android/soong/android"
Martin Stjernholmcd07bce2020-03-10 22:37:59 +000021
Paul Duffin2f6bc092019-12-13 10:40:56 +000022 "github.com/google/blueprint"
Paul Duffin13f02712020-03-06 12:30:43 +000023 "github.com/google/blueprint/proptools"
Paul Duffin2f6bc092019-12-13 10:40:56 +000024)
25
26// This file contains support for using cc library modules within an sdk.
27
Paul Duffina0843f62019-12-13 19:50:38 +000028var sharedLibrarySdkMemberType = &librarySdkMemberType{
29 SdkMemberTypeBase: android.SdkMemberTypeBase{
Martin Stjernholmcaa47d72020-07-11 04:52:24 +010030 PropertyName: "native_shared_libs",
31 SupportsSdk: true,
32 HostOsDependent: true,
Paul Duffina0843f62019-12-13 19:50:38 +000033 },
34 prebuiltModuleType: "cc_prebuilt_library_shared",
35 linkTypes: []string{"shared"},
36}
37
38var staticLibrarySdkMemberType = &librarySdkMemberType{
39 SdkMemberTypeBase: android.SdkMemberTypeBase{
Martin Stjernholmcaa47d72020-07-11 04:52:24 +010040 PropertyName: "native_static_libs",
41 SupportsSdk: true,
42 HostOsDependent: true,
Paul Duffina0843f62019-12-13 19:50:38 +000043 },
44 prebuiltModuleType: "cc_prebuilt_library_static",
45 linkTypes: []string{"static"},
46}
47
Paul Duffin9b76c0b2020-03-12 10:24:35 +000048var staticAndSharedLibrarySdkMemberType = &librarySdkMemberType{
49 SdkMemberTypeBase: android.SdkMemberTypeBase{
Martin Stjernholmcaa47d72020-07-11 04:52:24 +010050 PropertyName: "native_libs",
51 SupportsSdk: true,
52 HostOsDependent: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +000053 },
54 prebuiltModuleType: "cc_prebuilt_library",
55 linkTypes: []string{"static", "shared"},
56}
57
Paul Duffin255f18e2019-12-13 11:22:16 +000058func init() {
59 // Register sdk member types.
Paul Duffina0843f62019-12-13 19:50:38 +000060 android.RegisterSdkMemberType(sharedLibrarySdkMemberType)
61 android.RegisterSdkMemberType(staticLibrarySdkMemberType)
Paul Duffin9b76c0b2020-03-12 10:24:35 +000062 android.RegisterSdkMemberType(staticAndSharedLibrarySdkMemberType)
Paul Duffin2f6bc092019-12-13 10:40:56 +000063}
64
65type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +000066 android.SdkMemberTypeBase
67
Paul Duffin2f6bc092019-12-13 10:40:56 +000068 prebuiltModuleType string
69
Martin Stjernholmcd07bce2020-03-10 22:37:59 +000070 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 Duffin2f6bc092019-12-13 10:40:56 +000074 linkTypes []string
75}
76
Paul Duffin296701e2021-07-14 10:29:36 +010077func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffin93b750e2019-11-19 19:44:10 +000078 // 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 Duffin2f6bc092019-12-13 10:40:56 +000084 for _, lib := range names {
Paul Duffin93b750e2019-11-19 19:44:10 +000085 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 Duffinb1f0f2a2021-09-09 17:06:07 +0100105
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 Duffin63696222021-09-06 10:28:34 +0100136
Paul Duffin12a0a312021-09-15 17:25:10 +0100137 // If required add additional dependencies on the image:ramdisk variants.
138 if ctx.RequiresTrait(lib, ramdiskImageRequiredSdkTrait) {
139 memberDependencies = append(memberDependencies, memberDependency{
140 imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.RamdiskVariation}},
141 // Only add a dependency on the first target as that is the only one which will have an
142 // image:ramdisk variant.
143 targets: targets[:1],
144 })
145 }
146
Paul Duffin63696222021-09-06 10:28:34 +0100147 // If required add additional dependencies on the image:recovery variants.
148 if ctx.RequiresTrait(lib, recoveryImageRequiredSdkTrait) {
149 memberDependencies = append(memberDependencies, memberDependency{
150 imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.RecoveryVariation}},
151 // Only add a dependency on the first target as that is the only one which will have an
152 // image:recovery variant.
153 targets: targets[:1],
154 })
155 }
Paul Duffinb1f0f2a2021-09-09 17:06:07 +0100156 }
157
158 // For each dependency in the list add dependencies on the targets with the correct variations.
159 for _, dependency := range memberDependencies {
160 // For each target add a dependency on the target with any additional dependencies.
161 for _, target := range dependency.targets {
162 // Get the variations for the target.
163 variations := target.Variations()
164
165 // Add any additional dependencies needed.
166 variations = append(variations, dependency.imageVariations...)
167
168 if mt.linkTypes == nil {
169 // No link types are supported so add a dependency directly.
170 ctx.AddFarVariationDependencies(variations, dependencyTag, name)
171 } else {
172 // Otherwise, add a dependency on each supported link type in turn.
173 for _, linkType := range mt.linkTypes {
174 libVariations := append(variations,
175 blueprint.Variation{Mutator: "link", Variation: linkType})
176 // If this is for the device and a shared link type then add a dependency onto the
177 // appropriate version specific variant of the module.
178 if ctx.Device() && linkType == "shared" {
179 libVariations = append(libVariations,
180 blueprint.Variation{Mutator: "version", Variation: version})
181 }
182 ctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
Colin Crossa717db72020-10-23 14:53:06 -0700183 }
Paul Duffin91756d22020-02-21 16:29:57 +0000184 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000185 }
186 }
187 }
188}
189
190func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
Paul Duffina0843f62019-12-13 19:50:38 +0000191 // Check the module to see if it can be used with this module type.
192 if m, ok := module.(*Module); ok {
193 for _, allowableMemberType := range m.sdkMemberTypes {
194 if allowableMemberType == mt {
195 return true
196 }
197 }
198 }
199
200 return false
Paul Duffin2f6bc092019-12-13 10:40:56 +0000201}
202
Paul Duffin3a4eb502020-03-19 16:11:18 +0000203func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
204 pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
Paul Duffin0c394f32020-03-05 14:09:58 +0000205
206 ccModule := member.Variants()[0].(*Module)
207
Paul Duffin93b750e2019-11-19 19:44:10 +0000208 if ctx.RequiresTrait(nativeBridgeSdkTrait) {
209 pbm.AddProperty("native_bridge_supported", true)
210 }
211
Paul Duffin12a0a312021-09-15 17:25:10 +0100212 if ctx.RequiresTrait(ramdiskImageRequiredSdkTrait) {
213 pbm.AddProperty("ramdisk_available", true)
214 }
215
Paul Duffin63696222021-09-06 10:28:34 +0100216 if ctx.RequiresTrait(recoveryImageRequiredSdkTrait) {
Paul Duffind6abaa72020-09-07 16:39:22 +0100217 pbm.AddProperty("recovery_available", true)
218 }
219
Paul Duffind1edbd42020-08-13 19:45:31 +0100220 if proptools.Bool(ccModule.VendorProperties.Vendor_available) {
221 pbm.AddProperty("vendor_available", true)
222 }
223
Justin Yunebcf0c52021-01-08 18:00:19 +0900224 if proptools.Bool(ccModule.VendorProperties.Odm_available) {
225 pbm.AddProperty("odm_available", true)
226 }
227
Justin Yun63e9ec72020-10-29 16:49:43 +0900228 if proptools.Bool(ccModule.VendorProperties.Product_available) {
229 pbm.AddProperty("product_available", true)
230 }
231
Paul Duffin0c394f32020-03-05 14:09:58 +0000232 sdkVersion := ccModule.SdkVersion()
233 if sdkVersion != "" {
234 pbm.AddProperty("sdk_version", sdkVersion)
235 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000236
Paul Duffin13f02712020-03-06 12:30:43 +0000237 stl := ccModule.stl.Properties.Stl
238 if stl != nil {
Paul Duffin0174d8d2020-03-11 18:42:08 +0000239 pbm.AddProperty("stl", proptools.String(stl))
Paul Duffin13f02712020-03-06 12:30:43 +0000240 }
Martin Stjernholm47ed3522020-06-17 22:52:25 +0100241
242 if lib, ok := ccModule.linker.(*libraryDecorator); ok {
243 uhs := lib.Properties.Unique_host_soname
244 if uhs != nil {
245 pbm.AddProperty("unique_host_soname", proptools.Bool(uhs))
246 }
247 }
248
Paul Duffin0174d8d2020-03-11 18:42:08 +0000249 return pbm
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000250}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000251
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000252func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
253 return &nativeLibInfoProperties{memberType: mt}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000254}
255
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400256func isBazelOutDirectory(p android.Path) bool {
257 _, bazel := p.(android.BazelOutPath)
258 return bazel
259}
260
Paul Duffin2f6bc092019-12-13 10:40:56 +0000261func isGeneratedHeaderDirectory(p android.Path) bool {
262 _, gen := p.(android.WritablePath)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400263 // TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
264 // to support generated headers in mixed builds.
265 return gen && !isBazelOutDirectory(p)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000266}
267
Paul Duffin64f54b02020-02-20 14:33:54 +0000268type includeDirsProperty struct {
269 // Accessor to retrieve the paths
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000270 pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths
Paul Duffin64f54b02020-02-20 14:33:54 +0000271
272 // The name of the property in the prebuilt library, "" means there is no property.
273 propertyName string
274
275 // The directory within the snapshot directory into which items should be copied.
276 snapshotDir string
277
278 // True if the items on the path should be copied.
279 copy bool
280
281 // True if the paths represent directories, files if they represent files.
282 dirs bool
Paul Duffin74fc1902020-01-23 11:45:03 +0000283}
284
Paul Duffin64f54b02020-02-20 14:33:54 +0000285var includeDirProperties = []includeDirsProperty{
286 {
287 // ExportedIncludeDirs lists directories that contains some header files to be
288 // copied into a directory in the snapshot. The snapshot directories must be added to
289 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000290 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000291 propertyName: "export_include_dirs",
292 snapshotDir: nativeIncludeDir,
293 copy: true,
294 dirs: true,
295 },
296 {
297 // ExportedSystemIncludeDirs lists directories that contains some system header files to
298 // be copied into a directory in the snapshot. The snapshot directories must be added to
299 // the export_system_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000300 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000301 propertyName: "export_system_include_dirs",
302 snapshotDir: nativeIncludeDir,
303 copy: true,
304 dirs: true,
305 },
306 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000307 // ExportedGeneratedIncludeDirs lists directories that contains some header files
308 // that are explicitly listed in the ExportedGeneratedHeaders property. So, the contents
Paul Duffin64f54b02020-02-20 14:33:54 +0000309 // of these directories do not need to be copied, but these directories do need adding to
310 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000311 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000312 propertyName: "export_include_dirs",
313 snapshotDir: nativeGeneratedIncludeDir,
314 copy: false,
315 dirs: true,
316 },
317 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000318 // ExportedGeneratedHeaders lists header files that are in one of the directories
319 // specified in ExportedGeneratedIncludeDirs must be copied into the snapshot.
320 // As they are in a directory in ExportedGeneratedIncludeDirs they do not need adding to a
Paul Duffin64f54b02020-02-20 14:33:54 +0000321 // property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000322 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedHeaders },
Paul Duffin64f54b02020-02-20 14:33:54 +0000323 propertyName: "",
324 snapshotDir: nativeGeneratedIncludeDir,
325 copy: true,
326 dirs: false,
327 },
328}
329
330// Add properties that may, or may not, be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000331func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) {
332
Martin Stjernholmb0249572020-09-15 02:32:35 +0100333 outputProperties.AddProperty("sanitize", &libInfo.Sanitize)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100334
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000335 // Copy the generated library to the snapshot and add a reference to it in the .bp module.
336 if libInfo.outputFile != nil {
337 nativeLibraryPath := nativeLibraryPathFor(libInfo)
338 builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath)
339 outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
340 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000341
Paul Duffin13f02712020-03-06 12:30:43 +0000342 if len(libInfo.SharedLibs) > 0 {
343 outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
344 }
345
Martin Stjernholm10566a02020-03-24 01:19:52 +0000346 // SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
347 // so check for non-nil instead of nonzero length.
348 if libInfo.SystemSharedLibs != nil {
Paul Duffin13f02712020-03-06 12:30:43 +0000349 outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
350 }
351
Paul Duffin64f54b02020-02-20 14:33:54 +0000352 // Map from property name to the include dirs to add to the prebuilt module in the snapshot.
353 includeDirs := make(map[string][]string)
354
355 // Iterate over each include directory property, copying files and collating property
356 // values where necessary.
357 for _, propertyInfo := range includeDirProperties {
358 // Calculate the base directory in the snapshot into which the files will be copied.
Paul Duffin96f18322021-09-03 17:53:38 +0100359 // lib.archSubDir is "" for common properties.
360 targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archSubDir, propertyInfo.snapshotDir)
Paul Duffin64f54b02020-02-20 14:33:54 +0000361
362 propertyName := propertyInfo.propertyName
363
364 // Iterate over each path in one of the include directory properties.
365 for _, path := range propertyInfo.pathsGetter(libInfo) {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000366 inputPath := path.String()
367
368 // Map the input path to a snapshot relative path. The mapping is independent of the module
369 // that references them so that if multiple modules within the same snapshot export the same
370 // header files they end up in the same place in the snapshot and so do not get duplicated.
371 targetRelativePath := inputPath
372 if isGeneratedHeaderDirectory(path) {
373 // Remove everything up to the .intermediates/ from the generated output directory to
374 // leave a module relative path.
375 base := android.PathForIntermediates(sdkModuleContext, "")
376 targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath)
377 }
378
379 snapshotRelativePath := filepath.Join(targetDir, targetRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000380
381 // Copy the files/directories when necessary.
382 if propertyInfo.copy {
383 if propertyInfo.dirs {
384 // When copying a directory glob and copy all the headers within it.
385 // TODO(jiyong) copy headers having other suffixes
Paul Duffin42dd4e62021-02-22 11:35:24 +0000386 headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil)
Paul Duffin64f54b02020-02-20 14:33:54 +0000387 for _, file := range headers {
388 src := android.PathForSource(sdkModuleContext, file)
Paul Duffin42dd4e62021-02-22 11:35:24 +0000389
390 // The destination path in the snapshot is constructed from the snapshot relative path
391 // of the input directory and the input directory relative path of the header file.
392 inputRelativePath := android.Rel(sdkModuleContext, inputPath, file)
393 dest := filepath.Join(snapshotRelativePath, inputRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000394 builder.CopyToSnapshot(src, dest)
395 }
396 } else {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000397 // Otherwise, just copy the file to its snapshot relative path.
398 builder.CopyToSnapshot(path, snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000399 }
400 }
401
402 // Only directories are added to a property.
403 if propertyInfo.dirs {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000404 includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000405 }
406 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000407 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000408
409 // Add the collated include dir properties to the output.
Colin Cross2c033612020-09-11 15:44:31 -0700410 for _, property := range android.SortedStringKeys(includeDirs) {
411 outputProperties.AddProperty(property, includeDirs[property])
Paul Duffin74fc1902020-01-23 11:45:03 +0000412 }
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100413
Martin Stjernholm618b6712020-09-24 16:53:04 +0100414 if len(libInfo.StubsVersions) > 0 {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100415 stubsSet := outputProperties.AddPropertySet("stubs")
Martin Stjernholm618b6712020-09-24 16:53:04 +0100416 stubsSet.AddProperty("versions", libInfo.StubsVersions)
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100417 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000418}
419
Paul Duffin2f6bc092019-12-13 10:40:56 +0000420const (
421 nativeIncludeDir = "include"
422 nativeGeneratedIncludeDir = "include_gen"
423 nativeStubDir = "lib"
424)
425
426// path to the native library. Relative to <sdk_root>/<api_dir>
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000427func nativeLibraryPathFor(lib *nativeLibInfoProperties) string {
Paul Duffin96f18322021-09-03 17:53:38 +0100428 return filepath.Join(lib.OsPrefix(), lib.archSubDir,
Paul Duffin2f6bc092019-12-13 10:40:56 +0000429 nativeStubDir, lib.outputFile.Base())
430}
431
Paul Duffin2f6bc092019-12-13 10:40:56 +0000432// nativeLibInfoProperties represents properties of a native lib
433//
434// The exported (capitalized) fields will be examined and may be changed during common value extraction.
435// The unexported fields will be left untouched.
436type nativeLibInfoProperties struct {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000437 android.SdkMemberPropertiesBase
438
439 memberType *librarySdkMemberType
440
Paul Duffin96f18322021-09-03 17:53:38 +0100441 // archSubDir is the subdirectory within the OS directory in the sdk snapshot into which arch
442 // specific files will be copied.
443 //
444 // It is not exported since any value other than "" is always going to be arch specific.
445 // This is "" for non-arch specific common properties.
446 archSubDir string
Paul Duffin2f6bc092019-12-13 10:40:56 +0000447
Paul Duffin5efd1982020-02-20 14:33:54 +0000448 // The list of possibly common exported include dirs.
449 //
450 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100451 ExportedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000452
Paul Duffin5efd1982020-02-20 14:33:54 +0000453 // The list of arch specific exported generated include dirs.
454 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000455 // This field is exported as its contents may not be arch specific, e.g. protos.
456 ExportedGeneratedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000457
458 // The list of arch specific exported generated header files.
459 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000460 // This field is exported as its contents may not be arch specific, e.g. protos.
461 ExportedGeneratedHeaders android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000462
Paul Duffin5efd1982020-02-20 14:33:54 +0000463 // The list of possibly common exported system include dirs.
464 //
465 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100466 ExportedSystemIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000467
468 // The list of possibly common exported flags.
469 //
470 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100471 ExportedFlags []string `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000472
Paul Duffin13f02712020-03-06 12:30:43 +0000473 // The set of shared libraries
474 //
475 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100476 SharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000477
Martin Stjernholm10566a02020-03-24 01:19:52 +0000478 // The set of system shared libraries. Note nil and [] are semantically
479 // distinct - see BaseLinkerProperties.System_shared_libs.
Paul Duffin13f02712020-03-06 12:30:43 +0000480 //
481 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100482 SystemSharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000483
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100484 // The specific stubs version for the lib variant, or empty string if stubs
485 // are not in use.
Paul Duffin7a1f7f32020-05-04 15:32:08 +0100486 //
Martin Stjernholm618b6712020-09-24 16:53:04 +0100487 // Marked 'ignored-on-host' as the AllStubsVersions() from which this is
488 // initialized is not set on host and the stubs.versions property which this
489 // is written to does not vary by arch so cannot be android specific.
490 StubsVersions []string `sdk:"ignored-on-host"`
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100491
Martin Stjernholmb0249572020-09-15 02:32:35 +0100492 // Value of SanitizeProperties.Sanitize. Several - but not all - of these
493 // affect the expanded variants. All are propagated to avoid entangling the
494 // sanitizer logic with the snapshot generation.
495 Sanitize SanitizeUserProps `android:"arch_variant"`
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100496
Paul Duffin2f6bc092019-12-13 10:40:56 +0000497 // outputFile is not exported as it is always arch specific.
498 outputFile android.Path
499}
500
Paul Duffin3a4eb502020-03-19 16:11:18 +0000501func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000502 addOutputFile := true
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000503 ccModule := variant.(*Module)
504
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000505 if s := ccModule.sanitize; s != nil {
506 // We currently do not capture sanitizer flags for libs with sanitizers
507 // enabled, because they may vary among variants that cannot be represented
508 // in the input blueprint files. In particular, sanitizerDepsMutator enables
509 // various sanitizers on dependencies, but in many cases only on static
510 // ones, and we cannot specify sanitizer flags at the link type level (i.e.
511 // in StaticOrSharedProperties).
512 if s.isUnsanitizedVariant() {
513 // This still captures explicitly disabled sanitizers, which may be
514 // necessary to avoid cyclic dependencies.
515 p.Sanitize = s.Properties.Sanitize
516 } else {
517 // Do not add the output file to the snapshot if we don't represent it
518 // properly.
519 addOutputFile = false
520 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000521 }
522
Colin Cross0de8a1e2020-09-18 14:15:30 -0700523 exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
524
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000525 // Separate out the generated include dirs (which are arch specific) from the
526 // include dirs (which may not be).
527 exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
Colin Cross0de8a1e2020-09-18 14:15:30 -0700528 exportedInfo.IncludeDirs, isGeneratedHeaderDirectory)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000529
Paul Duffin93b750e2019-11-19 19:44:10 +0000530 target := ccModule.Target()
531 p.archSubDir = target.Arch.ArchType.String()
532 if target.NativeBridge == android.NativeBridgeEnabled {
533 p.archSubDir += "_native_bridge"
534 }
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000535
536 // Make sure that the include directories are unique.
537 p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs)
Paul Duffin7a7d0672021-02-17 12:17:40 +0000538 p.ExportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs)
Paul Duffinab5467d2020-06-18 16:31:04 +0100539
540 // Take a copy before filtering out duplicates to avoid changing the slice owned by the
541 // ccModule.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700542 dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...)
Paul Duffinab5467d2020-06-18 16:31:04 +0100543 p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs)
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000544
Colin Cross0de8a1e2020-09-18 14:15:30 -0700545 p.ExportedFlags = exportedInfo.Flags
Paul Duffin13f02712020-03-06 12:30:43 +0000546 if ccModule.linker != nil {
547 specifiedDeps := specifiedDeps{}
548 specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
549
Colin Cross31076b32020-10-23 17:22:06 -0700550 if lib := ccModule.library; lib != nil {
551 if !lib.hasStubsVariants() {
552 // Propagate dynamic dependencies for implementation libs, but not stubs.
553 p.SharedLibs = specifiedDeps.sharedLibs
554 } else {
555 // TODO(b/169373910): 1. Only output the specific version (from
556 // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
557 // the versioned stub libs are retained in the prebuilt tree; currently only
558 // the stub corresponding to ccModule.StubsVersion() is.
559 p.StubsVersions = lib.allStubsVersions()
560 }
Martin Stjernholmcc330d62020-04-21 20:45:35 +0100561 }
Paul Duffin13f02712020-03-06 12:30:43 +0000562 p.SystemSharedLibs = specifiedDeps.systemSharedLibs
563 }
Paul Duffin7a7d0672021-02-17 12:17:40 +0000564 p.ExportedGeneratedHeaders = exportedInfo.GeneratedHeaders
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100565
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000566 if !p.memberType.noOutputFiles && addOutputFile {
567 p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100568 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000569}
570
Paul Duffin712993c2020-05-05 14:11:57 +0100571func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path {
572 var path android.Path
573 outputFile := ccModule.OutputFile()
574 if outputFile.Valid() {
575 path = outputFile.Path()
576 } else {
577 ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule)
578 }
579 return path
580}
581
Paul Duffin3a4eb502020-03-19 16:11:18 +0000582func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
583 addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000584}