2016-07-30 03:48:20 +08: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 (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2016-10-01 08:10:16 +08:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
2017-02-09 05:45:53 +08:00
|
|
|
"android/soong/cc/config"
|
2016-07-30 03:48:20 +08:00
|
|
|
)
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type LibraryProperties struct {
|
2016-07-30 03:48:20 +08:00
|
|
|
Static struct {
|
2016-10-27 01:03:47 +08:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
2016-10-27 01:03:47 +08:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
2016-07-30 08:28:03 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
|
|
|
// local file name to pass to the linker as --version_script
|
|
|
|
Version_script *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -unexported_symbols_list
|
|
|
|
Unexported_symbols_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
|
|
|
Force_symbols_not_weak_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_weak_list
|
|
|
|
Force_symbols_weak_list *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// rename host libraries to prevent overlap with system installed libraries
|
|
|
|
Unique_host_soname *bool
|
|
|
|
|
2016-11-04 05:28:51 +08:00
|
|
|
Aidl struct {
|
|
|
|
// export headers generated from .aidl sources
|
|
|
|
Export_aidl_headers bool
|
|
|
|
}
|
|
|
|
|
2016-10-21 07:11:43 +08:00
|
|
|
Proto struct {
|
|
|
|
// export headers generated from .proto sources
|
|
|
|
Export_proto_headers bool
|
|
|
|
}
|
2017-02-15 07:28:44 +08:00
|
|
|
}
|
2016-10-21 07:11:43 +08:00
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
type LibraryMutatedProperties struct {
|
2016-07-30 03:48:20 +08:00
|
|
|
VariantName string `blueprint:"mutated"`
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
// Build a static variant
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
// Build a shared variant
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
// This variant is shared
|
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
// This variant is static
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type FlagExporterProperties struct {
|
|
|
|
// list of directories relative to the Blueprints file that will
|
2016-11-04 06:53:42 +08:00
|
|
|
// be added to the include path (using -I) for this module and any module that links
|
|
|
|
// against this module
|
2016-07-30 08:28:03 +08:00
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
|
|
|
|
Target struct {
|
|
|
|
Vendor struct {
|
|
|
|
// list of exported include directories, like
|
|
|
|
// export_include_dirs, that will be applied to the
|
|
|
|
// vendor variant of this library. This will overwrite
|
|
|
|
// any other declarations.
|
|
|
|
Export_include_dirs []string
|
|
|
|
}
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-10-13 05:28:16 +08:00
|
|
|
android.RegisterModuleType("cc_library_static", libraryStaticFactory)
|
|
|
|
android.RegisterModuleType("cc_library_shared", librarySharedFactory)
|
|
|
|
android.RegisterModuleType("cc_library", libraryFactory)
|
|
|
|
android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
|
|
|
|
android.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
|
2016-12-14 04:50:57 +08:00
|
|
|
android.RegisterModuleType("cc_library_headers", libraryHeaderFactory)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for combined static + shared libraries, device by default but with possible host
|
|
|
|
// support
|
|
|
|
func libraryFactory() (blueprint.Module, []interface{}) {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, _ := NewLibrary(android.HostAndDeviceSupported)
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for static libraries
|
|
|
|
func libraryStaticFactory() (blueprint.Module, []interface{}) {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyStatic()
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for shared libraries
|
|
|
|
func librarySharedFactory() (blueprint.Module, []interface{}) {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for host static libraries
|
|
|
|
func libraryHostStaticFactory() (blueprint.Module, []interface{}) {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyStatic()
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for host shared libraries
|
|
|
|
func libraryHostSharedFactory() (blueprint.Module, []interface{}) {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2016-12-14 04:50:57 +08:00
|
|
|
// Module factory for header-only libraries
|
|
|
|
func libraryHeaderFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.HeaderOnly()
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
type flagExporter struct {
|
|
|
|
Properties FlagExporterProperties
|
|
|
|
|
2016-09-30 03:13:36 +08:00
|
|
|
flags []string
|
|
|
|
flagsDeps android.Paths
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths {
|
|
|
|
if ctx.Vendor() && f.Properties.Target.Vendor.Export_include_dirs != nil {
|
|
|
|
return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Export_include_dirs)
|
|
|
|
} else {
|
|
|
|
return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
includeDirs := f.exportedIncludes(ctx)
|
2016-07-30 03:48:20 +08:00
|
|
|
for _, dir := range includeDirs.Strings() {
|
|
|
|
f.flags = append(f.flags, inc+dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) reexportFlags(flags []string) {
|
|
|
|
f.flags = append(f.flags, flags...)
|
|
|
|
}
|
|
|
|
|
2016-09-30 03:13:36 +08:00
|
|
|
func (f *flagExporter) reexportDeps(deps android.Paths) {
|
|
|
|
f.flagsDeps = append(f.flagsDeps, deps...)
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
func (f *flagExporter) exportedFlags() []string {
|
|
|
|
return f.flags
|
|
|
|
}
|
|
|
|
|
2016-09-30 03:13:36 +08:00
|
|
|
func (f *flagExporter) exportedFlagsDeps() android.Paths {
|
|
|
|
return f.flagsDeps
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
type exportedFlagsProducer interface {
|
|
|
|
exportedFlags() []string
|
2016-09-30 03:13:36 +08:00
|
|
|
exportedFlagsDeps() android.Paths
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ exportedFlagsProducer = (*flagExporter)(nil)
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
// libraryDecorator wraps baseCompiler, baseLinker and baseInstaller to provide library-specific
|
|
|
|
// functionality: static vs. shared linkage, reusing object files for shared libraries
|
|
|
|
type libraryDecorator struct {
|
2017-02-15 07:28:44 +08:00
|
|
|
Properties LibraryProperties
|
|
|
|
MutatedProperties LibraryMutatedProperties
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
// For reusing static library objects for shared library
|
2016-09-27 08:33:01 +08:00
|
|
|
reuseObjects Objects
|
2016-10-01 08:10:16 +08:00
|
|
|
// table-of-contents file to optimize out relinking when possible
|
|
|
|
tocFile android.OptionalPath
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
flagExporter
|
|
|
|
stripper
|
2016-09-15 06:04:48 +08:00
|
|
|
relocationPacker
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
// If we're used as a whole_static_lib, our missing dependencies need
|
|
|
|
// to be given
|
|
|
|
wholeStaticMissingDeps []string
|
|
|
|
|
|
|
|
// For whole_static_libs
|
2016-09-27 08:33:01 +08:00
|
|
|
objects Objects
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
// Uses the module's name if empty, but can be overridden. Does not include
|
|
|
|
// shlib suffix.
|
|
|
|
libName string
|
|
|
|
|
|
|
|
sanitize *sanitize
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
sabi *sabi
|
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
// Output archive of gcno coverage information files
|
|
|
|
coverageOutputFile android.OptionalPath
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
// linked Source Abi Dump
|
|
|
|
sAbiOutputFile android.OptionalPath
|
|
|
|
|
|
|
|
// Source Abi Diff
|
|
|
|
sAbiDiff android.OptionalPath
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
// Decorated interafaces
|
|
|
|
*baseCompiler
|
|
|
|
*baseLinker
|
|
|
|
*baseInstaller
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkerProps() []interface{} {
|
|
|
|
var props []interface{}
|
|
|
|
props = append(props, library.baseLinker.linkerProps()...)
|
|
|
|
return append(props,
|
|
|
|
&library.Properties,
|
2017-02-15 07:28:44 +08:00
|
|
|
&library.MutatedProperties,
|
2016-07-30 08:28:03 +08:00
|
|
|
&library.flagExporter.Properties,
|
2016-09-15 06:04:48 +08:00
|
|
|
&library.stripper.StripProperties,
|
|
|
|
&library.relocationPacker.Properties)
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseLinker.linkerFlags(ctx, flags)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
2017-04-05 03:59:48 +08:00
|
|
|
if !ctx.Windows() {
|
2016-07-30 03:48:20 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
if library.static() {
|
2016-07-30 03:48:20 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
|
2017-02-15 07:28:44 +08:00
|
|
|
} else if library.shared() {
|
2016-07-30 03:48:20 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
if library.shared() {
|
2016-07-30 08:28:03 +08:00
|
|
|
libName := library.getLibName(ctx)
|
|
|
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
|
|
|
sharedFlag := "-Wl,-shared"
|
|
|
|
if flags.Clang || ctx.Host() {
|
|
|
|
sharedFlag = "-shared"
|
|
|
|
}
|
|
|
|
var f []string
|
2016-06-14 08:19:03 +08:00
|
|
|
if ctx.toolchain().Bionic() {
|
2016-07-30 08:28:03 +08:00
|
|
|
f = append(f,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Darwin() {
|
|
|
|
f = append(f,
|
|
|
|
"-dynamiclib",
|
|
|
|
"-single_module",
|
|
|
|
"-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
|
|
|
|
)
|
2016-10-21 01:47:21 +08:00
|
|
|
if ctx.Arch().ArchType == android.X86 {
|
|
|
|
f = append(f,
|
|
|
|
"-read_only_relocs suppress",
|
|
|
|
)
|
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
} else {
|
|
|
|
f = append(f,
|
|
|
|
sharedFlag,
|
|
|
|
"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.LdFlags = append(f, flags.LdFlags...)
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-11-04 06:53:42 +08:00
|
|
|
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
|
2016-11-04 06:53:42 +08:00
|
|
|
if len(exportIncludeDirs) > 0 {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, includeDirsToFlags(exportIncludeDirs))
|
|
|
|
}
|
|
|
|
|
|
|
|
return library.baseCompiler.compilerFlags(ctx, flags)
|
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
2016-12-14 04:50:57 +08:00
|
|
|
if !library.buildShared() && !library.buildStatic() {
|
|
|
|
if len(library.baseCompiler.Properties.Srcs) > 0 {
|
|
|
|
ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs")
|
|
|
|
}
|
|
|
|
if len(library.Properties.Static.Srcs) > 0 {
|
|
|
|
ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs")
|
|
|
|
}
|
|
|
|
if len(library.Properties.Shared.Srcs) > 0 {
|
|
|
|
ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs")
|
|
|
|
}
|
|
|
|
return Objects{}
|
|
|
|
}
|
2017-02-09 05:45:53 +08:00
|
|
|
if ctx.createVndkSourceAbiDump() || (library.sabi.Properties.CreateSAbiDumps && ctx.Device()) {
|
|
|
|
exportIncludeDirs := android.PathsForModuleSrc(ctx, library.flagExporter.Properties.Export_include_dirs)
|
|
|
|
var SourceAbiFlags []string
|
|
|
|
for _, dir := range exportIncludeDirs.Strings() {
|
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I "+dir)
|
|
|
|
}
|
2016-12-14 04:50:57 +08:00
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
flags.SAbiFlags = SourceAbiFlags
|
|
|
|
total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) +
|
|
|
|
len(library.Properties.Static.Srcs)
|
|
|
|
if total_length > 0 {
|
|
|
|
flags.SAbiDump = true
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 08:33:01 +08:00
|
|
|
objs := library.baseCompiler.compile(ctx, flags, deps)
|
|
|
|
library.reuseObjects = objs
|
2016-10-27 01:03:47 +08:00
|
|
|
buildFlags := flagsToBuilderFlags(flags)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
if library.static() {
|
2016-10-27 01:03:47 +08:00
|
|
|
srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
|
|
|
srcs, library.baseCompiler.deps))
|
2017-02-15 07:28:44 +08:00
|
|
|
} else if library.shared() {
|
2016-10-27 01:03:47 +08:00
|
|
|
srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
|
|
|
srcs, library.baseCompiler.deps))
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
return objs
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type libraryInterface interface {
|
|
|
|
getWholeStaticMissingDeps() []string
|
|
|
|
static() bool
|
2016-09-27 08:33:01 +08:00
|
|
|
objs() Objects
|
|
|
|
reuseObjs() Objects
|
2016-10-01 08:10:16 +08:00
|
|
|
toc() android.OptionalPath
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
// Returns true if the build options for the module have selected a static or shared build
|
|
|
|
buildStatic() bool
|
|
|
|
buildShared() bool
|
|
|
|
|
|
|
|
// Sets whether a specific variant is static or shared
|
2017-02-15 07:28:44 +08:00
|
|
|
setStatic()
|
|
|
|
setShared()
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
2016-07-30 03:48:20 +08:00
|
|
|
name := library.libName
|
|
|
|
if name == "" {
|
2016-10-07 07:12:58 +08:00
|
|
|
name = ctx.baseModuleName()
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Host() && Bool(library.Properties.Unique_host_soname) {
|
|
|
|
if !strings.HasSuffix(name, "-host") {
|
|
|
|
name = name + "-host"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
return name + library.MutatedProperties.VariantName
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
|
|
|
location := InstallInSystem
|
2017-03-30 13:00:18 +08:00
|
|
|
if library.sanitize.inSanitizerDir() {
|
|
|
|
location = InstallInSanitizerDir
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
library.baseInstaller.location = location
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
library.baseLinker.linkerInit(ctx)
|
2016-09-15 06:04:48 +08:00
|
|
|
|
|
|
|
library.relocationPacker.packingInit(ctx)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-08-02 04:20:05 +08:00
|
|
|
deps = library.baseLinker.linkerDeps(ctx, deps)
|
2016-07-30 08:28:03 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
if library.static() {
|
2016-07-30 08:28:03 +08:00
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs,
|
|
|
|
library.Properties.Static.Whole_static_libs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
|
2017-02-15 07:28:44 +08:00
|
|
|
} else if library.shared() {
|
2016-11-17 17:02:25 +08:00
|
|
|
if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
if !ctx.sdk() {
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.CrtBegin = "crtbegin_so"
|
|
|
|
deps.CrtEnd = "crtend_so"
|
|
|
|
} else {
|
2016-11-09 07:06:22 +08:00
|
|
|
// TODO(danalbert): Add generation of crt objects.
|
|
|
|
// For `sdk_version: "current"`, we don't actually have a
|
|
|
|
// freshly generated set of CRT objects. Use the last stable
|
|
|
|
// version.
|
|
|
|
version := ctx.sdkVersion()
|
|
|
|
if version == "current" {
|
|
|
|
version = ctx.AConfig().PlatformSdkVersion()
|
|
|
|
}
|
|
|
|
deps.CrtBegin = "ndk_crtbegin_so." + version
|
|
|
|
deps.CrtEnd = "ndk_crtend_so." + version
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
2016-09-27 08:33:01 +08:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
library.objects = deps.WholeStaticLibObjs.Copy()
|
|
|
|
library.objects = library.objects.Append(objs)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
outputFile := android.PathForModuleOut(ctx,
|
2017-02-15 07:28:44 +08:00
|
|
|
ctx.ModuleName()+library.MutatedProperties.VariantName+staticLibraryExtension)
|
2017-02-10 08:16:31 +08:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles)
|
|
|
|
|
|
|
|
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags,
|
2017-02-15 07:28:44 +08:00
|
|
|
ctx.ModuleName()+library.MutatedProperties.VariantName)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
2016-09-27 08:33:01 +08:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
var linkerDeps android.Paths
|
|
|
|
|
|
|
|
versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
|
|
|
|
unexportedSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list)
|
|
|
|
forceNotWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list)
|
|
|
|
forceWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_weak_list)
|
|
|
|
if !ctx.Darwin() {
|
|
|
|
if versionScript.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
|
|
|
linkerDeps = append(linkerDeps, versionScript.Path())
|
|
|
|
}
|
|
|
|
if unexportedSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
if forceNotWeakSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
if forceWeakSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if versionScript.Valid() {
|
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
}
|
|
|
|
if unexportedSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceNotWeakSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceWeakSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
|
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
|
|
|
ret := outputFile
|
|
|
|
|
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
2017-04-05 04:00:15 +08:00
|
|
|
if !ctx.Darwin() && !ctx.Windows() {
|
2016-10-04 08:47:19 +08: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.
|
|
|
|
tocPath := outputFile.RelPathString()
|
|
|
|
tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc")
|
|
|
|
tocFile := android.PathForOutput(ctx, tocPath)
|
|
|
|
library.tocFile = android.OptionalPathForPath(tocFile)
|
|
|
|
TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
2016-09-15 06:04:48 +08:00
|
|
|
if library.relocationPacker.needsPacking(ctx) {
|
|
|
|
packedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unpacked", fileName)
|
|
|
|
library.relocationPacker.pack(ctx, outputFile, packedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
if library.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
|
|
|
library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
|
|
|
|
2016-08-11 05:34:08 +08:00
|
|
|
// TODO(danalbert): Clean this up when soong supports prebuilts.
|
|
|
|
if strings.HasPrefix(ctx.selectedStl(), "ndk_libc++") {
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, "libc++")
|
|
|
|
|
|
|
|
if strings.HasSuffix(ctx.selectedStl(), "_shared") {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs,
|
|
|
|
libDir.Join(ctx, "libandroid_support.a"))
|
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs,
|
|
|
|
libDir.Join(ctx, "libc++abi.a"),
|
|
|
|
libDir.Join(ctx, "libandroid_support.a"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs,
|
|
|
|
libDir.Join(ctx, "libunwind.a"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 08:10:16 +08:00
|
|
|
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
|
|
|
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
2016-09-27 06:45:04 +08:00
|
|
|
linkerDeps = append(linkerDeps, objs.tidyFiles...)
|
2016-10-01 08:10:16 +08:00
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
|
|
|
|
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
|
2017-02-09 05:45:53 +08:00
|
|
|
|
|
|
|
objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...)
|
|
|
|
objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...)
|
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx))
|
2017-02-09 05:45:53 +08:00
|
|
|
library.linkSAbiDumpFiles(ctx, objs, fileName)
|
2017-02-10 08:16:31 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string) {
|
|
|
|
//Also take into account object re-use.
|
|
|
|
if len(objs.sAbiDumpFiles) > 0 && ctx.createVndkSourceAbiDump() {
|
|
|
|
refSourceDumpFile := android.PathForVndkRefAbiDump(ctx, "current", fileName, vndkVsNdk(ctx), true)
|
|
|
|
versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
|
|
|
|
var symbolFile android.OptionalPath
|
|
|
|
if versionScript.Valid() {
|
|
|
|
symbolFile = versionScript
|
|
|
|
}
|
|
|
|
exportIncludeDirs := android.PathsForModuleSrc(ctx, library.flagExporter.Properties.Export_include_dirs)
|
|
|
|
var SourceAbiFlags []string
|
|
|
|
for _, dir := range exportIncludeDirs.Strings() {
|
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I "+dir)
|
|
|
|
}
|
|
|
|
exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
|
|
|
|
library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, symbolFile, "current", fileName, exportedHeaderFlags)
|
|
|
|
if refSourceDumpFile.Valid() {
|
|
|
|
library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(), refSourceDumpFile.Path(), fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func vndkVsNdk(ctx ModuleContext) bool {
|
|
|
|
if inList(ctx.baseModuleName(), config.LLndkLibraries()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) link(ctx ModuleContext,
|
2016-09-27 08:33:01 +08:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(deps.Objs)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
var out android.Path
|
2017-02-15 07:28:44 +08:00
|
|
|
if library.static() || library.header() {
|
2016-09-27 08:33:01 +08:00
|
|
|
out = library.linkStatic(ctx, flags, deps, objs)
|
2016-07-30 03:48:20 +08:00
|
|
|
} else {
|
2016-09-27 08:33:01 +08:00
|
|
|
out = library.linkShared(ctx, flags, deps, objs)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
library.exportIncludes(ctx, "-I")
|
|
|
|
library.reexportFlags(deps.ReexportedFlags)
|
2016-09-30 03:13:36 +08:00
|
|
|
library.reexportDeps(deps.ReexportedFlagsDeps)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-11-04 05:28:51 +08:00
|
|
|
if library.Properties.Aidl.Export_aidl_headers {
|
|
|
|
if library.baseCompiler.hasSrcExt(".aidl") {
|
|
|
|
library.reexportFlags([]string{
|
|
|
|
"-I" + android.PathForModuleGen(ctx, "aidl").String(),
|
|
|
|
})
|
|
|
|
library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to aidl deps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if library.Properties.Proto.Export_proto_headers {
|
|
|
|
if library.baseCompiler.hasSrcExt(".proto") {
|
2016-10-21 07:11:43 +08:00
|
|
|
library.reexportFlags([]string{
|
|
|
|
"-I" + protoSubDir(ctx).String(),
|
|
|
|
"-I" + protoDir(ctx).String(),
|
|
|
|
})
|
|
|
|
library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to proto deps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) buildStatic() bool {
|
2017-02-15 07:28:44 +08:00
|
|
|
return library.MutatedProperties.BuildStatic &&
|
2016-07-30 03:48:20 +08:00
|
|
|
(library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled)
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) buildShared() bool {
|
2017-02-15 07:28:44 +08:00
|
|
|
return library.MutatedProperties.BuildShared &&
|
2016-07-30 03:48:20 +08:00
|
|
|
(library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled)
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
|
2016-07-30 03:48:20 +08:00
|
|
|
return library.wholeStaticMissingDeps
|
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
func (library *libraryDecorator) objs() Objects {
|
|
|
|
return library.objects
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
func (library *libraryDecorator) reuseObjs() Objects {
|
|
|
|
return library.reuseObjects
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 08:10:16 +08:00
|
|
|
func (library *libraryDecorator) toc() android.OptionalPath {
|
|
|
|
return library.tocFile
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
|
2017-04-15 06:42:53 +08:00
|
|
|
if library.shared() {
|
2016-07-30 03:48:20 +08:00
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) static() bool {
|
2017-02-15 07:28:44 +08:00
|
|
|
return library.MutatedProperties.VariantIsStatic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) shared() bool {
|
|
|
|
return library.MutatedProperties.VariantIsShared
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) header() bool {
|
|
|
|
return !library.static() && !library.shared()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setStatic() {
|
|
|
|
library.MutatedProperties.VariantIsStatic = true
|
|
|
|
library.MutatedProperties.VariantIsShared = false
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
func (library *libraryDecorator) setShared() {
|
|
|
|
library.MutatedProperties.VariantIsStatic = false
|
|
|
|
library.MutatedProperties.VariantIsShared = true
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-12-10 06:46:15 +08:00
|
|
|
func (library *libraryDecorator) BuildOnlyStatic() {
|
2017-02-15 07:28:44 +08:00
|
|
|
library.MutatedProperties.BuildShared = false
|
2016-12-10 06:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) BuildOnlyShared() {
|
2017-02-15 07:28:44 +08:00
|
|
|
library.MutatedProperties.BuildStatic = false
|
2016-12-10 06:46:15 +08:00
|
|
|
}
|
|
|
|
|
2016-12-14 04:50:57 +08:00
|
|
|
func (library *libraryDecorator) HeaderOnly() {
|
2017-02-15 07:28:44 +08:00
|
|
|
library.MutatedProperties.BuildShared = false
|
|
|
|
library.MutatedProperties.BuildStatic = false
|
2016-12-14 04:50:57 +08:00
|
|
|
}
|
|
|
|
|
2016-12-10 06:46:15 +08:00
|
|
|
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
2016-07-30 08:28:03 +08:00
|
|
|
module := newModule(hod, android.MultilibBoth)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
library := &libraryDecorator{
|
2017-02-15 07:28:44 +08:00
|
|
|
MutatedProperties: LibraryMutatedProperties{
|
2016-12-10 06:46:15 +08:00
|
|
|
BuildShared: true,
|
|
|
|
BuildStatic: true,
|
2016-07-30 03:48:20 +08:00
|
|
|
},
|
2016-07-30 08:28:03 +08:00
|
|
|
baseCompiler: NewBaseCompiler(),
|
|
|
|
baseLinker: NewBaseLinker(),
|
|
|
|
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
|
|
|
|
sanitize: module.sanitize,
|
2017-02-09 05:45:53 +08:00
|
|
|
sabi: module.sabi,
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
module.compiler = library
|
|
|
|
module.linker = library
|
|
|
|
module.installer = library
|
|
|
|
|
|
|
|
return module, library
|
|
|
|
}
|
|
|
|
|
|
|
|
func linkageMutator(mctx android.BottomUpMutatorContext) {
|
|
|
|
if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
|
|
|
|
if library, ok := m.linker.(libraryInterface); ok {
|
|
|
|
var modules []blueprint.Module
|
|
|
|
if library.buildStatic() && library.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("static", "shared")
|
|
|
|
static := modules[0].(*Module)
|
|
|
|
shared := modules[1].(*Module)
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
static.linker.(libraryInterface).setStatic()
|
|
|
|
shared.linker.(libraryInterface).setShared()
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
|
|
|
sharedCompiler := shared.compiler.(*libraryDecorator)
|
|
|
|
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
|
|
|
len(sharedCompiler.Properties.Shared.Cflags) == 0 {
|
|
|
|
// Optimize out compiling common .o files twice for static+shared libraries
|
|
|
|
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
|
|
|
sharedCompiler.baseCompiler.Properties.Srcs = nil
|
|
|
|
sharedCompiler.baseCompiler.Properties.Generated_sources = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if library.buildStatic() {
|
|
|
|
modules = mctx.CreateLocalVariations("static")
|
2017-02-15 07:28:44 +08:00
|
|
|
modules[0].(*Module).linker.(libraryInterface).setStatic()
|
2016-07-30 08:28:03 +08:00
|
|
|
} else if library.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("shared")
|
2017-02-15 07:28:44 +08:00
|
|
|
modules[0].(*Module).linker.(libraryInterface).setShared()
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|