blob: df713409d47560ec85e3e6e0cabee76688a356a8 [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)
Chris Parsonsbf4f55f2020-11-23 17:02:44 -0500149 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
Colin Cross649d8172020-12-10 12:30:21 -0800193 if p.header() {
194 ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{})
195
196 return nil
197 }
198
Colin Crossce75d2c2016-10-06 16:12:58 -0700199 return nil
200}
201
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700202func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string {
203 sanitize := ctx.Module().(*Module).sanitize
Paul Duffinbce90da2020-03-12 20:17:14 +0000204 srcs := p.properties.Srcs
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700205 srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000206 if p.static() {
207 srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700208 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000209 }
210 if p.shared() {
211 srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700212 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...)
Paul Duffinbce90da2020-03-12 20:17:14 +0000213 }
Paul Duffinbce90da2020-03-12 20:17:14 +0000214 return srcs
215}
216
Jiyong Park379de2f2018-12-19 02:47:14 +0900217func (p *prebuiltLibraryLinker) shared() bool {
218 return p.libraryDecorator.shared()
219}
220
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700221func (p *prebuiltLibraryLinker) nativeCoverage() bool {
222 return false
223}
224
Colin Cross33b2fb72019-05-14 14:07:01 -0700225func (p *prebuiltLibraryLinker) disablePrebuilt() {
226 p.properties.Srcs = nil
227}
228
Paul Duffinac6e6082019-12-11 15:22:32 +0000229func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Leo Li74f7b972017-05-17 11:30:45 -0700230 module, library := NewLibrary(hod)
Colin Crossce75d2c2016-10-06 16:12:58 -0700231 module.compiler = nil
232
233 prebuilt := &prebuiltLibraryLinker{
234 libraryDecorator: library,
235 }
236 module.linker = prebuilt
Colin Cross31076b32020-10-23 17:22:06 -0700237 module.library = prebuilt
Colin Crossde89fb82017-03-17 13:28:06 -0700238
Colin Cross74d73e22017-08-02 11:05:49 -0700239 module.AddProperties(&prebuilt.properties)
240
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700241 srcsSupplier := func(ctx android.BaseModuleContext) []string {
242 return prebuilt.prebuiltSrcs(ctx)
Paul Duffinbce90da2020-03-12 20:17:14 +0000243 }
244
245 android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
Jiyong Park379de2f2018-12-19 02:47:14 +0900246
Paul Duffinac6e6082019-12-11 15:22:32 +0000247 // Prebuilt libraries can be used in SDKs.
Jiyong Parkd1063c12019-07-17 20:08:41 +0900248 android.InitSdkAwareModule(module)
Paul Duffinac6e6082019-12-11 15:22:32 +0000249 return module, library
250}
251
Paul Duffinbce90da2020-03-12 20:17:14 +0000252// cc_prebuilt_library installs a precompiled shared library that are
253// listed in the srcs property in the device's directory.
254func PrebuiltLibraryFactory() android.Module {
255 module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
256
257 // Prebuilt shared libraries can be included in APEXes
258 android.InitApexModule(module)
259
260 return module.Init()
261}
262
Paul Duffinac6e6082019-12-11 15:22:32 +0000263// cc_prebuilt_library_shared installs a precompiled shared library that are
264// listed in the srcs property in the device's directory.
265func PrebuiltSharedLibraryFactory() android.Module {
266 module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
267 return module.Init()
268}
269
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400270// cc_prebuilt_test_library_shared installs a precompiled shared library
271// to be used as a data dependency of a test-related module (such as cc_test, or
272// cc_test_library).
273func PrebuiltSharedTestLibraryFactory() android.Module {
274 module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported)
275 library.BuildOnlyShared()
276 library.baseInstaller = NewTestInstaller()
277 return module.Init()
278}
279
Paul Duffinac6e6082019-12-11 15:22:32 +0000280func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
281 module, library := NewPrebuiltLibrary(hod)
282 library.BuildOnlyShared()
283
284 // Prebuilt shared libraries can be included in APEXes
285 android.InitApexModule(module)
Jiyong Park379de2f2018-12-19 02:47:14 +0900286
Leo Li74f7b972017-05-17 11:30:45 -0700287 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700288}
289
Patrice Arruda3554a982019-03-27 19:09:10 -0700290// cc_prebuilt_library_static installs a precompiled static library that are
291// listed in the srcs property in the device's directory.
Jooyung Han344d5432019-08-23 11:17:39 +0900292func PrebuiltStaticLibraryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -0700293 module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported)
294 return module.Init()
295}
296
297func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Paul Duffinac6e6082019-12-11 15:22:32 +0000298 module, library := NewPrebuiltLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700299 library.BuildOnlyStatic()
Leo Li74f7b972017-05-17 11:30:45 -0700300 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700301}
302
Martin Stjernholm0b92ac82020-03-11 21:45:49 +0000303type prebuiltObjectProperties struct {
304 Srcs []string `android:"path,arch_variant"`
305}
306
307type prebuiltObjectLinker struct {
308 android.Prebuilt
309 objectLinker
310
311 properties prebuiltObjectProperties
312}
313
314func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt {
315 return &p.Prebuilt
316}
317
318var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil)
319
320func (p *prebuiltObjectLinker) link(ctx ModuleContext,
321 flags Flags, deps PathDeps, objs Objects) android.Path {
322 if len(p.properties.Srcs) > 0 {
323 return p.Prebuilt.SingleSourcePath(ctx)
324 }
325 return nil
326}
327
Inseob Kim1042d292020-06-01 23:23:05 +0900328func (p *prebuiltObjectLinker) object() bool {
329 return true
330}
331
Martin Stjernholm0b92ac82020-03-11 21:45:49 +0000332func newPrebuiltObject() *Module {
333 module := newObject()
334 prebuilt := &prebuiltObjectLinker{
335 objectLinker: objectLinker{
336 baseLinker: NewBaseLinker(nil),
337 },
338 }
339 module.linker = prebuilt
340 module.AddProperties(&prebuilt.properties)
341 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
342 android.InitSdkAwareModule(module)
343 return module
344}
345
346func prebuiltObjectFactory() android.Module {
347 module := newPrebuiltObject()
348 return module.Init()
349}
350
Colin Crossde89fb82017-03-17 13:28:06 -0700351type prebuiltBinaryLinker struct {
352 *binaryDecorator
353 prebuiltLinker
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100354
355 toolPath android.OptionalPath
Colin Crossde89fb82017-03-17 13:28:06 -0700356}
357
358var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
359
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100360func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath {
361 return p.toolPath
362}
363
Colin Crossde89fb82017-03-17 13:28:06 -0700364func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
365 flags Flags, deps PathDeps, objs Objects) android.Path {
366 // TODO(ccross): verify shared library dependencies
Colin Cross74d73e22017-08-02 11:05:49 -0700367 if len(p.properties.Srcs) > 0 {
Colin Cross88f6fef2018-09-05 14:20:03 -0700368 fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
369 in := p.Prebuilt.SingleSourcePath(ctx)
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100370 outputFile := android.PathForModuleOut(ctx, fileName)
Colin Crossb60190a2018-09-04 16:28:17 -0700371 p.unstrippedOutputFile = in
372
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100373 if ctx.Host() {
374 // Host binaries are symlinked to their prebuilt source locations. That
375 // way they are executed directly from there so the linker resolves their
376 // shared library dependencies relative to that location (using
377 // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt
378 // repository can supply the expected versions of the shared libraries
379 // without interference from what is in the out tree.
Colin Cross94921e72017-08-08 16:20:15 -0700380
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100381 // These shared lib paths may point to copies of the libs in
382 // .intermediates, which isn't where the binary will load them from, but
383 // it's fine for dependency tracking. If a library dependency is updated,
384 // the symlink will get a new timestamp, along with any installed symlinks
385 // handled in make.
386 sharedLibPaths := deps.EarlySharedLibs
387 sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...)
388 sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...)
389
Martin Stjernholm14ee8322020-09-21 21:45:49 +0100390 var fromPath = in.String()
391 if !filepath.IsAbs(fromPath) {
392 fromPath = "$$PWD/" + fromPath
393 }
394
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100395 ctx.Build(pctx, android.BuildParams{
396 Rule: android.Symlink,
397 Output: outputFile,
398 Input: in,
399 Implicits: sharedLibPaths,
400 Args: map[string]string{
Martin Stjernholm14ee8322020-09-21 21:45:49 +0100401 "fromPath": fromPath,
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100402 },
403 })
404
405 p.toolPath = android.OptionalPathForPath(outputFile)
406 } else {
407 if p.stripper.NeedsStrip(ctx) {
408 stripped := android.PathForModuleOut(ctx, "stripped", fileName)
409 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags))
410 in = stripped
411 }
412
413 // Copy binaries to a name matching the final installed name
414 ctx.Build(pctx, android.BuildParams{
415 Rule: android.CpExecutable,
416 Description: "prebuilt",
417 Output: outputFile,
418 Input: in,
419 })
420 }
Colin Cross94921e72017-08-08 16:20:15 -0700421
422 return outputFile
Colin Crossde89fb82017-03-17 13:28:06 -0700423 }
424
425 return nil
426}
427
Inseob Kim7f283f42020-06-01 21:53:49 +0900428func (p *prebuiltBinaryLinker) binary() bool {
429 return true
430}
431
Patrice Arruda3554a982019-03-27 19:09:10 -0700432// cc_prebuilt_binary installs a precompiled executable in srcs property in the
433// device's directory.
Colin Cross36242852017-06-23 15:06:31 -0700434func prebuiltBinaryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -0700435 module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
436 return module.Init()
437}
438
439func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
440 module, binary := NewBinary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700441 module.compiler = nil
442
443 prebuilt := &prebuiltBinaryLinker{
444 binaryDecorator: binary,
445 }
446 module.linker = prebuilt
Martin Stjernholm837ee1a2020-08-20 02:54:52 +0100447 module.installer = prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700448
Colin Cross74d73e22017-08-02 11:05:49 -0700449 module.AddProperties(&prebuilt.properties)
450
451 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
Leo Li74f7b972017-05-17 11:30:45 -0700452 return module, binary
Colin Crossce75d2c2016-10-06 16:12:58 -0700453}
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700454
455type Sanitized struct {
456 None struct {
457 Srcs []string `android:"path,arch_variant"`
458 } `android:"arch_variant"`
459 Address struct {
460 Srcs []string `android:"path,arch_variant"`
461 } `android:"arch_variant"`
462 Hwaddress struct {
463 Srcs []string `android:"path,arch_variant"`
464 } `android:"arch_variant"`
465}
466
467func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string {
468 if sanitize == nil {
469 return nil
470 }
471 if Bool(sanitize.Properties.Sanitize.Address) && sanitized.Address.Srcs != nil {
472 return sanitized.Address.Srcs
473 }
474 if Bool(sanitize.Properties.Sanitize.Hwaddress) && sanitized.Hwaddress.Srcs != nil {
475 return sanitized.Hwaddress.Srcs
476 }
477 return sanitized.None.Srcs
478}