2016-10-07 01:12:58 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-03-17 22:03:18 +01:00
|
|
|
android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory)
|
2017-03-17 21:28:06 +01:00
|
|
|
android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory)
|
|
|
|
android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltLinkerInterface interface {
|
|
|
|
Name(string) string
|
|
|
|
prebuilt() *android.Prebuilt
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
type prebuiltLinker struct {
|
2016-10-07 01:12:58 +02:00
|
|
|
android.Prebuilt
|
2018-11-20 04:59:08 +01:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
properties struct {
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2018-11-20 04:59:08 +01:00
|
|
|
|
|
|
|
// Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined
|
|
|
|
// symbols, etc), default true.
|
|
|
|
Check_elf_files *bool
|
2017-08-02 20:05:49 +02:00
|
|
|
}
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
|
2016-10-07 01:12:58 +02:00
|
|
|
return &p.Prebuilt
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (p *prebuiltLinker) PrebuiltSrcs() []string {
|
|
|
|
return p.properties.Srcs
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
type prebuiltLibraryLinker struct {
|
|
|
|
*libraryDecorator
|
|
|
|
prebuiltLinker
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
|
|
|
|
2018-08-14 01:02:49 +02:00
|
|
|
func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {}
|
|
|
|
|
|
|
|
func (p *prebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2019-01-14 08:35:08 +01:00
|
|
|
return p.libraryDecorator.linkerDeps(ctx, deps)
|
2018-08-14 01:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2018-09-04 20:02:37 +02:00
|
|
|
return flags
|
2018-08-14 01:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
|
|
|
return p.libraryDecorator.linkerProps()
|
|
|
|
}
|
|
|
|
|
2016-10-07 01:12:58 +02:00
|
|
|
func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
2016-09-27 02:33:01 +02:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-10-07 01:12:58 +02:00
|
|
|
// TODO(ccross): verify shared library dependencies
|
2017-08-02 20:05:49 +02:00
|
|
|
if len(p.properties.Srcs) > 0 {
|
2016-10-07 01:12:58 +02:00
|
|
|
p.libraryDecorator.exportIncludes(ctx, "-I")
|
|
|
|
p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
|
|
|
|
p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
|
2018-09-05 23:20:03 +02:00
|
|
|
|
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
in := p.Prebuilt.SingleSourcePath(ctx)
|
|
|
|
|
|
|
|
if p.shared() {
|
2018-09-05 01:28:17 +02:00
|
|
|
p.unstrippedOutputFile = in
|
2018-09-05 23:20:03 +02:00
|
|
|
libName := ctx.baseModuleName() + flags.Toolchain.ShlibSuffix()
|
|
|
|
if p.needsStrip(ctx) {
|
|
|
|
stripped := android.PathForModuleOut(ctx, "stripped", libName)
|
|
|
|
p.strip(ctx, in, stripped, builderFlags)
|
|
|
|
in = stripped
|
|
|
|
}
|
|
|
|
|
2018-09-05 01:28:17 +02:00
|
|
|
// Optimize out relinking against shared libraries whose interface hasn't changed by
|
|
|
|
// depending on a table of contents file instead of the library itself.
|
|
|
|
tocFile := android.PathForModuleOut(ctx, libName+".toc")
|
|
|
|
p.tocFile = android.OptionalPathForPath(tocFile)
|
|
|
|
TransformSharedObjectToToc(ctx, in, tocFile, builderFlags)
|
2018-09-05 23:20:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return in
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-18 18:47:14 +01:00
|
|
|
func (p *prebuiltLibraryLinker) shared() bool {
|
|
|
|
return p.libraryDecorator.shared()
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:31 +01:00
|
|
|
func (p *prebuiltLibraryLinker) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func prebuiltSharedLibraryFactory() android.Module {
|
2017-05-17 20:30:45 +02:00
|
|
|
module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
|
|
|
module, library := NewLibrary(hod)
|
2017-03-17 21:28:06 +01:00
|
|
|
library.BuildOnlyShared()
|
2016-10-07 01:12:58 +02:00
|
|
|
module.compiler = nil
|
|
|
|
|
|
|
|
prebuilt := &prebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
2017-03-17 21:28:06 +01:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
|
2018-12-18 18:47:14 +01:00
|
|
|
|
|
|
|
// Prebuilt libraries can be included in APEXes
|
|
|
|
android.InitApexModule(module)
|
|
|
|
|
2017-05-17 20:30:45 +02:00
|
|
|
return module, library
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func prebuiltStaticLibraryFactory() android.Module {
|
2017-05-17 20:30:45 +02:00
|
|
|
module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
|
|
|
module, library := NewLibrary(hod)
|
2017-03-17 21:28:06 +01:00
|
|
|
library.BuildOnlyStatic()
|
|
|
|
module.compiler = nil
|
|
|
|
|
|
|
|
prebuilt := &prebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
|
2017-05-17 20:30:45 +02:00
|
|
|
return module, library
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltBinaryLinker struct {
|
|
|
|
*binaryDecorator
|
|
|
|
prebuiltLinker
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
|
|
|
|
|
|
|
|
func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
|
|
|
// TODO(ccross): verify shared library dependencies
|
2017-08-02 20:05:49 +02:00
|
|
|
if len(p.properties.Srcs) > 0 {
|
2018-09-05 23:20:03 +02:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
2017-08-09 01:20:15 +02:00
|
|
|
|
|
|
|
fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
|
2018-09-05 23:20:03 +02:00
|
|
|
in := p.Prebuilt.SingleSourcePath(ctx)
|
|
|
|
|
2018-09-05 01:28:17 +02:00
|
|
|
p.unstrippedOutputFile = in
|
|
|
|
|
2018-09-05 23:20:03 +02:00
|
|
|
if p.needsStrip(ctx) {
|
|
|
|
stripped := android.PathForModuleOut(ctx, "stripped", fileName)
|
|
|
|
p.strip(ctx, in, stripped, builderFlags)
|
|
|
|
in = stripped
|
|
|
|
}
|
2017-08-09 01:20:15 +02:00
|
|
|
|
2018-09-05 23:20:03 +02:00
|
|
|
// Copy binaries to a name matching the final installed name
|
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-08-31 21:29:17 +02:00
|
|
|
Rule: android.CpExecutable,
|
2017-08-09 01:20:15 +02:00
|
|
|
Description: "prebuilt",
|
|
|
|
Output: outputFile,
|
2018-09-05 23:20:03 +02:00
|
|
|
Input: in,
|
2017-08-09 01:20:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return outputFile
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func prebuiltBinaryFactory() android.Module {
|
2017-05-17 20:30:45 +02:00
|
|
|
module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
|
|
|
module, binary := NewBinary(hod)
|
2017-03-17 21:28:06 +01:00
|
|
|
module.compiler = nil
|
|
|
|
|
|
|
|
prebuilt := &prebuiltBinaryLinker{
|
|
|
|
binaryDecorator: binary,
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
2016-10-07 01:12:58 +02:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
|
2017-05-17 20:30:45 +02:00
|
|
|
return module, binary
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|