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