blob: bed7954b26cbb9def3e98e4edcfef71e32239a6e [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 Duffin2f6bc092019-12-13 10:40:56 +0000105 for _, target := range targets {
106 name, version := StubsLibNameAndVersion(lib)
107 if version == "" {
Colin Crossd1f898e2020-08-18 18:35:15 -0700108 version = "latest"
Paul Duffin2f6bc092019-12-13 10:40:56 +0000109 }
Colin Cross42507332020-08-21 16:15:23 -0700110 variations := target.Variations()
Paul Duffin296701e2021-07-14 10:29:36 +0100111 if ctx.Device() {
Colin Cross42507332020-08-21 16:15:23 -0700112 variations = append(variations,
Colin Cross3146c5c2020-09-30 15:34:40 -0700113 blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
Colin Cross42507332020-08-21 16:15:23 -0700114 }
Paul Duffin91756d22020-02-21 16:29:57 +0000115 if mt.linkTypes == nil {
Paul Duffin296701e2021-07-14 10:29:36 +0100116 ctx.AddFarVariationDependencies(variations, dependencyTag, name)
Paul Duffin91756d22020-02-21 16:29:57 +0000117 } else {
118 for _, linkType := range mt.linkTypes {
Colin Cross42507332020-08-21 16:15:23 -0700119 libVariations := append(variations,
120 blueprint.Variation{Mutator: "link", Variation: linkType})
Paul Duffin296701e2021-07-14 10:29:36 +0100121 if ctx.Device() && linkType == "shared" {
Colin Crossa717db72020-10-23 14:53:06 -0700122 libVariations = append(libVariations,
123 blueprint.Variation{Mutator: "version", Variation: version})
124 }
Paul Duffin296701e2021-07-14 10:29:36 +0100125 ctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
Paul Duffin91756d22020-02-21 16:29:57 +0000126 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000127 }
128 }
129 }
130}
131
132func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
Paul Duffina0843f62019-12-13 19:50:38 +0000133 // Check the module to see if it can be used with this module type.
134 if m, ok := module.(*Module); ok {
135 for _, allowableMemberType := range m.sdkMemberTypes {
136 if allowableMemberType == mt {
137 return true
138 }
139 }
140 }
141
142 return false
Paul Duffin2f6bc092019-12-13 10:40:56 +0000143}
144
Paul Duffin3a4eb502020-03-19 16:11:18 +0000145func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
146 pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
Paul Duffin0c394f32020-03-05 14:09:58 +0000147
148 ccModule := member.Variants()[0].(*Module)
149
Paul Duffin93b750e2019-11-19 19:44:10 +0000150 if ctx.RequiresTrait(nativeBridgeSdkTrait) {
151 pbm.AddProperty("native_bridge_supported", true)
152 }
153
Paul Duffind6abaa72020-09-07 16:39:22 +0100154 if proptools.Bool(ccModule.Properties.Recovery_available) {
155 pbm.AddProperty("recovery_available", true)
156 }
157
Paul Duffind1edbd42020-08-13 19:45:31 +0100158 if proptools.Bool(ccModule.VendorProperties.Vendor_available) {
159 pbm.AddProperty("vendor_available", true)
160 }
161
Justin Yunebcf0c52021-01-08 18:00:19 +0900162 if proptools.Bool(ccModule.VendorProperties.Odm_available) {
163 pbm.AddProperty("odm_available", true)
164 }
165
Justin Yun63e9ec72020-10-29 16:49:43 +0900166 if proptools.Bool(ccModule.VendorProperties.Product_available) {
167 pbm.AddProperty("product_available", true)
168 }
169
Paul Duffin0c394f32020-03-05 14:09:58 +0000170 sdkVersion := ccModule.SdkVersion()
171 if sdkVersion != "" {
172 pbm.AddProperty("sdk_version", sdkVersion)
173 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000174
Paul Duffin13f02712020-03-06 12:30:43 +0000175 stl := ccModule.stl.Properties.Stl
176 if stl != nil {
Paul Duffin0174d8d2020-03-11 18:42:08 +0000177 pbm.AddProperty("stl", proptools.String(stl))
Paul Duffin13f02712020-03-06 12:30:43 +0000178 }
Martin Stjernholm47ed3522020-06-17 22:52:25 +0100179
180 if lib, ok := ccModule.linker.(*libraryDecorator); ok {
181 uhs := lib.Properties.Unique_host_soname
182 if uhs != nil {
183 pbm.AddProperty("unique_host_soname", proptools.Bool(uhs))
184 }
185 }
186
Paul Duffin0174d8d2020-03-11 18:42:08 +0000187 return pbm
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000188}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000189
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000190func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
191 return &nativeLibInfoProperties{memberType: mt}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000192}
193
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400194func isBazelOutDirectory(p android.Path) bool {
195 _, bazel := p.(android.BazelOutPath)
196 return bazel
197}
198
Paul Duffin2f6bc092019-12-13 10:40:56 +0000199func isGeneratedHeaderDirectory(p android.Path) bool {
200 _, gen := p.(android.WritablePath)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400201 // TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
202 // to support generated headers in mixed builds.
203 return gen && !isBazelOutDirectory(p)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000204}
205
Paul Duffin64f54b02020-02-20 14:33:54 +0000206type includeDirsProperty struct {
207 // Accessor to retrieve the paths
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000208 pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths
Paul Duffin64f54b02020-02-20 14:33:54 +0000209
210 // The name of the property in the prebuilt library, "" means there is no property.
211 propertyName string
212
213 // The directory within the snapshot directory into which items should be copied.
214 snapshotDir string
215
216 // True if the items on the path should be copied.
217 copy bool
218
219 // True if the paths represent directories, files if they represent files.
220 dirs bool
Paul Duffin74fc1902020-01-23 11:45:03 +0000221}
222
Paul Duffin64f54b02020-02-20 14:33:54 +0000223var includeDirProperties = []includeDirsProperty{
224 {
225 // ExportedIncludeDirs lists directories that contains some header files to be
226 // copied into a directory in the snapshot. The snapshot directories must be added to
227 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000228 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000229 propertyName: "export_include_dirs",
230 snapshotDir: nativeIncludeDir,
231 copy: true,
232 dirs: true,
233 },
234 {
235 // ExportedSystemIncludeDirs lists directories that contains some system header files to
236 // be copied into a directory in the snapshot. The snapshot directories must be added to
237 // the export_system_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000238 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000239 propertyName: "export_system_include_dirs",
240 snapshotDir: nativeIncludeDir,
241 copy: true,
242 dirs: true,
243 },
244 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000245 // ExportedGeneratedIncludeDirs lists directories that contains some header files
246 // that are explicitly listed in the ExportedGeneratedHeaders property. So, the contents
Paul Duffin64f54b02020-02-20 14:33:54 +0000247 // of these directories do not need to be copied, but these directories do need adding to
248 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000249 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000250 propertyName: "export_include_dirs",
251 snapshotDir: nativeGeneratedIncludeDir,
252 copy: false,
253 dirs: true,
254 },
255 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000256 // ExportedGeneratedHeaders lists header files that are in one of the directories
257 // specified in ExportedGeneratedIncludeDirs must be copied into the snapshot.
258 // As they are in a directory in ExportedGeneratedIncludeDirs they do not need adding to a
Paul Duffin64f54b02020-02-20 14:33:54 +0000259 // property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000260 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedHeaders },
Paul Duffin64f54b02020-02-20 14:33:54 +0000261 propertyName: "",
262 snapshotDir: nativeGeneratedIncludeDir,
263 copy: true,
264 dirs: false,
265 },
266}
267
268// Add properties that may, or may not, be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000269func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) {
270
Martin Stjernholmb0249572020-09-15 02:32:35 +0100271 outputProperties.AddProperty("sanitize", &libInfo.Sanitize)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100272
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000273 // Copy the generated library to the snapshot and add a reference to it in the .bp module.
274 if libInfo.outputFile != nil {
275 nativeLibraryPath := nativeLibraryPathFor(libInfo)
276 builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath)
277 outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
278 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000279
Paul Duffin13f02712020-03-06 12:30:43 +0000280 if len(libInfo.SharedLibs) > 0 {
281 outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
282 }
283
Martin Stjernholm10566a02020-03-24 01:19:52 +0000284 // SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
285 // so check for non-nil instead of nonzero length.
286 if libInfo.SystemSharedLibs != nil {
Paul Duffin13f02712020-03-06 12:30:43 +0000287 outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
288 }
289
Paul Duffin64f54b02020-02-20 14:33:54 +0000290 // Map from property name to the include dirs to add to the prebuilt module in the snapshot.
291 includeDirs := make(map[string][]string)
292
293 // Iterate over each include directory property, copying files and collating property
294 // values where necessary.
295 for _, propertyInfo := range includeDirProperties {
296 // Calculate the base directory in the snapshot into which the files will be copied.
Paul Duffin96f18322021-09-03 17:53:38 +0100297 // lib.archSubDir is "" for common properties.
298 targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archSubDir, propertyInfo.snapshotDir)
Paul Duffin64f54b02020-02-20 14:33:54 +0000299
300 propertyName := propertyInfo.propertyName
301
302 // Iterate over each path in one of the include directory properties.
303 for _, path := range propertyInfo.pathsGetter(libInfo) {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000304 inputPath := path.String()
305
306 // Map the input path to a snapshot relative path. The mapping is independent of the module
307 // that references them so that if multiple modules within the same snapshot export the same
308 // header files they end up in the same place in the snapshot and so do not get duplicated.
309 targetRelativePath := inputPath
310 if isGeneratedHeaderDirectory(path) {
311 // Remove everything up to the .intermediates/ from the generated output directory to
312 // leave a module relative path.
313 base := android.PathForIntermediates(sdkModuleContext, "")
314 targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath)
315 }
316
317 snapshotRelativePath := filepath.Join(targetDir, targetRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000318
319 // Copy the files/directories when necessary.
320 if propertyInfo.copy {
321 if propertyInfo.dirs {
322 // When copying a directory glob and copy all the headers within it.
323 // TODO(jiyong) copy headers having other suffixes
Paul Duffin42dd4e62021-02-22 11:35:24 +0000324 headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil)
Paul Duffin64f54b02020-02-20 14:33:54 +0000325 for _, file := range headers {
326 src := android.PathForSource(sdkModuleContext, file)
Paul Duffin42dd4e62021-02-22 11:35:24 +0000327
328 // The destination path in the snapshot is constructed from the snapshot relative path
329 // of the input directory and the input directory relative path of the header file.
330 inputRelativePath := android.Rel(sdkModuleContext, inputPath, file)
331 dest := filepath.Join(snapshotRelativePath, inputRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000332 builder.CopyToSnapshot(src, dest)
333 }
334 } else {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000335 // Otherwise, just copy the file to its snapshot relative path.
336 builder.CopyToSnapshot(path, snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000337 }
338 }
339
340 // Only directories are added to a property.
341 if propertyInfo.dirs {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000342 includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000343 }
344 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000345 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000346
347 // Add the collated include dir properties to the output.
Colin Cross2c033612020-09-11 15:44:31 -0700348 for _, property := range android.SortedStringKeys(includeDirs) {
349 outputProperties.AddProperty(property, includeDirs[property])
Paul Duffin74fc1902020-01-23 11:45:03 +0000350 }
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100351
Martin Stjernholm618b6712020-09-24 16:53:04 +0100352 if len(libInfo.StubsVersions) > 0 {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100353 stubsSet := outputProperties.AddPropertySet("stubs")
Martin Stjernholm618b6712020-09-24 16:53:04 +0100354 stubsSet.AddProperty("versions", libInfo.StubsVersions)
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100355 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000356}
357
Paul Duffin2f6bc092019-12-13 10:40:56 +0000358const (
359 nativeIncludeDir = "include"
360 nativeGeneratedIncludeDir = "include_gen"
361 nativeStubDir = "lib"
362)
363
364// path to the native library. Relative to <sdk_root>/<api_dir>
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000365func nativeLibraryPathFor(lib *nativeLibInfoProperties) string {
Paul Duffin96f18322021-09-03 17:53:38 +0100366 return filepath.Join(lib.OsPrefix(), lib.archSubDir,
Paul Duffin2f6bc092019-12-13 10:40:56 +0000367 nativeStubDir, lib.outputFile.Base())
368}
369
Paul Duffin2f6bc092019-12-13 10:40:56 +0000370// nativeLibInfoProperties represents properties of a native lib
371//
372// The exported (capitalized) fields will be examined and may be changed during common value extraction.
373// The unexported fields will be left untouched.
374type nativeLibInfoProperties struct {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000375 android.SdkMemberPropertiesBase
376
377 memberType *librarySdkMemberType
378
Paul Duffin96f18322021-09-03 17:53:38 +0100379 // archSubDir is the subdirectory within the OS directory in the sdk snapshot into which arch
380 // specific files will be copied.
381 //
382 // It is not exported since any value other than "" is always going to be arch specific.
383 // This is "" for non-arch specific common properties.
384 archSubDir string
Paul Duffin2f6bc092019-12-13 10:40:56 +0000385
Paul Duffin5efd1982020-02-20 14:33:54 +0000386 // The list of possibly common exported include dirs.
387 //
388 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100389 ExportedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000390
Paul Duffin5efd1982020-02-20 14:33:54 +0000391 // The list of arch specific exported generated include dirs.
392 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000393 // This field is exported as its contents may not be arch specific, e.g. protos.
394 ExportedGeneratedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000395
396 // The list of arch specific exported generated header files.
397 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000398 // This field is exported as its contents may not be arch specific, e.g. protos.
399 ExportedGeneratedHeaders android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000400
Paul Duffin5efd1982020-02-20 14:33:54 +0000401 // The list of possibly common exported system include dirs.
402 //
403 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100404 ExportedSystemIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000405
406 // The list of possibly common exported flags.
407 //
408 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100409 ExportedFlags []string `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000410
Paul Duffin13f02712020-03-06 12:30:43 +0000411 // The set of shared libraries
412 //
413 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100414 SharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000415
Martin Stjernholm10566a02020-03-24 01:19:52 +0000416 // The set of system shared libraries. Note nil and [] are semantically
417 // distinct - see BaseLinkerProperties.System_shared_libs.
Paul Duffin13f02712020-03-06 12:30:43 +0000418 //
419 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100420 SystemSharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000421
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100422 // The specific stubs version for the lib variant, or empty string if stubs
423 // are not in use.
Paul Duffin7a1f7f32020-05-04 15:32:08 +0100424 //
Martin Stjernholm618b6712020-09-24 16:53:04 +0100425 // Marked 'ignored-on-host' as the AllStubsVersions() from which this is
426 // initialized is not set on host and the stubs.versions property which this
427 // is written to does not vary by arch so cannot be android specific.
428 StubsVersions []string `sdk:"ignored-on-host"`
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100429
Martin Stjernholmb0249572020-09-15 02:32:35 +0100430 // Value of SanitizeProperties.Sanitize. Several - but not all - of these
431 // affect the expanded variants. All are propagated to avoid entangling the
432 // sanitizer logic with the snapshot generation.
433 Sanitize SanitizeUserProps `android:"arch_variant"`
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100434
Paul Duffin2f6bc092019-12-13 10:40:56 +0000435 // outputFile is not exported as it is always arch specific.
436 outputFile android.Path
437}
438
Paul Duffin3a4eb502020-03-19 16:11:18 +0000439func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000440 addOutputFile := true
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000441 ccModule := variant.(*Module)
442
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000443 if s := ccModule.sanitize; s != nil {
444 // We currently do not capture sanitizer flags for libs with sanitizers
445 // enabled, because they may vary among variants that cannot be represented
446 // in the input blueprint files. In particular, sanitizerDepsMutator enables
447 // various sanitizers on dependencies, but in many cases only on static
448 // ones, and we cannot specify sanitizer flags at the link type level (i.e.
449 // in StaticOrSharedProperties).
450 if s.isUnsanitizedVariant() {
451 // This still captures explicitly disabled sanitizers, which may be
452 // necessary to avoid cyclic dependencies.
453 p.Sanitize = s.Properties.Sanitize
454 } else {
455 // Do not add the output file to the snapshot if we don't represent it
456 // properly.
457 addOutputFile = false
458 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000459 }
460
Colin Cross0de8a1e2020-09-18 14:15:30 -0700461 exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
462
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000463 // Separate out the generated include dirs (which are arch specific) from the
464 // include dirs (which may not be).
465 exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
Colin Cross0de8a1e2020-09-18 14:15:30 -0700466 exportedInfo.IncludeDirs, isGeneratedHeaderDirectory)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000467
Paul Duffin93b750e2019-11-19 19:44:10 +0000468 target := ccModule.Target()
469 p.archSubDir = target.Arch.ArchType.String()
470 if target.NativeBridge == android.NativeBridgeEnabled {
471 p.archSubDir += "_native_bridge"
472 }
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000473
474 // Make sure that the include directories are unique.
475 p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs)
Paul Duffin7a7d0672021-02-17 12:17:40 +0000476 p.ExportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs)
Paul Duffinab5467d2020-06-18 16:31:04 +0100477
478 // Take a copy before filtering out duplicates to avoid changing the slice owned by the
479 // ccModule.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700480 dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...)
Paul Duffinab5467d2020-06-18 16:31:04 +0100481 p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs)
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000482
Colin Cross0de8a1e2020-09-18 14:15:30 -0700483 p.ExportedFlags = exportedInfo.Flags
Paul Duffin13f02712020-03-06 12:30:43 +0000484 if ccModule.linker != nil {
485 specifiedDeps := specifiedDeps{}
486 specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
487
Colin Cross31076b32020-10-23 17:22:06 -0700488 if lib := ccModule.library; lib != nil {
489 if !lib.hasStubsVariants() {
490 // Propagate dynamic dependencies for implementation libs, but not stubs.
491 p.SharedLibs = specifiedDeps.sharedLibs
492 } else {
493 // TODO(b/169373910): 1. Only output the specific version (from
494 // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
495 // the versioned stub libs are retained in the prebuilt tree; currently only
496 // the stub corresponding to ccModule.StubsVersion() is.
497 p.StubsVersions = lib.allStubsVersions()
498 }
Martin Stjernholmcc330d62020-04-21 20:45:35 +0100499 }
Paul Duffin13f02712020-03-06 12:30:43 +0000500 p.SystemSharedLibs = specifiedDeps.systemSharedLibs
501 }
Paul Duffin7a7d0672021-02-17 12:17:40 +0000502 p.ExportedGeneratedHeaders = exportedInfo.GeneratedHeaders
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100503
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000504 if !p.memberType.noOutputFiles && addOutputFile {
505 p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100506 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000507}
508
Paul Duffin712993c2020-05-05 14:11:57 +0100509func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path {
510 var path android.Path
511 outputFile := ccModule.OutputFile()
512 if outputFile.Valid() {
513 path = outputFile.Path()
514 } else {
515 ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule)
516 }
517 return path
518}
519
Paul Duffin3a4eb502020-03-19 16:11:18 +0000520func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
521 addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000522}