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