blob: 73187bd62d53563b373e37ccda61f44e51acaa1b [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 })
136 }
137
138 // For each dependency in the list add dependencies on the targets with the correct variations.
139 for _, dependency := range memberDependencies {
140 // For each target add a dependency on the target with any additional dependencies.
141 for _, target := range dependency.targets {
142 // Get the variations for the target.
143 variations := target.Variations()
144
145 // Add any additional dependencies needed.
146 variations = append(variations, dependency.imageVariations...)
147
148 if mt.linkTypes == nil {
149 // No link types are supported so add a dependency directly.
150 ctx.AddFarVariationDependencies(variations, dependencyTag, name)
151 } else {
152 // Otherwise, add a dependency on each supported link type in turn.
153 for _, linkType := range mt.linkTypes {
154 libVariations := append(variations,
155 blueprint.Variation{Mutator: "link", Variation: linkType})
156 // If this is for the device and a shared link type then add a dependency onto the
157 // appropriate version specific variant of the module.
158 if ctx.Device() && linkType == "shared" {
159 libVariations = append(libVariations,
160 blueprint.Variation{Mutator: "version", Variation: version})
161 }
162 ctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
Colin Crossa717db72020-10-23 14:53:06 -0700163 }
Paul Duffin91756d22020-02-21 16:29:57 +0000164 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000165 }
166 }
167 }
168}
169
170func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
Paul Duffina0843f62019-12-13 19:50:38 +0000171 // Check the module to see if it can be used with this module type.
172 if m, ok := module.(*Module); ok {
173 for _, allowableMemberType := range m.sdkMemberTypes {
174 if allowableMemberType == mt {
175 return true
176 }
177 }
178 }
179
180 return false
Paul Duffin2f6bc092019-12-13 10:40:56 +0000181}
182
Paul Duffin3a4eb502020-03-19 16:11:18 +0000183func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
184 pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
Paul Duffin0c394f32020-03-05 14:09:58 +0000185
186 ccModule := member.Variants()[0].(*Module)
187
Paul Duffin93b750e2019-11-19 19:44:10 +0000188 if ctx.RequiresTrait(nativeBridgeSdkTrait) {
189 pbm.AddProperty("native_bridge_supported", true)
190 }
191
Paul Duffind6abaa72020-09-07 16:39:22 +0100192 if proptools.Bool(ccModule.Properties.Recovery_available) {
193 pbm.AddProperty("recovery_available", true)
194 }
195
Paul Duffind1edbd42020-08-13 19:45:31 +0100196 if proptools.Bool(ccModule.VendorProperties.Vendor_available) {
197 pbm.AddProperty("vendor_available", true)
198 }
199
Justin Yunebcf0c52021-01-08 18:00:19 +0900200 if proptools.Bool(ccModule.VendorProperties.Odm_available) {
201 pbm.AddProperty("odm_available", true)
202 }
203
Justin Yun63e9ec72020-10-29 16:49:43 +0900204 if proptools.Bool(ccModule.VendorProperties.Product_available) {
205 pbm.AddProperty("product_available", true)
206 }
207
Paul Duffin0c394f32020-03-05 14:09:58 +0000208 sdkVersion := ccModule.SdkVersion()
209 if sdkVersion != "" {
210 pbm.AddProperty("sdk_version", sdkVersion)
211 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000212
Paul Duffin13f02712020-03-06 12:30:43 +0000213 stl := ccModule.stl.Properties.Stl
214 if stl != nil {
Paul Duffin0174d8d2020-03-11 18:42:08 +0000215 pbm.AddProperty("stl", proptools.String(stl))
Paul Duffin13f02712020-03-06 12:30:43 +0000216 }
Martin Stjernholm47ed3522020-06-17 22:52:25 +0100217
218 if lib, ok := ccModule.linker.(*libraryDecorator); ok {
219 uhs := lib.Properties.Unique_host_soname
220 if uhs != nil {
221 pbm.AddProperty("unique_host_soname", proptools.Bool(uhs))
222 }
223 }
224
Paul Duffin0174d8d2020-03-11 18:42:08 +0000225 return pbm
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000226}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000227
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000228func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
229 return &nativeLibInfoProperties{memberType: mt}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000230}
231
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400232func isBazelOutDirectory(p android.Path) bool {
233 _, bazel := p.(android.BazelOutPath)
234 return bazel
235}
236
Paul Duffin2f6bc092019-12-13 10:40:56 +0000237func isGeneratedHeaderDirectory(p android.Path) bool {
238 _, gen := p.(android.WritablePath)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400239 // TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
240 // to support generated headers in mixed builds.
241 return gen && !isBazelOutDirectory(p)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000242}
243
Paul Duffin64f54b02020-02-20 14:33:54 +0000244type includeDirsProperty struct {
245 // Accessor to retrieve the paths
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000246 pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths
Paul Duffin64f54b02020-02-20 14:33:54 +0000247
248 // The name of the property in the prebuilt library, "" means there is no property.
249 propertyName string
250
251 // The directory within the snapshot directory into which items should be copied.
252 snapshotDir string
253
254 // True if the items on the path should be copied.
255 copy bool
256
257 // True if the paths represent directories, files if they represent files.
258 dirs bool
Paul Duffin74fc1902020-01-23 11:45:03 +0000259}
260
Paul Duffin64f54b02020-02-20 14:33:54 +0000261var includeDirProperties = []includeDirsProperty{
262 {
263 // ExportedIncludeDirs lists directories that contains some header files to be
264 // copied into a directory in the snapshot. The snapshot directories must be added to
265 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000266 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000267 propertyName: "export_include_dirs",
268 snapshotDir: nativeIncludeDir,
269 copy: true,
270 dirs: true,
271 },
272 {
273 // ExportedSystemIncludeDirs lists directories that contains some system header files to
274 // be copied into a directory in the snapshot. The snapshot directories must be added to
275 // the export_system_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000276 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000277 propertyName: "export_system_include_dirs",
278 snapshotDir: nativeIncludeDir,
279 copy: true,
280 dirs: true,
281 },
282 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000283 // ExportedGeneratedIncludeDirs lists directories that contains some header files
284 // that are explicitly listed in the ExportedGeneratedHeaders property. So, the contents
Paul Duffin64f54b02020-02-20 14:33:54 +0000285 // of these directories do not need to be copied, but these directories do need adding to
286 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000287 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000288 propertyName: "export_include_dirs",
289 snapshotDir: nativeGeneratedIncludeDir,
290 copy: false,
291 dirs: true,
292 },
293 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000294 // ExportedGeneratedHeaders lists header files that are in one of the directories
295 // specified in ExportedGeneratedIncludeDirs must be copied into the snapshot.
296 // As they are in a directory in ExportedGeneratedIncludeDirs they do not need adding to a
Paul Duffin64f54b02020-02-20 14:33:54 +0000297 // property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000298 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedHeaders },
Paul Duffin64f54b02020-02-20 14:33:54 +0000299 propertyName: "",
300 snapshotDir: nativeGeneratedIncludeDir,
301 copy: true,
302 dirs: false,
303 },
304}
305
306// Add properties that may, or may not, be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000307func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) {
308
Martin Stjernholmb0249572020-09-15 02:32:35 +0100309 outputProperties.AddProperty("sanitize", &libInfo.Sanitize)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100310
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000311 // Copy the generated library to the snapshot and add a reference to it in the .bp module.
312 if libInfo.outputFile != nil {
313 nativeLibraryPath := nativeLibraryPathFor(libInfo)
314 builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath)
315 outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
316 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000317
Paul Duffin13f02712020-03-06 12:30:43 +0000318 if len(libInfo.SharedLibs) > 0 {
319 outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
320 }
321
Martin Stjernholm10566a02020-03-24 01:19:52 +0000322 // SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
323 // so check for non-nil instead of nonzero length.
324 if libInfo.SystemSharedLibs != nil {
Paul Duffin13f02712020-03-06 12:30:43 +0000325 outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
326 }
327
Paul Duffin64f54b02020-02-20 14:33:54 +0000328 // Map from property name to the include dirs to add to the prebuilt module in the snapshot.
329 includeDirs := make(map[string][]string)
330
331 // Iterate over each include directory property, copying files and collating property
332 // values where necessary.
333 for _, propertyInfo := range includeDirProperties {
334 // Calculate the base directory in the snapshot into which the files will be copied.
Paul Duffin96f18322021-09-03 17:53:38 +0100335 // lib.archSubDir is "" for common properties.
336 targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archSubDir, propertyInfo.snapshotDir)
Paul Duffin64f54b02020-02-20 14:33:54 +0000337
338 propertyName := propertyInfo.propertyName
339
340 // Iterate over each path in one of the include directory properties.
341 for _, path := range propertyInfo.pathsGetter(libInfo) {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000342 inputPath := path.String()
343
344 // Map the input path to a snapshot relative path. The mapping is independent of the module
345 // that references them so that if multiple modules within the same snapshot export the same
346 // header files they end up in the same place in the snapshot and so do not get duplicated.
347 targetRelativePath := inputPath
348 if isGeneratedHeaderDirectory(path) {
349 // Remove everything up to the .intermediates/ from the generated output directory to
350 // leave a module relative path.
351 base := android.PathForIntermediates(sdkModuleContext, "")
352 targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath)
353 }
354
355 snapshotRelativePath := filepath.Join(targetDir, targetRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000356
357 // Copy the files/directories when necessary.
358 if propertyInfo.copy {
359 if propertyInfo.dirs {
360 // When copying a directory glob and copy all the headers within it.
361 // TODO(jiyong) copy headers having other suffixes
Paul Duffin42dd4e62021-02-22 11:35:24 +0000362 headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil)
Paul Duffin64f54b02020-02-20 14:33:54 +0000363 for _, file := range headers {
364 src := android.PathForSource(sdkModuleContext, file)
Paul Duffin42dd4e62021-02-22 11:35:24 +0000365
366 // The destination path in the snapshot is constructed from the snapshot relative path
367 // of the input directory and the input directory relative path of the header file.
368 inputRelativePath := android.Rel(sdkModuleContext, inputPath, file)
369 dest := filepath.Join(snapshotRelativePath, inputRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000370 builder.CopyToSnapshot(src, dest)
371 }
372 } else {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000373 // Otherwise, just copy the file to its snapshot relative path.
374 builder.CopyToSnapshot(path, snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000375 }
376 }
377
378 // Only directories are added to a property.
379 if propertyInfo.dirs {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000380 includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000381 }
382 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000383 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000384
385 // Add the collated include dir properties to the output.
Colin Cross2c033612020-09-11 15:44:31 -0700386 for _, property := range android.SortedStringKeys(includeDirs) {
387 outputProperties.AddProperty(property, includeDirs[property])
Paul Duffin74fc1902020-01-23 11:45:03 +0000388 }
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100389
Martin Stjernholm618b6712020-09-24 16:53:04 +0100390 if len(libInfo.StubsVersions) > 0 {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100391 stubsSet := outputProperties.AddPropertySet("stubs")
Martin Stjernholm618b6712020-09-24 16:53:04 +0100392 stubsSet.AddProperty("versions", libInfo.StubsVersions)
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100393 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000394}
395
Paul Duffin2f6bc092019-12-13 10:40:56 +0000396const (
397 nativeIncludeDir = "include"
398 nativeGeneratedIncludeDir = "include_gen"
399 nativeStubDir = "lib"
400)
401
402// path to the native library. Relative to <sdk_root>/<api_dir>
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000403func nativeLibraryPathFor(lib *nativeLibInfoProperties) string {
Paul Duffin96f18322021-09-03 17:53:38 +0100404 return filepath.Join(lib.OsPrefix(), lib.archSubDir,
Paul Duffin2f6bc092019-12-13 10:40:56 +0000405 nativeStubDir, lib.outputFile.Base())
406}
407
Paul Duffin2f6bc092019-12-13 10:40:56 +0000408// nativeLibInfoProperties represents properties of a native lib
409//
410// The exported (capitalized) fields will be examined and may be changed during common value extraction.
411// The unexported fields will be left untouched.
412type nativeLibInfoProperties struct {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000413 android.SdkMemberPropertiesBase
414
415 memberType *librarySdkMemberType
416
Paul Duffin96f18322021-09-03 17:53:38 +0100417 // archSubDir is the subdirectory within the OS directory in the sdk snapshot into which arch
418 // specific files will be copied.
419 //
420 // It is not exported since any value other than "" is always going to be arch specific.
421 // This is "" for non-arch specific common properties.
422 archSubDir string
Paul Duffin2f6bc092019-12-13 10:40:56 +0000423
Paul Duffin5efd1982020-02-20 14:33:54 +0000424 // The list of possibly common exported include dirs.
425 //
426 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100427 ExportedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000428
Paul Duffin5efd1982020-02-20 14:33:54 +0000429 // The list of arch specific exported generated include dirs.
430 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000431 // This field is exported as its contents may not be arch specific, e.g. protos.
432 ExportedGeneratedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000433
434 // The list of arch specific exported generated header files.
435 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000436 // This field is exported as its contents may not be arch specific, e.g. protos.
437 ExportedGeneratedHeaders android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000438
Paul Duffin5efd1982020-02-20 14:33:54 +0000439 // The list of possibly common exported system include dirs.
440 //
441 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100442 ExportedSystemIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000443
444 // The list of possibly common exported flags.
445 //
446 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100447 ExportedFlags []string `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000448
Paul Duffin13f02712020-03-06 12:30:43 +0000449 // The set of shared libraries
450 //
451 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100452 SharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000453
Martin Stjernholm10566a02020-03-24 01:19:52 +0000454 // The set of system shared libraries. Note nil and [] are semantically
455 // distinct - see BaseLinkerProperties.System_shared_libs.
Paul Duffin13f02712020-03-06 12:30:43 +0000456 //
457 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100458 SystemSharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000459
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100460 // The specific stubs version for the lib variant, or empty string if stubs
461 // are not in use.
Paul Duffin7a1f7f32020-05-04 15:32:08 +0100462 //
Martin Stjernholm618b6712020-09-24 16:53:04 +0100463 // Marked 'ignored-on-host' as the AllStubsVersions() from which this is
464 // initialized is not set on host and the stubs.versions property which this
465 // is written to does not vary by arch so cannot be android specific.
466 StubsVersions []string `sdk:"ignored-on-host"`
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100467
Martin Stjernholmb0249572020-09-15 02:32:35 +0100468 // Value of SanitizeProperties.Sanitize. Several - but not all - of these
469 // affect the expanded variants. All are propagated to avoid entangling the
470 // sanitizer logic with the snapshot generation.
471 Sanitize SanitizeUserProps `android:"arch_variant"`
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100472
Paul Duffin2f6bc092019-12-13 10:40:56 +0000473 // outputFile is not exported as it is always arch specific.
474 outputFile android.Path
475}
476
Paul Duffin3a4eb502020-03-19 16:11:18 +0000477func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000478 addOutputFile := true
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000479 ccModule := variant.(*Module)
480
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000481 if s := ccModule.sanitize; s != nil {
482 // We currently do not capture sanitizer flags for libs with sanitizers
483 // enabled, because they may vary among variants that cannot be represented
484 // in the input blueprint files. In particular, sanitizerDepsMutator enables
485 // various sanitizers on dependencies, but in many cases only on static
486 // ones, and we cannot specify sanitizer flags at the link type level (i.e.
487 // in StaticOrSharedProperties).
488 if s.isUnsanitizedVariant() {
489 // This still captures explicitly disabled sanitizers, which may be
490 // necessary to avoid cyclic dependencies.
491 p.Sanitize = s.Properties.Sanitize
492 } else {
493 // Do not add the output file to the snapshot if we don't represent it
494 // properly.
495 addOutputFile = false
496 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000497 }
498
Colin Cross0de8a1e2020-09-18 14:15:30 -0700499 exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
500
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000501 // Separate out the generated include dirs (which are arch specific) from the
502 // include dirs (which may not be).
503 exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
Colin Cross0de8a1e2020-09-18 14:15:30 -0700504 exportedInfo.IncludeDirs, isGeneratedHeaderDirectory)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000505
Paul Duffin93b750e2019-11-19 19:44:10 +0000506 target := ccModule.Target()
507 p.archSubDir = target.Arch.ArchType.String()
508 if target.NativeBridge == android.NativeBridgeEnabled {
509 p.archSubDir += "_native_bridge"
510 }
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000511
512 // Make sure that the include directories are unique.
513 p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs)
Paul Duffin7a7d0672021-02-17 12:17:40 +0000514 p.ExportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs)
Paul Duffinab5467d2020-06-18 16:31:04 +0100515
516 // Take a copy before filtering out duplicates to avoid changing the slice owned by the
517 // ccModule.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700518 dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...)
Paul Duffinab5467d2020-06-18 16:31:04 +0100519 p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs)
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000520
Colin Cross0de8a1e2020-09-18 14:15:30 -0700521 p.ExportedFlags = exportedInfo.Flags
Paul Duffin13f02712020-03-06 12:30:43 +0000522 if ccModule.linker != nil {
523 specifiedDeps := specifiedDeps{}
524 specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
525
Colin Cross31076b32020-10-23 17:22:06 -0700526 if lib := ccModule.library; lib != nil {
527 if !lib.hasStubsVariants() {
528 // Propagate dynamic dependencies for implementation libs, but not stubs.
529 p.SharedLibs = specifiedDeps.sharedLibs
530 } else {
531 // TODO(b/169373910): 1. Only output the specific version (from
532 // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
533 // the versioned stub libs are retained in the prebuilt tree; currently only
534 // the stub corresponding to ccModule.StubsVersion() is.
535 p.StubsVersions = lib.allStubsVersions()
536 }
Martin Stjernholmcc330d62020-04-21 20:45:35 +0100537 }
Paul Duffin13f02712020-03-06 12:30:43 +0000538 p.SystemSharedLibs = specifiedDeps.systemSharedLibs
539 }
Paul Duffin7a7d0672021-02-17 12:17:40 +0000540 p.ExportedGeneratedHeaders = exportedInfo.GeneratedHeaders
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100541
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000542 if !p.memberType.noOutputFiles && addOutputFile {
543 p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100544 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000545}
546
Paul Duffin712993c2020-05-05 14:11:57 +0100547func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path {
548 var path android.Path
549 outputFile := ccModule.OutputFile()
550 if outputFile.Valid() {
551 path = outputFile.Path()
552 } else {
553 ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule)
554 }
555 return path
556}
557
Paul Duffin3a4eb502020-03-19 16:11:18 +0000558func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
559 addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000560}