blob: 14ff4d891e907a0619528ab99c925fd2a49e1d15 [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
77func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
78 targets := mctx.MultiTargets()
79 for _, lib := range names {
80 for _, target := range targets {
81 name, version := StubsLibNameAndVersion(lib)
82 if version == "" {
Colin Crossd1f898e2020-08-18 18:35:15 -070083 version = "latest"
Paul Duffin2f6bc092019-12-13 10:40:56 +000084 }
Colin Cross42507332020-08-21 16:15:23 -070085 variations := target.Variations()
86 if mctx.Device() {
87 variations = append(variations,
Colin Cross3146c5c2020-09-30 15:34:40 -070088 blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
Colin Cross42507332020-08-21 16:15:23 -070089 }
Paul Duffin91756d22020-02-21 16:29:57 +000090 if mt.linkTypes == nil {
Colin Cross42507332020-08-21 16:15:23 -070091 mctx.AddFarVariationDependencies(variations, dependencyTag, name)
Paul Duffin91756d22020-02-21 16:29:57 +000092 } else {
93 for _, linkType := range mt.linkTypes {
Colin Cross42507332020-08-21 16:15:23 -070094 libVariations := append(variations,
95 blueprint.Variation{Mutator: "link", Variation: linkType})
Colin Crossa717db72020-10-23 14:53:06 -070096 if mctx.Device() && linkType == "shared" {
97 libVariations = append(libVariations,
98 blueprint.Variation{Mutator: "version", Variation: version})
99 }
Colin Cross42507332020-08-21 16:15:23 -0700100 mctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
Paul Duffin91756d22020-02-21 16:29:57 +0000101 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000102 }
103 }
104 }
105}
106
107func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
Paul Duffina0843f62019-12-13 19:50:38 +0000108 // Check the module to see if it can be used with this module type.
109 if m, ok := module.(*Module); ok {
110 for _, allowableMemberType := range m.sdkMemberTypes {
111 if allowableMemberType == mt {
112 return true
113 }
114 }
115 }
116
117 return false
Paul Duffin2f6bc092019-12-13 10:40:56 +0000118}
119
Paul Duffin3a4eb502020-03-19 16:11:18 +0000120func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
121 pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
Paul Duffin0c394f32020-03-05 14:09:58 +0000122
123 ccModule := member.Variants()[0].(*Module)
124
Paul Duffind6abaa72020-09-07 16:39:22 +0100125 if proptools.Bool(ccModule.Properties.Recovery_available) {
126 pbm.AddProperty("recovery_available", true)
127 }
128
Paul Duffind1edbd42020-08-13 19:45:31 +0100129 if proptools.Bool(ccModule.VendorProperties.Vendor_available) {
130 pbm.AddProperty("vendor_available", true)
131 }
132
Justin Yunebcf0c52021-01-08 18:00:19 +0900133 if proptools.Bool(ccModule.VendorProperties.Odm_available) {
134 pbm.AddProperty("odm_available", true)
135 }
136
Justin Yun63e9ec72020-10-29 16:49:43 +0900137 if proptools.Bool(ccModule.VendorProperties.Product_available) {
138 pbm.AddProperty("product_available", true)
139 }
140
Paul Duffin0c394f32020-03-05 14:09:58 +0000141 sdkVersion := ccModule.SdkVersion()
142 if sdkVersion != "" {
143 pbm.AddProperty("sdk_version", sdkVersion)
144 }
Paul Duffin2f6bc092019-12-13 10:40:56 +0000145
Paul Duffin13f02712020-03-06 12:30:43 +0000146 stl := ccModule.stl.Properties.Stl
147 if stl != nil {
Paul Duffin0174d8d2020-03-11 18:42:08 +0000148 pbm.AddProperty("stl", proptools.String(stl))
Paul Duffin13f02712020-03-06 12:30:43 +0000149 }
Martin Stjernholm47ed3522020-06-17 22:52:25 +0100150
151 if lib, ok := ccModule.linker.(*libraryDecorator); ok {
152 uhs := lib.Properties.Unique_host_soname
153 if uhs != nil {
154 pbm.AddProperty("unique_host_soname", proptools.Bool(uhs))
155 }
156 }
157
Paul Duffin0174d8d2020-03-11 18:42:08 +0000158 return pbm
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000159}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000160
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000161func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
162 return &nativeLibInfoProperties{memberType: mt}
Paul Duffin2f6bc092019-12-13 10:40:56 +0000163}
164
165func isGeneratedHeaderDirectory(p android.Path) bool {
166 _, gen := p.(android.WritablePath)
167 return gen
168}
169
Paul Duffin64f54b02020-02-20 14:33:54 +0000170type includeDirsProperty struct {
171 // Accessor to retrieve the paths
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000172 pathsGetter func(libInfo *nativeLibInfoProperties) android.Paths
Paul Duffin64f54b02020-02-20 14:33:54 +0000173
174 // The name of the property in the prebuilt library, "" means there is no property.
175 propertyName string
176
177 // The directory within the snapshot directory into which items should be copied.
178 snapshotDir string
179
180 // True if the items on the path should be copied.
181 copy bool
182
183 // True if the paths represent directories, files if they represent files.
184 dirs bool
Paul Duffin74fc1902020-01-23 11:45:03 +0000185}
186
Paul Duffin64f54b02020-02-20 14:33:54 +0000187var includeDirProperties = []includeDirsProperty{
188 {
189 // ExportedIncludeDirs lists directories that contains some header files to be
190 // copied into a directory in the snapshot. The snapshot directories must be added to
191 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000192 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000193 propertyName: "export_include_dirs",
194 snapshotDir: nativeIncludeDir,
195 copy: true,
196 dirs: true,
197 },
198 {
199 // ExportedSystemIncludeDirs lists directories that contains some system header files to
200 // be copied into a directory in the snapshot. The snapshot directories must be added to
201 // the export_system_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000202 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.ExportedSystemIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000203 propertyName: "export_system_include_dirs",
204 snapshotDir: nativeIncludeDir,
205 copy: true,
206 dirs: true,
207 },
208 {
209 // exportedGeneratedIncludeDirs lists directories that contains some header files
210 // that are explicitly listed in the exportedGeneratedHeaders property. So, the contents
211 // of these directories do not need to be copied, but these directories do need adding to
212 // the export_include_dirs property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000213 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.exportedGeneratedIncludeDirs },
Paul Duffin64f54b02020-02-20 14:33:54 +0000214 propertyName: "export_include_dirs",
215 snapshotDir: nativeGeneratedIncludeDir,
216 copy: false,
217 dirs: true,
218 },
219 {
220 // exportedGeneratedHeaders lists header files that are in one of the directories
221 // specified in exportedGeneratedIncludeDirs must be copied into the snapshot.
222 // As they are in a directory in exportedGeneratedIncludeDirs they do not need adding to a
223 // property in the prebuilt module in the snapshot.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000224 pathsGetter: func(libInfo *nativeLibInfoProperties) android.Paths { return libInfo.exportedGeneratedHeaders },
Paul Duffin64f54b02020-02-20 14:33:54 +0000225 propertyName: "",
226 snapshotDir: nativeGeneratedIncludeDir,
227 copy: true,
228 dirs: false,
229 },
230}
231
232// Add properties that may, or may not, be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000233func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) {
234
Martin Stjernholmb0249572020-09-15 02:32:35 +0100235 outputProperties.AddProperty("sanitize", &libInfo.Sanitize)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100236
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000237 // Copy the generated library to the snapshot and add a reference to it in the .bp module.
238 if libInfo.outputFile != nil {
239 nativeLibraryPath := nativeLibraryPathFor(libInfo)
240 builder.CopyToSnapshot(libInfo.outputFile, nativeLibraryPath)
241 outputProperties.AddProperty("srcs", []string{nativeLibraryPath})
242 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000243
Paul Duffin13f02712020-03-06 12:30:43 +0000244 if len(libInfo.SharedLibs) > 0 {
245 outputProperties.AddPropertyWithTag("shared_libs", libInfo.SharedLibs, builder.SdkMemberReferencePropertyTag(false))
246 }
247
Martin Stjernholm10566a02020-03-24 01:19:52 +0000248 // SystemSharedLibs needs to be propagated if it's a list, even if it's empty,
249 // so check for non-nil instead of nonzero length.
250 if libInfo.SystemSharedLibs != nil {
Paul Duffin13f02712020-03-06 12:30:43 +0000251 outputProperties.AddPropertyWithTag("system_shared_libs", libInfo.SystemSharedLibs, builder.SdkMemberReferencePropertyTag(false))
252 }
253
Paul Duffin64f54b02020-02-20 14:33:54 +0000254 // Map from property name to the include dirs to add to the prebuilt module in the snapshot.
255 includeDirs := make(map[string][]string)
256
257 // Iterate over each include directory property, copying files and collating property
258 // values where necessary.
259 for _, propertyInfo := range includeDirProperties {
260 // Calculate the base directory in the snapshot into which the files will be copied.
Paul Duffin42dd4e62021-02-22 11:35:24 +0000261 // lib.archType is "" for common properties.
Paul Duffined62b9c2020-06-16 16:12:50 +0100262 targetDir := filepath.Join(libInfo.OsPrefix(), libInfo.archType, propertyInfo.snapshotDir)
Paul Duffin64f54b02020-02-20 14:33:54 +0000263
264 propertyName := propertyInfo.propertyName
265
266 // Iterate over each path in one of the include directory properties.
267 for _, path := range propertyInfo.pathsGetter(libInfo) {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000268 inputPath := path.String()
269
270 // Map the input path to a snapshot relative path. The mapping is independent of the module
271 // that references them so that if multiple modules within the same snapshot export the same
272 // header files they end up in the same place in the snapshot and so do not get duplicated.
273 targetRelativePath := inputPath
274 if isGeneratedHeaderDirectory(path) {
275 // Remove everything up to the .intermediates/ from the generated output directory to
276 // leave a module relative path.
277 base := android.PathForIntermediates(sdkModuleContext, "")
278 targetRelativePath = android.Rel(sdkModuleContext, base.String(), inputPath)
279 }
280
281 snapshotRelativePath := filepath.Join(targetDir, targetRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000282
283 // Copy the files/directories when necessary.
284 if propertyInfo.copy {
285 if propertyInfo.dirs {
286 // When copying a directory glob and copy all the headers within it.
287 // TODO(jiyong) copy headers having other suffixes
Paul Duffin42dd4e62021-02-22 11:35:24 +0000288 headers, _ := sdkModuleContext.GlobWithDeps(inputPath+"/**/*.h", nil)
Paul Duffin64f54b02020-02-20 14:33:54 +0000289 for _, file := range headers {
290 src := android.PathForSource(sdkModuleContext, file)
Paul Duffin42dd4e62021-02-22 11:35:24 +0000291
292 // The destination path in the snapshot is constructed from the snapshot relative path
293 // of the input directory and the input directory relative path of the header file.
294 inputRelativePath := android.Rel(sdkModuleContext, inputPath, file)
295 dest := filepath.Join(snapshotRelativePath, inputRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000296 builder.CopyToSnapshot(src, dest)
297 }
298 } else {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000299 // Otherwise, just copy the file to its snapshot relative path.
300 builder.CopyToSnapshot(path, snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000301 }
302 }
303
304 // Only directories are added to a property.
305 if propertyInfo.dirs {
Paul Duffin42dd4e62021-02-22 11:35:24 +0000306 includeDirs[propertyName] = append(includeDirs[propertyName], snapshotRelativePath)
Paul Duffin64f54b02020-02-20 14:33:54 +0000307 }
308 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000309 }
Paul Duffin64f54b02020-02-20 14:33:54 +0000310
311 // Add the collated include dir properties to the output.
Colin Cross2c033612020-09-11 15:44:31 -0700312 for _, property := range android.SortedStringKeys(includeDirs) {
313 outputProperties.AddProperty(property, includeDirs[property])
Paul Duffin74fc1902020-01-23 11:45:03 +0000314 }
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100315
Martin Stjernholm618b6712020-09-24 16:53:04 +0100316 if len(libInfo.StubsVersions) > 0 {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100317 stubsSet := outputProperties.AddPropertySet("stubs")
Martin Stjernholm618b6712020-09-24 16:53:04 +0100318 stubsSet.AddProperty("versions", libInfo.StubsVersions)
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100319 }
Paul Duffin74fc1902020-01-23 11:45:03 +0000320}
321
Paul Duffin2f6bc092019-12-13 10:40:56 +0000322const (
323 nativeIncludeDir = "include"
324 nativeGeneratedIncludeDir = "include_gen"
325 nativeStubDir = "lib"
326)
327
328// path to the native library. Relative to <sdk_root>/<api_dir>
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000329func nativeLibraryPathFor(lib *nativeLibInfoProperties) string {
Paul Duffina04c1072020-03-02 10:16:35 +0000330 return filepath.Join(lib.OsPrefix(), lib.archType,
Paul Duffin2f6bc092019-12-13 10:40:56 +0000331 nativeStubDir, lib.outputFile.Base())
332}
333
Paul Duffin2f6bc092019-12-13 10:40:56 +0000334// nativeLibInfoProperties represents properties of a native lib
335//
336// The exported (capitalized) fields will be examined and may be changed during common value extraction.
337// The unexported fields will be left untouched.
338type nativeLibInfoProperties struct {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000339 android.SdkMemberPropertiesBase
340
341 memberType *librarySdkMemberType
342
Paul Duffin2f6bc092019-12-13 10:40:56 +0000343 // archType is not exported as if set (to a non default value) it is always arch specific.
344 // This is "" for common properties.
345 archType string
346
Paul Duffin5efd1982020-02-20 14:33:54 +0000347 // The list of possibly common exported include dirs.
348 //
349 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100350 ExportedIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin2f6bc092019-12-13 10:40:56 +0000351
Paul Duffin5efd1982020-02-20 14:33:54 +0000352 // The list of arch specific exported generated include dirs.
353 //
354 // This field is not exported as its contents are always arch specific.
355 exportedGeneratedIncludeDirs android.Paths
356
357 // The list of arch specific exported generated header files.
358 //
359 // This field is not exported as its contents are is always arch specific.
Paul Duffin2f6bc092019-12-13 10:40:56 +0000360 exportedGeneratedHeaders android.Paths
361
Paul Duffin5efd1982020-02-20 14:33:54 +0000362 // The list of possibly common exported system include dirs.
363 //
364 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100365 ExportedSystemIncludeDirs android.Paths `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000366
367 // The list of possibly common exported flags.
368 //
369 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100370 ExportedFlags []string `android:"arch_variant"`
Paul Duffin5efd1982020-02-20 14:33:54 +0000371
Paul Duffin13f02712020-03-06 12:30:43 +0000372 // The set of shared libraries
373 //
374 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100375 SharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000376
Martin Stjernholm10566a02020-03-24 01:19:52 +0000377 // The set of system shared libraries. Note nil and [] are semantically
378 // distinct - see BaseLinkerProperties.System_shared_libs.
Paul Duffin13f02712020-03-06 12:30:43 +0000379 //
380 // This field is exported as its contents may not be arch specific.
Paul Duffin864e1b42020-05-06 10:23:19 +0100381 SystemSharedLibs []string `android:"arch_variant"`
Paul Duffin13f02712020-03-06 12:30:43 +0000382
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100383 // The specific stubs version for the lib variant, or empty string if stubs
384 // are not in use.
Paul Duffin7a1f7f32020-05-04 15:32:08 +0100385 //
Martin Stjernholm618b6712020-09-24 16:53:04 +0100386 // Marked 'ignored-on-host' as the AllStubsVersions() from which this is
387 // initialized is not set on host and the stubs.versions property which this
388 // is written to does not vary by arch so cannot be android specific.
389 StubsVersions []string `sdk:"ignored-on-host"`
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100390
Martin Stjernholmb0249572020-09-15 02:32:35 +0100391 // Value of SanitizeProperties.Sanitize. Several - but not all - of these
392 // affect the expanded variants. All are propagated to avoid entangling the
393 // sanitizer logic with the snapshot generation.
394 Sanitize SanitizeUserProps `android:"arch_variant"`
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100395
Paul Duffin2f6bc092019-12-13 10:40:56 +0000396 // outputFile is not exported as it is always arch specific.
397 outputFile android.Path
398}
399
Paul Duffin3a4eb502020-03-19 16:11:18 +0000400func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000401 addOutputFile := true
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000402 ccModule := variant.(*Module)
403
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000404 if s := ccModule.sanitize; s != nil {
405 // We currently do not capture sanitizer flags for libs with sanitizers
406 // enabled, because they may vary among variants that cannot be represented
407 // in the input blueprint files. In particular, sanitizerDepsMutator enables
408 // various sanitizers on dependencies, but in many cases only on static
409 // ones, and we cannot specify sanitizer flags at the link type level (i.e.
410 // in StaticOrSharedProperties).
411 if s.isUnsanitizedVariant() {
412 // This still captures explicitly disabled sanitizers, which may be
413 // necessary to avoid cyclic dependencies.
414 p.Sanitize = s.Properties.Sanitize
415 } else {
416 // Do not add the output file to the snapshot if we don't represent it
417 // properly.
418 addOutputFile = false
419 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000420 }
421
Colin Cross0de8a1e2020-09-18 14:15:30 -0700422 exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
423
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000424 // Separate out the generated include dirs (which are arch specific) from the
425 // include dirs (which may not be).
426 exportedIncludeDirs, exportedGeneratedIncludeDirs := android.FilterPathListPredicate(
Colin Cross0de8a1e2020-09-18 14:15:30 -0700427 exportedInfo.IncludeDirs, isGeneratedHeaderDirectory)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000428
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000429 p.archType = ccModule.Target().Arch.ArchType.String()
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000430
431 // Make sure that the include directories are unique.
432 p.ExportedIncludeDirs = android.FirstUniquePaths(exportedIncludeDirs)
433 p.exportedGeneratedIncludeDirs = android.FirstUniquePaths(exportedGeneratedIncludeDirs)
Paul Duffinab5467d2020-06-18 16:31:04 +0100434
435 // Take a copy before filtering out duplicates to avoid changing the slice owned by the
436 // ccModule.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700437 dirs := append(android.Paths(nil), exportedInfo.SystemIncludeDirs...)
Paul Duffinab5467d2020-06-18 16:31:04 +0100438 p.ExportedSystemIncludeDirs = android.FirstUniquePaths(dirs)
Paul Duffin9b76c0b2020-03-12 10:24:35 +0000439
Colin Cross0de8a1e2020-09-18 14:15:30 -0700440 p.ExportedFlags = exportedInfo.Flags
Paul Duffin13f02712020-03-06 12:30:43 +0000441 if ccModule.linker != nil {
442 specifiedDeps := specifiedDeps{}
443 specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
444
Colin Cross31076b32020-10-23 17:22:06 -0700445 if lib := ccModule.library; lib != nil {
446 if !lib.hasStubsVariants() {
447 // Propagate dynamic dependencies for implementation libs, but not stubs.
448 p.SharedLibs = specifiedDeps.sharedLibs
449 } else {
450 // TODO(b/169373910): 1. Only output the specific version (from
451 // ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
452 // the versioned stub libs are retained in the prebuilt tree; currently only
453 // the stub corresponding to ccModule.StubsVersion() is.
454 p.StubsVersions = lib.allStubsVersions()
455 }
Martin Stjernholmcc330d62020-04-21 20:45:35 +0100456 }
Paul Duffin13f02712020-03-06 12:30:43 +0000457 p.SystemSharedLibs = specifiedDeps.systemSharedLibs
458 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700459 p.exportedGeneratedHeaders = exportedInfo.GeneratedHeaders
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +0100460
Martin Stjernholm59e0c7a2020-10-28 23:38:33 +0000461 if !p.memberType.noOutputFiles && addOutputFile {
462 p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100463 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000464}
465
Paul Duffin712993c2020-05-05 14:11:57 +0100466func getRequiredMemberOutputFile(ctx android.SdkMemberContext, ccModule *Module) android.Path {
467 var path android.Path
468 outputFile := ccModule.OutputFile()
469 if outputFile.Valid() {
470 path = outputFile.Path()
471 } else {
472 ctx.SdkModuleContext().ModuleErrorf("member variant %s does not have a valid output file", ccModule)
473 }
474 return path
475}
476
Paul Duffin3a4eb502020-03-19 16:11:18 +0000477func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
478 addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
Paul Duffin2f6bc092019-12-13 10:40:56 +0000479}