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 15package cc 16 17import ( 18 "path/filepath" 19 "strings" 20 21 "android/soong/android" 22 "android/soong/bazel" 23) 24 25func init() { 26 RegisterPrebuiltBuildComponents(android.InitRegistrationContext) 27} 28 29func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { 30 ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory) 31 ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) 32 ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) 33 ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) 34 ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) 35 ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) 36} 37 38type prebuiltLinkerInterface interface { 39 Name(string) string 40 prebuilt() *android.Prebuilt 41} 42 43type prebuiltLinkerProperties struct { 44 // a prebuilt library or binary. Can reference a genrule module that generates an executable file. 45 Srcs []string `android:"path,arch_variant"` 46 47 Sanitized Sanitized `android:"arch_variant"` 48 49 // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined 50 // symbols, etc), default true. 51 Check_elf_files *bool 52 53 // Optionally provide an import library if this is a Windows PE DLL prebuilt. 54 // This is needed only if this library is linked by other modules in build time. 55 // Only makes sense for the Windows target. 56 Windows_import_lib *string `android:"path,arch_variant"` 57} 58 59type prebuiltLinker struct { 60 android.Prebuilt 61 62 properties prebuiltLinkerProperties 63} 64 65func (p *prebuiltLinker) prebuilt() *android.Prebuilt { 66 return &p.Prebuilt 67} 68 69func (p *prebuiltLinker) PrebuiltSrcs() []string { 70 return p.properties.Srcs 71} 72 73type prebuiltLibraryInterface interface { 74 libraryInterface 75 prebuiltLinkerInterface 76 disablePrebuilt() 77} 78 79type prebuiltLibraryLinker struct { 80 *libraryDecorator 81 prebuiltLinker 82} 83 84var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) 85var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) 86 87func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} 88 89func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { 90 return p.libraryDecorator.linkerDeps(ctx, deps) 91} 92 93func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { 94 return flags 95} 96 97func (p *prebuiltLibraryLinker) linkerProps() []interface{} { 98 return p.libraryDecorator.linkerProps() 99} 100 101func (p *prebuiltLibraryLinker) link(ctx ModuleContext, 102 flags Flags, deps PathDeps, objs Objects) android.Path { 103 104 p.libraryDecorator.flagExporter.exportIncludes(ctx) 105 p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...) 106 p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...) 107 p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...) 108 p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...) 109 p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) 110 111 p.libraryDecorator.flagExporter.setProvider(ctx) 112 113 // TODO(ccross): verify shared library dependencies 114 srcs := p.prebuiltSrcs(ctx) 115 if len(srcs) > 0 { 116 if len(srcs) > 1 { 117 ctx.PropertyErrorf("srcs", "multiple prebuilt source files") 118 return nil 119 } 120 121 p.libraryDecorator.exportVersioningMacroIfNeeded(ctx) 122 123 in := android.PathForModuleSrc(ctx, srcs[0]) 124 125 if p.static() { 126 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() 127 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ 128 StaticLibrary: in, 129 130 TransitiveStaticLibrariesForOrdering: depSet, 131 }) 132 return in 133 } 134 135 if p.shared() { 136 p.unstrippedOutputFile = in 137 libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix() 138 outputFile := android.PathForModuleOut(ctx, libName) 139 var implicits android.Paths 140 141 if p.stripper.NeedsStrip(ctx) { 142 stripFlags := flagsToStripFlags(flags) 143 stripped := android.PathForModuleOut(ctx, "stripped", libName) 144 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) 145 in = stripped 146 } 147 148 // Optimize out relinking against shared libraries whose interface hasn't changed by 149 // depending on a table of contents file instead of the library itself. 150 tocFile := android.PathForModuleOut(ctx, libName+".toc") 151 p.tocFile = android.OptionalPathForPath(tocFile) 152 TransformSharedObjectToToc(ctx, outputFile, tocFile) 153 154 if ctx.Windows() && p.properties.Windows_import_lib != nil { 155 // Consumers of this library actually links to the import library in build 156 // time and dynamically links to the DLL in run time. i.e. 157 // a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll 158 importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib)) 159 importLibName := p.libraryDecorator.getLibName(ctx) + ".lib" 160 importLibOutputFile := android.PathForModuleOut(ctx, importLibName) 161 implicits = append(implicits, importLibOutputFile) 162 163 ctx.Build(pctx, android.BuildParams{ 164 Rule: android.Cp, 165 Description: "prebuilt import library", 166 Input: importLibSrc, 167 Output: importLibOutputFile, 168 Args: map[string]string{ 169 "cpFlags": "-L", 170 }, 171 }) 172 } 173 174 ctx.Build(pctx, android.BuildParams{ 175 Rule: android.Cp, 176 Description: "prebuilt shared library", 177 Implicits: implicits, 178 Input: in, 179 Output: outputFile, 180 Args: map[string]string{ 181 "cpFlags": "-L", 182 }, 183 }) 184 185 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ 186 SharedLibrary: outputFile, 187 Target: ctx.Target(), 188 189 TableOfContents: p.tocFile, 190 }) 191 192 // TODO(b/220898484): Mainline module sdk prebuilts of stub libraries use a stub 193 // library as their source and must not be installed, but libclang_rt.* libraries 194 // have stubs because they are LLNDK libraries, but use an implementation library 195 // as their source and need to be installed. This discrepancy should be resolved 196 // without the prefix hack below. 197 if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() && 198 !strings.HasPrefix(ctx.baseModuleName(), "libclang_rt.") { 199 ctx.Module().MakeUninstallable() 200 } 201 202 return outputFile 203 } 204 } 205 206 if p.header() { 207 ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{}) 208 209 // Need to return an output path so that the AndroidMk logic doesn't skip 210 // the prebuilt header. For compatibility, in case Android.mk files use a 211 // header lib in LOCAL_STATIC_LIBRARIES, create an empty ar file as 212 // placeholder, just like non-prebuilt header modules do in linkStatic(). 213 ph := android.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension) 214 transformObjToStaticLib(ctx, nil, nil, builderFlags{}, ph, nil, nil) 215 return ph 216 } 217 218 return nil 219} 220 221func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string { 222 sanitize := ctx.Module().(*Module).sanitize 223 srcs := p.properties.Srcs 224 srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...) 225 if p.static() { 226 srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...) 227 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...) 228 } 229 if p.shared() { 230 srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...) 231 srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...) 232 } 233 return srcs 234} 235 236func (p *prebuiltLibraryLinker) shared() bool { 237 return p.libraryDecorator.shared() 238} 239 240func (p *prebuiltLibraryLinker) nativeCoverage() bool { 241 return false 242} 243 244func (p *prebuiltLibraryLinker) disablePrebuilt() { 245 p.properties.Srcs = nil 246} 247 248// Implements versionedInterface 249func (p *prebuiltLibraryLinker) implementationModuleName(name string) string { 250 return android.RemoveOptionalPrebuiltPrefix(name) 251} 252 253func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) { 254 module, library := NewLibrary(hod) 255 module.compiler = nil 256 module.bazelable = true 257 258 prebuilt := &prebuiltLibraryLinker{ 259 libraryDecorator: library, 260 } 261 module.linker = prebuilt 262 module.library = prebuilt 263 264 module.AddProperties(&prebuilt.properties) 265 266 if srcsProperty == "" { 267 android.InitPrebuiltModuleWithoutSrcs(module) 268 } else { 269 srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string { 270 return prebuilt.prebuiltSrcs(ctx) 271 } 272 273 android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcsProperty) 274 } 275 276 // Prebuilt libraries can be used in SDKs. 277 android.InitSdkAwareModule(module) 278 return module, library 279} 280 281// cc_prebuilt_library installs a precompiled shared library that are 282// listed in the srcs property in the device's directory. 283func PrebuiltLibraryFactory() android.Module { 284 module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") 285 286 // Prebuilt shared libraries can be included in APEXes 287 android.InitApexModule(module) 288 289 return module.Init() 290} 291 292// cc_prebuilt_library_shared installs a precompiled shared library that are 293// listed in the srcs property in the device's directory. 294func PrebuiltSharedLibraryFactory() android.Module { 295 module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported) 296 return module.Init() 297} 298 299// cc_prebuilt_test_library_shared installs a precompiled shared library 300// to be used as a data dependency of a test-related module (such as cc_test, or 301// cc_test_library). 302func PrebuiltSharedTestLibraryFactory() android.Module { 303 module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs") 304 library.BuildOnlyShared() 305 library.baseInstaller = NewTestInstaller() 306 return module.Init() 307} 308 309func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { 310 module, library := NewPrebuiltLibrary(hod, "srcs") 311 library.BuildOnlyShared() 312 module.bazelable = true 313 module.bazelHandler = &prebuiltSharedLibraryBazelHandler{module: module, library: library} 314 315 // Prebuilt shared libraries can be included in APEXes 316 android.InitApexModule(module) 317 318 return module, library 319} 320 321// cc_prebuilt_library_static installs a precompiled static library that are 322// listed in the srcs property in the device's directory. 323func PrebuiltStaticLibraryFactory() android.Module { 324 module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported) 325 return module.Init() 326} 327 328func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { 329 module, library := NewPrebuiltLibrary(hod, "srcs") 330 library.BuildOnlyStatic() 331 module.bazelable = true 332 module.bazelHandler = &prebuiltStaticLibraryBazelHandler{module: module, library: library} 333 return module, library 334} 335 336type bazelPrebuiltLibraryStaticAttributes struct { 337 Static_library bazel.LabelAttribute 338 Export_includes bazel.StringListAttribute 339 Export_system_includes bazel.StringListAttribute 340} 341 342// TODO(b/228623543): The below is not entirely true until the bug is fixed. For now, both targets are always generated 343// Implements bp2build for cc_prebuilt_library modules. This will generate: 344// * Only a prebuilt_library_static if the shared.enabled property is set to false across all variants. 345// * Only a prebuilt_library_shared if the static.enabled property is set to false across all variants 346// * Both a prebuilt_library_static and prebuilt_library_shared if the aforementioned properties are not false across 347// all variants 348// 349// In all cases, prebuilt_library_static target names will be appended with "_bp2build_cc_library_static". 350func prebuiltLibraryBp2Build(ctx android.TopDownMutatorContext, module *Module) { 351 prebuiltLibraryStaticBp2Build(ctx, module, true) 352 prebuiltLibrarySharedBp2Build(ctx, module) 353} 354 355func prebuiltLibraryStaticBp2Build(ctx android.TopDownMutatorContext, module *Module, fullBuild bool) { 356 prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, true) 357 exportedIncludes := Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx, module) 358 359 attrs := &bazelPrebuiltLibraryStaticAttributes{ 360 Static_library: prebuiltAttrs.Src, 361 Export_includes: exportedIncludes.Includes, 362 Export_system_includes: exportedIncludes.SystemIncludes, 363 } 364 365 props := bazel.BazelTargetModuleProperties{ 366 Rule_class: "prebuilt_library_static", 367 Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_static.bzl", 368 } 369 370 name := android.RemoveOptionalPrebuiltPrefix(module.Name()) 371 if fullBuild { 372 name += "_bp2build_cc_library_static" 373 } 374 ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name}, attrs, prebuiltAttrs.Enabled) 375} 376 377type bazelPrebuiltLibrarySharedAttributes struct { 378 Shared_library bazel.LabelAttribute 379} 380 381func prebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext, module *Module) { 382 prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, false) 383 384 attrs := &bazelPrebuiltLibrarySharedAttributes{ 385 Shared_library: prebuiltAttrs.Src, 386 } 387 388 props := bazel.BazelTargetModuleProperties{ 389 Rule_class: "prebuilt_library_shared", 390 Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_shared.bzl", 391 } 392 393 name := android.RemoveOptionalPrebuiltPrefix(module.Name()) 394 ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name}, attrs, prebuiltAttrs.Enabled) 395} 396 397type prebuiltObjectProperties struct { 398 Srcs []string `android:"path,arch_variant"` 399} 400 401type prebuiltObjectLinker struct { 402 android.Prebuilt 403 objectLinker 404 405 properties prebuiltObjectProperties 406} 407 408type prebuiltStaticLibraryBazelHandler struct { 409 android.BazelHandler 410 411 module *Module 412 library *libraryDecorator 413} 414 415func (h *prebuiltStaticLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool { 416 bazelCtx := ctx.Config().BazelContext 417 ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx)) 418 if err != nil { 419 ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err) 420 } 421 if !ok { 422 return false 423 } 424 staticLibs := ccInfo.CcStaticLibraryFiles 425 if len(staticLibs) > 1 { 426 ctx.ModuleErrorf("expected 1 static library from bazel target %q, got %s", label, staticLibs) 427 return false 428 } 429 430 // TODO(b/184543518): cc_prebuilt_library_static may have properties for re-exporting flags 431 432 // TODO(eakammer):Add stub-related flags if this library is a stub library. 433 // h.library.exportVersioningMacroIfNeeded(ctx) 434 435 // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise 436 // validation will fail. For now, set this to an empty list. 437 // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation. 438 h.library.collectedSnapshotHeaders = android.Paths{} 439 440 if len(staticLibs) == 0 { 441 h.module.outputFile = android.OptionalPath{} 442 return true 443 } 444 445 out := android.PathForBazelOut(ctx, staticLibs[0]) 446 h.module.outputFile = android.OptionalPathForPath(out) 447 448 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(out).Build() 449 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ 450 StaticLibrary: out, 451 452 TransitiveStaticLibrariesForOrdering: depSet, 453 }) 454 455 return true 456} 457 458type prebuiltSharedLibraryBazelHandler struct { 459 android.BazelHandler 460 461 module *Module 462 library *libraryDecorator 463} 464 465func (h *prebuiltSharedLibraryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool { 466 bazelCtx := ctx.Config().BazelContext 467 ccInfo, ok, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx)) 468 if err != nil { 469 ctx.ModuleErrorf("Error getting Bazel CcInfo for %s: %s", label, err) 470 } 471 if !ok { 472 return false 473 } 474 sharedLibs := ccInfo.CcSharedLibraryFiles 475 if len(sharedLibs) != 1 { 476 ctx.ModuleErrorf("expected 1 shared library from bazel target %s, got %q", label, sharedLibs) 477 return false 478 } 479 480 // TODO(b/184543518): cc_prebuilt_library_shared may have properties for re-exporting flags 481 482 // TODO(eakammer):Add stub-related flags if this library is a stub library. 483 // h.library.exportVersioningMacroIfNeeded(ctx) 484 485 // Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise 486 // validation will fail. For now, set this to an empty list. 487 // TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation. 488 h.library.collectedSnapshotHeaders = android.Paths{} 489 490 if len(sharedLibs) == 0 { 491 h.module.outputFile = android.OptionalPath{} 492 return true 493 } 494 495 out := android.PathForBazelOut(ctx, sharedLibs[0]) 496 h.module.outputFile = android.OptionalPathForPath(out) 497 498 // FIXME(b/214600441): We don't yet strip prebuilt shared libraries 499 h.library.unstrippedOutputFile = out 500 501 var toc android.Path 502 if len(ccInfo.TocFile) > 0 { 503 toc = android.PathForBazelOut(ctx, ccInfo.TocFile) 504 } else { 505 toc = out // Just reuse `out` so ninja still gets an input but won't matter 506 } 507 508 info := SharedLibraryInfo{ 509 SharedLibrary: out, 510 TableOfContents: android.OptionalPathForPath(toc), 511 Target: ctx.Target(), 512 } 513 ctx.SetProvider(SharedLibraryInfoProvider, info) 514 515 h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo) 516 h.module.maybeUnhideFromMake() 517 518 return true 519} 520 521func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt { 522 return &p.Prebuilt 523} 524 525var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil) 526 527func (p *prebuiltObjectLinker) link(ctx ModuleContext, 528 flags Flags, deps PathDeps, objs Objects) android.Path { 529 if len(p.properties.Srcs) > 0 { 530 // Copy objects to a name matching the final installed name 531 in := p.Prebuilt.SingleSourcePath(ctx) 532 outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".o") 533 ctx.Build(pctx, android.BuildParams{ 534 Rule: android.CpExecutable, 535 Description: "prebuilt", 536 Output: outputFile, 537 Input: in, 538 }) 539 return outputFile 540 } 541 return nil 542} 543 544func (p *prebuiltObjectLinker) object() bool { 545 return true 546} 547 548func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module { 549 module := newObject(hod) 550 prebuilt := &prebuiltObjectLinker{ 551 objectLinker: objectLinker{ 552 baseLinker: NewBaseLinker(nil), 553 }, 554 } 555 module.linker = prebuilt 556 module.AddProperties(&prebuilt.properties) 557 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) 558 android.InitSdkAwareModule(module) 559 return module 560} 561 562func prebuiltObjectFactory() android.Module { 563 module := NewPrebuiltObject(android.HostAndDeviceSupported) 564 return module.Init() 565} 566 567type prebuiltBinaryLinker struct { 568 *binaryDecorator 569 prebuiltLinker 570 571 toolPath android.OptionalPath 572} 573 574var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) 575 576func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath { 577 return p.toolPath 578} 579 580func (p *prebuiltBinaryLinker) link(ctx ModuleContext, 581 flags Flags, deps PathDeps, objs Objects) android.Path { 582 // TODO(ccross): verify shared library dependencies 583 if len(p.properties.Srcs) > 0 { 584 fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix() 585 in := p.Prebuilt.SingleSourcePath(ctx) 586 outputFile := android.PathForModuleOut(ctx, fileName) 587 p.unstrippedOutputFile = in 588 589 if ctx.Host() { 590 // Host binaries are symlinked to their prebuilt source locations. That 591 // way they are executed directly from there so the linker resolves their 592 // shared library dependencies relative to that location (using 593 // $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt 594 // repository can supply the expected versions of the shared libraries 595 // without interference from what is in the out tree. 596 597 // These shared lib paths may point to copies of the libs in 598 // .intermediates, which isn't where the binary will load them from, but 599 // it's fine for dependency tracking. If a library dependency is updated, 600 // the symlink will get a new timestamp, along with any installed symlinks 601 // handled in make. 602 sharedLibPaths := deps.EarlySharedLibs 603 sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...) 604 sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...) 605 606 var fromPath = in.String() 607 if !filepath.IsAbs(fromPath) { 608 fromPath = "$$PWD/" + fromPath 609 } 610 611 ctx.Build(pctx, android.BuildParams{ 612 Rule: android.Symlink, 613 Output: outputFile, 614 Input: in, 615 Implicits: sharedLibPaths, 616 Args: map[string]string{ 617 "fromPath": fromPath, 618 }, 619 }) 620 621 p.toolPath = android.OptionalPathForPath(outputFile) 622 } else { 623 if p.stripper.NeedsStrip(ctx) { 624 stripped := android.PathForModuleOut(ctx, "stripped", fileName) 625 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags)) 626 in = stripped 627 } 628 629 // Copy binaries to a name matching the final installed name 630 ctx.Build(pctx, android.BuildParams{ 631 Rule: android.CpExecutable, 632 Description: "prebuilt", 633 Output: outputFile, 634 Input: in, 635 }) 636 } 637 638 return outputFile 639 } 640 641 return nil 642} 643 644func (p *prebuiltBinaryLinker) binary() bool { 645 return true 646} 647 648// cc_prebuilt_binary installs a precompiled executable in srcs property in the 649// device's directory. 650func prebuiltBinaryFactory() android.Module { 651 module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported) 652 return module.Init() 653} 654 655func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { 656 module, binary := newBinary(hod, false) 657 module.compiler = nil 658 659 prebuilt := &prebuiltBinaryLinker{ 660 binaryDecorator: binary, 661 } 662 module.linker = prebuilt 663 module.installer = prebuilt 664 665 module.AddProperties(&prebuilt.properties) 666 667 android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) 668 return module, binary 669} 670 671type Sanitized struct { 672 None struct { 673 Srcs []string `android:"path,arch_variant"` 674 } `android:"arch_variant"` 675 Address struct { 676 Srcs []string `android:"path,arch_variant"` 677 } `android:"arch_variant"` 678 Hwaddress struct { 679 Srcs []string `android:"path,arch_variant"` 680 } `android:"arch_variant"` 681} 682 683func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string { 684 if sanitize == nil { 685 return nil 686 } 687 if Bool(sanitize.Properties.Sanitize.Address) && sanitized.Address.Srcs != nil { 688 return sanitized.Address.Srcs 689 } 690 if Bool(sanitize.Properties.Sanitize.Hwaddress) && sanitized.Hwaddress.Srcs != nil { 691 return sanitized.Hwaddress.Srcs 692 } 693 return sanitized.None.Srcs 694} 695