| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package cc | 
|  | 16 |  | 
|  | 17 | import ( | 
| Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 18 | "path/filepath" | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | "android/soong/android" | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 21 | "android/soong/bazel" | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 22 | ) | 
|  | 23 |  | 
|  | 24 | func init() { | 
| Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 25 | RegisterPrebuiltBuildComponents(android.InitRegistrationContext) | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 29 | ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory) | 
| Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 30 | ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) | 
|  | 31 | ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) | 
| Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 32 | ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) | 
| Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 33 | ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) | 
| Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 34 | ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 35 |  | 
|  | 36 | android.RegisterBp2BuildMutator("cc_prebuilt_library_shared", PrebuiltLibrarySharedBp2Build) | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | type prebuiltLinkerInterface interface { | 
|  | 40 | Name(string) string | 
|  | 41 | prebuilt() *android.Prebuilt | 
|  | 42 | } | 
|  | 43 |  | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 44 | type prebuiltLinkerProperties struct { | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 45 | // a prebuilt library or binary. Can reference a genrule module that generates an executable file. | 
|  | 46 | Srcs []string `android:"path,arch_variant"` | 
|  | 47 |  | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 48 | Sanitized Sanitized `android:"arch_variant"` | 
|  | 49 |  | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 50 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined | 
|  | 51 | // symbols, etc), default true. | 
|  | 52 | Check_elf_files *bool | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 53 |  | 
|  | 54 | // Optionally provide an import library if this is a Windows PE DLL prebuilt. | 
|  | 55 | // This is needed only if this library is linked by other modules in build time. | 
|  | 56 | // Only makes sense for the Windows target. | 
|  | 57 | Windows_import_lib *string `android:"path,arch_variant"` | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 58 | } | 
|  | 59 |  | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 60 | type prebuiltLinker struct { | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 61 | android.Prebuilt | 
| Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 62 |  | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 63 | properties prebuiltLinkerProperties | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 66 | func (p *prebuiltLinker) prebuilt() *android.Prebuilt { | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 67 | return &p.Prebuilt | 
|  | 68 | } | 
|  | 69 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 70 | func (p *prebuiltLinker) PrebuiltSrcs() []string { | 
|  | 71 | return p.properties.Srcs | 
|  | 72 | } | 
|  | 73 |  | 
| Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 74 | type prebuiltLibraryInterface interface { | 
|  | 75 | libraryInterface | 
|  | 76 | prebuiltLinkerInterface | 
|  | 77 | disablePrebuilt() | 
|  | 78 | } | 
|  | 79 |  | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 80 | type prebuiltLibraryLinker struct { | 
|  | 81 | *libraryDecorator | 
|  | 82 | prebuiltLinker | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) | 
| Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 86 | var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 87 |  | 
| Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 88 | func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} | 
|  | 89 |  | 
|  | 90 | func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { | 
| Logan Chien | c7f797e | 2019-01-14 15:35:08 +0800 | [diff] [blame] | 91 | return p.libraryDecorator.linkerDeps(ctx, deps) | 
| Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
|  | 94 | func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { | 
| Colin Cross | 1ab10a7 | 2018-09-04 11:02:37 -0700 | [diff] [blame] | 95 | return flags | 
| Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
|  | 98 | func (p *prebuiltLibraryLinker) linkerProps() []interface{} { | 
|  | 99 | return p.libraryDecorator.linkerProps() | 
|  | 100 | } | 
|  | 101 |  | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 102 | func (p *prebuiltLibraryLinker) link(ctx ModuleContext, | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 103 | flags Flags, deps PathDeps, objs Objects) android.Path { | 
| Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 104 |  | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 105 | p.libraryDecorator.flagExporter.exportIncludes(ctx) | 
|  | 106 | p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...) | 
|  | 107 | p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...) | 
|  | 108 | p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...) | 
|  | 109 | p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...) | 
|  | 110 | p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) | 
|  | 111 |  | 
|  | 112 | p.libraryDecorator.flagExporter.setProvider(ctx) | 
| Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 113 |  | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 114 | // TODO(ccross): verify shared library dependencies | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 115 | srcs := p.prebuiltSrcs(ctx) | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 116 | if len(srcs) > 0 { | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 117 | if len(srcs) > 1 { | 
|  | 118 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") | 
|  | 119 | return nil | 
|  | 120 | } | 
|  | 121 |  | 
| Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 122 | p.libraryDecorator.exportVersioningMacroIfNeeded(ctx) | 
|  | 123 |  | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 124 | in := android.PathForModuleSrc(ctx, srcs[0]) | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 125 |  | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 126 | if p.static() { | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 127 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() | 
|  | 128 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ | 
|  | 129 | StaticLibrary: in, | 
|  | 130 |  | 
|  | 131 | TransitiveStaticLibrariesForOrdering: depSet, | 
|  | 132 | }) | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 133 | return in | 
|  | 134 | } | 
|  | 135 |  | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 136 | if p.shared() { | 
| Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 137 | p.unstrippedOutputFile = in | 
| Colin Cross | 0fd6a41 | 2019-08-16 14:22:10 -0700 | [diff] [blame] | 138 | libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix() | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 139 | outputFile := android.PathForModuleOut(ctx, libName) | 
|  | 140 | var implicits android.Paths | 
|  | 141 |  | 
| Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 142 | if p.stripper.NeedsStrip(ctx) { | 
|  | 143 | stripFlags := flagsToStripFlags(flags) | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 144 | stripped := android.PathForModuleOut(ctx, "stripped", libName) | 
| Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 145 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 146 | in = stripped | 
|  | 147 | } | 
|  | 148 |  | 
| Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 149 | // Optimize out relinking against shared libraries whose interface hasn't changed by | 
|  | 150 | // depending on a table of contents file instead of the library itself. | 
|  | 151 | tocFile := android.PathForModuleOut(ctx, libName+".toc") | 
|  | 152 | p.tocFile = android.OptionalPathForPath(tocFile) | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 153 | TransformSharedObjectToToc(ctx, outputFile, tocFile) | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 154 |  | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 155 | if ctx.Windows() && p.properties.Windows_import_lib != nil { | 
|  | 156 | // Consumers of this library actually links to the import library in build | 
|  | 157 | // time and dynamically links to the DLL in run time. i.e. | 
|  | 158 | // a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll | 
|  | 159 | importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib)) | 
|  | 160 | importLibName := p.libraryDecorator.getLibName(ctx) + ".lib" | 
|  | 161 | importLibOutputFile := android.PathForModuleOut(ctx, importLibName) | 
|  | 162 | implicits = append(implicits, importLibOutputFile) | 
|  | 163 |  | 
|  | 164 | ctx.Build(pctx, android.BuildParams{ | 
|  | 165 | Rule:        android.Cp, | 
|  | 166 | Description: "prebuilt import library", | 
|  | 167 | Input:       importLibSrc, | 
|  | 168 | Output:      importLibOutputFile, | 
|  | 169 | Args: map[string]string{ | 
|  | 170 | "cpFlags": "-L", | 
|  | 171 | }, | 
|  | 172 | }) | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | ctx.Build(pctx, android.BuildParams{ | 
|  | 176 | Rule:        android.Cp, | 
|  | 177 | Description: "prebuilt shared library", | 
|  | 178 | Implicits:   implicits, | 
|  | 179 | Input:       in, | 
|  | 180 | Output:      outputFile, | 
|  | 181 | Args: map[string]string{ | 
|  | 182 | "cpFlags": "-L", | 
|  | 183 | }, | 
|  | 184 | }) | 
|  | 185 |  | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 186 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ | 
| Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 187 | SharedLibrary: outputFile, | 
|  | 188 | Target:        ctx.Target(), | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 189 |  | 
|  | 190 | TableOfContents: p.tocFile, | 
|  | 191 | }) | 
|  | 192 |  | 
| Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 193 | return outputFile | 
|  | 194 | } | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 197 | if p.header() { | 
|  | 198 | ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{}) | 
|  | 199 |  | 
| Martin Stjernholm | d51cb5c | 2021-11-30 18:49:03 +0000 | [diff] [blame] | 200 | // Need to return an output path so that the AndroidMk logic doesn't skip | 
|  | 201 | // the prebuilt header. For compatibility, in case Android.mk files use a | 
|  | 202 | // header lib in LOCAL_STATIC_LIBRARIES, create an empty ar file as | 
|  | 203 | // placeholder, just like non-prebuilt header modules do in linkStatic(). | 
|  | 204 | ph := android.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension) | 
|  | 205 | transformObjToStaticLib(ctx, nil, nil, builderFlags{}, ph, nil, nil) | 
|  | 206 | return ph | 
| Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 207 | } | 
|  | 208 |  | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 209 | return nil | 
|  | 210 | } | 
|  | 211 |  | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 212 | func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string { | 
|  | 213 | sanitize := ctx.Module().(*Module).sanitize | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 214 | srcs := p.properties.Srcs | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 215 | srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...) | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 216 | if p.static() { | 
|  | 217 | srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...) | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 218 | srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...) | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 219 | } | 
|  | 220 | if p.shared() { | 
|  | 221 | srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...) | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 222 | srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...) | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 223 | } | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 224 | return srcs | 
|  | 225 | } | 
|  | 226 |  | 
| Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 227 | func (p *prebuiltLibraryLinker) shared() bool { | 
|  | 228 | return p.libraryDecorator.shared() | 
|  | 229 | } | 
|  | 230 |  | 
| Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 231 | func (p *prebuiltLibraryLinker) nativeCoverage() bool { | 
|  | 232 | return false | 
|  | 233 | } | 
|  | 234 |  | 
| Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 235 | func (p *prebuiltLibraryLinker) disablePrebuilt() { | 
|  | 236 | p.properties.Srcs = nil | 
|  | 237 | } | 
|  | 238 |  | 
| Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 239 | // Implements versionedInterface | 
|  | 240 | func (p *prebuiltLibraryLinker) implementationModuleName(name string) string { | 
| Paul Duffin | 9804da0 | 2021-10-26 10:42:42 +0100 | [diff] [blame] | 241 | return android.RemoveOptionalPrebuiltPrefix(name) | 
| Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 244 | func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) { | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 245 | module, library := NewLibrary(hod) | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 246 | module.compiler = nil | 
|  | 247 |  | 
|  | 248 | prebuilt := &prebuiltLibraryLinker{ | 
|  | 249 | libraryDecorator: library, | 
|  | 250 | } | 
|  | 251 | module.linker = prebuilt | 
| Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 252 | module.library = prebuilt | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 253 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 254 | module.AddProperties(&prebuilt.properties) | 
|  | 255 |  | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 256 | if srcsProperty == "" { | 
|  | 257 | android.InitPrebuiltModuleWithoutSrcs(module) | 
|  | 258 | } else { | 
|  | 259 | srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string { | 
|  | 260 | return prebuilt.prebuiltSrcs(ctx) | 
|  | 261 | } | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 262 |  | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 263 | android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcsProperty) | 
|  | 264 | } | 
| Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 265 |  | 
| Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 266 | // Prebuilt libraries can be used in SDKs. | 
| Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 267 | android.InitSdkAwareModule(module) | 
| Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 268 | return module, library | 
|  | 269 | } | 
|  | 270 |  | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 271 | // cc_prebuilt_library installs a precompiled shared library that are | 
|  | 272 | // listed in the srcs property in the device's directory. | 
|  | 273 | func PrebuiltLibraryFactory() android.Module { | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 274 | module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") | 
| Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 275 |  | 
|  | 276 | // Prebuilt shared libraries can be included in APEXes | 
|  | 277 | android.InitApexModule(module) | 
|  | 278 |  | 
|  | 279 | return module.Init() | 
|  | 280 | } | 
|  | 281 |  | 
| Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 282 | // cc_prebuilt_library_shared installs a precompiled shared library that are | 
|  | 283 | // listed in the srcs property in the device's directory. | 
|  | 284 | func PrebuiltSharedLibraryFactory() android.Module { | 
|  | 285 | module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported) | 
|  | 286 | return module.Init() | 
|  | 287 | } | 
|  | 288 |  | 
| Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 289 | // cc_prebuilt_test_library_shared installs a precompiled shared library | 
|  | 290 | // to be used as a data dependency of a test-related module (such as cc_test, or | 
|  | 291 | // cc_test_library). | 
|  | 292 | func PrebuiltSharedTestLibraryFactory() android.Module { | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 293 | module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") | 
| Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 294 | library.BuildOnlyShared() | 
|  | 295 | library.baseInstaller = NewTestInstaller() | 
|  | 296 | return module.Init() | 
|  | 297 | } | 
|  | 298 |  | 
| Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 299 | func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 300 | module, library := NewPrebuiltLibrary(hod, "srcs") | 
| Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 301 | library.BuildOnlyShared() | 
|  | 302 |  | 
|  | 303 | // Prebuilt shared libraries can be included in APEXes | 
|  | 304 | android.InitApexModule(module) | 
| Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 305 |  | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 306 | return module, library | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 307 | } | 
|  | 308 |  | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 309 | // cc_prebuilt_library_static installs a precompiled static library that are | 
|  | 310 | // listed in the srcs property in the device's directory. | 
| Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 311 | func PrebuiltStaticLibraryFactory() android.Module { | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 312 | module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported) | 
|  | 313 | return module.Init() | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { | 
| Martin Stjernholm | e65c3ae | 2021-11-23 01:24:06 +0000 | [diff] [blame] | 317 | module, library := NewPrebuiltLibrary(hod, "srcs") | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 318 | library.BuildOnlyStatic() | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 319 | module.bazelHandler = &prebuiltStaticLibraryBazelHandler{module: module, library: library} | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 320 | return module, library | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 321 | } | 
|  | 322 |  | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 323 | type bazelPrebuiltLibrarySharedAttributes struct { | 
|  | 324 | Shared_library bazel.LabelAttribute | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | func PrebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext) { | 
|  | 328 | module, ok := ctx.Module().(*Module) | 
|  | 329 | if !ok { | 
|  | 330 | // Not a cc module | 
|  | 331 | return | 
|  | 332 | } | 
|  | 333 | if !module.ConvertWithBp2build(ctx) { | 
|  | 334 | return | 
|  | 335 | } | 
|  | 336 | if ctx.ModuleType() != "cc_prebuilt_library_shared" { | 
|  | 337 | return | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | prebuiltLibrarySharedBp2BuildInternal(ctx, module) | 
|  | 341 | } | 
|  | 342 |  | 
|  | 343 | func prebuiltLibrarySharedBp2BuildInternal(ctx android.TopDownMutatorContext, module *Module) { | 
|  | 344 | prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module) | 
|  | 345 |  | 
|  | 346 | attrs := &bazelPrebuiltLibrarySharedAttributes{ | 
|  | 347 | Shared_library: prebuiltAttrs.Src, | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | props := bazel.BazelTargetModuleProperties{ | 
|  | 351 | Rule_class:        "prebuilt_library_shared", | 
|  | 352 | Bzl_load_location: "//build/bazel/rules:prebuilt_library_shared.bzl", | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | name := android.RemoveOptionalPrebuiltPrefix(module.Name()) | 
|  | 356 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) | 
|  | 357 | } | 
|  | 358 |  | 
| Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 359 | type prebuiltObjectProperties struct { | 
|  | 360 | Srcs []string `android:"path,arch_variant"` | 
|  | 361 | } | 
|  | 362 |  | 
|  | 363 | type prebuiltObjectLinker struct { | 
|  | 364 | android.Prebuilt | 
|  | 365 | objectLinker | 
|  | 366 |  | 
|  | 367 | properties prebuiltObjectProperties | 
|  | 368 | } | 
|  | 369 |  | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 370 | type prebuiltStaticLibraryBazelHandler struct { | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 371 | android.BazelHandler | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 372 |  | 
|  | 373 | module  *Module | 
|  | 374 | library *libraryDecorator | 
|  | 375 | } | 
|  | 376 |  | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0d99045 | 2021-08-11 16:46:13 +0000 | [diff] [blame] | 377 | func (h *prebuiltStaticLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool { | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 378 | bazelCtx := ctx.Config().BazelContext | 
| Chris Parsons | 787fb36 | 2021-10-14 18:43:51 -0400 | [diff] [blame] | 379 | ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx)) | 
| Liz Kammer | fe23bf3 | 2021-04-09 16:17:05 -0400 | [diff] [blame] | 380 | if err != nil { | 
|  | 381 | ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err) | 
|  | 382 | } | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 383 | if !ok { | 
|  | 384 | return false | 
|  | 385 | } | 
| Liz Kammer | fe23bf3 | 2021-04-09 16:17:05 -0400 | [diff] [blame] | 386 | staticLibs := ccInfo.CcStaticLibraryFiles | 
| Liz Kammer | 3f9e155 | 2021-04-02 18:47:09 -0400 | [diff] [blame] | 387 | if len(staticLibs) > 1 { | 
|  | 388 | ctx.ModuleErrorf("expected 1 static library from bazel target %q, got %s", label, staticLibs) | 
|  | 389 | return false | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | // TODO(b/184543518): cc_prebuilt_library_static may have properties for re-exporting flags | 
|  | 393 |  | 
|  | 394 | // TODO(eakammer):Add stub-related flags if this library is a stub library. | 
|  | 395 | // h.library.exportVersioningMacroIfNeeded(ctx) | 
|  | 396 |  | 
|  | 397 | // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise | 
|  | 398 | // validation will fail. For now, set this to an empty list. | 
|  | 399 | // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation. | 
|  | 400 | h.library.collectedSnapshotHeaders = android.Paths{} | 
|  | 401 |  | 
|  | 402 | if len(staticLibs) == 0 { | 
|  | 403 | h.module.outputFile = android.OptionalPath{} | 
|  | 404 | return true | 
|  | 405 | } | 
|  | 406 |  | 
|  | 407 | out := android.PathForBazelOut(ctx, staticLibs[0]) | 
|  | 408 | h.module.outputFile = android.OptionalPathForPath(out) | 
|  | 409 |  | 
|  | 410 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(out).Build() | 
|  | 411 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ | 
|  | 412 | StaticLibrary: out, | 
|  | 413 |  | 
|  | 414 | TransitiveStaticLibrariesForOrdering: depSet, | 
|  | 415 | }) | 
|  | 416 |  | 
|  | 417 | return true | 
|  | 418 | } | 
|  | 419 |  | 
| Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 420 | func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt { | 
|  | 421 | return &p.Prebuilt | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil) | 
|  | 425 |  | 
|  | 426 | func (p *prebuiltObjectLinker) link(ctx ModuleContext, | 
|  | 427 | flags Flags, deps PathDeps, objs Objects) android.Path { | 
|  | 428 | if len(p.properties.Srcs) > 0 { | 
|  | 429 | return p.Prebuilt.SingleSourcePath(ctx) | 
|  | 430 | } | 
|  | 431 | return nil | 
|  | 432 | } | 
|  | 433 |  | 
| Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 434 | func (p *prebuiltObjectLinker) object() bool { | 
|  | 435 | return true | 
|  | 436 | } | 
|  | 437 |  | 
| Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 438 | func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module { | 
|  | 439 | module := newObject(hod) | 
| Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 440 | prebuilt := &prebuiltObjectLinker{ | 
|  | 441 | objectLinker: objectLinker{ | 
|  | 442 | baseLinker: NewBaseLinker(nil), | 
|  | 443 | }, | 
|  | 444 | } | 
|  | 445 | module.linker = prebuilt | 
|  | 446 | module.AddProperties(&prebuilt.properties) | 
|  | 447 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) | 
|  | 448 | android.InitSdkAwareModule(module) | 
|  | 449 | return module | 
|  | 450 | } | 
|  | 451 |  | 
|  | 452 | func prebuiltObjectFactory() android.Module { | 
| Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 453 | module := NewPrebuiltObject(android.HostAndDeviceSupported) | 
| Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 454 | return module.Init() | 
|  | 455 | } | 
|  | 456 |  | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 457 | type prebuiltBinaryLinker struct { | 
|  | 458 | *binaryDecorator | 
|  | 459 | prebuiltLinker | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 460 |  | 
|  | 461 | toolPath android.OptionalPath | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
|  | 464 | var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) | 
|  | 465 |  | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 466 | func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath { | 
|  | 467 | return p.toolPath | 
|  | 468 | } | 
|  | 469 |  | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 470 | func (p *prebuiltBinaryLinker) link(ctx ModuleContext, | 
|  | 471 | flags Flags, deps PathDeps, objs Objects) android.Path { | 
|  | 472 | // TODO(ccross): verify shared library dependencies | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 473 | if len(p.properties.Srcs) > 0 { | 
| Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 474 | fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix() | 
|  | 475 | in := p.Prebuilt.SingleSourcePath(ctx) | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 476 | outputFile := android.PathForModuleOut(ctx, fileName) | 
| Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 477 | p.unstrippedOutputFile = in | 
|  | 478 |  | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 479 | if ctx.Host() { | 
|  | 480 | // Host binaries are symlinked to their prebuilt source locations. That | 
|  | 481 | // way they are executed directly from there so the linker resolves their | 
|  | 482 | // shared library dependencies relative to that location (using | 
|  | 483 | // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt | 
|  | 484 | // repository can supply the expected versions of the shared libraries | 
|  | 485 | // without interference from what is in the out tree. | 
| Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 486 |  | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 487 | // These shared lib paths may point to copies of the libs in | 
|  | 488 | // .intermediates, which isn't where the binary will load them from, but | 
|  | 489 | // it's fine for dependency tracking. If a library dependency is updated, | 
|  | 490 | // the symlink will get a new timestamp, along with any installed symlinks | 
|  | 491 | // handled in make. | 
|  | 492 | sharedLibPaths := deps.EarlySharedLibs | 
|  | 493 | sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...) | 
|  | 494 | sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...) | 
|  | 495 |  | 
| Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 496 | var fromPath = in.String() | 
|  | 497 | if !filepath.IsAbs(fromPath) { | 
|  | 498 | fromPath = "$$PWD/" + fromPath | 
|  | 499 | } | 
|  | 500 |  | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 501 | ctx.Build(pctx, android.BuildParams{ | 
|  | 502 | Rule:      android.Symlink, | 
|  | 503 | Output:    outputFile, | 
|  | 504 | Input:     in, | 
|  | 505 | Implicits: sharedLibPaths, | 
|  | 506 | Args: map[string]string{ | 
| Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 507 | "fromPath": fromPath, | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 508 | }, | 
|  | 509 | }) | 
|  | 510 |  | 
|  | 511 | p.toolPath = android.OptionalPathForPath(outputFile) | 
|  | 512 | } else { | 
|  | 513 | if p.stripper.NeedsStrip(ctx) { | 
|  | 514 | stripped := android.PathForModuleOut(ctx, "stripped", fileName) | 
|  | 515 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags)) | 
|  | 516 | in = stripped | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | // Copy binaries to a name matching the final installed name | 
|  | 520 | ctx.Build(pctx, android.BuildParams{ | 
|  | 521 | Rule:        android.CpExecutable, | 
|  | 522 | Description: "prebuilt", | 
|  | 523 | Output:      outputFile, | 
|  | 524 | Input:       in, | 
|  | 525 | }) | 
|  | 526 | } | 
| Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 527 |  | 
|  | 528 | return outputFile | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 529 | } | 
|  | 530 |  | 
|  | 531 | return nil | 
|  | 532 | } | 
|  | 533 |  | 
| Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 534 | func (p *prebuiltBinaryLinker) binary() bool { | 
|  | 535 | return true | 
|  | 536 | } | 
|  | 537 |  | 
| Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 538 | // cc_prebuilt_binary installs a precompiled executable in srcs property in the | 
|  | 539 | // device's directory. | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 540 | func prebuiltBinaryFactory() android.Module { | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 541 | module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported) | 
|  | 542 | return module.Init() | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { | 
|  | 546 | module, binary := NewBinary(hod) | 
| Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 547 | module.compiler = nil | 
|  | 548 |  | 
|  | 549 | prebuilt := &prebuiltBinaryLinker{ | 
|  | 550 | binaryDecorator: binary, | 
|  | 551 | } | 
|  | 552 | module.linker = prebuilt | 
| Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 553 | module.installer = prebuilt | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 554 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 555 | module.AddProperties(&prebuilt.properties) | 
|  | 556 |  | 
|  | 557 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) | 
| Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 558 | return module, binary | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 559 | } | 
| Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 560 |  | 
|  | 561 | type Sanitized struct { | 
|  | 562 | None struct { | 
|  | 563 | Srcs []string `android:"path,arch_variant"` | 
|  | 564 | } `android:"arch_variant"` | 
|  | 565 | Address struct { | 
|  | 566 | Srcs []string `android:"path,arch_variant"` | 
|  | 567 | } `android:"arch_variant"` | 
|  | 568 | Hwaddress struct { | 
|  | 569 | Srcs []string `android:"path,arch_variant"` | 
|  | 570 | } `android:"arch_variant"` | 
|  | 571 | } | 
|  | 572 |  | 
|  | 573 | func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string { | 
|  | 574 | if sanitize == nil { | 
|  | 575 | return nil | 
|  | 576 | } | 
|  | 577 | if Bool(sanitize.Properties.Sanitize.Address) && sanitized.Address.Srcs != nil { | 
|  | 578 | return sanitized.Address.Srcs | 
|  | 579 | } | 
|  | 580 | if Bool(sanitize.Properties.Sanitize.Hwaddress) && sanitized.Hwaddress.Srcs != nil { | 
|  | 581 | return sanitized.Hwaddress.Srcs | 
|  | 582 | } | 
|  | 583 | return sanitized.None.Srcs | 
|  | 584 | } |