blob: a28ccd062219ec406b42c99fe6b9f7f4c65e102b [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
137 // If required add additional dependencies on the image:recovery variants.
138 if ctx.RequiresTrait(lib, recoveryImageRequiredSdkTrait) {
139 memberDependencies = append(memberDependencies, memberDependency{
140 imageVariations: []blueprint.Variation{{Mutator: "image", Variation: android.RecoveryVariation}},
141 // Only add a dependency on the first target as that is the only one which will have an
142 // image:recovery variant.
143 targets: targets[:1],
144 })
145 }
Paul Duffinb1f0f2a2021-09-09 17:06:07 +0100146 }
147
148 // For each dependency in the list add dependencies on the targets with the correct variations.
149 for _, dependency := range memberDependencies {
150 // For each target add a dependency on the target with any additional dependencies.
151 for _, target := range dependency.targets {
152 // Get the variations for the target.
153 variations := target.Variations()
154
155 // Add any additional dependencies needed.
156 variations = append(variations, dependency.imageVariations...)
157
158 if mt.linkTypes == nil {
159 // No link types are supported so add a dependency directly.
160 ctx.AddFarVariationDependencies(variations, dependencyTag, name)
161 } else {
162 // Otherwise, add a dependency on each supported link type in turn.
163 for _, linkType := range mt.linkTypes {
164 libVariations := append(variations,
165 blueprint.Variation{Mutator: "link", Variation: linkType})
166 // If this is for the device and a shared link type then add a dependency onto the
167 // appropriate version specific variant of the module.
168 if ctx.Device() && linkType == "shared" {
169 libVariations = append(libVariations,
170 blueprint.Variation{Mutator: "version", Variation: version})
171 }
172 ctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
Colin Crossa717db72020-10-23 14:53:06 -0700173 }
Paul Duffin91756d22020-02-21 16:29:57 +0000174 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000175 }
176 }
177 }
178}
179
180func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
Paul Duffina0843f62019-12-13 19:50:38 +0000181 // Check the module to see if it can be used with this module type.
182 if m, ok := module.(*Module); ok {
183 for _, allowableMemberType := range m.sdkMemberTypes {
184 if allowableMemberType == mt {
185 return true
186 }
187 }
188 }
189
190 return false
Paul Duffin2f6bc092019-12-13 10:40:56 +0000191}
192
Paul Duffin3a4eb502020-03-19 16:11:18 +0000193func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
194 pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
Paul Duffin0c394f32020-03-05 14:09:58 +0000195
196 ccModule := member.Variants()[0].(*Module)
197
Paul Duffin93b750e2019-11-19 19:44:10 +0000198 if ctx.RequiresTrait(nativeBridgeSdkTrait) {
199 pbm.AddProperty("native_bridge_supported", true)
200 }
201
Paul Duffin63696222021-09-06 10:28:34 +0100202 if ctx.RequiresTrait(recoveryImageRequiredSdkTrait) {
Paul Duffind6abaa72020-09-07 16:39:22 +0100203 pbm.AddProperty("recovery_available", true)
204 }
205
Paul Duffind1edbd42020-08-13 19:45:31 +0100206 if proptools.Bool(ccModule.VendorProperties.Vendor_available) {
207 pbm.AddProperty("vendor_available", true)
208 }
209
Justin Yunebcf0c52021-01-08 18:00:19 +0900210 if proptools.Bool(ccModule.VendorProperties.Odm_available) {
211 pbm.AddProperty("odm_available", true)
212 }
213
Justin Yun63e9ec72020-10-29 16:49:43 +0900214 if proptools.Bool(ccModule.VendorProperties.Product_available) {
215 pbm.AddProperty("product_available", true)
216 }
217
Paul Duffin0c394f32020-03-05 14:09:58 +0000218 sdkVersion := ccModule.SdkVersion()
219 if sdkVersion != "" {
220 pbm.AddProperty("sdk_version", sdkVersion)
221 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000222
Paul Duffin13f02712020-03-06 12:30:43 +0000223 stl := ccModule.stl.Properties.Stl
224 if stl != nil {
Paul Duffin0174d8d2020-03-11 18:42:08 +0000225 pbm.AddProperty("stl", proptools.String(stl))
Paul Duffin13f02712020-03-06 12:30:43 +0000226 }
Martin Stjernholm47ed3522020-06-17 22:52:25 +0100227
228 if lib, ok := ccModule.linker.(*libraryDecorator); ok {
229 uhs := lib.Properties.Unique_host_soname
230 if uhs != nil {
231 pbm.AddProperty("unique_host_soname", proptools.Bool(uhs))
232 }
233 }
234
Paul Duffin0174d8d2020-03-11 18:42:08 +0000235 return pbm
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000236}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000237
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000238func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
239 return &nativeLibInfoProperties{memberType: mt}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000240}
241
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400242func isBazelOutDirectory(p android.Path) bool {
243 _, bazel := p.(android.BazelOutPath)
244 return bazel
245}
246
Paul Duffin2f6bc092019-12-13 10:40:56 +0000247func isGeneratedHeaderDirectory(p android.Path) bool {
248 _, gen := p.(android.WritablePath)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400249 // TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
250 // to support generated headers in mixed builds.
251 return gen && !isBazelOutDirectory(p)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000252}
253
Paul Duffin64f54b02020-02-20 14:33:54 +0000254type includeDirsProperty struct {
255 // Accessor to retrieve the paths
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000256 pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths
Paul Duffin64f54b02020-02-20 14:33:54 +0000257
258 // The name of the property in the prebuilt library, "" means there is no property.
259 propertyName string
260
261 // The directory within the snapshot directory into which items should be copied.
262 snapshotDir string
263
264 // True if the items on the path should be copied.
265 copy bool
266
267 // True if the paths represent directories, files if they represent files.
268 dirs bool
Paul Duffin74fc1902020-01-23 11:45:03 +0000269}
270
Paul Duffin64f54b02020-02-20 14:33:54 +0000271var includeDirProperties = []includeDirsProperty{
272 {
273 // ExportedIncludeDirs lists directories that contains some header files to be
274 // copied into a directory in the snapshot. The snapshot directories must be added to
275 // the export_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.ExportedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000277 propertyName: "export_include_dirs",
278 snapshotDir: nativeIncludeDir,
279 copy: true,
280 dirs: true,
281 },
282 {
283 // ExportedSystemIncludeDirs lists directories that contains some system header files to
284 // be copied into a directory in the snapshot. The snapshot directories must be added to
285 // the export_system_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000286 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000287 propertyName: "export_system_include_dirs",
288 snapshotDir: nativeIncludeDir,
289 copy: true,
290 dirs: true,
291 },
292 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000293 // ExportedGeneratedIncludeDirs lists directories that contains some header files
294 // that are explicitly listed in the ExportedGeneratedHeaders property. So, the contents
Paul Duffin64f54b02020-02-20 14:33:54 +0000295 // of these directories do not need to be copied, but these directories do need adding to
296 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000297 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000298 propertyName: "export_include_dirs",
299 snapshotDir: nativeGeneratedIncludeDir,
300 copy: false,
301 dirs: true,
302 },
303 {
Paul Duffin7a7d0672021-02-17 12:17:40 +0000304 // ExportedGeneratedHeaders lists header files that are in one of the directories
305 // specified in ExportedGeneratedIncludeDirs must be copied into the snapshot.
306 // As they are in a directory in ExportedGeneratedIncludeDirs they do not need adding to a
Paul Duffin64f54b02020-02-20 14:33:54 +0000307 // property in the prebuilt module in the snapshot.
Paul Duffin7a7d0672021-02-17 12:17:40 +0000308 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedGeneratedHeaders },
Paul Duffin64f54b02020-02-20 14:33:54 +0000309 propertyName: "",
310 snapshotDir: nativeGeneratedIncludeDir,
311 copy: true,
312 dirs: false,
313 },
314}
315
316// Add properties that may, or may not, be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000317func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) {
318
Martin Stjernholmb0249572020-09-15 02:32:35 +0100319 outputProperties.AddProperty("sanitize", &libInfo.Sanitize)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100320
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000321 // Copy the generated library to the snapshot and add a reference to it in the .bp module.
322 if libInfo.outputFile != nil {
323 nativeLibraryPath := nativeLibraryPathFor(libInfo)
324 builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath)
325 outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
326 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000327
Paul Duffin13f02712020-03-06 12:30:43 +0000328 if len(libInfo.SharedLibs) > 0 {
329 outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
330 }
331
Martin Stjernholm10566a02020-03-24 01:19:52 +0000332 // SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
333 // so check for non-nil instead of nonzero length.
334 if libInfo.SystemSharedLibs != nil {
Paul Duffin13f02712020-03-06 12:30:43 +0000335 outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
336 }
337
Paul Duffin64f54b02020-02-20 14:33:54 +0000338 // Map from property name to the include dirs to add to the prebuilt module in the snapshot.
339 includeDirs := make(map[string][]string)
340
341 // Iterate over each include directory property, copying files and collating property
342 // values where necessary.
343 for _, propertyInfo := range includeDirProperties {
344 // Calculate the base directory in the snapshot into which the files will be copied.
Paul Duffin96f18322021-09-03 17:53:38 +0100345 // lib.archSubDir is "" for common properties.
346 targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archSubDir, propertyInfo.snapshotDir)
Paul Duffin64f54b02020-02-20 14:33:54 +0000347
348 propertyName := propertyInfo.propertyName
349
350 // Iterate over each path in one of the include directory properties.
351 for _, path := range propertyInfo.pathsGetter(libInfo) {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000352 inputPath := path.String()
353
354 // Map the input path to a snapshot relative path. The mapping is independent of the module
355 // that references them so that if multiple modules within the same snapshot export the same
356 // header files they end up in the same place in the snapshot and so do not get duplicated.
357 targetRelativePath := inputPath
358 if isGeneratedHeaderDirectory(path) {
359 // Remove everything up to the .intermediates/ from the generated output directory to
360 // leave a module relative path.
361 base := android.PathForIntermediates(sdkModuleContext, "")
362 targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath)
363 }
364
365 snapshotRelativePath := filepath.Join(targetDir, targetRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000366
367 // Copy the files/directories when necessary.
368 if propertyInfo.copy {
369 if propertyInfo.dirs {
370 // When copying a directory glob and copy all the headers within it.
371 // TODO(jiyong) copy headers having other suffixes
Paul Duffin42dd4e62021-02-22 11:35:24 +0000372 headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil)
Paul Duffin64f54b02020-02-20 14:33:54 +0000373 for _, file := range headers {
374 src := android.PathForSource(sdkModuleContext, file)
Paul Duffin42dd4e62021-02-22 11:35:24 +0000375
376 // The destination path in the snapshot is constructed from the snapshot relative path
377 // of the input directory and the input directory relative path of the header file.
378 inputRelativePath := android.Rel(sdkModuleContext, inputPath, file)
379 dest := filepath.Join(snapshotRelativePath, inputRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000380 builder.CopyToSnapshot(src, dest)
381 }
382 } else {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000383 // Otherwise, just copy the file to its snapshot relative path.
384 builder.CopyToSnapshot(path, snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000385 }
386 }
387
388 // Only directories are added to a property.
389 if propertyInfo.dirs {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000390 includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000391 }
392 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000393 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000394
395 // Add the collated include dir properties to the output.
Colin Cross2c033612020-09-11 15:44:31 -0700396 for _, property := range android.SortedStringKeys(includeDirs) {
397 outputProperties.AddProperty(property, includeDirs[property])
Paul Duffin74fc1902020-01-23 11:45:03 +0000398 }
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100399
Martin Stjernholm618b6712020-09-24 16:53:04 +0100400 if len(libInfo.StubsVersions) > 0 {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100401 stubsSet := outputProperties.AddPropertySet("stubs")
Martin Stjernholm618b6712020-09-24 16:53:04 +0100402 stubsSet.AddProperty("versions", libInfo.StubsVersions)
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100403 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000404}
405
Paul Duffin2f6bc092019-12-13 10:40:56 +0000406const (
407 nativeIncludeDir = "include"
408 nativeGeneratedIncludeDir = "include_gen"
409 nativeStubDir = "lib"
410)
411
412// path to the native library. Relative to <sdk_root>/<api_dir>
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000413func nativeLibraryPathFor(lib *nativeLibInfoProperties) string {
Paul Duffin96f18322021-09-03 17:53:38 +0100414 return filepath.Join(lib.OsPrefix(), lib.archSubDir,
Paul Duffin2f6bc092019-12-13 10:40:56 +0000415 nativeStubDir, lib.outputFile.Base())
416}
417
Paul Duffin2f6bc092019-12-13 10:40:56 +0000418// nativeLibInfoProperties represents properties of a native lib
419//
420// The exported (capitalized) fields will be examined and may be changed during common value extraction.
421// The unexported fields will be left untouched.
422type nativeLibInfoProperties struct {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000423 android.SdkMemberPropertiesBase
424
425 memberType *librarySdkMemberType
426
Paul Duffin96f18322021-09-03 17:53:38 +0100427 // archSubDir is the subdirectory within the OS directory in the sdk snapshot into which arch
428 // specific files will be copied.
429 //
430 // It is not exported since any value other than "" is always going to be arch specific.
431 // This is "" for non-arch specific common properties.
432 archSubDir string
Paul Duffin2f6bc092019-12-13 10:40:56 +0000433
Paul Duffin5efd1982020-02-20 14:33:54 +0000434 // The list of possibly common exported include dirs.
435 //
436 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100437 ExportedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000438
Paul Duffin5efd1982020-02-20 14:33:54 +0000439 // The list of arch specific exported generated include dirs.
440 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000441 // This field is exported as its contents may not be arch specific, e.g. protos.
442 ExportedGeneratedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000443
444 // The list of arch specific exported generated header files.
445 //
Paul Duffin7a7d0672021-02-17 12:17:40 +0000446 // This field is exported as its contents may not be arch specific, e.g. protos.
447 ExportedGeneratedHeaders android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000448
Paul Duffin5efd1982020-02-20 14:33:54 +0000449 // The list of possibly common exported system include dirs.
450 //
451 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100452 ExportedSystemIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000453
454 // The list of possibly common exported flags.
455 //
456 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100457 ExportedFlags []string `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000458
Paul Duffin13f02712020-03-06 12:30:43 +0000459 // The set of shared libraries
460 //
461 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100462 SharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000463
Martin Stjernholm10566a02020-03-24 01:19:52 +0000464 // The set of system shared libraries. Note nil and [] are semantically
465 // distinct - see BaseLinkerProperties.System_shared_libs.
Paul Duffin13f02712020-03-06 12:30:43 +0000466 //
467 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100468 SystemSharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000469
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100470 // The specific stubs version for the lib variant, or empty string if stubs
471 // are not in use.
Paul Duffin7a1f7f32020-05-04 15:32:08 +0100472 //
Martin Stjernholm618b6712020-09-24 16:53:04 +0100473 // Marked 'ignored-on-host' as the AllStubsVersions() from which this is
474 // initialized is not set on host and the stubs.versions property which this
475 // is written to does not vary by arch so cannot be android specific.
476 StubsVersions []string `sdk:"ignored-on-host"`
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100477
Martin Stjernholmb0249572020-09-15 02:32:35 +0100478 // Value of SanitizeProperties.Sanitize. Several - but not all - of these
479 // affect the expanded variants. All are propagated to avoid entangling the
480 // sanitizer logic with the snapshot generation.
481 Sanitize SanitizeUserProps `android:"arch_variant"`
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100482
Paul Duffin2f6bc092019-12-13 10:40:56 +0000483 // outputFile is not exported as it is always arch specific.
484 outputFile android.Path
485}
486
Paul Duffin3a4eb502020-03-19 16:11:18 +0000487func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000488 addOutputFile := true
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000489 ccModule := variant.(*Module)
490
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000491 if s := ccModule.sanitize; s != nil {
492 // We currently do not capture sanitizer flags for libs with sanitizers
493 // enabled, because they may vary among variants that cannot be represented
494 // in the input blueprint files. In particular, sanitizerDepsMutator enables
495 // various sanitizers on dependencies, but in many cases only on static
496 // ones, and we cannot specify sanitizer flags at the link type level (i.e.
497 // in StaticOrSharedProperties).
498 if s.isUnsanitizedVariant() {
499 // This still captures explicitly disabled sanitizers, which may be
500 // necessary to avoid cyclic dependencies.
501 p.Sanitize = s.Properties.Sanitize
502 } else {
503 // Do not add the output file to the snapshot if we don't represent it
504 // properly.
505 addOutputFile = false
506 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000507 }
508
Colin Cross0de8a1e2020-09-18 14:15:30 -0700509 exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
510
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000511 // Separate out the generated include dirs (which are arch specific) from the
512 // include dirs (which may not be).
513 exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
Colin Cross0de8a1e2020-09-18 14:15:30 -0700514 exportedInfo.IncludeDirs, isGeneratedHeaderDirectory)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000515
Paul Duffin93b750e2019-11-19 19:44:10 +0000516 target := ccModule.Target()
517 p.archSubDir = target.Arch.ArchType.String()
518 if target.NativeBridge == android.NativeBridgeEnabled {
519 p.archSubDir += "_native_bridge"
520 }
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000521
522 // Make sure that the include directories are unique.
523 p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs)
Paul Duffin7a7d0672021-02-17 12:17:40 +0000524 p.ExportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs)
Paul Duffinab5467d2020-06-18 16:31:04 +0100525
526 // Take a copy before filtering out duplicates to avoid changing the slice owned by the
527 // ccModule.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700528 dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...)
Paul Duffinab5467d2020-06-18 16:31:04 +0100529 p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs)
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000530
Colin Cross0de8a1e2020-09-18 14:15:30 -0700531 p.ExportedFlags = exportedInfo.Flags
Paul Duffin13f02712020-03-06 12:30:43 +0000532 if ccModule.linker != nil {
533 specifiedDeps := specifiedDeps{}
534 specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
535
Colin Cross31076b32020-10-23 17:22:06 -0700536 if lib := ccModule.library; lib != nil {
537 if !lib.hasStubsVariants() {
538 // Propagate dynamic dependencies for implementation libs, but not stubs.
539 p.SharedLibs = specifiedDeps.sharedLibs
540 } else {
541 // TODO(b/169373910): 1. Only output the specific version (from
542 // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
543 // the versioned stub libs are retained in the prebuilt tree; currently only
544 // the stub corresponding to ccModule.StubsVersion() is.
545 p.StubsVersions = lib.allStubsVersions()
546 }
Martin Stjernholmcc330d62020-04-21 20:45:35 +0100547 }
Paul Duffin13f02712020-03-06 12:30:43 +0000548 p.SystemSharedLibs = specifiedDeps.systemSharedLibs
549 }
Paul Duffin7a7d0672021-02-17 12:17:40 +0000550 p.ExportedGeneratedHeaders = exportedInfo.GeneratedHeaders
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100551
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000552 if !p.memberType.noOutputFiles && addOutputFile {
553 p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100554 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000555}
556
Paul Duffin712993c2020-05-05 14:11:57 +0100557func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path {
558 var path android.Path
559 outputFile := ccModule.OutputFile()
560 if outputFile.Valid() {
561 path = outputFile.Path()
562 } else {
563 ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule)
564 }
565 return path
566}
567
Paul Duffin3a4eb502020-03-19 16:11:18 +0000568func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
569 addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000570}