blob: 45d3eb1afb26efcac72ef12b6f526275483d65ab [file] [log] [blame]
Colin Crossce75d2c2016-10-06 16:12:58 -07001// Copyright 2016 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 "android/soong/android"
Martin Stjernholm14ee8322020-09-21 21:45:49 +010019 "path/filepath"
Colin Crossce75d2c2016-10-06 16:12:58 -070020)
21
22func init() {
Paul Duffin59986b22019-12-19 14:38:36 +000023 RegisterPrebuiltBuildComponents(android.InitRegistrationContext)
24}
25
26func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
Paul Duffinbce90da2020-03-12 20:17:14 +000027 ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory)
Paul Duffin59986b22019-12-19 14:38:36 +000028 ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
29 ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
Chris Parsons1f6d90f2020-06-17 16:10:42 -040030 ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
Martin Stjernholm0b92ac82020-03-11 21:45:49 +000031 ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory)
Paul Duffin59986b22019-12-19 14:38:36 +000032 ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
Colin Crossce75d2c2016-10-06 16:12:58 -070033}
34
35type prebuiltLinkerInterface interface {
36 Name(string) string
37 prebuilt() *android.Prebuilt
38}
39
Patrice Arruda3554a982019-03-27 19:09:10 -070040type prebuiltLinkerProperties struct {
Patrice Arruda3554a982019-03-27 19:09:10 -070041 // a prebuilt library or binary. Can reference a genrule module that generates an executable file.
42 Srcs []string `android:"path,arch_variant"`
43
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -070044 Sanitized Sanitized `android:"arch_variant"`
45
Patrice Arruda3554a982019-03-27 19:09:10 -070046 // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined
47 // symbols, etc), default true.
48 Check_elf_files *bool
Yo Chianga3ad9b22020-03-18 14:19:07 +080049
50 // Optionally provide an import library if this is a Windows PE DLL prebuilt.
51 // This is needed only if this library is linked by other modules in build time.
52 // Only makes sense for the Windows target.
53 Windows_import_lib *string `android:"path,arch_variant"`
Patrice Arruda3554a982019-03-27 19:09:10 -070054}
55
Colin Crossde89fb82017-03-17 13:28:06 -070056type prebuiltLinker struct {
Colin Crossce75d2c2016-10-06 16:12:58 -070057 android.Prebuilt
Logan Chien4fcea3d2018-11-20 11:59:08 +080058
Patrice Arruda3554a982019-03-27 19:09:10 -070059 properties prebuiltLinkerProperties
Colin Crossce75d2c2016-10-06 16:12:58 -070060}
61
Colin Crossde89fb82017-03-17 13:28:06 -070062func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
Colin Crossce75d2c2016-10-06 16:12:58 -070063 return &p.Prebuilt
64}
65
Colin Cross74d73e22017-08-02 11:05:49 -070066func (p *prebuiltLinker) PrebuiltSrcs() []string {
67 return p.properties.Srcs
68}
69
Colin Cross33b2fb72019-05-14 14:07:01 -070070type prebuiltLibraryInterface interface {
71 libraryInterface
72 prebuiltLinkerInterface
73 disablePrebuilt()
74}
75
Colin Crossde89fb82017-03-17 13:28:06 -070076type prebuiltLibraryLinker struct {
77 *libraryDecorator
78 prebuiltLinker
79}
80
81var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
Colin Cross33b2fb72019-05-14 14:07:01 -070082var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil)
Colin Crossde89fb82017-03-17 13:28:06 -070083
Yi Kong00981662018-08-13 16:02:49 -070084func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {}
85
86func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Logan Chienc7f797e2019-01-14 15:35:08 +080087 return p.libraryDecorator.linkerDeps(ctx, deps)
Yi Kong00981662018-08-13 16:02:49 -070088}
89
90func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross1ab10a72018-09-04 11:02:37 -070091 return flags
Yi Kong00981662018-08-13 16:02:49 -070092}
93
94func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
95 return p.libraryDecorator.linkerProps()
96}
97
Colin Crossce75d2c2016-10-06 16:12:58 -070098func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070099 flags Flags, deps PathDeps, objs Objects) android.Path {
Paul Duffinf5ea9e12020-02-21 10:57:00 +0000100
Colin Cross0de8a1e2020-09-18 14:15:30 -0700101 p.libraryDecorator.flagExporter.exportIncludes(ctx)
102 p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...)
103 p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...)
104 p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...)
105 p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...)
106 p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
107
108 p.libraryDecorator.flagExporter.setProvider(ctx)
Paul Duffinf5ea9e12020-02-21 10:57:00 +0000109
Colin Crossce75d2c2016-10-06 16:12:58 -0700110 // TODO(ccross): verify shared library dependencies
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700111 srcs := p.prebuiltSrcs(ctx)
Paul Duffinbce90da2020-03-12 20:17:14 +0000112 if len(srcs) > 0 {
Colin Cross88f6fef2018-09-05 14:20:03 -0700113 builderFlags := flagsToBuilderFlags(flags)
114
Paul Duffinbce90da2020-03-12 20:17:14 +0000115 if len(srcs) > 1 {
116 ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
117 return nil
118 }
119
120 in := android.PathForModuleSrc(ctx, srcs[0])
Colin Cross88f6fef2018-09-05 14:20:03 -0700121
Yo Chianga3ad9b22020-03-18 14:19:07 +0800122 if p.static() {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700123 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
124 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
125 StaticLibrary: in,
126
127 TransitiveStaticLibrariesForOrdering: depSet,
128 })
Yo Chianga3ad9b22020-03-18 14:19:07 +0800129 return in
130 }
131
Colin Cross88f6fef2018-09-05 14:20:03 -0700132 if p.shared() {
Colin Crossb60190a2018-09-04 16:28:17 -0700133 p.unstrippedOutputFile = in
Colin Cross0fd6a412019-08-16 14:22:10 -0700134 libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
Yo Chianga3ad9b22020-03-18 14:19:07 +0800135 outputFile := android.PathForModuleOut(ctx, libName)
136 var implicits android.Paths
137
ThiƩbaud Weksteend4587452020-08-19 14:53:01 +0200138 if p.stripper.NeedsStrip(ctx) {
139 stripFlags := flagsToStripFlags(flags)
Colin Cross88f6fef2018-09-05 14:20:03 -0700140 stripped := android.PathForModuleOut(ctx, "stripped", libName)
ThiƩbaud Weksteend4587452020-08-19 14:53:01 +0200141 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
Colin Cross88f6fef2018-09-05 14:20:03 -0700142 in = stripped
143 }
144
Colin Crossb60190a2018-09-04 16:28:17 -0700145 // Optimize out relinking against shared libraries whose interface hasn't changed by
146 // depending on a table of contents file instead of the library itself.
147 tocFile := android.PathForModuleOut(ctx, libName+".toc")
148 p.tocFile = android.OptionalPathForPath(tocFile)
Yo Chianga3ad9b22020-03-18 14:19:07 +0800149 TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
Colin Cross88f6fef2018-09-05 14:20:03 -0700150
Yo Chianga3ad9b22020-03-18 14:19:07 +0800151 if ctx.Windows() && p.properties.Windows_import_lib != nil {
152 // Consumers of this library actually links to the import library in build
153 // time and dynamically links to the DLL in run time. i.e.
154 // a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll
155 importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib))
156 importLibName := p.libraryDecorator.getLibName(ctx) + ".lib"
157 importLibOutputFile := android.PathForModuleOut(ctx, importLibName)
158 implicits = append(implicits, importLibOutputFile)
159
160 ctx.Build(pctx, android.BuildParams{
161 Rule: android.Cp,
162 Description: "prebuilt import library",
163 Input: importLibSrc,
164 Output: importLibOutputFile,
165 Args: map[string]string{
166 "cpFlags": "-L",
167 },
168 })
169 }
170
171 ctx.Build(pctx, android.BuildParams{
172 Rule: android.Cp,
173 Description: "prebuilt shared library",
174 Implicits: implicits,
175 Input: in,
176 Output: outputFile,
177 Args: map[string]string{
178 "cpFlags": "-L",
179 },
180 })
181
Colin Cross0de8a1e2020-09-18 14:15:30 -0700182 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
183 SharedLibrary: outputFile,
184 UnstrippedSharedLibrary: p.unstrippedOutputFile,
185
186 TableOfContents: p.tocFile,
187 })
188
Yo Chianga3ad9b22020-03-18 14:19:07 +0800189 return outputFile
190 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700191 }
192
193 return nil
194}
195
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700196func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string {
197 sanitize := ctx.Module().(*Module).sanitize
Paul Duffinbce90da2020-03-12 20:17:14 +0000198 srcs := p.properties.Srcs
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700199 srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000200 if p.static() {
201 srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700202 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000203 }
204 if p.shared() {
205 srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700206 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000207 }
Paul Duffinbce90da2020-03-12 20:17:14 +0000208 return srcs
209}
210
Jiyong Park379de2f2018-12-19 02:47:14 +0900211func (p *prebuiltLibraryLinker) shared() bool {
212 return p.libraryDecorator.shared()
213}
214
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700215func (p *prebuiltLibraryLinker) nativeCoverage() bool {
216 return false
217}
218
Colin Cross33b2fb72019-05-14 14:07:01 -0700219func (p *prebuiltLibraryLinker) disablePrebuilt() {
220 p.properties.Srcs = nil
221}
222
Paul Duffinac6e6082019-12-11 15:22:32 +0000223func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Leo Li74f7b972017-05-17 11:30:45 -0700224 module, library := NewLibrary(hod)
Colin Crossce75d2c2016-10-06 16:12:58 -0700225 module.compiler = nil
226
227 prebuilt := &prebuiltLibraryLinker{
228 libraryDecorator: library,
229 }
230 module.linker = prebuilt
Colin Crossde89fb82017-03-17 13:28:06 -0700231
Colin Cross74d73e22017-08-02 11:05:49 -0700232 module.AddProperties(&prebuilt.properties)
233
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700234 srcsSupplier := func(ctx android.BaseModuleContext) []string {
235 return prebuilt.prebuiltSrcs(ctx)
Paul Duffinbce90da2020-03-12 20:17:14 +0000236 }
237
238 android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
Jiyong Park379de2f2018-12-19 02:47:14 +0900239
Paul Duffinac6e6082019-12-11 15:22:32 +0000240 // Prebuilt libraries can be used in SDKs.
Jiyong Parkd1063c12019-07-17 20:08:41 +0900241 android.InitSdkAwareModule(module)
Paul Duffinac6e6082019-12-11 15:22:32 +0000242 return module, library
243}
244
Paul Duffinbce90da2020-03-12 20:17:14 +0000245// cc_prebuilt_library installs a precompiled shared library that are
246// listed in the srcs property in the device's directory.
247func PrebuiltLibraryFactory() android.Module {
248 module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
249
250 // Prebuilt shared libraries can be included in APEXes
251 android.InitApexModule(module)
252
253 return module.Init()
254}
255
Paul Duffinac6e6082019-12-11 15:22:32 +0000256// cc_prebuilt_library_shared installs a precompiled shared library that are
257// listed in the srcs property in the device's directory.
258func PrebuiltSharedLibraryFactory() android.Module {
259 module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
260 return module.Init()
261}
262
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400263// cc_prebuilt_test_library_shared installs a precompiled shared library
264// to be used as a data dependency of a test-related module (such as cc_test, or
265// cc_test_library).
266func PrebuiltSharedTestLibraryFactory() android.Module {
267 module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported)
268 library.BuildOnlyShared()
269 library.baseInstaller = NewTestInstaller()
270 return module.Init()
271}
272
Paul Duffinac6e6082019-12-11 15:22:32 +0000273func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
274 module, library := NewPrebuiltLibrary(hod)
275 library.BuildOnlyShared()
276
277 // Prebuilt shared libraries can be included in APEXes
278 android.InitApexModule(module)
Jiyong Park379de2f2018-12-19 02:47:14 +0900279
Leo Li74f7b972017-05-17 11:30:45 -0700280 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700281}
282
Patrice Arruda3554a982019-03-27 19:09:10 -0700283// cc_prebuilt_library_static installs a precompiled static library that are
284// listed in the srcs property in the device's directory.
Jooyung Han344d5432019-08-23 11:17:39 +0900285func PrebuiltStaticLibraryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -0700286 module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported)
287 return module.Init()
288}
289
290func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Paul Duffinac6e6082019-12-11 15:22:32 +0000291 module, library := NewPrebuiltLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700292 library.BuildOnlyStatic()
Leo Li74f7b972017-05-17 11:30:45 -0700293 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700294}
295
Martin Stjernholm0b92ac82020-03-11 21:45:49 +0000296type prebuiltObjectProperties struct {
297 Srcs []string `android:"path,arch_variant"`
298}
299
300type prebuiltObjectLinker struct {
301 android.Prebuilt
302 objectLinker
303
304 properties prebuiltObjectProperties
305}
306
307func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt {
308 return &p.Prebuilt
309}
310
311var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil)
312
313func (p *prebuiltObjectLinker) link(ctx ModuleContext,
314 flags Flags, deps PathDeps, objs Objects) android.Path {
315 if len(p.properties.Srcs) > 0 {
316 return p.Prebuilt.SingleSourcePath(ctx)
317 }
318 return nil
319}
320
Inseob Kim1042d292020-06-01 23:23:05 +0900321func (p *prebuiltObjectLinker) object() bool {
322 return true
323}
324
Martin Stjernholm0b92ac82020-03-11 21:45:49 +0000325func newPrebuiltObject() *Module {
326 module := newObject()
327 prebuilt := &prebuiltObjectLinker{
328 objectLinker: objectLinker{
329 baseLinker: NewBaseLinker(nil),
330 },
331 }
332 module.linker = prebuilt
333 module.AddProperties(&prebuilt.properties)
334 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
335 android.InitSdkAwareModule(module)
336 return module
337}
338
339func prebuiltObjectFactory() android.Module {
340 module := newPrebuiltObject()
341 return module.Init()
342}
343
Colin Crossde89fb82017-03-17 13:28:06 -0700344type prebuiltBinaryLinker struct {
345 *binaryDecorator
346 prebuiltLinker
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100347
348 toolPath android.OptionalPath
Colin Crossde89fb82017-03-17 13:28:06 -0700349}
350
351var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
352
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100353func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath {
354 return p.toolPath
355}
356
Colin Crossde89fb82017-03-17 13:28:06 -0700357func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
358 flags Flags, deps PathDeps, objs Objects) android.Path {
359 // TODO(ccross): verify shared library dependencies
Colin Cross74d73e22017-08-02 11:05:49 -0700360 if len(p.properties.Srcs) > 0 {
Colin Cross88f6fef2018-09-05 14:20:03 -0700361 fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
362 in := p.Prebuilt.SingleSourcePath(ctx)
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100363 outputFile := android.PathForModuleOut(ctx, fileName)
Colin Crossb60190a2018-09-04 16:28:17 -0700364 p.unstrippedOutputFile = in
365
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100366 if ctx.Host() {
367 // Host binaries are symlinked to their prebuilt source locations. That
368 // way they are executed directly from there so the linker resolves their
369 // shared library dependencies relative to that location (using
370 // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt
371 // repository can supply the expected versions of the shared libraries
372 // without interference from what is in the out tree.
Colin Cross94921e72017-08-08 16:20:15 -0700373
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100374 // These shared lib paths may point to copies of the libs in
375 // .intermediates, which isn't where the binary will load them from, but
376 // it's fine for dependency tracking. If a library dependency is updated,
377 // the symlink will get a new timestamp, along with any installed symlinks
378 // handled in make.
379 sharedLibPaths := deps.EarlySharedLibs
380 sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...)
381 sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...)
382
Martin Stjernholm14ee8322020-09-21 21:45:49 +0100383 var fromPath = in.String()
384 if !filepath.IsAbs(fromPath) {
385 fromPath = "$$PWD/" + fromPath
386 }
387
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100388 ctx.Build(pctx, android.BuildParams{
389 Rule: android.Symlink,
390 Output: outputFile,
391 Input: in,
392 Implicits: sharedLibPaths,
393 Args: map[string]string{
Martin Stjernholm14ee8322020-09-21 21:45:49 +0100394 "fromPath": fromPath,
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100395 },
396 })
397
398 p.toolPath = android.OptionalPathForPath(outputFile)
399 } else {
400 if p.stripper.NeedsStrip(ctx) {
401 stripped := android.PathForModuleOut(ctx, "stripped", fileName)
402 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags))
403 in = stripped
404 }
405
406 // Copy binaries to a name matching the final installed name
407 ctx.Build(pctx, android.BuildParams{
408 Rule: android.CpExecutable,
409 Description: "prebuilt",
410 Output: outputFile,
411 Input: in,
412 })
413 }
Colin Cross94921e72017-08-08 16:20:15 -0700414
415 return outputFile
Colin Crossde89fb82017-03-17 13:28:06 -0700416 }
417
418 return nil
419}
420
Inseob Kim7f283f42020-06-01 21:53:49 +0900421func (p *prebuiltBinaryLinker) binary() bool {
422 return true
423}
424
Patrice Arruda3554a982019-03-27 19:09:10 -0700425// cc_prebuilt_binary installs a precompiled executable in srcs property in the
426// device's directory.
Colin Cross36242852017-06-23 15:06:31 -0700427func prebuiltBinaryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -0700428 module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
429 return module.Init()
430}
431
432func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
433 module, binary := NewBinary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700434 module.compiler = nil
435
436 prebuilt := &prebuiltBinaryLinker{
437 binaryDecorator: binary,
438 }
439 module.linker = prebuilt
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100440 module.installer = prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700441
Colin Cross74d73e22017-08-02 11:05:49 -0700442 module.AddProperties(&prebuilt.properties)
443
444 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
Leo Li74f7b972017-05-17 11:30:45 -0700445 return module, binary
Colin Crossce75d2c2016-10-06 16:12:58 -0700446}
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700447
448type Sanitized struct {
449 None struct {
450 Srcs []string `android:"path,arch_variant"`
451 } `android:"arch_variant"`
452 Address struct {
453 Srcs []string `android:"path,arch_variant"`
454 } `android:"arch_variant"`
455 Hwaddress struct {
456 Srcs []string `android:"path,arch_variant"`
457 } `android:"arch_variant"`
458}
459
460func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string {
461 if sanitize == nil {
462 return nil
463 }
464 if Bool(sanitize.Properties.Sanitize.Address) && sanitized.Address.Srcs != nil {
465 return sanitized.Address.Srcs
466 }
467 if Bool(sanitize.Properties.Sanitize.Hwaddress) && sanitized.Hwaddress.Srcs != nil {
468 return sanitized.Hwaddress.Srcs
469 }
470 return sanitized.None.Srcs
471}