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 (
|
2020-09-21 22:45:49 +02:00
|
|
|
"path/filepath"
|
2021-08-11 18:46:13 +02:00
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2021-08-11 18:46:13 +02:00
|
|
|
"android/soong/android"
|
2016-10-07 01:12:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-12-19 15:38:36 +01:00
|
|
|
RegisterPrebuiltBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
|
2020-03-12 21:17:14 +01:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory)
|
2019-12-19 15:38:36 +01:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
2020-06-17 22:10:42 +02:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
|
2022-12-06 01:46:39 +01:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_object", PrebuiltObjectFactory)
|
2022-09-01 17:04:04 +02:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_binary", PrebuiltBinaryFactory)
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltLinkerInterface interface {
|
|
|
|
Name(string) string
|
|
|
|
prebuilt() *android.Prebuilt
|
2024-01-19 01:22:22 +01:00
|
|
|
sourceModuleName() string
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
type prebuiltLinkerProperties struct {
|
2024-01-19 01:22:22 +01:00
|
|
|
// Name of the source soong module that gets shadowed by this prebuilt
|
|
|
|
// If unspecified, follows the naming convention that the source module of
|
|
|
|
// the prebuilt is Name() without "prebuilt_" prefix
|
|
|
|
Source_module_name *string
|
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
// a prebuilt library or binary. Can reference a genrule module that generates an executable file.
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
|
2020-07-25 00:35:40 +02:00
|
|
|
Sanitized Sanitized `android:"arch_variant"`
|
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
// Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined
|
|
|
|
// symbols, etc), default true.
|
|
|
|
Check_elf_files *bool
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
|
2022-08-10 10:25:54 +02:00
|
|
|
// if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols *string
|
|
|
|
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
// Optionally provide an import library if this is a Windows PE DLL prebuilt.
|
|
|
|
// This is needed only if this library is linked by other modules in build time.
|
|
|
|
// Only makes sense for the Windows target.
|
|
|
|
Windows_import_lib *string `android:"path,arch_variant"`
|
2019-03-28 03:09:10 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
properties prebuiltLinkerProperties
|
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
|
|
|
|
}
|
|
|
|
|
2019-05-14 23:07:01 +02:00
|
|
|
type prebuiltLibraryInterface interface {
|
|
|
|
libraryInterface
|
|
|
|
prebuiltLinkerInterface
|
|
|
|
disablePrebuilt()
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
type prebuiltLibraryLinker struct {
|
|
|
|
*libraryDecorator
|
|
|
|
prebuiltLinker
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
2019-05-14 23:07:01 +02:00
|
|
|
var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil)
|
2017-03-17 21:28:06 +01:00
|
|
|
|
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 {
|
2020-02-21 11:57:00 +01:00
|
|
|
|
2020-09-18 23:15:30 +02:00
|
|
|
p.libraryDecorator.flagExporter.exportIncludes(ctx)
|
|
|
|
p.libraryDecorator.flagExporter.reexportDirs(deps.ReexportedDirs...)
|
|
|
|
p.libraryDecorator.flagExporter.reexportSystemDirs(deps.ReexportedSystemDirs...)
|
|
|
|
p.libraryDecorator.flagExporter.reexportFlags(deps.ReexportedFlags...)
|
|
|
|
p.libraryDecorator.flagExporter.reexportDeps(deps.ReexportedDeps...)
|
|
|
|
p.libraryDecorator.flagExporter.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
|
|
|
|
|
|
|
p.libraryDecorator.flagExporter.setProvider(ctx)
|
2020-02-21 11:57:00 +01:00
|
|
|
|
2016-10-07 01:12:58 +02:00
|
|
|
// TODO(ccross): verify shared library dependencies
|
2020-07-25 00:35:40 +02:00
|
|
|
srcs := p.prebuiltSrcs(ctx)
|
2020-03-12 21:17:14 +01:00
|
|
|
if len(srcs) > 0 {
|
|
|
|
if len(srcs) > 1 {
|
|
|
|
ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-14 01:20:00 +01:00
|
|
|
p.libraryDecorator.exportVersioningMacroIfNeeded(ctx)
|
|
|
|
|
2020-03-12 21:17:14 +01:00
|
|
|
in := android.PathForModuleSrc(ctx, srcs[0])
|
2018-09-05 23:20:03 +02:00
|
|
|
|
2022-08-10 10:25:54 +02:00
|
|
|
if String(p.prebuiltLinker.properties.Prefix_symbols) != "" {
|
|
|
|
prefixed := android.PathForModuleOut(ctx, "prefixed", srcs[0])
|
|
|
|
transformBinaryPrefixSymbols(ctx, String(p.prebuiltLinker.properties.Prefix_symbols),
|
|
|
|
in, flagsToBuilderFlags(flags), prefixed)
|
|
|
|
in = prefixed
|
|
|
|
}
|
|
|
|
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
if p.static() {
|
2022-04-21 21:50:51 +02:00
|
|
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(in).Build()
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, StaticLibraryInfoProvider, StaticLibraryInfo{
|
2020-09-18 23:15:30 +02:00
|
|
|
StaticLibrary: in,
|
|
|
|
|
|
|
|
TransitiveStaticLibrariesForOrdering: depSet,
|
|
|
|
})
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:20:03 +02:00
|
|
|
if p.shared() {
|
2018-09-05 01:28:17 +02:00
|
|
|
p.unstrippedOutputFile = in
|
2019-08-16 23:22:10 +02:00
|
|
|
libName := p.libraryDecorator.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
outputFile := android.PathForModuleOut(ctx, libName)
|
|
|
|
var implicits android.Paths
|
|
|
|
|
2020-08-19 14:53:01 +02:00
|
|
|
if p.stripper.NeedsStrip(ctx) {
|
|
|
|
stripFlags := flagsToStripFlags(flags)
|
2018-09-05 23:20:03 +02:00
|
|
|
stripped := android.PathForModuleOut(ctx, "stripped", libName)
|
2020-08-19 14:53:01 +02:00
|
|
|
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
|
2018-09-05 23:20:03 +02:00
|
|
|
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)
|
2021-11-03 20:30:18 +01:00
|
|
|
TransformSharedObjectToToc(ctx, outputFile, tocFile)
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
|
|
|
|
if ctx.Windows() && p.properties.Windows_import_lib != nil {
|
|
|
|
// Consumers of this library actually links to the import library in build
|
|
|
|
// time and dynamically links to the DLL in run time. i.e.
|
|
|
|
// a.exe <-- static link --> foo.lib <-- dynamic link --> foo.dll
|
|
|
|
importLibSrc := android.PathForModuleSrc(ctx, String(p.properties.Windows_import_lib))
|
|
|
|
importLibName := p.libraryDecorator.getLibName(ctx) + ".lib"
|
|
|
|
importLibOutputFile := android.PathForModuleOut(ctx, importLibName)
|
|
|
|
implicits = append(implicits, importLibOutputFile)
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Description: "prebuilt import library",
|
|
|
|
Input: importLibSrc,
|
|
|
|
Output: importLibOutputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"cpFlags": "-L",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-09-05 23:20:03 +02:00
|
|
|
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Description: "prebuilt shared library",
|
|
|
|
Implicits: implicits,
|
|
|
|
Input: in,
|
|
|
|
Output: outputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"cpFlags": "-L",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{
|
2021-06-08 21:37:09 +02:00
|
|
|
SharedLibrary: outputFile,
|
|
|
|
Target: ctx.Target(),
|
2020-09-18 23:15:30 +02:00
|
|
|
|
|
|
|
TableOfContents: p.tocFile,
|
|
|
|
})
|
|
|
|
|
2022-02-06 23:07:45 +01:00
|
|
|
// TODO(b/220898484): Mainline module sdk prebuilts of stub libraries use a stub
|
2023-03-23 06:31:19 +01:00
|
|
|
// library as their source and must not be installed, but other prebuilts like
|
|
|
|
// libclang_rt.* libraries set `stubs` property because they are LLNDK libraries,
|
|
|
|
// but use an implementation library as their source and need to be installed.
|
|
|
|
// This discrepancy should be resolved without the prefix hack below.
|
|
|
|
isModuleSdkPrebuilts := android.HasAnyPrefix(ctx.ModuleDir(), []string{
|
|
|
|
"prebuilts/runtime/mainline/", "prebuilts/module_sdk/"})
|
|
|
|
if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() && isModuleSdkPrebuilts {
|
2023-03-20 12:05:16 +01:00
|
|
|
ctx.Module().MakeUninstallable()
|
2022-02-06 23:07:45 +01:00
|
|
|
}
|
|
|
|
|
cc_prebuilt_library respect module name and stem
Installed name of prebuilt shared library should be stem or module name.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libbar.so"],
}
should install with the filename libfoo.so, and
cc_prebuilt_library_shared {
name: "libfoo",
stem: "libbaz",
srcs: ["libbar.so"],
}
should install with the filename libbaz.so.
Prebuilt Windows PE library should specify its import library.
For example:
cc_prebuilt_library_shared {
name: "libfoo",
srcs: ["libfoo.dll"],
windows_import_lib: "libfoo.lib",
enabled: false,
target: {
windows: {
enabled: true,
},
},
}
Bug: 151744695
Test: prebuilt_test.go && built walleye-userdebug
Change-Id: Ia8d0afb7fa46783c670870440432779c5fc7321a
2020-03-18 07:19:07 +01:00
|
|
|
return outputFile
|
|
|
|
}
|
2016-10-07 01:12:58 +02:00
|
|
|
}
|
|
|
|
|
2020-12-10 21:30:21 +01:00
|
|
|
if p.header() {
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, HeaderLibraryInfoProvider, HeaderLibraryInfo{})
|
2020-12-10 21:30:21 +01:00
|
|
|
|
2021-11-30 19:49:03 +01:00
|
|
|
// Need to return an output path so that the AndroidMk logic doesn't skip
|
|
|
|
// the prebuilt header. For compatibility, in case Android.mk files use a
|
|
|
|
// header lib in LOCAL_STATIC_LIBRARIES, create an empty ar file as
|
|
|
|
// placeholder, just like non-prebuilt header modules do in linkStatic().
|
|
|
|
ph := android.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension)
|
|
|
|
transformObjToStaticLib(ctx, nil, nil, builderFlags{}, ph, nil, nil)
|
|
|
|
return ph
|
2020-12-10 21:30:21 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 01:12:58 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-25 00:35:40 +02:00
|
|
|
func (p *prebuiltLibraryLinker) prebuiltSrcs(ctx android.BaseModuleContext) []string {
|
|
|
|
sanitize := ctx.Module().(*Module).sanitize
|
2020-03-12 21:17:14 +01:00
|
|
|
srcs := p.properties.Srcs
|
2020-07-25 00:35:40 +02:00
|
|
|
srcs = append(srcs, srcsForSanitizer(sanitize, p.properties.Sanitized)...)
|
2020-03-12 21:17:14 +01:00
|
|
|
if p.static() {
|
|
|
|
srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...)
|
2020-07-25 00:35:40 +02:00
|
|
|
srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.StaticProperties.Static.Sanitized)...)
|
2020-03-12 21:17:14 +01:00
|
|
|
}
|
|
|
|
if p.shared() {
|
|
|
|
srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...)
|
2020-07-25 00:35:40 +02:00
|
|
|
srcs = append(srcs, srcsForSanitizer(sanitize, p.libraryDecorator.SharedProperties.Shared.Sanitized)...)
|
2020-03-12 21:17:14 +01:00
|
|
|
}
|
|
|
|
return srcs
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-05-14 23:07:01 +02:00
|
|
|
func (p *prebuiltLibraryLinker) disablePrebuilt() {
|
|
|
|
p.properties.Srcs = nil
|
2024-02-29 03:59:30 +01:00
|
|
|
p.properties.Sanitized.None.Srcs = nil
|
|
|
|
p.properties.Sanitized.Address.Srcs = nil
|
|
|
|
p.properties.Sanitized.Hwaddress.Srcs = nil
|
2019-05-14 23:07:01 +02:00
|
|
|
}
|
|
|
|
|
2020-12-14 01:20:00 +01:00
|
|
|
// Implements versionedInterface
|
|
|
|
func (p *prebuiltLibraryLinker) implementationModuleName(name string) string {
|
2021-10-26 11:42:42 +02:00
|
|
|
return android.RemoveOptionalPrebuiltPrefix(name)
|
2020-12-14 01:20:00 +01:00
|
|
|
}
|
|
|
|
|
2021-11-23 02:24:06 +01:00
|
|
|
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) {
|
2017-05-17 20:30:45 +02:00
|
|
|
module, library := NewLibrary(hod)
|
2016-10-07 01:12:58 +02:00
|
|
|
module.compiler = nil
|
|
|
|
|
|
|
|
prebuilt := &prebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
2020-10-24 02:22:06 +02:00
|
|
|
module.library = prebuilt
|
2017-03-17 21:28:06 +01:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
|
2021-11-23 02:24:06 +01:00
|
|
|
if srcsProperty == "" {
|
|
|
|
android.InitPrebuiltModuleWithoutSrcs(module)
|
|
|
|
} else {
|
|
|
|
srcsSupplier := func(ctx android.BaseModuleContext, _ android.Module) []string {
|
|
|
|
return prebuilt.prebuiltSrcs(ctx)
|
|
|
|
}
|
2020-03-12 21:17:14 +01:00
|
|
|
|
2021-11-23 02:24:06 +01:00
|
|
|
android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, srcsProperty)
|
|
|
|
}
|
2018-12-18 18:47:14 +01:00
|
|
|
|
2019-12-11 16:22:32 +01:00
|
|
|
return module, library
|
|
|
|
}
|
|
|
|
|
2020-03-12 21:17:14 +01:00
|
|
|
// cc_prebuilt_library installs a precompiled shared library that are
|
|
|
|
// listed in the srcs property in the device's directory.
|
|
|
|
func PrebuiltLibraryFactory() android.Module {
|
2021-11-23 02:24:06 +01:00
|
|
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs")
|
2020-03-12 21:17:14 +01:00
|
|
|
|
|
|
|
// Prebuilt shared libraries can be included in APEXes
|
|
|
|
android.InitApexModule(module)
|
|
|
|
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:22:32 +01:00
|
|
|
// cc_prebuilt_library_shared installs a precompiled shared library that are
|
|
|
|
// listed in the srcs property in the device's directory.
|
|
|
|
func PrebuiltSharedLibraryFactory() android.Module {
|
|
|
|
module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-06-17 22:10:42 +02:00
|
|
|
// cc_prebuilt_test_library_shared installs a precompiled shared library
|
|
|
|
// to be used as a data dependency of a test-related module (such as cc_test, or
|
|
|
|
// cc_test_library).
|
|
|
|
func PrebuiltSharedTestLibraryFactory() android.Module {
|
2021-11-23 02:24:06 +01:00
|
|
|
module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "srcs")
|
2020-06-17 22:10:42 +02:00
|
|
|
library.BuildOnlyShared()
|
|
|
|
library.baseInstaller = NewTestInstaller()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:22:32 +01:00
|
|
|
func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
2021-11-23 02:24:06 +01:00
|
|
|
module, library := NewPrebuiltLibrary(hod, "srcs")
|
2019-12-11 16:22:32 +01:00
|
|
|
library.BuildOnlyShared()
|
|
|
|
|
|
|
|
// Prebuilt shared libraries can be included in APEXes
|
|
|
|
android.InitApexModule(module)
|
2018-12-18 18:47:14 +01:00
|
|
|
|
2017-05-17 20:30:45 +02:00
|
|
|
return module, library
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
// cc_prebuilt_library_static installs a precompiled static library that are
|
|
|
|
// listed in the srcs property in the device's directory.
|
2019-08-23 04:17:39 +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) {
|
2021-11-23 02:24:06 +01:00
|
|
|
module, library := NewPrebuiltLibrary(hod, "srcs")
|
2017-03-17 21:28:06 +01:00
|
|
|
library.BuildOnlyStatic()
|
2022-05-17 23:59:36 +02:00
|
|
|
|
2017-05-17 20:30:45 +02:00
|
|
|
return module, library
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 22:45:49 +01:00
|
|
|
type prebuiltObjectProperties struct {
|
2024-01-19 01:22:22 +01:00
|
|
|
// Name of the source soong module that gets shadowed by this prebuilt
|
|
|
|
// If unspecified, follows the naming convention that the source module of
|
|
|
|
// the prebuilt is Name() without "prebuilt_" prefix
|
|
|
|
Source_module_name *string
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2020-03-11 22:45:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type prebuiltObjectLinker struct {
|
|
|
|
android.Prebuilt
|
|
|
|
objectLinker
|
|
|
|
|
|
|
|
properties prebuiltObjectProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt {
|
|
|
|
return &p.Prebuilt
|
|
|
|
}
|
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
func (p *prebuiltObjectLinker) sourceModuleName() string {
|
|
|
|
return proptools.String(p.properties.Source_module_name)
|
|
|
|
}
|
|
|
|
|
2020-03-11 22:45:49 +01:00
|
|
|
var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil)
|
|
|
|
|
|
|
|
func (p *prebuiltObjectLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
|
|
|
if len(p.properties.Srcs) > 0 {
|
2022-04-16 00:16:02 +02:00
|
|
|
// Copy objects to a name matching the final installed name
|
|
|
|
in := p.Prebuilt.SingleSourcePath(ctx)
|
|
|
|
outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".o")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.CpExecutable,
|
|
|
|
Description: "prebuilt",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: in,
|
|
|
|
})
|
|
|
|
return outputFile
|
2020-03-11 22:45:49 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-01 16:23:05 +02:00
|
|
|
func (p *prebuiltObjectLinker) object() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-06-25 23:21:04 +02:00
|
|
|
func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module {
|
|
|
|
module := newObject(hod)
|
2020-03-11 22:45:49 +01:00
|
|
|
prebuilt := &prebuiltObjectLinker{
|
|
|
|
objectLinker: objectLinker{
|
|
|
|
baseLinker: NewBaseLinker(nil),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
|
|
|
module.AddProperties(&prebuilt.properties)
|
|
|
|
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2022-12-06 01:46:39 +01:00
|
|
|
func PrebuiltObjectFactory() android.Module {
|
2021-06-25 23:21:04 +02:00
|
|
|
module := NewPrebuiltObject(android.HostAndDeviceSupported)
|
2020-03-11 22:45:49 +01:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
type prebuiltBinaryLinker struct {
|
|
|
|
*binaryDecorator
|
|
|
|
prebuiltLinker
|
2020-08-20 03:54:52 +02:00
|
|
|
|
|
|
|
toolPath android.OptionalPath
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
|
|
|
|
|
2020-08-20 03:54:52 +02:00
|
|
|
func (p *prebuiltBinaryLinker) hostToolPath() android.OptionalPath {
|
|
|
|
return p.toolPath
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:28:06 +01:00
|
|
|
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 {
|
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)
|
2020-08-20 03:54:52 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2018-09-05 01:28:17 +02:00
|
|
|
p.unstrippedOutputFile = in
|
|
|
|
|
2020-08-20 03:54:52 +02:00
|
|
|
if ctx.Host() {
|
|
|
|
// Host binaries are symlinked to their prebuilt source locations. That
|
|
|
|
// way they are executed directly from there so the linker resolves their
|
|
|
|
// shared library dependencies relative to that location (using
|
|
|
|
// $ORIGIN/../lib(64):$ORIGIN/lib(64) as RUNPATH). This way the prebuilt
|
|
|
|
// repository can supply the expected versions of the shared libraries
|
|
|
|
// without interference from what is in the out tree.
|
|
|
|
|
|
|
|
// These shared lib paths may point to copies of the libs in
|
|
|
|
// .intermediates, which isn't where the binary will load them from, but
|
|
|
|
// it's fine for dependency tracking. If a library dependency is updated,
|
|
|
|
// the symlink will get a new timestamp, along with any installed symlinks
|
|
|
|
// handled in make.
|
|
|
|
sharedLibPaths := deps.EarlySharedLibs
|
|
|
|
sharedLibPaths = append(sharedLibPaths, deps.SharedLibs...)
|
|
|
|
sharedLibPaths = append(sharedLibPaths, deps.LateSharedLibs...)
|
2017-08-09 01:20:15 +02:00
|
|
|
|
2020-09-21 22:45:49 +02:00
|
|
|
var fromPath = in.String()
|
|
|
|
if !filepath.IsAbs(fromPath) {
|
|
|
|
fromPath = "$$PWD/" + fromPath
|
|
|
|
}
|
|
|
|
|
2020-08-20 03:54:52 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Symlink,
|
|
|
|
Output: outputFile,
|
|
|
|
Input: in,
|
|
|
|
Implicits: sharedLibPaths,
|
|
|
|
Args: map[string]string{
|
2020-09-21 22:45:49 +02:00
|
|
|
"fromPath": fromPath,
|
2020-08-20 03:54:52 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p.toolPath = android.OptionalPathForPath(outputFile)
|
|
|
|
} else {
|
|
|
|
if p.stripper.NeedsStrip(ctx) {
|
|
|
|
stripped := android.PathForModuleOut(ctx, "stripped", fileName)
|
|
|
|
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, flagsToStripFlags(flags))
|
|
|
|
in = stripped
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy binaries to a name matching the final installed name
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.CpExecutable,
|
|
|
|
Description: "prebuilt",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: in,
|
|
|
|
})
|
|
|
|
}
|
2017-08-09 01:20:15 +02:00
|
|
|
|
|
|
|
return outputFile
|
2017-03-17 21:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-01 14:53:49 +02:00
|
|
|
func (p *prebuiltBinaryLinker) binary() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:09:10 +01:00
|
|
|
// cc_prebuilt_binary installs a precompiled executable in srcs property in the
|
2022-09-01 17:04:04 +02:00
|
|
|
// device's directory, for both the host and device
|
|
|
|
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) {
|
2023-12-07 22:10:56 +01:00
|
|
|
module, binary := newBinary(hod)
|
2017-03-17 21:28:06 +01:00
|
|
|
module.compiler = nil
|
|
|
|
|
|
|
|
prebuilt := &prebuiltBinaryLinker{
|
|
|
|
binaryDecorator: binary,
|
|
|
|
}
|
|
|
|
module.linker = prebuilt
|
2020-08-20 03:54:52 +02:00
|
|
|
module.installer = 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
|
|
|
}
|
2020-07-25 00:35:40 +02:00
|
|
|
|
|
|
|
type Sanitized struct {
|
|
|
|
None struct {
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Address struct {
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Hwaddress struct {
|
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func srcsForSanitizer(sanitize *sanitize, sanitized Sanitized) []string {
|
|
|
|
if sanitize == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-10-03 21:07:37 +02:00
|
|
|
if sanitize.isSanitizerEnabled(Asan) && sanitized.Address.Srcs != nil {
|
2020-07-25 00:35:40 +02:00
|
|
|
return sanitized.Address.Srcs
|
|
|
|
}
|
2022-10-03 21:07:37 +02:00
|
|
|
if sanitize.isSanitizerEnabled(Hwasan) && sanitized.Hwaddress.Srcs != nil {
|
2020-07-25 00:35:40 +02:00
|
|
|
return sanitized.Hwaddress.Srcs
|
|
|
|
}
|
|
|
|
return sanitized.None.Srcs
|
|
|
|
}
|
2024-01-19 01:22:22 +01:00
|
|
|
|
|
|
|
func (p *prebuiltLinker) sourceModuleName() string {
|
|
|
|
return proptools.String(p.properties.Source_module_name)
|
|
|
|
}
|