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