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 (
|
2019-06-03 18:10:47 +08:00
|
|
|
"fmt"
|
2019-04-10 13:33:58 +08:00
|
|
|
"io"
|
2019-02-25 10:05:47 +08:00
|
|
|
"path/filepath"
|
2018-11-02 17:23:15 +08:00
|
|
|
"regexp"
|
2016-07-30 03:48:20 +08:00
|
|
|
"strings"
|
2018-11-02 17:23:15 +08:00
|
|
|
"sync"
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-10-01 08:10:16 +08:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
2018-04-26 07:05:30 +08:00
|
|
|
"android/soong/cc/config"
|
2016-07-30 03:48:20 +08:00
|
|
|
)
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// LibraryProperties is a collection of properties shared by cc library rules.
|
2016-07-30 08:28:03 +08:00
|
|
|
type LibraryProperties struct {
|
2016-07-30 03:48:20 +08:00
|
|
|
// local file name to pass to the linker as -unexported_symbols_list
|
2019-03-05 14:35:41 +08:00
|
|
|
Unexported_symbols_list *string `android:"path,arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
2019-03-05 14:35:41 +08:00
|
|
|
Force_symbols_not_weak_list *string `android:"path,arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
// local file name to pass to the linker as -force_symbols_weak_list
|
2019-03-05 14:35:41 +08:00
|
|
|
Force_symbols_weak_list *string `android:"path,arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
// 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
|
2017-11-08 02:57:05 +08:00
|
|
|
Export_aidl_headers *bool
|
2016-11-04 05:28:51 +08:00
|
|
|
}
|
|
|
|
|
2016-10-21 07:11:43 +08:00
|
|
|
Proto struct {
|
|
|
|
// export headers generated from .proto sources
|
2017-11-08 02:57:05 +08:00
|
|
|
Export_proto_headers *bool
|
2016-10-21 07:11:43 +08:00
|
|
|
}
|
2017-10-13 15:29:00 +08:00
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
Sysprop struct {
|
|
|
|
// Whether platform owns this sysprop library.
|
|
|
|
Platform *bool
|
2019-03-05 11:40:24 +08:00
|
|
|
} `blueprint:"mutated"`
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2017-11-08 02:57:05 +08:00
|
|
|
Static_ndk_lib *bool
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
|
|
|
|
Stubs struct {
|
|
|
|
// Relative path to the symbol map. The symbol map provides the list of
|
|
|
|
// symbols that are exported for stubs variant of this library.
|
2019-03-05 14:35:41 +08:00
|
|
|
Symbol_file *string `android:"path"`
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
|
|
|
|
// List versions to generate stubs libs for.
|
|
|
|
Versions []string
|
|
|
|
}
|
2018-11-07 20:43:34 +08:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string `android:"arch_variant"`
|
|
|
|
|
2019-08-17 05:22:10 +08:00
|
|
|
// set suffix of the name of the output
|
|
|
|
Suffix *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
Target struct {
|
2020-10-29 15:49:43 +08:00
|
|
|
Vendor, Product struct {
|
2019-08-17 05:22:10 +08:00
|
|
|
// set suffix of the name of the output
|
|
|
|
Suffix *string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 20:43:34 +08:00
|
|
|
// Names of modules to be overridden. Listed modules can only be other shared libraries
|
|
|
|
// (in Make or Soong).
|
|
|
|
// This does not completely prevent installation of the overridden libraries, but if both
|
|
|
|
// binaries would be installed by default (in PRODUCT_PACKAGES) the other library will be removed
|
|
|
|
// from PRODUCT_PACKAGES.
|
|
|
|
Overrides []string
|
2019-01-17 00:18:02 +08:00
|
|
|
|
|
|
|
// Properties for ABI compatibility checker
|
|
|
|
Header_abi_checker struct {
|
2019-04-10 13:33:58 +08:00
|
|
|
// Enable ABI checks (even if this is not an LLNDK/VNDK lib)
|
|
|
|
Enabled *bool
|
|
|
|
|
2019-01-17 00:18:02 +08:00
|
|
|
// Path to a symbol file that specifies the symbols to be included in the generated
|
|
|
|
// ABI dump file
|
2019-03-05 14:35:41 +08:00
|
|
|
Symbol_file *string `android:"path"`
|
2019-01-17 00:18:02 +08:00
|
|
|
|
|
|
|
// Symbol versions that should be ignored from the symbol file
|
|
|
|
Exclude_symbol_versions []string
|
|
|
|
|
|
|
|
// Symbol tags that should be ignored from the symbol file
|
|
|
|
Exclude_symbol_tags []string
|
2019-10-02 06:58:07 +08:00
|
|
|
|
|
|
|
// Run checks on all APIs (in addition to the ones referred by
|
|
|
|
// one of exported ELF symbols.)
|
|
|
|
Check_all_apis *bool
|
2019-01-17 00:18:02 +08:00
|
|
|
}
|
2019-06-25 07:08:48 +08:00
|
|
|
|
|
|
|
// Order symbols in .bss section by their sizes. Only useful for shared libraries.
|
|
|
|
Sort_bss_symbols_by_size *bool
|
2019-08-07 05:19:59 +08:00
|
|
|
|
|
|
|
// Inject boringssl hash into the shared library. This is only intended for use by external/boringssl.
|
|
|
|
Inject_bssl_hash *bool `android:"arch_variant"`
|
2020-10-14 09:43:54 +08:00
|
|
|
|
|
|
|
// If this is an LLNDK library, the name of the equivalent llndk_library module.
|
|
|
|
Llndk_stubs *string
|
2017-02-15 07:28:44 +08:00
|
|
|
}
|
2016-10-21 07:11:43 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// StaticProperties is a properties stanza to affect only attributes of the "static" variants of a
|
|
|
|
// library module.
|
2019-09-25 05:55:04 +08:00
|
|
|
type StaticProperties struct {
|
|
|
|
Static StaticOrSharedProperties `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// SharedProperties is a properties stanza to affect only attributes of the "shared" variants of a
|
|
|
|
// library module.
|
2019-09-25 05:55:04 +08:00
|
|
|
type SharedProperties struct {
|
|
|
|
Shared StaticOrSharedProperties `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// StaticOrSharedProperties is an embedded struct representing properties to affect attributes of
|
|
|
|
// either only the "static" variants or only the "shared" variants of a library module. These override
|
|
|
|
// the base properties of the same name.
|
|
|
|
// Use `StaticProperties` or `SharedProperties`, depending on which variant is needed.
|
|
|
|
// `StaticOrSharedProperties` exists only to avoid duplication.
|
2019-09-25 05:55:04 +08:00
|
|
|
type StaticOrSharedProperties struct {
|
2020-07-25 06:35:40 +08:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
Sanitized Sanitized `android:"arch_variant"`
|
|
|
|
|
2019-09-25 05:55:04 +08:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
System_shared_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
Export_shared_lib_headers []string `android:"arch_variant"`
|
|
|
|
Export_static_lib_headers []string `android:"arch_variant"`
|
2019-10-07 14:47:24 +08:00
|
|
|
|
|
|
|
Apex_available []string `android:"arch_variant"`
|
2019-09-25 05:55:04 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
type LibraryMutatedProperties struct {
|
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"`
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
|
|
|
|
// This variant is a stubs lib
|
|
|
|
BuildStubs bool `blueprint:"mutated"`
|
|
|
|
// Version of the stubs lib
|
|
|
|
StubsVersion string `blueprint:"mutated"`
|
2020-08-19 09:35:15 +08:00
|
|
|
// List of all stubs versions associated with an implementation lib
|
|
|
|
AllStubsVersions []string `blueprint:"mutated"`
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-10-18 07:15:50 +08:00
|
|
|
// against this module. Directories listed in export_include_dirs do not need to be
|
|
|
|
// listed in local_include_dirs.
|
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
|
|
|
|
2019-10-22 19:31:18 +08:00
|
|
|
// list of directories that will be added to the system include path
|
|
|
|
// using -isystem for this module and any module that links against this module.
|
|
|
|
Export_system_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 {
|
2020-10-29 15:49:43 +08:00
|
|
|
Vendor, Product struct {
|
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
|
|
|
// list of exported include directories, like
|
2020-10-29 15:49:43 +08:00
|
|
|
// export_include_dirs, that will be applied to
|
|
|
|
// vendor or product variant of this library.
|
|
|
|
// This will overwrite any other declarations.
|
2018-01-06 06:42:54 +08:00
|
|
|
Override_export_include_dirs []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
|
|
|
}
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2019-12-19 23:02:40 +08:00
|
|
|
RegisterLibraryBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("cc_library_static", LibraryStaticFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_shared", LibrarySharedFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library", LibraryFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_host_static", LibraryHostStaticFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 06:32:39 +08:00
|
|
|
// cc_library creates both static and/or shared libraries for a device and/or
|
|
|
|
// host. By default, a cc_library has a single variant that targets the device.
|
|
|
|
// Specifying `host_supported: true` also creates a library that targets the
|
|
|
|
// host.
|
2017-11-03 08:00:50 +08:00
|
|
|
func LibraryFactory() android.Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, _ := NewLibrary(android.HostAndDeviceSupported)
|
2019-12-14 03:50:38 +08:00
|
|
|
// Can be used as both a static and a shared library.
|
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{
|
|
|
|
sharedLibrarySdkMemberType,
|
|
|
|
staticLibrarySdkMemberType,
|
2020-03-12 18:24:35 +08:00
|
|
|
staticAndSharedLibrarySdkMemberType,
|
2019-12-14 03:50:38 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:32:39 +08:00
|
|
|
// cc_library_static creates a static library for a device and/or host binary.
|
2017-11-03 08:00:50 +08:00
|
|
|
func LibraryStaticFactory() android.Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyStatic()
|
2019-12-14 03:50:38 +08:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:32:39 +08:00
|
|
|
// cc_library_shared creates a shared library for a device and/or host.
|
2017-11-03 08:00:50 +08:00
|
|
|
func LibrarySharedFactory() android.Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2019-12-14 03:50:38 +08:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:32:39 +08:00
|
|
|
// cc_library_host_static creates a static library that is linkable to a host
|
|
|
|
// binary.
|
2017-11-03 08:00:50 +08:00
|
|
|
func LibraryHostStaticFactory() android.Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyStatic()
|
2019-12-14 03:50:38 +08:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:32:39 +08:00
|
|
|
// cc_library_host_shared creates a shared library that is usable on a host.
|
2017-11-03 08:00:50 +08:00
|
|
|
func LibraryHostSharedFactory() android.Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostSupported)
|
|
|
|
library.BuildOnlyShared()
|
2019-12-14 03:50:38 +08:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// flagExporter is a separated portion of libraryDecorator pertaining to exported
|
|
|
|
// include paths and flags. Keeping this dependency-related information separate
|
|
|
|
// from the rest of library information is helpful in keeping data more structured
|
|
|
|
// and explicit.
|
2016-07-30 03:48:20 +08:00
|
|
|
type flagExporter struct {
|
|
|
|
Properties FlagExporterProperties
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
dirs android.Paths // Include directories to be included with -I
|
|
|
|
systemDirs android.Paths // System include directories to be included with -isystem
|
|
|
|
flags []string // Exported raw flags.
|
2019-06-03 18:10:47 +08:00
|
|
|
deps android.Paths
|
2019-12-06 12:15:38 +08:00
|
|
|
headers android.Paths
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// exportedIncludes returns the effective include paths for this module and
|
|
|
|
// any module that links against this module. This is obtained from
|
|
|
|
// the export_include_dirs property in the appropriate target stanza.
|
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 {
|
2020-10-29 15:49:43 +08:00
|
|
|
// TODO(b/150902910): product variant must use Target.Product
|
2018-01-06 06:42:54 +08:00
|
|
|
if ctx.useVndk() && f.Properties.Target.Vendor.Override_export_include_dirs != nil {
|
|
|
|
return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Override_export_include_dirs)
|
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
|
|
|
} else {
|
|
|
|
return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// exportIncludes registers the include directories and system include directories to be exported
|
|
|
|
// transitively to modules depending on this module.
|
2019-06-03 18:10:47 +08:00
|
|
|
func (f *flagExporter) exportIncludes(ctx ModuleContext) {
|
2019-10-22 19:19:51 +08:00
|
|
|
f.dirs = append(f.dirs, f.exportedIncludes(ctx)...)
|
2019-10-22 19:31:18 +08:00
|
|
|
f.systemDirs = append(f.systemDirs, android.PathsForModuleSrc(ctx, f.Properties.Export_system_include_dirs)...)
|
2019-06-03 18:10:47 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// exportIncludesAsSystem registers the include directories and system include directories to be
|
|
|
|
// exported transitively both as system include directories to modules depending on this module.
|
2019-06-03 18:10:47 +08:00
|
|
|
func (f *flagExporter) exportIncludesAsSystem(ctx ModuleContext) {
|
2019-10-22 19:31:18 +08:00
|
|
|
// all dirs are force exported as system
|
2019-10-22 19:19:51 +08:00
|
|
|
f.systemDirs = append(f.systemDirs, f.exportedIncludes(ctx)...)
|
2019-10-22 19:31:18 +08:00
|
|
|
f.systemDirs = append(f.systemDirs, android.PathsForModuleSrc(ctx, f.Properties.Export_system_include_dirs)...)
|
2019-06-03 18:10:47 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// reexportDirs registers the given directories as include directories to be exported transitively
|
|
|
|
// to modules depending on this module.
|
2019-10-22 19:19:51 +08:00
|
|
|
func (f *flagExporter) reexportDirs(dirs ...android.Path) {
|
2019-06-03 18:10:47 +08:00
|
|
|
f.dirs = append(f.dirs, dirs...)
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// reexportSystemDirs registers the given directories as system include directories
|
|
|
|
// to be exported transitively to modules depending on this module.
|
2019-10-22 19:19:51 +08:00
|
|
|
func (f *flagExporter) reexportSystemDirs(dirs ...android.Path) {
|
2019-06-03 18:10:47 +08:00
|
|
|
f.systemDirs = append(f.systemDirs, dirs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// reexportFlags registers the flags to be exported transitively to modules depending on this
|
|
|
|
// module.
|
2019-06-03 18:10:47 +08:00
|
|
|
func (f *flagExporter) reexportFlags(flags ...string) {
|
2020-02-11 23:54:35 +08:00
|
|
|
if android.PrefixInList(flags, "-I") || android.PrefixInList(flags, "-isystem") {
|
|
|
|
panic(fmt.Errorf("Exporting invalid flag %q: "+
|
|
|
|
"use reexportDirs or reexportSystemDirs to export directories", flag))
|
2019-06-03 18:10:47 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
f.flags = append(f.flags, flags...)
|
|
|
|
}
|
|
|
|
|
2019-06-03 18:10:47 +08:00
|
|
|
func (f *flagExporter) reexportDeps(deps ...android.Path) {
|
|
|
|
f.deps = append(f.deps, deps...)
|
|
|
|
}
|
|
|
|
|
2019-12-06 12:15:38 +08:00
|
|
|
// addExportedGeneratedHeaders does nothing but collects generated header files.
|
|
|
|
// This can be differ to exportedDeps which may contain phony files to minimize ninja.
|
|
|
|
func (f *flagExporter) addExportedGeneratedHeaders(headers ...android.Path) {
|
|
|
|
f.headers = append(f.headers, headers...)
|
|
|
|
}
|
|
|
|
|
2020-09-19 05:15:30 +08:00
|
|
|
func (f *flagExporter) setProvider(ctx android.ModuleContext) {
|
|
|
|
ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
|
|
|
|
IncludeDirs: f.dirs,
|
|
|
|
SystemIncludeDirs: f.systemDirs,
|
|
|
|
Flags: f.flags,
|
|
|
|
Deps: f.deps,
|
|
|
|
GeneratedHeaders: f.headers,
|
|
|
|
})
|
2019-06-03 18:10:47 +08:00
|
|
|
}
|
|
|
|
|
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
|
2019-09-25 05:55:04 +08:00
|
|
|
StaticProperties StaticProperties
|
|
|
|
SharedProperties SharedProperties
|
2017-02-15 07:28:44 +08:00
|
|
|
MutatedProperties LibraryMutatedProperties
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
// For reusing static library objects for shared library
|
2019-06-03 18:10:47 +08:00
|
|
|
reuseObjects Objects
|
2017-05-04 02:01:58 +08:00
|
|
|
|
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
|
2020-08-19 20:53:01 +08:00
|
|
|
stripper Stripper
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
// Location of the static library in the sysroot. Empty if the library is
|
|
|
|
// not included in the NDK.
|
|
|
|
ndkSysrootPath android.Path
|
|
|
|
|
2018-09-05 07:28:17 +08:00
|
|
|
// Location of the linked, unstripped library for shared libraries
|
|
|
|
unstrippedOutputFile android.Path
|
|
|
|
|
2018-11-20 01:33:29 +08:00
|
|
|
// Location of the file that should be copied to dist dir when requested
|
2020-06-15 13:24:19 +08:00
|
|
|
distFile android.Path
|
2018-11-20 01:33:29 +08:00
|
|
|
|
2020-09-29 09:28:02 +08:00
|
|
|
versionScriptPath android.OptionalPath
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
|
2019-02-25 10:05:47 +08:00
|
|
|
post_install_cmds []string
|
|
|
|
|
2018-11-13 12:19:56 +08:00
|
|
|
// If useCoreVariant is true, the vendor variant of a VNDK library is
|
|
|
|
// not installed.
|
2020-01-09 06:32:28 +08:00
|
|
|
useCoreVariant bool
|
|
|
|
checkSameCoreVariant bool
|
2018-11-13 12:19:56 +08:00
|
|
|
|
2020-10-01 02:41:33 +08:00
|
|
|
skipAPIDefine bool
|
|
|
|
|
2020-04-02 03:38:01 +08:00
|
|
|
// Decorated interfaces
|
2016-07-30 08:28:03 +08:00
|
|
|
*baseCompiler
|
|
|
|
*baseLinker
|
|
|
|
*baseInstaller
|
2020-03-03 21:06:32 +08:00
|
|
|
|
|
|
|
collectedSnapshotHeaders android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
// collectHeadersForSnapshot collects all exported headers from library.
|
|
|
|
// It globs header files in the source tree for exported include directories,
|
|
|
|
// and tracks generated header files separately.
|
|
|
|
//
|
|
|
|
// This is to be called from GenerateAndroidBuildActions, and then collected
|
|
|
|
// header files can be retrieved by snapshotHeaders().
|
|
|
|
func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext) {
|
|
|
|
ret := android.Paths{}
|
|
|
|
|
|
|
|
// Headers in the source tree should be globbed. On the contrast, generated headers
|
|
|
|
// can't be globbed, and they should be manually collected.
|
|
|
|
// So, we first filter out intermediate directories (which contains generated headers)
|
|
|
|
// from exported directories, and then glob headers under remaining directories.
|
2020-09-19 05:15:30 +08:00
|
|
|
for _, path := range append(android.CopyOfPaths(l.flagExporter.dirs), l.flagExporter.systemDirs...) {
|
2020-03-03 21:06:32 +08:00
|
|
|
dir := path.String()
|
|
|
|
// Skip if dir is for generated headers
|
|
|
|
if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) {
|
|
|
|
continue
|
|
|
|
}
|
2020-05-29 21:30:58 +08:00
|
|
|
// libeigen wrongly exports the root directory "external/eigen". But only two
|
|
|
|
// subdirectories "Eigen" and "unsupported" contain exported header files. Even worse
|
|
|
|
// some of them have no extension. So we need special treatment for libeigen in order
|
|
|
|
// to glob correctly.
|
|
|
|
if dir == "external/eigen" {
|
|
|
|
// Only these two directories contains exported headers.
|
|
|
|
for _, subdir := range []string{"Eigen", "unsupported/Eigen"} {
|
|
|
|
glob, err := ctx.GlobWithDeps("external/eigen/"+subdir+"/**/*", nil)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("glob failed: %#v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, header := range glob {
|
|
|
|
if strings.HasSuffix(header, "/") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ext := filepath.Ext(header)
|
|
|
|
if ext != "" && ext != ".h" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret = append(ret, android.PathForSource(ctx, header))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2020-03-03 21:06:32 +08:00
|
|
|
exts := headerExts
|
|
|
|
// Glob all files under this special directory, because of C++ headers.
|
|
|
|
if strings.HasPrefix(dir, "external/libcxx/include") {
|
|
|
|
exts = []string{""}
|
|
|
|
}
|
|
|
|
for _, ext := range exts {
|
|
|
|
glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("glob failed: %#v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, header := range glob {
|
|
|
|
if strings.HasSuffix(header, "/") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret = append(ret, android.PathForSource(ctx, header))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect generated headers
|
2020-09-19 05:15:30 +08:00
|
|
|
for _, header := range append(android.CopyOfPaths(l.flagExporter.headers), l.flagExporter.deps...) {
|
2020-03-03 21:06:32 +08:00
|
|
|
// TODO(b/148123511): remove exportedDeps after cleaning up genrule
|
|
|
|
if strings.HasSuffix(header.Base(), "-phony") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret = append(ret, header)
|
|
|
|
}
|
|
|
|
|
|
|
|
l.collectedSnapshotHeaders = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns all exported header files, both generated ones and headers from source tree.
|
|
|
|
// collectHeadersForSnapshot() must be called before calling this.
|
|
|
|
func (l *libraryDecorator) snapshotHeaders() android.Paths {
|
|
|
|
if l.collectedSnapshotHeaders == nil {
|
|
|
|
panic("snapshotHeaders() must be called after collectHeadersForSnapshot()")
|
|
|
|
}
|
|
|
|
return l.collectedSnapshotHeaders
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// linkerProps returns the list of properties structs relevant for this library. (For example, if
|
|
|
|
// the library is cc_shared_library, then static-library properties are omitted.)
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkerProps() []interface{} {
|
|
|
|
var props []interface{}
|
|
|
|
props = append(props, library.baseLinker.linkerProps()...)
|
2019-09-25 05:55:04 +08:00
|
|
|
props = append(props,
|
2016-07-30 08:28:03 +08:00
|
|
|
&library.Properties,
|
2017-02-15 07:28:44 +08:00
|
|
|
&library.MutatedProperties,
|
2016-07-30 08:28:03 +08:00
|
|
|
&library.flagExporter.Properties,
|
2018-09-06 01:43:13 +08:00
|
|
|
&library.stripper.StripProperties)
|
2019-09-25 05:55:04 +08:00
|
|
|
|
|
|
|
if library.MutatedProperties.BuildShared {
|
|
|
|
props = append(props, &library.SharedProperties)
|
|
|
|
}
|
|
|
|
if library.MutatedProperties.BuildStatic {
|
|
|
|
props = append(props, &library.StaticProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
return props
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// linkerFlags takes a Flags struct and augments it to contain linker flags that are defined by this
|
|
|
|
// library, or that are implied by attributes of this library (such as whether this library is a
|
|
|
|
// shared library).
|
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() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.CFlags = append(flags.Global.CFlags, "-fPIC")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
if library.static() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, library.StaticProperties.Static.Cflags...)
|
2017-02-15 07:28:44 +08:00
|
|
|
} else if library.shared() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, library.SharedProperties.Shared.Cflags...)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 07:28:44 +08:00
|
|
|
if library.shared() {
|
2016-07-30 08:28:03 +08:00
|
|
|
libName := library.getLibName(ctx)
|
|
|
|
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 {
|
2019-06-08 08:58:59 +08:00
|
|
|
f = append(f, "-shared")
|
|
|
|
if !ctx.Windows() {
|
|
|
|
f = append(f, "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
|
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, f...)
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// compilerFlags takes a Flags and augments it to contain compile flags from global values,
|
|
|
|
// per-target values, module type values, per-module Blueprints properties, extra flags from
|
|
|
|
// `flags`, and generated sources from `deps`.
|
2017-11-17 06:33:08 +08:00
|
|
|
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) 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 {
|
2017-04-27 05:55:27 +08:00
|
|
|
f := includeDirsToFlags(exportIncludeDirs)
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
|
|
|
|
flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
|
2016-11-04 06:53:42 +08:00
|
|
|
}
|
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
flags = library.baseCompiler.compilerFlags(ctx, flags, deps)
|
|
|
|
if library.buildStubs() {
|
2018-12-13 17:37:29 +08:00
|
|
|
// Remove -include <file> when compiling stubs. Otherwise, the force included
|
|
|
|
// headers might cause conflicting types error with the symbols in the
|
|
|
|
// generated stubs source code. e.g.
|
|
|
|
// double acos(double); // in header
|
|
|
|
// void acos() {} // in the generated source code
|
|
|
|
removeInclude := func(flags []string) []string {
|
|
|
|
ret := flags[:0]
|
|
|
|
for _, f := range flags {
|
|
|
|
if strings.HasPrefix(f, "-include ") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret = append(ret, f)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CommonFlags = removeInclude(flags.Local.CommonFlags)
|
|
|
|
flags.Local.CFlags = removeInclude(flags.Local.CFlags)
|
2018-12-13 17:37:29 +08:00
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
flags = addStubLibraryCompilerFlags(flags)
|
|
|
|
}
|
|
|
|
return flags
|
2016-11-04 06:53:42 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 17:10:45 +08:00
|
|
|
// Returns a string that represents the class of the ABI dump.
|
|
|
|
// Returns an empty string if ABI check is disabled for this library.
|
|
|
|
func (library *libraryDecorator) classifySourceAbiDump(ctx ModuleContext) string {
|
|
|
|
enabled := library.Properties.Header_abi_checker.Enabled
|
|
|
|
if enabled != nil && !Bool(enabled) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// Return NDK if the library is both NDK and LLNDK.
|
2020-10-30 11:47:22 +08:00
|
|
|
if ctx.isNdk(ctx.Config()) {
|
2019-07-31 17:10:45 +08:00
|
|
|
return "NDK"
|
2019-07-29 17:46:59 +08:00
|
|
|
}
|
|
|
|
if ctx.isLlndkPublic(ctx.Config()) {
|
2019-07-31 17:10:45 +08:00
|
|
|
return "LLNDK"
|
2019-07-29 17:46:59 +08:00
|
|
|
}
|
|
|
|
if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(ctx.Config()) {
|
2019-07-31 17:10:45 +08:00
|
|
|
if ctx.isVndkSp() {
|
|
|
|
if ctx.isVndkExt() {
|
|
|
|
return "VNDK-SP-ext"
|
|
|
|
} else {
|
|
|
|
return "VNDK-SP"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ctx.isVndkExt() {
|
|
|
|
return "VNDK-ext"
|
|
|
|
} else {
|
|
|
|
return "VNDK-core"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-24 08:22:06 +08:00
|
|
|
if Bool(enabled) || library.hasStubsVariants() {
|
2019-07-31 17:10:45 +08:00
|
|
|
return "PLATFORM"
|
2019-07-29 17:46:59 +08:00
|
|
|
}
|
2019-07-31 17:10:45 +08:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx ModuleContext) bool {
|
|
|
|
if !ctx.shouldCreateSourceAbiDump() {
|
|
|
|
return false
|
|
|
|
}
|
2019-12-04 03:18:32 +08:00
|
|
|
if !ctx.isForPlatform() {
|
2020-10-24 08:22:06 +08:00
|
|
|
if !library.hasStubsVariants() {
|
2019-12-04 03:18:32 +08:00
|
|
|
// Skip ABI checks if this library is for APEX but isn't exported.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !Bool(library.Properties.Header_abi_checker.Enabled) {
|
|
|
|
// Skip ABI checks if this library is for APEX and did not explicitly enable
|
|
|
|
// ABI checks.
|
|
|
|
// TODO(b/145608479): ABI checks should be enabled by default. Remove this
|
|
|
|
// after evaluating the extra build time.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2019-07-31 17:10:45 +08:00
|
|
|
return library.classifySourceAbiDump(ctx) != ""
|
2019-04-10 13:33:58 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
if library.buildStubs() {
|
2018-12-07 15:25:39 +08:00
|
|
|
objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex")
|
2020-09-29 09:28:02 +08:00
|
|
|
library.versionScriptPath = android.OptionalPathForPath(versionScript)
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
}
|
2019-09-25 05:55:04 +08:00
|
|
|
if len(library.StaticProperties.Static.Srcs) > 0 {
|
2016-12-14 04:50:57 +08:00
|
|
|
ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs")
|
|
|
|
}
|
2019-09-25 05:55:04 +08:00
|
|
|
if len(library.SharedProperties.Shared.Srcs) > 0 {
|
2016-12-14 04:50:57 +08:00
|
|
|
ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs")
|
|
|
|
}
|
|
|
|
return Objects{}
|
|
|
|
}
|
2019-07-29 17:46:59 +08:00
|
|
|
if library.shouldCreateSourceAbiDump(ctx) || library.sabi.Properties.CreateSAbiDumps {
|
2017-09-07 04:10:03 +08:00
|
|
|
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
|
2017-02-09 05:45:53 +08:00
|
|
|
var SourceAbiFlags []string
|
|
|
|
for _, dir := range exportIncludeDirs.Strings() {
|
2017-04-20 21:53:59 +08:00
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
|
|
|
|
}
|
2019-06-03 18:10:47 +08:00
|
|
|
for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes {
|
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude)
|
2017-02-09 05:45:53 +08:00
|
|
|
}
|
|
|
|
flags.SAbiFlags = SourceAbiFlags
|
2019-09-25 05:55:04 +08:00
|
|
|
total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) +
|
|
|
|
len(library.SharedProperties.Shared.Srcs) + len(library.StaticProperties.Static.Srcs)
|
2017-02-09 05:45:53 +08:00
|
|
|
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() {
|
2019-09-25 05:55:04 +08:00
|
|
|
srcs := android.PathsForModuleSrc(ctx, library.StaticProperties.Static.Srcs)
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
2018-01-24 02:49:04 +08:00
|
|
|
srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
|
2017-02-15 07:28:44 +08:00
|
|
|
} else if library.shared() {
|
2019-09-25 05:55:04 +08:00
|
|
|
srcs := android.PathsForModuleSrc(ctx, library.SharedProperties.Shared.Srcs)
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
2018-01-24 02:49:04 +08:00
|
|
|
srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
|
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 {
|
2020-10-02 06:58:11 +08:00
|
|
|
versionedInterface
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
static() bool
|
2019-05-14 17:52:49 +08:00
|
|
|
shared() bool
|
2016-09-27 08:33:01 +08:00
|
|
|
objs() Objects
|
2020-09-19 05:15:30 +08:00
|
|
|
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()
|
2019-04-10 13:33:58 +08:00
|
|
|
|
|
|
|
// Write LOCAL_ADDITIONAL_DEPENDENCIES for ABI diff
|
|
|
|
androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer)
|
2019-10-07 14:47:24 +08:00
|
|
|
|
|
|
|
availableFor(string) bool
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-09-29 08:32:47 +08:00
|
|
|
type versionedInterface interface {
|
|
|
|
buildStubs() bool
|
|
|
|
setBuildStubs()
|
|
|
|
hasStubsVariants() bool
|
|
|
|
setStubsVersion(string)
|
|
|
|
stubsVersion() string
|
|
|
|
|
2020-10-02 06:58:11 +08:00
|
|
|
stubsVersions(ctx android.BaseMutatorContext) []string
|
2020-09-29 08:32:47 +08:00
|
|
|
setAllStubsVersions([]string)
|
|
|
|
allStubsVersions() []string
|
2020-10-14 09:43:54 +08:00
|
|
|
|
|
|
|
implementationModuleName(name string) string
|
2020-09-29 08:32:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ libraryInterface = (*libraryDecorator)(nil)
|
|
|
|
var _ versionedInterface = (*libraryDecorator)(nil)
|
|
|
|
|
2019-10-30 17:43:49 +08:00
|
|
|
func (library *libraryDecorator) getLibNameHelper(baseModuleName string, useVndk bool) string {
|
2016-07-30 03:48:20 +08:00
|
|
|
name := library.libName
|
|
|
|
if name == "" {
|
2018-11-07 20:43:34 +08:00
|
|
|
name = String(library.Properties.Stem)
|
|
|
|
if name == "" {
|
2019-10-30 17:43:49 +08:00
|
|
|
name = baseModuleName
|
2018-11-07 20:43:34 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 05:22:10 +08:00
|
|
|
suffix := ""
|
2019-10-30 17:43:49 +08:00
|
|
|
if useVndk {
|
2020-10-29 15:49:43 +08:00
|
|
|
// TODO(b/150902910): product variant must use Target.Product
|
2019-08-17 05:22:10 +08:00
|
|
|
suffix = String(library.Properties.Target.Vendor.Suffix)
|
|
|
|
}
|
|
|
|
if suffix == "" {
|
|
|
|
suffix = String(library.Properties.Suffix)
|
|
|
|
}
|
|
|
|
|
2019-10-30 17:43:49 +08:00
|
|
|
return name + suffix
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// getLibName returns the actual canonical name of the library (the name which
|
|
|
|
// should be passed to the linker via linker flags).
|
2019-10-30 17:43:49 +08:00
|
|
|
func (library *libraryDecorator) getLibName(ctx BaseModuleContext) string {
|
|
|
|
name := library.getLibNameHelper(ctx.baseModuleName(), ctx.useVndk())
|
2019-08-17 05:22:10 +08:00
|
|
|
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
if ctx.isVndkExt() {
|
2019-10-22 18:53:47 +08:00
|
|
|
// vndk-ext lib should have the same name with original lib
|
|
|
|
ctx.VisitDirectDepsWithTag(vndkExtDepTag, func(module android.Module) {
|
|
|
|
originalName := module.(*Module).outputFile.Path()
|
|
|
|
name = strings.TrimSuffix(originalName.Base(), originalName.Ext())
|
|
|
|
})
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-04 13:38:27 +08:00
|
|
|
return name
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2018-11-02 17:23:15 +08:00
|
|
|
var versioningMacroNamesListMutex sync.Mutex
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
|
|
|
location := InstallInSystem
|
2018-07-27 05:00:24 +08:00
|
|
|
if library.baseLinker.sanitize.inSanitizerDir() {
|
2017-03-30 13:00:18 +08:00
|
|
|
location = InstallInSanitizerDir
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
library.baseInstaller.location = location
|
|
|
|
library.baseLinker.linkerInit(ctx)
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
// Let baseLinker know whether this variant is for stubs or not, so that
|
|
|
|
// it can omit things that are not required for linking stubs.
|
|
|
|
library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs()
|
2018-11-02 17:23:15 +08:00
|
|
|
|
|
|
|
if library.buildStubs() {
|
|
|
|
macroNames := versioningMacroNamesList(ctx.Config())
|
|
|
|
myName := versioningMacroName(ctx.ModuleName())
|
|
|
|
versioningMacroNamesListMutex.Lock()
|
|
|
|
defer versioningMacroNamesListMutex.Unlock()
|
|
|
|
if (*macroNames)[myName] == "" {
|
|
|
|
(*macroNames)[myName] = ctx.ModuleName()
|
|
|
|
} else if (*macroNames)[myName] != ctx.ModuleName() {
|
|
|
|
ctx.ModuleErrorf("Macro name %q for versioning conflicts with macro name from module %q ", myName, (*macroNames)[myName])
|
|
|
|
}
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 23:28:14 +08:00
|
|
|
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|
|
|
deps = library.baseCompiler.compilerDeps(ctx, deps)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2018-12-04 07:25:46 +08:00
|
|
|
if library.static() {
|
2020-03-24 09:19:52 +08:00
|
|
|
// Compare with nil because an empty list needs to be propagated.
|
2019-09-25 05:55:04 +08:00
|
|
|
if library.StaticProperties.Static.System_shared_libs != nil {
|
|
|
|
library.baseLinker.Properties.System_shared_libs = library.StaticProperties.Static.System_shared_libs
|
2018-12-04 07:25:46 +08:00
|
|
|
}
|
|
|
|
} else if library.shared() {
|
2020-03-24 09:19:52 +08:00
|
|
|
// Compare with nil because an empty list needs to be propagated.
|
2019-09-25 05:55:04 +08:00
|
|
|
if library.SharedProperties.Shared.System_shared_libs != nil {
|
|
|
|
library.baseLinker.Properties.System_shared_libs = library.SharedProperties.Shared.System_shared_libs
|
2018-12-04 07:25:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2019-09-25 05:55:04 +08:00
|
|
|
library.StaticProperties.Static.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.StaticProperties.Static.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.StaticProperties.Static.Shared_libs...)
|
2019-01-23 06:41:08 +08:00
|
|
|
|
2019-09-25 05:55:04 +08:00
|
|
|
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.StaticProperties.Static.Export_shared_lib_headers...)
|
|
|
|
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.StaticProperties.Static.Export_static_lib_headers...)
|
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) {
|
2020-07-16 04:33:30 +08:00
|
|
|
deps.CrtBegin = "crtbegin_so"
|
|
|
|
deps.CrtEnd = "crtend_so"
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2019-09-25 05:55:04 +08:00
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.SharedProperties.Shared.Shared_libs...)
|
2019-01-23 06:41:08 +08:00
|
|
|
|
2019-09-25 05:55:04 +08:00
|
|
|
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.SharedProperties.Shared.Export_shared_lib_headers...)
|
|
|
|
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.SharedProperties.Shared.Export_static_lib_headers...)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2020-10-29 15:49:43 +08:00
|
|
|
// TODO(b/150902910): product variant must use Target.Product
|
2017-10-13 08:17:01 +08:00
|
|
|
if ctx.useVndk() {
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
|
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
|
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
|
2019-01-31 00:02:22 +08:00
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
|
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
|
2017-10-13 08:17:01 +08:00
|
|
|
}
|
2018-01-31 23:54:12 +08:00
|
|
|
if ctx.inRecovery() {
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
|
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
|
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
|
2019-01-31 00:02:22 +08:00
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
|
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
|
2018-01-31 23:54:12 +08:00
|
|
|
}
|
2020-01-22 09:04:13 +08:00
|
|
|
if ctx.inRamdisk() {
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Ramdisk.Exclude_static_libs)
|
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Ramdisk.Exclude_shared_libs)
|
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Ramdisk.Exclude_static_libs)
|
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Ramdisk.Exclude_shared_libs)
|
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Ramdisk.Exclude_static_libs)
|
|
|
|
}
|
2020-10-28 06:01:21 +08:00
|
|
|
if ctx.inVendorRamdisk() {
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Vendor_ramdisk.Exclude_shared_libs)
|
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Vendor_ramdisk.Exclude_shared_libs)
|
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Vendor_ramdisk.Exclude_static_libs)
|
|
|
|
}
|
2018-02-07 06:40:13 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2020-03-06 20:30:43 +08:00
|
|
|
func (library *libraryDecorator) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
|
|
|
|
specifiedDeps = library.baseLinker.linkerSpecifiedDeps(specifiedDeps)
|
|
|
|
var properties StaticOrSharedProperties
|
|
|
|
if library.static() {
|
|
|
|
properties = library.StaticProperties.Static
|
|
|
|
} else if library.shared() {
|
|
|
|
properties = library.SharedProperties.Shared
|
|
|
|
}
|
|
|
|
|
|
|
|
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, properties.Shared_libs...)
|
2020-03-24 09:19:52 +08:00
|
|
|
|
|
|
|
// Must distinguish nil and [] in system_shared_libs - ensure that [] in
|
|
|
|
// either input list doesn't come out as nil.
|
|
|
|
if specifiedDeps.systemSharedLibs == nil {
|
|
|
|
specifiedDeps.systemSharedLibs = properties.System_shared_libs
|
|
|
|
} else {
|
|
|
|
specifiedDeps.systemSharedLibs = append(specifiedDeps.systemSharedLibs, properties.System_shared_libs...)
|
|
|
|
}
|
2020-03-06 20:30:43 +08:00
|
|
|
|
|
|
|
specifiedDeps.sharedLibs = android.FirstUniqueStrings(specifiedDeps.sharedLibs)
|
2020-03-24 09:19:52 +08:00
|
|
|
if len(specifiedDeps.systemSharedLibs) > 0 {
|
|
|
|
// Skip this if systemSharedLibs is either nil or [], to ensure they are
|
|
|
|
// retained.
|
|
|
|
specifiedDeps.systemSharedLibs = android.FirstUniqueStrings(specifiedDeps.systemSharedLibs)
|
|
|
|
}
|
2020-03-06 20:30:43 +08:00
|
|
|
return specifiedDeps
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-07-04 13:38:27 +08:00
|
|
|
fileName := ctx.ModuleName() + staticLibraryExtension
|
2018-02-16 06:12:26 +08:00
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2017-02-10 08:16:31 +08:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-11-20 01:33:29 +08:00
|
|
|
if Bool(library.baseLinker.Properties.Use_version_lib) {
|
|
|
|
if ctx.Host() {
|
|
|
|
versionedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
|
|
|
|
library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
|
|
|
|
} else {
|
|
|
|
versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
|
2020-06-15 13:24:19 +08:00
|
|
|
library.distFile = versionedOutputFile
|
2018-11-20 01:33:29 +08:00
|
|
|
library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
|
|
|
|
}
|
2018-02-16 06:12:26 +08:00
|
|
|
}
|
|
|
|
|
2020-11-24 06:02:44 +08:00
|
|
|
transformObjToStaticLib(ctx, library.objects.objFiles, deps.WholeStaticLibsFromPrebuilts, builderFlags, outputFile, objs.tidyFiles)
|
2017-02-10 08:16:31 +08:00
|
|
|
|
2020-11-24 06:02:44 +08:00
|
|
|
library.coverageOutputFile = transformCoverageFilesToZip(ctx, library.objects, ctx.ModuleName())
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
2020-09-19 05:15:30 +08:00
|
|
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
|
|
|
StaticLibrary: outputFile,
|
|
|
|
ReuseObjects: library.reuseObjects,
|
|
|
|
Objects: library.objects,
|
|
|
|
|
|
|
|
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
|
|
|
|
Direct(outputFile).
|
|
|
|
Transitive(deps.TranstiveStaticLibrariesForOrdering).
|
|
|
|
Build(),
|
|
|
|
})
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
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
|
2017-09-01 14:38:27 +08:00
|
|
|
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-02-07 06:40:13 +08:00
|
|
|
unexportedSymbols := ctx.ExpandOptionalSource(library.Properties.Unexported_symbols_list, "unexported_symbols_list")
|
|
|
|
forceNotWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_not_weak_list, "force_symbols_not_weak_list")
|
|
|
|
forceWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_weak_list, "force_symbols_weak_list")
|
2016-07-30 03:48:20 +08:00
|
|
|
if !ctx.Darwin() {
|
|
|
|
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 unexportedSymbols.Valid() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
2016-07-30 03:48:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceNotWeakSymbols.Valid() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
2016-07-30 03:48:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceWeakSymbols.Valid() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
2016-07-30 03:48:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 09:28:02 +08:00
|
|
|
if library.versionScriptPath.Valid() {
|
2019-01-12 12:39:10 +08:00
|
|
|
linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String()
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlags)
|
2020-09-29 09:28:02 +08:00
|
|
|
linkerDeps = append(linkerDeps, library.versionScriptPath.Path())
|
2019-01-12 12:39:10 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
|
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2020-09-19 05:15:30 +08:00
|
|
|
unstrippedOutputFile := outputFile
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-06-08 08:58:59 +08:00
|
|
|
var implicitOutputs android.WritablePaths
|
|
|
|
if ctx.Windows() {
|
|
|
|
importLibraryPath := android.PathForModuleOut(ctx, pathtools.ReplaceExtension(fileName, "lib"))
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--out-implib="+importLibraryPath.String())
|
2019-06-08 08:58:59 +08:00
|
|
|
implicitOutputs = append(implicitOutputs, importLibraryPath)
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
2018-09-11 07:50:05 +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.
|
2019-10-02 13:05:35 +08:00
|
|
|
tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.ShlibSuffix()[1:]+".toc")
|
2018-09-11 07:50:05 +08:00
|
|
|
library.tocFile = android.OptionalPathForPath(tocFile)
|
2020-11-24 06:02:44 +08:00
|
|
|
transformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
|
2016-09-15 06:04:48 +08:00
|
|
|
|
2020-08-19 20:53:01 +08:00
|
|
|
stripFlags := flagsToStripFlags(flags)
|
|
|
|
if library.stripper.NeedsStrip(ctx) {
|
2018-11-08 08:28:49 +08:00
|
|
|
if ctx.Darwin() {
|
2020-08-19 20:53:01 +08:00
|
|
|
stripFlags.StripUseGnuStrip = true
|
2018-11-08 08:28:49 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
strippedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
2020-08-19 20:53:01 +08:00
|
|
|
library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, stripFlags)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-09-05 07:28:17 +08:00
|
|
|
library.unstrippedOutputFile = outputFile
|
|
|
|
|
2019-09-06 05:26:33 +08:00
|
|
|
outputFile = maybeInjectBoringSSLHash(ctx, outputFile, library.Properties.Inject_bssl_hash, fileName)
|
2019-08-07 05:19:59 +08:00
|
|
|
|
2018-11-20 01:33:29 +08:00
|
|
|
if Bool(library.baseLinker.Properties.Use_version_lib) {
|
|
|
|
if ctx.Host() {
|
|
|
|
versionedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
|
|
|
|
library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
|
|
|
|
} else {
|
|
|
|
versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
|
2020-06-15 13:24:19 +08:00
|
|
|
library.distFile = versionedOutputFile
|
2018-11-20 01:33:29 +08:00
|
|
|
|
2020-08-19 20:53:01 +08:00
|
|
|
if library.stripper.NeedsStrip(ctx) {
|
2018-11-20 01:33:29 +08:00
|
|
|
out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
|
2020-06-15 13:24:19 +08:00
|
|
|
library.distFile = out
|
2020-08-19 20:53:01 +08:00
|
|
|
library.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags)
|
2018-11-20 01:33:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
|
|
|
|
}
|
2018-02-16 06:12:26 +08:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:37:08 +08:00
|
|
|
sharedLibs := deps.EarlySharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.SharedLibs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
|
|
|
|
2019-01-18 13:37:08 +08:00
|
|
|
linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...)
|
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
|
|
|
|
2019-06-25 07:08:48 +08:00
|
|
|
if Bool(library.Properties.Sort_bss_symbols_by_size) {
|
|
|
|
unsortedOutputFile := android.PathForModuleOut(ctx, "unsorted", fileName)
|
2020-11-24 06:02:44 +08:00
|
|
|
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
2019-06-25 07:08:48 +08:00
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, unsortedOutputFile, implicitOutputs)
|
|
|
|
|
|
|
|
symbolOrderingFile := android.PathForModuleOut(ctx, "unsorted", fileName+".symbol_order")
|
|
|
|
symbolOrderingFlag := library.baseLinker.sortBssSymbolsBySize(ctx, unsortedOutputFile, symbolOrderingFile, builderFlags)
|
2019-11-06 23:06:58 +08:00
|
|
|
builderFlags.localLdFlags += " " + symbolOrderingFlag
|
2019-06-25 07:08:48 +08:00
|
|
|
linkerDeps = append(linkerDeps, symbolOrderingFile)
|
|
|
|
}
|
|
|
|
|
2020-11-24 06:02:44 +08:00
|
|
|
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
2019-06-08 08:58:59 +08:00
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile, implicitOutputs)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
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...)
|
|
|
|
|
2020-11-24 06:02:44 +08:00
|
|
|
library.coverageOutputFile = transformCoverageFilesToZip(ctx, objs, library.getLibName(ctx))
|
2020-09-19 05:15:30 +08:00
|
|
|
library.linkSAbiDumpFiles(ctx, objs, fileName, unstrippedOutputFile)
|
|
|
|
|
|
|
|
var staticAnalogue *StaticLibraryInfo
|
|
|
|
if static := ctx.GetDirectDepsWithTag(staticVariantTag); len(static) > 0 {
|
|
|
|
s := ctx.OtherModuleProvider(static[0], StaticLibraryInfoProvider).(StaticLibraryInfo)
|
|
|
|
staticAnalogue = &s
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
|
|
|
|
TableOfContents: android.OptionalPathForPath(tocFile),
|
|
|
|
SharedLibrary: unstrippedOutputFile,
|
|
|
|
UnstrippedSharedLibrary: library.unstrippedOutputFile,
|
|
|
|
CoverageSharedLibrary: library.coverageOutputFile,
|
|
|
|
StaticAnalogue: staticAnalogue,
|
|
|
|
})
|
|
|
|
|
|
|
|
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
|
|
|
|
if len(stubs) > 0 {
|
2020-11-21 01:42:07 +08:00
|
|
|
var stubsInfo []SharedStubLibrary
|
2020-09-19 05:15:30 +08:00
|
|
|
for _, stub := range stubs {
|
|
|
|
stubInfo := ctx.OtherModuleProvider(stub, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
|
|
|
flagInfo := ctx.OtherModuleProvider(stub, FlagExporterInfoProvider).(FlagExporterInfo)
|
2020-11-21 01:42:07 +08:00
|
|
|
stubsInfo = append(stubsInfo, SharedStubLibrary{
|
2020-10-24 08:22:06 +08:00
|
|
|
Version: moduleLibraryInterface(stub).stubsVersion(),
|
2020-09-19 05:15:30 +08:00
|
|
|
SharedLibraryInfo: stubInfo,
|
|
|
|
FlagExporterInfo: flagInfo,
|
|
|
|
})
|
|
|
|
}
|
2020-11-21 01:42:07 +08:00
|
|
|
ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{
|
|
|
|
SharedStubLibraries: stubsInfo,
|
2020-09-19 05:15:30 +08:00
|
|
|
|
|
|
|
IsLLNDK: ctx.isLlndk(ctx.Config()),
|
|
|
|
})
|
|
|
|
}
|
2017-02-10 08:16:31 +08:00
|
|
|
|
2020-09-19 05:15:30 +08:00
|
|
|
return unstrippedOutputFile
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-31 11:21:23 +08:00
|
|
|
func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
|
|
|
|
return library.unstrippedOutputFile
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:53:01 +08:00
|
|
|
func (library *libraryDecorator) disableStripping() {
|
|
|
|
library.stripper.StripProperties.Strip.None = BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2019-03-26 01:21:31 +08:00
|
|
|
func (library *libraryDecorator) nativeCoverage() bool {
|
|
|
|
if library.header() || library.buildStubs() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:44:36 +08:00
|
|
|
func (library *libraryDecorator) coverageOutputFilePath() android.OptionalPath {
|
|
|
|
return library.coverageOutputFile
|
|
|
|
}
|
|
|
|
|
2018-07-11 18:10:41 +08:00
|
|
|
func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
|
2020-03-26 17:50:29 +08:00
|
|
|
// The logic must be consistent with classifySourceAbiDump.
|
2020-10-30 11:47:22 +08:00
|
|
|
isNdk := ctx.isNdk(ctx.Config())
|
2020-03-26 17:50:29 +08:00
|
|
|
isLlndkOrVndk := ctx.isLlndkPublic(ctx.Config()) || (ctx.useVndk() && ctx.isVndk())
|
2018-07-11 18:10:41 +08:00
|
|
|
|
2019-07-31 17:10:45 +08:00
|
|
|
refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, false)
|
|
|
|
refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, true)
|
2018-07-11 18:10:41 +08:00
|
|
|
|
|
|
|
if refAbiDumpTextFile.Valid() {
|
|
|
|
if refAbiDumpGzipFile.Valid() {
|
|
|
|
ctx.ModuleErrorf(
|
|
|
|
"Two reference ABI dump files are found: %q and %q. Please delete the stale one.",
|
|
|
|
refAbiDumpTextFile, refAbiDumpGzipFile)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return refAbiDumpTextFile.Path()
|
|
|
|
}
|
|
|
|
if refAbiDumpGzipFile.Valid() {
|
2020-11-24 06:02:44 +08:00
|
|
|
return unzipRefDump(ctx, refAbiDumpGzipFile.Path(), fileName)
|
2018-07-11 18:10:41 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:52:58 +08:00
|
|
|
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
|
2019-07-29 17:46:59 +08:00
|
|
|
if library.shouldCreateSourceAbiDump(ctx) {
|
2020-06-09 21:05:09 +08:00
|
|
|
var vndkVersion string
|
|
|
|
|
|
|
|
if ctx.useVndk() {
|
|
|
|
// For modules linking against vndk, follow its vndk version
|
|
|
|
vndkVersion = ctx.Module().(*Module).VndkVersion()
|
|
|
|
} else {
|
|
|
|
// Regard the other modules as PLATFORM_VNDK_VERSION
|
|
|
|
vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
}
|
|
|
|
|
2017-09-07 04:10:03 +08:00
|
|
|
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
|
2017-02-09 05:45:53 +08:00
|
|
|
var SourceAbiFlags []string
|
|
|
|
for _, dir := range exportIncludeDirs.Strings() {
|
2017-04-20 21:53:59 +08:00
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
|
|
|
|
}
|
2019-06-03 18:10:47 +08:00
|
|
|
for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes {
|
|
|
|
SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude)
|
2017-02-09 05:45:53 +08:00
|
|
|
}
|
|
|
|
exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
|
2020-11-24 06:02:44 +08:00
|
|
|
library.sAbiOutputFile = transformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags,
|
2019-08-27 13:02:19 +08:00
|
|
|
android.OptionalPathForModuleSrc(ctx, library.symbolFileForAbiCheck(ctx)),
|
2019-01-17 00:18:02 +08:00
|
|
|
library.Properties.Header_abi_checker.Exclude_symbol_versions,
|
|
|
|
library.Properties.Header_abi_checker.Exclude_symbol_tags)
|
2018-07-10 15:01:19 +08:00
|
|
|
|
2019-07-31 17:10:45 +08:00
|
|
|
addLsdumpPath(library.classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
|
|
|
|
|
2018-07-11 18:10:41 +08:00
|
|
|
refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
|
|
|
|
if refAbiDumpFile != nil {
|
2020-11-24 06:02:44 +08:00
|
|
|
library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
|
2019-10-02 06:58:07 +08:00
|
|
|
refAbiDumpFile, fileName, exportedHeaderFlags,
|
|
|
|
Bool(library.Properties.Header_abi_checker.Check_all_apis),
|
2020-10-30 11:47:22 +08:00
|
|
|
ctx.isLlndk(ctx.Config()), ctx.isNdk(ctx.Config()), ctx.isVndkExt())
|
2017-02-09 05:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// link registers actions to link this library, and sets various fields
|
|
|
|
// on this library to reflect information that should be exported up the build
|
|
|
|
// tree (for example, exported flags and include paths).
|
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
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Linking this library consists of linking `deps.Objs` (.o files in dependencies
|
|
|
|
// of this library), together with `objs` (.o files created by compiling this
|
|
|
|
// library).
|
2017-11-17 06:29:11 +08:00
|
|
|
objs = deps.Objs.Copy().Append(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
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Export include paths and flags to be propagated up the tree.
|
2019-06-03 18:10:47 +08:00
|
|
|
library.exportIncludes(ctx)
|
|
|
|
library.reexportDirs(deps.ReexportedDirs...)
|
|
|
|
library.reexportSystemDirs(deps.ReexportedSystemDirs...)
|
|
|
|
library.reexportFlags(deps.ReexportedFlags...)
|
|
|
|
library.reexportDeps(deps.ReexportedDeps...)
|
2019-12-06 12:15:38 +08:00
|
|
|
library.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Optionally export aidl headers.
|
2017-11-08 02:57:05 +08:00
|
|
|
if Bool(library.Properties.Aidl.Export_aidl_headers) {
|
2016-11-04 05:28:51 +08:00
|
|
|
if library.baseCompiler.hasSrcExt(".aidl") {
|
2019-10-22 19:19:51 +08:00
|
|
|
dir := android.PathForModuleGen(ctx, "aidl")
|
2019-06-03 18:10:47 +08:00
|
|
|
library.reexportDirs(dir)
|
2019-12-06 12:15:38 +08:00
|
|
|
|
|
|
|
// TODO: restrict to aidl deps
|
|
|
|
library.reexportDeps(library.baseCompiler.pathDeps...)
|
|
|
|
library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...)
|
2016-11-04 05:28:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Optionally export proto headers.
|
2017-11-08 02:57:05 +08:00
|
|
|
if Bool(library.Properties.Proto.Export_proto_headers) {
|
2016-11-04 05:28:51 +08:00
|
|
|
if library.baseCompiler.hasSrcExt(".proto") {
|
2019-10-22 19:19:51 +08:00
|
|
|
var includes android.Paths
|
2019-03-29 05:45:07 +08:00
|
|
|
if flags.proto.CanonicalPathFromRoot {
|
2019-10-22 19:19:51 +08:00
|
|
|
includes = append(includes, flags.proto.SubDir)
|
2017-05-04 02:01:58 +08:00
|
|
|
}
|
2019-10-22 19:19:51 +08:00
|
|
|
includes = append(includes, flags.proto.Dir)
|
2019-06-03 18:10:47 +08:00
|
|
|
library.reexportDirs(includes...)
|
2019-12-06 12:15:38 +08:00
|
|
|
|
|
|
|
// TODO: restrict to proto deps
|
|
|
|
library.reexportDeps(library.baseCompiler.pathDeps...)
|
|
|
|
library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...)
|
2016-10-21 07:11:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:43:02 +08:00
|
|
|
// If the library is sysprop_library, expose either public or internal header selectively.
|
2018-09-05 23:55:20 +08:00
|
|
|
if library.baseCompiler.hasSrcExt(".sysprop") {
|
2019-10-22 19:19:51 +08:00
|
|
|
dir := android.PathForModuleGen(ctx, "sysprop", "include")
|
2019-02-08 20:00:45 +08:00
|
|
|
if library.Properties.Sysprop.Platform != nil {
|
2020-11-23 13:43:02 +08:00
|
|
|
isClientProduct := ctx.ProductSpecific() && !ctx.useVndk()
|
|
|
|
isClientVendor := ctx.useVndk()
|
2019-02-08 20:00:45 +08:00
|
|
|
isOwnerPlatform := Bool(library.Properties.Sysprop.Platform)
|
|
|
|
|
2020-11-23 13:43:02 +08:00
|
|
|
// If the owner is different from the user, expose public header. That is,
|
|
|
|
// 1) if the user is product (as owner can only be platform / vendor)
|
|
|
|
// 2) if one is platform and the other is vendor
|
|
|
|
// Exceptions are ramdisk and recovery. They are not enforced at all. So
|
|
|
|
// they always use internal header.
|
2020-10-22 06:17:56 +08:00
|
|
|
if !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() &&
|
2020-11-23 13:43:02 +08:00
|
|
|
(isClientProduct || (isOwnerPlatform == isClientVendor)) {
|
2019-10-22 19:19:51 +08:00
|
|
|
dir = android.PathForModuleGen(ctx, "sysprop/public", "include")
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Add sysprop-related directories to the exported directories of this library.
|
2019-06-03 18:10:47 +08:00
|
|
|
library.reexportDirs(dir)
|
|
|
|
library.reexportDeps(library.baseCompiler.pathDeps...)
|
2019-12-06 12:15:38 +08:00
|
|
|
library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...)
|
2018-09-05 23:55:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Add stub-related flags if this library is a stub library.
|
2020-10-01 02:41:33 +08:00
|
|
|
if library.buildStubs() && !library.skipAPIDefine {
|
2020-10-14 09:43:54 +08:00
|
|
|
library.reexportFlags("-D" + versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx)) + "=" + library.stubsVersion())
|
2018-11-02 17:23:15 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// Propagate a Provider containing information about exported flags, deps, and include paths.
|
2020-09-19 05:15:30 +08:00
|
|
|
library.flagExporter.setProvider(ctx)
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// buildStatic returns true if this library should be built as a static library.
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) buildStatic() bool {
|
2019-09-25 05:55:04 +08:00
|
|
|
return library.MutatedProperties.BuildStatic &&
|
|
|
|
BoolDefault(library.StaticProperties.Static.Enabled, true)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// buildShared returns true if this library should be built as a shared library.
|
2016-07-30 08:28:03 +08:00
|
|
|
func (library *libraryDecorator) buildShared() bool {
|
2019-09-25 05:55:04 +08:00
|
|
|
return library.MutatedProperties.BuildShared &&
|
|
|
|
BoolDefault(library.SharedProperties.Shared.Enabled, true)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
func (library *libraryDecorator) objs() Objects {
|
|
|
|
return library.objects
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-09-19 05:15:30 +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
|
|
|
|
}
|
|
|
|
|
2019-02-25 10:05:47 +08:00
|
|
|
func (library *libraryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) {
|
|
|
|
dir := library.baseInstaller.installDir(ctx)
|
|
|
|
dirOnDevice := android.InstallPathToOnDevicePath(ctx, dir)
|
|
|
|
target := "/" + filepath.Join("apex", "com.android.runtime", dir.Base(), "bionic", file.Base())
|
|
|
|
ctx.InstallAbsoluteSymlink(dir, file.Base(), target)
|
|
|
|
library.post_install_cmds = append(library.post_install_cmds, makeSymlinkCmd(dirOnDevice, file.Base(), target))
|
|
|
|
}
|
|
|
|
|
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() {
|
2017-12-07 16:18:15 +08:00
|
|
|
if ctx.Device() && ctx.useVndk() {
|
2020-10-20 17:54:21 +08:00
|
|
|
// set subDir for VNDK extensions
|
|
|
|
if ctx.isVndkExt() {
|
|
|
|
if ctx.isVndkSp() {
|
|
|
|
library.baseInstaller.subDir = "vndk-sp"
|
|
|
|
} else {
|
|
|
|
library.baseInstaller.subDir = "vndk"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In some cases we want to use core variant for VNDK-Core libs
|
|
|
|
if ctx.isVndk() && !ctx.isVndkSp() && !ctx.isVndkExt() {
|
2020-02-01 02:38:40 +08:00
|
|
|
mayUseCoreVariant := true
|
|
|
|
|
|
|
|
if ctx.mustUseVendorVariant() {
|
|
|
|
mayUseCoreVariant = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 {
|
|
|
|
mayUseCoreVariant = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if mayUseCoreVariant {
|
2020-01-09 06:32:28 +08:00
|
|
|
library.checkSameCoreVariant = true
|
|
|
|
if ctx.DeviceConfig().VndkUseCoreVariant() {
|
|
|
|
library.useCoreVariant = true
|
|
|
|
}
|
2018-11-13 12:19:56 +08:00
|
|
|
}
|
2017-12-07 16:18:15 +08:00
|
|
|
}
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
|
2020-10-20 17:54:21 +08:00
|
|
|
// do not install vndk libs
|
|
|
|
// vndk libs are packaged into VNDK APEX
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
if ctx.isVndk() && !ctx.isVndkExt() {
|
2020-10-20 17:54:21 +08:00
|
|
|
return
|
2017-06-23 18:24:43 +08:00
|
|
|
}
|
2020-09-16 09:30:11 +08:00
|
|
|
} else if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.directlyInAnyApex() {
|
2019-02-25 10:05:47 +08:00
|
|
|
// Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory.
|
|
|
|
// The original path becomes a symlink to the corresponding file in the
|
|
|
|
// runtime APEX.
|
2019-09-18 05:45:31 +08:00
|
|
|
translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
|
2020-09-16 09:30:11 +08:00
|
|
|
if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() &&
|
2020-10-22 06:17:56 +08:00
|
|
|
!translatedArch && !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() {
|
2019-09-11 06:18:20 +08:00
|
|
|
if ctx.Device() {
|
2019-03-16 00:10:08 +08:00
|
|
|
library.installSymlinkToRuntimeApex(ctx, file)
|
|
|
|
}
|
2019-01-16 21:31:11 +08:00
|
|
|
library.baseInstaller.subDir = "bootstrap"
|
|
|
|
}
|
2020-09-16 09:30:11 +08:00
|
|
|
} else if ctx.directlyInAnyApex() && ctx.isLlndk(ctx.Config()) && !isBionic(ctx.baseModuleName()) {
|
2019-07-12 21:06:23 +08:00
|
|
|
// Skip installing LLNDK (non-bionic) libraries moved to APEX.
|
|
|
|
ctx.Module().SkipInstall()
|
2017-06-23 18:24:43 +08:00
|
|
|
}
|
2019-07-12 21:06:23 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
2017-10-13 15:29:00 +08:00
|
|
|
|
2017-12-14 07:03:47 +08:00
|
|
|
if Bool(library.Properties.Static_ndk_lib) && library.static() &&
|
2020-10-22 06:17:56 +08:00
|
|
|
!ctx.useVndk() && !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() && ctx.Device() &&
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
library.baseLinker.sanitize.isUnsanitizedVariant() &&
|
2020-04-08 00:50:32 +08:00
|
|
|
!library.buildStubs() && ctx.sdkVersion() == "" {
|
2017-10-13 15:29:00 +08:00
|
|
|
installPath := getNdkSysrootBase(ctx).Join(
|
2018-04-26 07:05:30 +08:00
|
|
|
ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base())
|
2017-10-13 15:29:00 +08:00
|
|
|
|
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Description: "install " + installPath.Base(),
|
|
|
|
Output: installPath,
|
|
|
|
Input: file,
|
|
|
|
})
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
library.ndkSysrootPath = installPath
|
2017-10-13 15:29:00 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:52:46 +08:00
|
|
|
func (library *libraryDecorator) everInstallable() bool {
|
|
|
|
// Only shared and static libraries are installed. Header libraries (which are
|
|
|
|
// neither static or shared) are not installed.
|
|
|
|
return library.shared() || library.static()
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// static returns true if this library is for a "static' variant.
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// shared returns true if this library is for a "shared' variant.
|
2017-02-15 07:28:44 +08:00
|
|
|
func (library *libraryDecorator) shared() bool {
|
|
|
|
return library.MutatedProperties.VariantIsShared
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// header returns true if this library is for a header-only variant.
|
2017-02-15 07:28:44 +08:00
|
|
|
func (library *libraryDecorator) header() bool {
|
2020-11-21 01:42:07 +08:00
|
|
|
// Neither "static" nor "shared" implies this library is header-only.
|
2017-02-15 07:28:44 +08:00
|
|
|
return !library.static() && !library.shared()
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// setStatic marks the library variant as "static".
|
2017-02-15 07:28:44 +08:00
|
|
|
func (library *libraryDecorator) setStatic() {
|
|
|
|
library.MutatedProperties.VariantIsStatic = true
|
|
|
|
library.MutatedProperties.VariantIsShared = false
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// setShared marks the library variant as "shared".
|
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
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// BuildOnlyStatic disables building this library as a shared library.
|
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
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// BuildOnlyShared disables building this library as a static library.
|
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
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// HeaderOnly disables building this library as a shared or static library;
|
|
|
|
// the library only exists to propagate header file dependencies up the build graph.
|
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
|
|
|
}
|
|
|
|
|
2020-10-14 09:43:54 +08:00
|
|
|
func (library *libraryDecorator) implementationModuleName(name string) string {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
func (library *libraryDecorator) buildStubs() bool {
|
|
|
|
return library.MutatedProperties.BuildStubs
|
|
|
|
}
|
|
|
|
|
2019-08-27 13:02:19 +08:00
|
|
|
func (library *libraryDecorator) symbolFileForAbiCheck(ctx ModuleContext) *string {
|
|
|
|
if library.Properties.Header_abi_checker.Symbol_file != nil {
|
|
|
|
return library.Properties.Header_abi_checker.Symbol_file
|
|
|
|
}
|
2020-10-24 08:22:06 +08:00
|
|
|
if library.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil {
|
2019-08-27 13:02:19 +08:00
|
|
|
return library.Properties.Stubs.Symbol_file
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-29 08:32:47 +08:00
|
|
|
func (library *libraryDecorator) hasStubsVariants() bool {
|
|
|
|
return len(library.Properties.Stubs.Versions) > 0
|
|
|
|
}
|
|
|
|
|
2020-10-02 06:58:11 +08:00
|
|
|
func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
|
2020-09-29 08:32:47 +08:00
|
|
|
return library.Properties.Stubs.Versions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setStubsVersion(version string) {
|
|
|
|
library.MutatedProperties.StubsVersion = version
|
|
|
|
}
|
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
func (library *libraryDecorator) stubsVersion() string {
|
|
|
|
return library.MutatedProperties.StubsVersion
|
|
|
|
}
|
|
|
|
|
2020-09-29 08:32:47 +08:00
|
|
|
func (library *libraryDecorator) setBuildStubs() {
|
|
|
|
library.MutatedProperties.BuildStubs = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) setAllStubsVersions(versions []string) {
|
|
|
|
library.MutatedProperties.AllStubsVersions = versions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) allStubsVersions() []string {
|
|
|
|
return library.MutatedProperties.AllStubsVersions
|
|
|
|
}
|
|
|
|
|
2020-02-27 16:56:44 +08:00
|
|
|
func (library *libraryDecorator) isLatestStubVersion() bool {
|
|
|
|
versions := library.Properties.Stubs.Versions
|
|
|
|
return versions[len(versions)-1] == library.stubsVersion()
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:47:24 +08:00
|
|
|
func (library *libraryDecorator) availableFor(what string) bool {
|
|
|
|
var list []string
|
|
|
|
if library.static() {
|
|
|
|
list = library.StaticProperties.Static.Apex_available
|
|
|
|
} else if library.shared() {
|
|
|
|
list = library.SharedProperties.Shared.Apex_available
|
|
|
|
}
|
|
|
|
if len(list) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return android.CheckAvailableForApex(what, list)
|
|
|
|
}
|
|
|
|
|
2020-08-07 05:34:42 +08:00
|
|
|
func (library *libraryDecorator) makeUninstallable(mod *Module) {
|
2020-03-31 23:05:34 +08:00
|
|
|
if library.static() && library.buildStatic() && !library.buildStubs() {
|
2020-08-07 05:34:42 +08:00
|
|
|
// If we're asked to make a static library uninstallable we don't do
|
|
|
|
// anything since AndroidMkEntries always sets LOCAL_UNINSTALLABLE_MODULE
|
|
|
|
// for these entries. This is done to still get the make targets for NOTICE
|
|
|
|
// files from notice_files.mk, which other libraries might depend on.
|
2020-03-31 23:05:34 +08:00
|
|
|
return
|
|
|
|
}
|
2020-08-07 05:34:42 +08:00
|
|
|
mod.ModuleBase.MakeUninstallable()
|
2020-03-31 23:05:34 +08:00
|
|
|
}
|
|
|
|
|
2019-02-05 03:22:08 +08:00
|
|
|
var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList")
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// versioningMacroNamesList returns a singleton map, where keys are "version macro names",
|
|
|
|
// and values are the module name responsible for registering the version macro name.
|
|
|
|
//
|
|
|
|
// Version macros are used when building against stubs, to provide version information about
|
|
|
|
// the stub. Only stub libraries should have an entry in this list.
|
|
|
|
//
|
|
|
|
// For example, when building against libFoo#ver, __LIBFOO_API__ macro is set to ver so
|
|
|
|
// that headers from libFoo can be conditionally compiled (this may hide APIs
|
|
|
|
// that are not available for the version).
|
|
|
|
//
|
|
|
|
// This map is used to ensure that there aren't conflicts between these version macro names.
|
2018-11-02 17:23:15 +08:00
|
|
|
func versioningMacroNamesList(config android.Config) *map[string]string {
|
2019-02-05 03:22:08 +08:00
|
|
|
return config.Once(versioningMacroNamesListKey, func() interface{} {
|
2018-11-02 17:23:15 +08:00
|
|
|
m := make(map[string]string)
|
|
|
|
return &m
|
|
|
|
}).(*map[string]string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// alphanumeric and _ characters are preserved.
|
|
|
|
// other characters are all converted to _
|
|
|
|
var charsNotForMacro = regexp.MustCompile("[^a-zA-Z0-9_]+")
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// versioningMacroName returns the canonical version macro name for the given module.
|
2018-11-02 17:23:15 +08:00
|
|
|
func versioningMacroName(moduleName string) string {
|
|
|
|
macroName := charsNotForMacro.ReplaceAllString(moduleName, "_")
|
2020-03-13 17:57:35 +08:00
|
|
|
macroName = strings.ToUpper(macroName)
|
2018-11-02 17:23:15 +08:00
|
|
|
return "__" + macroName + "_API__"
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// NewLibrary builds and returns a new Module corresponding to a C++ library.
|
|
|
|
// Individual module implementations which comprise a C++ library (or something like
|
|
|
|
// a C++ library) should call this function, set some fields on the result, and
|
|
|
|
// then call the Init function.
|
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(),
|
2018-07-27 05:00:24 +08:00
|
|
|
baseLinker: NewBaseLinker(module.sanitize),
|
2016-07-30 08:28:03 +08:00
|
|
|
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
|
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
|
2020-10-24 08:22:06 +08:00
|
|
|
module.library = library
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
return module, library
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:01:58 +08:00
|
|
|
// connects a shared library to a static library in order to reuse its .o files to avoid
|
|
|
|
// compiling source files twice.
|
|
|
|
func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
|
|
|
|
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
|
|
|
sharedCompiler := shared.compiler.(*libraryDecorator)
|
2018-12-04 07:25:46 +08:00
|
|
|
|
|
|
|
// Check libraries in addition to cflags, since libraries may be exporting different
|
|
|
|
// include directories.
|
2019-09-25 05:55:04 +08:00
|
|
|
if len(staticCompiler.StaticProperties.Static.Cflags) == 0 &&
|
|
|
|
len(sharedCompiler.SharedProperties.Shared.Cflags) == 0 &&
|
|
|
|
len(staticCompiler.StaticProperties.Static.Whole_static_libs) == 0 &&
|
|
|
|
len(sharedCompiler.SharedProperties.Shared.Whole_static_libs) == 0 &&
|
|
|
|
len(staticCompiler.StaticProperties.Static.Static_libs) == 0 &&
|
|
|
|
len(sharedCompiler.SharedProperties.Shared.Static_libs) == 0 &&
|
|
|
|
len(staticCompiler.StaticProperties.Static.Shared_libs) == 0 &&
|
|
|
|
len(sharedCompiler.SharedProperties.Shared.Shared_libs) == 0 &&
|
2020-03-24 09:19:52 +08:00
|
|
|
// Compare System_shared_libs properties with nil because empty lists are
|
|
|
|
// semantically significant for them.
|
2019-09-25 05:55:04 +08:00
|
|
|
staticCompiler.StaticProperties.Static.System_shared_libs == nil &&
|
|
|
|
sharedCompiler.SharedProperties.Shared.System_shared_libs == nil {
|
2017-05-04 02:01:58 +08:00
|
|
|
|
|
|
|
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
|
|
|
sharedCompiler.baseCompiler.Properties.OriginalSrcs =
|
|
|
|
sharedCompiler.baseCompiler.Properties.Srcs
|
|
|
|
sharedCompiler.baseCompiler.Properties.Srcs = nil
|
|
|
|
sharedCompiler.baseCompiler.Properties.Generated_sources = nil
|
|
|
|
}
|
2020-09-19 05:15:30 +08:00
|
|
|
|
|
|
|
// This dep is just to reference static variant from shared variant
|
|
|
|
mctx.AddInterVariantDependency(staticVariantTag, shared, static)
|
2017-05-04 02:01:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// LinkageMutator adds "static" or "shared" variants for modules depending
|
|
|
|
// on whether the module can be built as a static library or a shared library.
|
2018-10-03 13:25:58 +08:00
|
|
|
func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
2019-10-19 05:49:46 +08:00
|
|
|
cc_prebuilt := false
|
2016-07-30 08:28:03 +08:00
|
|
|
if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
|
2019-10-19 05:49:46 +08:00
|
|
|
_, cc_prebuilt = m.linker.(prebuiltLibraryInterface)
|
|
|
|
}
|
|
|
|
if cc_prebuilt {
|
|
|
|
library := mctx.Module().(*Module).linker.(prebuiltLibraryInterface)
|
|
|
|
|
2020-02-21 18:57:00 +08:00
|
|
|
// Differentiate between header only and building an actual static/shared library
|
|
|
|
if library.buildStatic() || library.buildShared() {
|
|
|
|
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
|
|
|
|
// that is not being used. This allows them to share the name of a cc_library module, which requires that
|
|
|
|
// all the variants of the cc_library also exist on the prebuilt.
|
|
|
|
modules := mctx.CreateLocalVariations("static", "shared")
|
|
|
|
static := modules[0].(*Module)
|
|
|
|
shared := modules[1].(*Module)
|
|
|
|
|
|
|
|
static.linker.(prebuiltLibraryInterface).setStatic()
|
|
|
|
shared.linker.(prebuiltLibraryInterface).setShared()
|
|
|
|
|
2020-08-07 08:46:48 +08:00
|
|
|
if library.buildShared() {
|
|
|
|
mctx.AliasVariation("shared")
|
|
|
|
} else if library.buildStatic() {
|
|
|
|
mctx.AliasVariation("static")
|
|
|
|
}
|
|
|
|
|
2020-02-21 18:57:00 +08:00
|
|
|
if !library.buildStatic() {
|
|
|
|
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
|
|
|
|
}
|
|
|
|
if !library.buildShared() {
|
|
|
|
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Header only
|
2019-10-19 05:49:46 +08:00
|
|
|
}
|
2020-02-21 18:57:00 +08:00
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library, ok := mctx.Module().(LinkableInterface); ok && library.CcLibraryInterface() {
|
2016-07-30 08:28:03 +08:00
|
|
|
|
2019-11-22 04:30:50 +08:00
|
|
|
// Non-cc.Modules may need an empty variant for their mutators.
|
|
|
|
variations := []string{}
|
|
|
|
if library.NonCcVariants() {
|
|
|
|
variations = append(variations, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
if library.BuildStaticVariant() && library.BuildSharedVariant() {
|
|
|
|
variations := append([]string{"static", "shared"}, variations...)
|
2016-07-30 08:28:03 +08:00
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
modules := mctx.CreateLocalVariations(variations...)
|
|
|
|
static := modules[0].(LinkableInterface)
|
|
|
|
shared := modules[1].(LinkableInterface)
|
2017-05-04 02:01:58 +08:00
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
static.SetStatic()
|
|
|
|
shared.SetShared()
|
|
|
|
|
|
|
|
if _, ok := library.(*Module); ok {
|
|
|
|
reuseStaticLibrary(mctx, static.(*Module), shared.(*Module))
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
2020-08-07 08:46:48 +08:00
|
|
|
mctx.AliasVariation("shared")
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library.BuildStaticVariant() {
|
2019-11-22 04:30:50 +08:00
|
|
|
variations := append([]string{"static"}, variations...)
|
|
|
|
|
|
|
|
modules := mctx.CreateLocalVariations(variations...)
|
2019-10-19 05:49:46 +08:00
|
|
|
modules[0].(LinkableInterface).SetStatic()
|
2020-08-07 08:46:48 +08:00
|
|
|
mctx.AliasVariation("static")
|
2019-10-19 05:49:46 +08:00
|
|
|
} else if library.BuildSharedVariant() {
|
2019-11-22 04:30:50 +08:00
|
|
|
variations := append([]string{"shared"}, variations...)
|
|
|
|
|
|
|
|
modules := mctx.CreateLocalVariations(variations...)
|
2019-10-19 05:49:46 +08:00
|
|
|
modules[0].(LinkableInterface).SetShared()
|
2020-08-07 08:46:48 +08:00
|
|
|
mctx.AliasVariation("shared")
|
2019-11-22 04:30:50 +08:00
|
|
|
} else if len(variations) > 0 {
|
|
|
|
mctx.CreateLocalVariations(variations...)
|
2020-08-07 08:46:48 +08:00
|
|
|
mctx.AliasVariation(variations[0])
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// normalizeVersions modifies `versions` in place, so that each raw version
|
|
|
|
// string becomes its normalized canonical form.
|
|
|
|
// Validates that the versions in `versions` are specified in least to greatest order.
|
2020-04-02 00:41:41 +08:00
|
|
|
func normalizeVersions(ctx android.BaseModuleContext, versions []string) {
|
2020-07-23 13:32:17 +08:00
|
|
|
var previous android.ApiLevel
|
2020-02-27 16:56:44 +08:00
|
|
|
for i, v := range versions {
|
2020-07-23 13:32:17 +08:00
|
|
|
ver, err := android.ApiLevelFromUser(ctx, v)
|
2020-02-27 16:56:44 +08:00
|
|
|
if err != nil {
|
2020-04-02 00:41:41 +08:00
|
|
|
ctx.PropertyErrorf("versions", "%s", err.Error())
|
|
|
|
return
|
2020-02-27 16:56:44 +08:00
|
|
|
}
|
2020-07-23 13:32:17 +08:00
|
|
|
if i > 0 && ver.LessThanOrEqualTo(previous) {
|
|
|
|
ctx.PropertyErrorf("versions", "not sorted: %v", versions)
|
|
|
|
}
|
|
|
|
versions[i] = ver.String()
|
|
|
|
previous = ver
|
2020-04-02 00:41:41 +08:00
|
|
|
}
|
2020-02-27 16:56:44 +08:00
|
|
|
}
|
|
|
|
|
2020-03-21 22:21:46 +08:00
|
|
|
func createVersionVariations(mctx android.BottomUpMutatorContext, versions []string) {
|
2020-08-19 09:35:15 +08:00
|
|
|
// "" is for the non-stubs (implementation) variant.
|
2020-09-19 05:15:30 +08:00
|
|
|
variants := append(android.CopyOf(versions), "")
|
2020-03-21 22:21:46 +08:00
|
|
|
|
2020-08-19 09:35:15 +08:00
|
|
|
modules := mctx.CreateLocalVariations(variants...)
|
2020-03-21 22:21:46 +08:00
|
|
|
for i, m := range modules {
|
2020-08-19 09:35:15 +08:00
|
|
|
if variants[i] != "" {
|
2020-10-24 08:22:06 +08:00
|
|
|
c := m.(*Module)
|
|
|
|
c.Properties.HideFromMake = true
|
|
|
|
c.sanitize = nil
|
|
|
|
c.stl = nil
|
|
|
|
c.Properties.PreventInstall = true
|
|
|
|
lib := moduleLibraryInterface(m)
|
|
|
|
lib.setBuildStubs()
|
|
|
|
lib.setStubsVersion(variants[i])
|
2020-09-19 05:15:30 +08:00
|
|
|
// The implementation depends on the stubs
|
|
|
|
mctx.AddInterVariantDependency(stubImplDepTag, modules[len(modules)-1], modules[i])
|
2020-03-21 22:21:46 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-07 08:38:25 +08:00
|
|
|
mctx.AliasVariation("")
|
2020-08-19 09:35:15 +08:00
|
|
|
latestVersion := ""
|
|
|
|
if len(versions) > 0 {
|
|
|
|
latestVersion = versions[len(versions)-1]
|
|
|
|
}
|
|
|
|
mctx.CreateAliasVariation("latest", latestVersion)
|
2020-03-21 22:21:46 +08:00
|
|
|
}
|
|
|
|
|
2020-10-01 03:27:01 +08:00
|
|
|
func createPerApiVersionVariations(mctx android.BottomUpMutatorContext, minSdkVersion string) {
|
|
|
|
from, err := nativeApiLevelFromUser(mctx, minSdkVersion)
|
|
|
|
if err != nil {
|
|
|
|
mctx.PropertyErrorf("min_sdk_version", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
versionStrs := ndkLibraryVersions(mctx, from)
|
|
|
|
modules := mctx.CreateLocalVariations(versionStrs...)
|
|
|
|
|
|
|
|
for i, module := range modules {
|
|
|
|
module.(*Module).Properties.Sdk_version = StringPtr(versionStrs[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 06:34:40 +08:00
|
|
|
func CanBeOrLinkAgainstVersionVariants(module interface {
|
2020-04-10 11:57:24 +08:00
|
|
|
Host() bool
|
|
|
|
InRamdisk() bool
|
2020-10-22 06:17:56 +08:00
|
|
|
InVendorRamdisk() bool
|
2020-04-10 11:57:24 +08:00
|
|
|
InRecovery() bool
|
|
|
|
}) bool {
|
2020-10-22 06:17:56 +08:00
|
|
|
return !module.Host() && !module.InRamdisk() && !module.InVendorRamdisk() && !module.InRecovery()
|
2020-04-10 11:57:24 +08:00
|
|
|
}
|
|
|
|
|
2020-10-01 06:34:40 +08:00
|
|
|
func CanBeVersionVariant(module interface {
|
|
|
|
Host() bool
|
|
|
|
InRamdisk() bool
|
2020-10-22 06:17:56 +08:00
|
|
|
InVendorRamdisk() bool
|
2020-10-01 06:34:40 +08:00
|
|
|
InRecovery() bool
|
|
|
|
CcLibraryInterface() bool
|
|
|
|
Shared() bool
|
|
|
|
}) bool {
|
|
|
|
return CanBeOrLinkAgainstVersionVariants(module) &&
|
2020-10-24 05:53:06 +08:00
|
|
|
module.CcLibraryInterface() && module.Shared()
|
2020-10-01 06:34:40 +08:00
|
|
|
}
|
|
|
|
|
2020-10-24 08:22:06 +08:00
|
|
|
func moduleLibraryInterface(module android.Module) libraryInterface {
|
|
|
|
if m, ok := module.(*Module); ok {
|
|
|
|
return m.library
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:35:15 +08:00
|
|
|
// versionSelector normalizes the versions in the Stubs.Versions property into MutatedProperties.AllStubsVersions,
|
|
|
|
// and propagates the value from implementation libraries to llndk libraries with the same name.
|
|
|
|
func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
|
2020-10-24 08:22:06 +08:00
|
|
|
if library := moduleLibraryInterface(mctx.Module()); library != nil && CanBeVersionVariant(mctx.Module().(*Module)) {
|
|
|
|
if library.buildShared() {
|
|
|
|
versions := library.stubsVersions(mctx)
|
2020-10-02 06:58:11 +08:00
|
|
|
if len(versions) > 0 {
|
|
|
|
normalizeVersions(mctx, versions)
|
|
|
|
if mctx.Failed() {
|
2020-10-01 03:27:01 +08:00
|
|
|
return
|
|
|
|
}
|
2020-10-02 06:58:11 +08:00
|
|
|
// Set the versions on the pre-mutated module so they can be read by any llndk modules that
|
|
|
|
// depend on the implementation library and haven't been mutated yet.
|
2020-10-24 08:22:06 +08:00
|
|
|
library.setAllStubsVersions(versions)
|
2020-02-27 16:56:44 +08:00
|
|
|
return
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
}
|
2020-03-21 21:58:19 +08:00
|
|
|
}
|
2020-08-19 09:35:15 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-21 22:21:46 +08:00
|
|
|
|
2020-08-19 09:35:15 +08:00
|
|
|
// versionMutator splits a module into the mandatory non-stubs variant
|
|
|
|
// (which is unnamed) and zero or more stubs variants.
|
|
|
|
func versionMutator(mctx android.BottomUpMutatorContext) {
|
2020-10-24 08:22:06 +08:00
|
|
|
if library := moduleLibraryInterface(mctx.Module()); library != nil && CanBeVersionVariant(mctx.Module().(*Module)) {
|
|
|
|
createVersionVariations(mctx, library.allStubsVersions())
|
2020-10-01 03:27:01 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if m, ok := mctx.Module().(*Module); ok {
|
|
|
|
if m.SplitPerApiLevel() && m.IsSdkVariant() {
|
|
|
|
if mctx.Os() != android.Android {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
createPerApiVersionVariations(mctx, m.MinSdkVersion())
|
|
|
|
}
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
}
|
|
|
|
}
|
2019-09-06 05:26:33 +08:00
|
|
|
|
|
|
|
// maybeInjectBoringSSLHash adds a rule to run bssl_inject_hash on the output file if the module has the
|
|
|
|
// inject_bssl_hash or if any static library dependencies have inject_bssl_hash set. It returns the output path
|
|
|
|
// that the linked output file should be written to.
|
|
|
|
// TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
|
|
|
|
func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.ModuleOutPath,
|
|
|
|
inject *bool, fileName string) android.ModuleOutPath {
|
|
|
|
// TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
|
|
|
|
injectBoringSSLHash := Bool(inject)
|
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
2020-07-28 12:26:48 +08:00
|
|
|
if tag, ok := ctx.OtherModuleDependencyTag(dep).(libraryDependencyTag); ok && tag.static() {
|
2019-09-06 05:26:33 +08:00
|
|
|
if cc, ok := dep.(*Module); ok {
|
|
|
|
if library, ok := cc.linker.(*libraryDecorator); ok {
|
|
|
|
if Bool(library.Properties.Inject_bssl_hash) {
|
|
|
|
injectBoringSSLHash = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if injectBoringSSLHash {
|
|
|
|
hashedOutputfile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unhashed", fileName)
|
|
|
|
|
2020-11-17 09:32:30 +08:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-09-06 05:26:33 +08:00
|
|
|
rule.Command().
|
2020-11-17 09:32:30 +08:00
|
|
|
BuiltTool("bssl_inject_hash").
|
2019-10-02 00:03:17 +08:00
|
|
|
Flag("-sha256").
|
2019-09-06 05:26:33 +08:00
|
|
|
FlagWithInput("-in-object ", outputFile).
|
|
|
|
FlagWithOutput("-o ", hashedOutputfile)
|
2020-11-17 09:32:30 +08:00
|
|
|
rule.Build("injectCryptoHash", "inject crypto hash")
|
2019-09-06 05:26:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|