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 ( |
| 18 | "android/soong/android" |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | func init() { |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 23 | RegisterPrebuiltBuildComponents(android.InitRegistrationContext) |
| 24 | } |
| 25 | |
| 26 | func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 27 | ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory) |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 28 | ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) |
| 29 | ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 30 | ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 31 | ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) |
Paul Duffin | 59986b2 | 2019-12-19 14:38:36 +0000 | [diff] [blame] | 32 | ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | type prebuiltLinkerInterface interface { |
| 36 | Name(string) string |
| 37 | prebuilt() *android.Prebuilt |
| 38 | } |
| 39 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 40 | type prebuiltLinkerProperties struct { |
| 41 | |
| 42 | // a prebuilt library or binary. Can reference a genrule module that generates an executable file. |
| 43 | Srcs []string `android:"path,arch_variant"` |
| 44 | |
| 45 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined |
| 46 | // symbols, etc), default true. |
| 47 | Check_elf_files *bool |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 48 | |
| 49 | // Optionally provide an import library if this is a Windows PE DLL prebuilt. |
| 50 | // This is needed only if this library is linked by other modules in build time. |
| 51 | // Only makes sense for the Windows target. |
| 52 | Windows_import_lib *string `android:"path,arch_variant"` |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 55 | type prebuiltLinker struct { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 56 | android.Prebuilt |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 57 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 58 | properties prebuiltLinkerProperties |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 61 | func (p *prebuiltLinker) prebuilt() *android.Prebuilt { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 62 | return &p.Prebuilt |
| 63 | } |
| 64 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 65 | func (p *prebuiltLinker) PrebuiltSrcs() []string { |
| 66 | return p.properties.Srcs |
| 67 | } |
| 68 | |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 69 | type prebuiltLibraryInterface interface { |
| 70 | libraryInterface |
| 71 | prebuiltLinkerInterface |
| 72 | disablePrebuilt() |
| 73 | } |
| 74 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 75 | type prebuiltLibraryLinker struct { |
| 76 | *libraryDecorator |
| 77 | prebuiltLinker |
| 78 | } |
| 79 | |
| 80 | var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 81 | var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 82 | |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 83 | func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} |
| 84 | |
| 85 | func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Logan Chien | c7f797e | 2019-01-14 15:35:08 +0800 | [diff] [blame] | 86 | return p.libraryDecorator.linkerDeps(ctx, deps) |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 1ab10a7 | 2018-09-04 11:02:37 -0700 | [diff] [blame] | 90 | return flags |
Yi Kong | 0098166 | 2018-08-13 16:02:49 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func (p *prebuiltLibraryLinker) linkerProps() []interface{} { |
| 94 | return p.libraryDecorator.linkerProps() |
| 95 | } |
| 96 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 97 | func (p *prebuiltLibraryLinker) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 98 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 99 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 100 | p.libraryDecorator.flagExporter.exportIncludes(ctx) |
| 101 | p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...) |
| 102 | p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...) |
| 103 | p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...) |
| 104 | p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...) |
| 105 | p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) |
| 106 | |
| 107 | p.libraryDecorator.flagExporter.setProvider(ctx) |
Paul Duffin | f5ea9e1 | 2020-02-21 10:57:00 +0000 | [diff] [blame] | 108 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 109 | // TODO(ccross): verify shared library dependencies |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 110 | srcs := p.prebuiltSrcs() |
| 111 | if len(srcs) > 0 { |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 112 | builderFlags := flagsToBuilderFlags(flags) |
| 113 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 114 | if len(srcs) > 1 { |
| 115 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | in := android.PathForModuleSrc(ctx, srcs[0]) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 120 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 121 | if p.static() { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 122 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 123 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 124 | StaticLibrary: in, |
| 125 | |
| 126 | TransitiveStaticLibrariesForOrdering: depSet, |
| 127 | }) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 128 | return in |
| 129 | } |
| 130 | |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 131 | if p.shared() { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 132 | p.unstrippedOutputFile = in |
Colin Cross | 0fd6a41 | 2019-08-16 14:22:10 -0700 | [diff] [blame] | 133 | libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix() |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 134 | outputFile := android.PathForModuleOut(ctx, libName) |
| 135 | var implicits android.Paths |
| 136 | |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 137 | if p.stripper.NeedsStrip(ctx) { |
| 138 | stripFlags := flagsToStripFlags(flags) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 139 | stripped := android.PathForModuleOut(ctx, "stripped", libName) |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 140 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 141 | in = stripped |
| 142 | } |
| 143 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 144 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 145 | // depending on a table of contents file instead of the library itself. |
| 146 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 147 | p.tocFile = android.OptionalPathForPath(tocFile) |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 148 | TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags) |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 149 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 150 | if ctx.Windows() && p.properties.Windows_import_lib != nil { |
| 151 | // Consumers of this library actually links to the import library in build |
| 152 | // time and dynamically links to the DLL in run time. i.e. |
| 153 | // a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll |
| 154 | importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib)) |
| 155 | importLibName := p.libraryDecorator.getLibName(ctx) + ".lib" |
| 156 | importLibOutputFile := android.PathForModuleOut(ctx, importLibName) |
| 157 | implicits = append(implicits, importLibOutputFile) |
| 158 | |
| 159 | ctx.Build(pctx, android.BuildParams{ |
| 160 | Rule: android.Cp, |
| 161 | Description: "prebuilt import library", |
| 162 | Input: importLibSrc, |
| 163 | Output: importLibOutputFile, |
| 164 | Args: map[string]string{ |
| 165 | "cpFlags": "-L", |
| 166 | }, |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | ctx.Build(pctx, android.BuildParams{ |
| 171 | Rule: android.Cp, |
| 172 | Description: "prebuilt shared library", |
| 173 | Implicits: implicits, |
| 174 | Input: in, |
| 175 | Output: outputFile, |
| 176 | Args: map[string]string{ |
| 177 | "cpFlags": "-L", |
| 178 | }, |
| 179 | }) |
| 180 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 181 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 182 | SharedLibrary: outputFile, |
| 183 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 184 | |
| 185 | TableOfContents: p.tocFile, |
| 186 | }) |
| 187 | |
Yo Chiang | a3ad9b2 | 2020-03-18 14:19:07 +0800 | [diff] [blame] | 188 | return outputFile |
| 189 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return nil |
| 193 | } |
| 194 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 195 | func (p *prebuiltLibraryLinker) prebuiltSrcs() []string { |
| 196 | srcs := p.properties.Srcs |
| 197 | if p.static() { |
| 198 | srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...) |
| 199 | } |
| 200 | if p.shared() { |
| 201 | srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...) |
| 202 | } |
| 203 | |
| 204 | return srcs |
| 205 | } |
| 206 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 207 | func (p *prebuiltLibraryLinker) shared() bool { |
| 208 | return p.libraryDecorator.shared() |
| 209 | } |
| 210 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 211 | func (p *prebuiltLibraryLinker) nativeCoverage() bool { |
| 212 | return false |
| 213 | } |
| 214 | |
Colin Cross | 33b2fb7 | 2019-05-14 14:07:01 -0700 | [diff] [blame] | 215 | func (p *prebuiltLibraryLinker) disablePrebuilt() { |
| 216 | p.properties.Srcs = nil |
| 217 | } |
| 218 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 219 | func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 220 | module, library := NewLibrary(hod) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 221 | module.compiler = nil |
| 222 | |
| 223 | prebuilt := &prebuiltLibraryLinker{ |
| 224 | libraryDecorator: library, |
| 225 | } |
| 226 | module.linker = prebuilt |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 227 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 228 | module.AddProperties(&prebuilt.properties) |
| 229 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 230 | srcsSupplier := func() []string { |
| 231 | return prebuilt.prebuiltSrcs() |
| 232 | } |
| 233 | |
| 234 | android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs") |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 235 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 236 | // Prebuilt libraries can be used in SDKs. |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 237 | android.InitSdkAwareModule(module) |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 238 | return module, library |
| 239 | } |
| 240 | |
Paul Duffin | bce90da | 2020-03-12 20:17:14 +0000 | [diff] [blame] | 241 | // cc_prebuilt_library installs a precompiled shared library that are |
| 242 | // listed in the srcs property in the device's directory. |
| 243 | func PrebuiltLibraryFactory() android.Module { |
| 244 | module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported) |
| 245 | |
| 246 | // Prebuilt shared libraries can be included in APEXes |
| 247 | android.InitApexModule(module) |
| 248 | |
| 249 | return module.Init() |
| 250 | } |
| 251 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 252 | // cc_prebuilt_library_shared installs a precompiled shared library that are |
| 253 | // listed in the srcs property in the device's directory. |
| 254 | func PrebuiltSharedLibraryFactory() android.Module { |
| 255 | module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported) |
| 256 | return module.Init() |
| 257 | } |
| 258 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 259 | // cc_prebuilt_test_library_shared installs a precompiled shared library |
| 260 | // to be used as a data dependency of a test-related module (such as cc_test, or |
| 261 | // cc_test_library). |
| 262 | func PrebuiltSharedTestLibraryFactory() android.Module { |
| 263 | module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported) |
| 264 | library.BuildOnlyShared() |
| 265 | library.baseInstaller = NewTestInstaller() |
| 266 | return module.Init() |
| 267 | } |
| 268 | |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 269 | func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
| 270 | module, library := NewPrebuiltLibrary(hod) |
| 271 | library.BuildOnlyShared() |
| 272 | |
| 273 | // Prebuilt shared libraries can be included in APEXes |
| 274 | android.InitApexModule(module) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 275 | |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 276 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 279 | // cc_prebuilt_library_static installs a precompiled static library that are |
| 280 | // listed in the srcs property in the device's directory. |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 281 | func PrebuiltStaticLibraryFactory() android.Module { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 282 | module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported) |
| 283 | return module.Init() |
| 284 | } |
| 285 | |
| 286 | func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Paul Duffin | ac6e608 | 2019-12-11 15:22:32 +0000 | [diff] [blame] | 287 | module, library := NewPrebuiltLibrary(hod) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 288 | library.BuildOnlyStatic() |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 289 | return module, library |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 292 | type prebuiltObjectProperties struct { |
| 293 | Srcs []string `android:"path,arch_variant"` |
| 294 | } |
| 295 | |
| 296 | type prebuiltObjectLinker struct { |
| 297 | android.Prebuilt |
| 298 | objectLinker |
| 299 | |
| 300 | properties prebuiltObjectProperties |
| 301 | } |
| 302 | |
| 303 | func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt { |
| 304 | return &p.Prebuilt |
| 305 | } |
| 306 | |
| 307 | var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil) |
| 308 | |
| 309 | func (p *prebuiltObjectLinker) link(ctx ModuleContext, |
| 310 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 311 | if len(p.properties.Srcs) > 0 { |
| 312 | return p.Prebuilt.SingleSourcePath(ctx) |
| 313 | } |
| 314 | return nil |
| 315 | } |
| 316 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 317 | func (p *prebuiltObjectLinker) object() bool { |
| 318 | return true |
| 319 | } |
| 320 | |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 321 | func newPrebuiltObject() *Module { |
| 322 | module := newObject() |
| 323 | prebuilt := &prebuiltObjectLinker{ |
| 324 | objectLinker: objectLinker{ |
| 325 | baseLinker: NewBaseLinker(nil), |
| 326 | }, |
| 327 | } |
| 328 | module.linker = prebuilt |
| 329 | module.AddProperties(&prebuilt.properties) |
| 330 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) |
| 331 | android.InitSdkAwareModule(module) |
| 332 | return module |
| 333 | } |
| 334 | |
| 335 | func prebuiltObjectFactory() android.Module { |
| 336 | module := newPrebuiltObject() |
| 337 | return module.Init() |
| 338 | } |
| 339 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 340 | type prebuiltBinaryLinker struct { |
| 341 | *binaryDecorator |
| 342 | prebuiltLinker |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 343 | |
| 344 | toolPath android.OptionalPath |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) |
| 348 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 349 | func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath { |
| 350 | return p.toolPath |
| 351 | } |
| 352 | |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 353 | func (p *prebuiltBinaryLinker) link(ctx ModuleContext, |
| 354 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 355 | // TODO(ccross): verify shared library dependencies |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 356 | if len(p.properties.Srcs) > 0 { |
Colin Cross | 88f6fef | 2018-09-05 14:20:03 -0700 | [diff] [blame] | 357 | fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
| 358 | in := p.Prebuilt.SingleSourcePath(ctx) |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 359 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 360 | p.unstrippedOutputFile = in |
| 361 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 362 | if ctx.Host() { |
| 363 | // Host binaries are symlinked to their prebuilt source locations. That |
| 364 | // way they are executed directly from there so the linker resolves their |
| 365 | // shared library dependencies relative to that location (using |
| 366 | // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt |
| 367 | // repository can supply the expected versions of the shared libraries |
| 368 | // without interference from what is in the out tree. |
Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 369 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 370 | // These shared lib paths may point to copies of the libs in |
| 371 | // .intermediates, which isn't where the binary will load them from, but |
| 372 | // it's fine for dependency tracking. If a library dependency is updated, |
| 373 | // the symlink will get a new timestamp, along with any installed symlinks |
| 374 | // handled in make. |
| 375 | sharedLibPaths := deps.EarlySharedLibs |
| 376 | sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...) |
| 377 | sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...) |
| 378 | |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 379 | var fromPath = in.String() |
| 380 | if !filepath.IsAbs(fromPath) { |
| 381 | fromPath = "$$PWD/" + fromPath |
| 382 | } |
| 383 | |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 384 | ctx.Build(pctx, android.BuildParams{ |
| 385 | Rule: android.Symlink, |
| 386 | Output: outputFile, |
| 387 | Input: in, |
| 388 | Implicits: sharedLibPaths, |
| 389 | Args: map[string]string{ |
Martin Stjernholm | 14ee832 | 2020-09-21 21:45:49 +0100 | [diff] [blame] | 390 | "fromPath": fromPath, |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 391 | }, |
| 392 | }) |
| 393 | |
| 394 | p.toolPath = android.OptionalPathForPath(outputFile) |
| 395 | } else { |
| 396 | if p.stripper.NeedsStrip(ctx) { |
| 397 | stripped := android.PathForModuleOut(ctx, "stripped", fileName) |
| 398 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags)) |
| 399 | in = stripped |
| 400 | } |
| 401 | |
| 402 | // Copy binaries to a name matching the final installed name |
| 403 | ctx.Build(pctx, android.BuildParams{ |
| 404 | Rule: android.CpExecutable, |
| 405 | Description: "prebuilt", |
| 406 | Output: outputFile, |
| 407 | Input: in, |
| 408 | }) |
| 409 | } |
Colin Cross | 94921e7 | 2017-08-08 16:20:15 -0700 | [diff] [blame] | 410 | |
| 411 | return outputFile |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | return nil |
| 415 | } |
| 416 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 417 | func (p *prebuiltBinaryLinker) binary() bool { |
| 418 | return true |
| 419 | } |
| 420 | |
Patrice Arruda | 3554a98 | 2019-03-27 19:09:10 -0700 | [diff] [blame] | 421 | // cc_prebuilt_binary installs a precompiled executable in srcs property in the |
| 422 | // device's directory. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 423 | func prebuiltBinaryFactory() android.Module { |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 424 | module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported) |
| 425 | return module.Init() |
| 426 | } |
| 427 | |
| 428 | func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { |
| 429 | module, binary := NewBinary(hod) |
Colin Cross | de89fb8 | 2017-03-17 13:28:06 -0700 | [diff] [blame] | 430 | module.compiler = nil |
| 431 | |
| 432 | prebuilt := &prebuiltBinaryLinker{ |
| 433 | binaryDecorator: binary, |
| 434 | } |
| 435 | module.linker = prebuilt |
Martin Stjernholm | 837ee1a | 2020-08-20 02:54:52 +0100 | [diff] [blame] | 436 | module.installer = prebuilt |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 437 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 438 | module.AddProperties(&prebuilt.properties) |
| 439 | |
| 440 | android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) |
Leo Li | 74f7b97 | 2017-05-17 11:30:45 -0700 | [diff] [blame] | 441 | return module, binary |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 442 | } |