2016-06-18 01:45:24 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-07-30 23:32:55 +02:00
|
|
|
"path/filepath"
|
2021-06-07 22:19:49 +02:00
|
|
|
"runtime"
|
2016-06-18 01:45:24 +02:00
|
|
|
"strings"
|
2016-08-08 06:17:54 +02:00
|
|
|
"sync"
|
2016-06-18 01:45:24 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2021-04-06 10:40:32 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2016-06-18 01:45:24 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2022-08-19 20:17:28 +02:00
|
|
|
"android/soong/bazel"
|
2022-01-11 06:42:49 +01:00
|
|
|
"android/soong/cc/config"
|
2016-06-18 01:45:24 +02:00
|
|
|
)
|
|
|
|
|
2020-05-29 22:37:12 +02:00
|
|
|
func init() {
|
2020-06-23 00:10:31 +02:00
|
|
|
pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen")
|
2023-06-30 22:52:17 +02:00
|
|
|
pctx.HostBinToolVariable("stg", "stg")
|
2023-07-01 00:28:15 +02:00
|
|
|
pctx.HostBinToolVariable("stgdiff", "stgdiff")
|
2020-05-29 22:37:12 +02:00
|
|
|
}
|
|
|
|
|
2016-06-18 01:45:24 +02:00
|
|
|
var (
|
2016-08-30 01:14:13 +02:00
|
|
|
genStubSrc = pctx.AndroidStaticRule("genStubSrc",
|
2016-06-18 01:45:24 +02:00
|
|
|
blueprint.RuleParams{
|
2020-06-23 00:10:31 +02:00
|
|
|
Command: "$ndkStubGenerator --arch $arch --api $apiLevel " +
|
|
|
|
"--api-map $apiMap $flags $in $out",
|
|
|
|
CommandDeps: []string{"$ndkStubGenerator"},
|
2018-12-07 08:25:39 +01:00
|
|
|
}, "arch", "apiLevel", "apiMap", "flags")
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2023-08-23 12:06:35 +02:00
|
|
|
// $headersList should include paths to public headers. All types
|
|
|
|
// that are defined outside of public headers will be excluded from
|
|
|
|
// ABI monitoring.
|
|
|
|
//
|
|
|
|
// STG tool doesn't access content of files listed in $headersList,
|
|
|
|
// so there is no need to add them to dependencies.
|
2023-07-03 13:25:27 +02:00
|
|
|
stg = pctx.AndroidStaticRule("stg",
|
|
|
|
blueprint.RuleParams{
|
2023-08-23 12:06:35 +02:00
|
|
|
Command: "$stg -S :$symbolList --file-filter :$headersList --elf $in -o $out",
|
2023-07-03 13:25:27 +02:00
|
|
|
CommandDeps: []string{"$stg"},
|
2023-08-23 12:06:35 +02:00
|
|
|
}, "symbolList", "headersList")
|
2023-07-03 13:25:27 +02:00
|
|
|
|
2023-07-01 00:28:15 +02:00
|
|
|
stgdiff = pctx.AndroidStaticRule("stgdiff",
|
2020-07-30 23:32:55 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
// Need to create *some* output for ninja. We don't want to use tee
|
|
|
|
// because we don't want to spam the build output with "nothing
|
|
|
|
// changed" messages, so redirect output message to $out, and if
|
|
|
|
// changes were detected print the output and fail.
|
2023-10-05 23:43:41 +02:00
|
|
|
Command: "$stgdiff $args --stg $in -o $out || (cat $out && echo 'Run $$ANDROID_BUILD_TOP/development/tools/ndk/update_ndk_abi.sh to update the ABI dumps.' && false)",
|
2023-07-01 00:28:15 +02:00
|
|
|
CommandDeps: []string{"$stgdiff"},
|
2020-07-30 23:32:55 +02:00
|
|
|
}, "args")
|
|
|
|
|
2016-06-18 01:45:24 +02:00
|
|
|
ndkLibrarySuffix = ".ndk"
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2020-10-30 04:47:22 +01:00
|
|
|
ndkKnownLibsKey = android.NewOnceKey("ndkKnownLibsKey")
|
2020-06-30 21:32:51 +02:00
|
|
|
// protects ndkKnownLibs writes during parallel BeginMutator.
|
|
|
|
ndkKnownLibsLock sync.Mutex
|
2020-07-30 23:32:55 +02:00
|
|
|
|
|
|
|
stubImplementation = dependencyTag{name: "stubImplementation"}
|
2016-06-18 01:45:24 +02:00
|
|
|
)
|
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
// The First_version and Unversioned_until properties of this struct should not
|
|
|
|
// be used directly, but rather through the ApiLevel returning methods
|
|
|
|
// firstVersion() and unversionedUntil().
|
|
|
|
|
2016-06-18 01:45:24 +02:00
|
|
|
// Creates a stub shared library based on the provided version file.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2022-08-19 01:26:00 +02:00
|
|
|
// ndk_library {
|
|
|
|
//
|
|
|
|
// name: "libfoo",
|
|
|
|
// symbol_file: "libfoo.map.txt",
|
|
|
|
// first_version: "9",
|
|
|
|
//
|
|
|
|
// }
|
2016-06-18 01:45:24 +02:00
|
|
|
type libraryProperties struct {
|
|
|
|
// Relative path to the symbol map.
|
|
|
|
// An example file can be seen here: TODO(danalbert): Make an example.
|
2022-04-27 03:30:34 +02:00
|
|
|
Symbol_file *string `android:"path"`
|
2016-06-18 01:45:24 +02:00
|
|
|
|
|
|
|
// The first API level a library was available. A library will be generated
|
|
|
|
// for every API level beginning with this one.
|
2017-11-07 19:57:05 +01:00
|
|
|
First_version *string
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2017-01-04 00:16:29 +01:00
|
|
|
// The first API level that library should have the version script applied.
|
|
|
|
// This defaults to the value of first_version, and should almost never be
|
|
|
|
// used. This is only needed to work around platform bugs like
|
|
|
|
// https://github.com/android-ndk/ndk/issues/265.
|
2017-11-07 19:57:05 +01:00
|
|
|
Unversioned_until *string
|
2021-06-15 22:23:44 +02:00
|
|
|
|
2022-08-19 01:26:00 +02:00
|
|
|
// Headers presented by this library to the Public API Surface
|
|
|
|
Export_header_libs []string
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type stubDecorator struct {
|
|
|
|
*libraryDecorator
|
2016-06-18 01:45:24 +02:00
|
|
|
|
|
|
|
properties libraryProperties
|
2016-07-29 02:40:28 +02:00
|
|
|
|
2020-05-29 22:37:12 +02:00
|
|
|
versionScriptPath android.ModuleGenPath
|
|
|
|
parsedCoverageXmlPath android.ModuleOutPath
|
|
|
|
installPath android.Path
|
2020-07-30 23:32:55 +02:00
|
|
|
abiDumpPath android.OutputPath
|
|
|
|
abiDiffPaths android.Paths
|
2017-03-30 03:22:39 +02:00
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
apiLevel android.ApiLevel
|
|
|
|
firstVersion android.ApiLevel
|
|
|
|
unversionedUntil android.ApiLevel
|
2016-11-08 23:34:24 +01:00
|
|
|
}
|
|
|
|
|
2020-10-14 03:43:54 +02:00
|
|
|
var _ versionedInterface = (*stubDecorator)(nil)
|
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool {
|
|
|
|
return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil)
|
2017-01-04 00:16:29 +01:00
|
|
|
}
|
|
|
|
|
2020-10-14 03:43:54 +02:00
|
|
|
func (stub *stubDecorator) implementationModuleName(name string) string {
|
|
|
|
return strings.TrimSuffix(name, ndkLibrarySuffix)
|
|
|
|
}
|
|
|
|
|
2020-10-02 00:58:11 +02:00
|
|
|
func ndkLibraryVersions(ctx android.BaseMutatorContext, from android.ApiLevel) []string {
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
var versions []android.ApiLevel
|
|
|
|
versionStrs := []string{}
|
|
|
|
for _, version := range ctx.Config().AllSupportedApiLevels() {
|
|
|
|
if version.GreaterThanOrEqualTo(from) {
|
|
|
|
versions = append(versions, version)
|
|
|
|
versionStrs = append(versionStrs, version.String())
|
|
|
|
}
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
2020-07-24 01:43:25 +02:00
|
|
|
versionStrs = append(versionStrs, android.FutureApiLevel.String())
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2020-09-30 20:41:33 +02:00
|
|
|
return versionStrs
|
|
|
|
}
|
|
|
|
|
2020-10-02 00:58:11 +02:00
|
|
|
func (this *stubDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
|
|
|
|
if !ctx.Module().Enabled() {
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-30 23:32:55 +02:00
|
|
|
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
|
|
|
|
ctx.Module().Disable()
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-02 00:58:11 +02:00
|
|
|
firstVersion, err := nativeApiLevelFromUser(ctx,
|
|
|
|
String(this.properties.First_version))
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("first_version", err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ndkLibraryVersions(ctx, firstVersion)
|
|
|
|
}
|
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
|
2020-09-30 20:41:33 +02:00
|
|
|
this.apiLevel = nativeApiLevelOrPanic(ctx, this.stubsVersion())
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
this.firstVersion, err = nativeApiLevelFromUser(ctx,
|
|
|
|
String(this.properties.First_version))
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("first_version", err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:40:32 +02:00
|
|
|
str := proptools.StringDefault(this.properties.Unversioned_until, "minimum")
|
|
|
|
this.unversionedUntil, err = nativeApiLevelFromUser(ctx, str)
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("unversioned_until", err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-30 04:47:22 +01:00
|
|
|
func getNDKKnownLibs(config android.Config) *[]string {
|
|
|
|
return config.Once(ndkKnownLibsKey, func() interface{} {
|
|
|
|
return &[]string{}
|
|
|
|
}).(*[]string)
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
|
2016-08-04 22:02:36 +02:00
|
|
|
c.baseCompiler.compilerInit(ctx)
|
|
|
|
|
2017-04-08 00:21:13 +02:00
|
|
|
name := ctx.baseModuleName()
|
|
|
|
if strings.HasSuffix(name, ndkLibrarySuffix) {
|
|
|
|
ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
|
|
|
|
}
|
|
|
|
|
2020-06-30 21:32:51 +02:00
|
|
|
ndkKnownLibsLock.Lock()
|
|
|
|
defer ndkKnownLibsLock.Unlock()
|
2020-10-30 04:47:22 +01:00
|
|
|
ndkKnownLibs := getNDKKnownLibs(ctx.Config())
|
|
|
|
for _, lib := range *ndkKnownLibs {
|
2016-08-04 22:02:36 +02:00
|
|
|
if lib == name {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-10-30 04:47:22 +01:00
|
|
|
*ndkKnownLibs = append(*ndkKnownLibs, name)
|
2016-08-04 22:02:36 +02:00
|
|
|
}
|
|
|
|
|
2022-01-11 06:42:49 +01:00
|
|
|
var stubLibraryCompilerFlags = []string{
|
|
|
|
// We're knowingly doing some otherwise unsightly things with builtin
|
|
|
|
// functions here. We're just generating stub libraries, so ignore it.
|
|
|
|
"-Wno-incompatible-library-redeclaration",
|
|
|
|
"-Wno-incomplete-setjmp-declaration",
|
|
|
|
"-Wno-builtin-requires-header",
|
|
|
|
"-Wno-invalid-noreturn",
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
|
|
|
// These libraries aren't actually used. Don't worry about unwinding
|
|
|
|
// (avoids the need to link an unwinder into a fake library).
|
|
|
|
"-fno-unwind-tables",
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
config.ExportStringList("StubLibraryCompilerFlags", stubLibraryCompilerFlags)
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:39:53 +02:00
|
|
|
func addStubLibraryCompilerFlags(flags Flags) Flags {
|
2022-01-11 06:42:49 +01:00
|
|
|
flags.Global.CFlags = append(flags.Global.CFlags, stubLibraryCompilerFlags...)
|
2019-11-21 07:11:49 +01:00
|
|
|
// All symbols in the stubs library should be visible.
|
|
|
|
if inList("-fvisibility=hidden", flags.Local.CFlags) {
|
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
|
|
|
|
}
|
2017-07-19 20:39:53 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:33:08 +01:00
|
|
|
func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
|
|
|
|
flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
|
2017-07-19 20:39:53 +02:00
|
|
|
return addStubLibraryCompilerFlags(flags)
|
|
|
|
}
|
|
|
|
|
2020-07-30 23:32:55 +02:00
|
|
|
type ndkApiOutputs struct {
|
|
|
|
stubSrc android.ModuleGenPath
|
|
|
|
versionScript android.ModuleGenPath
|
|
|
|
symbolList android.ModuleGenPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseNativeAbiDefinition(ctx ModuleContext, symbolFile string,
|
|
|
|
apiLevel android.ApiLevel, genstubFlags string) ndkApiOutputs {
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2017-03-19 21:44:32 +01:00
|
|
|
stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
|
|
|
|
versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
|
|
|
|
symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
|
2020-07-30 23:32:55 +02:00
|
|
|
symbolListPath := android.PathForModuleGen(ctx, "abi_symbol_list.txt")
|
2017-03-29 00:00:46 +02:00
|
|
|
apiLevelsJson := android.GetApiLevelsJson(ctx)
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: genStubSrc,
|
|
|
|
Description: "generate stubs " + symbolFilePath.Rel(),
|
2020-07-30 23:32:55 +02:00
|
|
|
Outputs: []android.WritablePath{stubSrcPath, versionScriptPath,
|
|
|
|
symbolListPath},
|
|
|
|
Input: symbolFilePath,
|
|
|
|
Implicits: []android.Path{apiLevelsJson},
|
2016-06-18 01:45:24 +02:00
|
|
|
Args: map[string]string{
|
2020-07-30 23:32:55 +02:00
|
|
|
"arch": ctx.Arch().ArchType.String(),
|
|
|
|
"apiLevel": apiLevel.String(),
|
2017-03-29 00:00:46 +02:00
|
|
|
"apiMap": apiLevelsJson.String(),
|
2018-12-07 08:25:39 +01:00
|
|
|
"flags": genstubFlags,
|
2016-06-18 01:45:24 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-07-30 23:32:55 +02:00
|
|
|
return ndkApiOutputs{
|
|
|
|
stubSrc: stubSrcPath,
|
|
|
|
versionScript: versionScriptPath,
|
|
|
|
symbolList: symbolListPath,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func compileStubLibrary(ctx ModuleContext, flags Flags, src android.Path) Objects {
|
2022-04-29 22:12:28 +02:00
|
|
|
// libc/libm stubs libraries end up mismatching with clang's internal definition of these
|
|
|
|
// functions (which have noreturn attributes and other things). Because we just want to create a
|
|
|
|
// stub with symbol definitions, and types aren't important in C, ignore the mismatch.
|
|
|
|
flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, "-fno-builtin")
|
2020-07-30 23:32:55 +02:00
|
|
|
return compileObjs(ctx, flagsToBuilderFlags(flags), "",
|
2022-02-17 21:54:45 +01:00
|
|
|
android.Paths{src}, nil, nil, nil, nil)
|
2017-03-19 21:44:32 +01:00
|
|
|
}
|
|
|
|
|
2020-07-30 23:32:55 +02:00
|
|
|
func (this *stubDecorator) findImplementationLibrary(ctx ModuleContext) android.Path {
|
|
|
|
dep := ctx.GetDirectDepWithTag(strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix),
|
|
|
|
stubImplementation)
|
|
|
|
if dep == nil {
|
|
|
|
ctx.ModuleErrorf("Could not find implementation for stub")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
impl, ok := dep.(*Module)
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("Implementation for stub is not correct module type")
|
2022-11-01 15:05:08 +01:00
|
|
|
return nil
|
2020-07-30 23:32:55 +02:00
|
|
|
}
|
|
|
|
output := impl.UnstrippedOutputFile()
|
|
|
|
if output == nil {
|
|
|
|
ctx.ModuleErrorf("implementation module (%s) has no output", impl)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *stubDecorator) libraryName(ctx ModuleContext) string {
|
|
|
|
return strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *stubDecorator) findPrebuiltAbiDump(ctx ModuleContext,
|
|
|
|
apiLevel android.ApiLevel) android.OptionalPath {
|
|
|
|
|
|
|
|
subpath := filepath.Join("prebuilts/abi-dumps/ndk", apiLevel.String(),
|
2023-06-30 22:52:17 +02:00
|
|
|
ctx.Arch().ArchType.String(), this.libraryName(ctx), "abi.stg")
|
2020-07-30 23:32:55 +02:00
|
|
|
return android.ExistentPathForSource(ctx, subpath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Feature flag.
|
2022-04-15 01:08:51 +02:00
|
|
|
func canDumpAbi(config android.Config) bool {
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// abidw doesn't currently handle top-byte-ignore correctly. Disable ABI
|
|
|
|
// dumping for those configs while we wait for a fix. We'll still have ABI
|
|
|
|
// checking coverage from non-hwasan builds.
|
|
|
|
// http://b/190554910
|
|
|
|
if android.InList("hwaddress", config.SanitizeDevice()) {
|
|
|
|
return false
|
|
|
|
}
|
2023-04-20 19:38:29 +02:00
|
|
|
// http://b/156513478
|
|
|
|
// http://b/277624006
|
|
|
|
// This step is expensive. We're not able to do anything with the outputs of
|
|
|
|
// this step yet (canDiffAbi is flagged off because libabigail isn't able to
|
|
|
|
// handle all our libraries), disable it. There's no sense in protecting
|
|
|
|
// against checking in code that breaks abidw since by the time any of this
|
|
|
|
// can be turned on we'll need to migrate to STG anyway.
|
|
|
|
return false
|
2020-07-30 23:32:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Feature flag to disable diffing against prebuilts.
|
2021-06-07 22:19:49 +02:00
|
|
|
func canDiffAbi() bool {
|
2020-07-30 23:32:55 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-07-03 13:25:27 +02:00
|
|
|
func (this *stubDecorator) dumpAbi(ctx ModuleContext, symbolList android.Path) {
|
|
|
|
implementationLibrary := this.findImplementationLibrary(ctx)
|
|
|
|
this.abiDumpPath = getNdkAbiDumpInstallBase(ctx).Join(ctx,
|
|
|
|
this.apiLevel.String(), ctx.Arch().ArchType.String(),
|
|
|
|
this.libraryName(ctx), "abi.stg")
|
2023-08-23 12:06:35 +02:00
|
|
|
headersList := getNdkABIHeadersFile(ctx)
|
2023-07-03 13:25:27 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: stg,
|
|
|
|
Description: fmt.Sprintf("stg %s", implementationLibrary),
|
|
|
|
Input: implementationLibrary,
|
2023-08-23 12:06:35 +02:00
|
|
|
Implicits: []android.Path{
|
|
|
|
symbolList,
|
|
|
|
headersList,
|
|
|
|
},
|
|
|
|
Output: this.abiDumpPath,
|
2023-07-03 13:25:27 +02:00
|
|
|
Args: map[string]string{
|
2023-08-23 12:06:35 +02:00
|
|
|
"symbolList": symbolList.String(),
|
|
|
|
"headersList": headersList.String(),
|
2023-07-03 13:25:27 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-30 23:32:55 +02:00
|
|
|
func findNextApiLevel(ctx ModuleContext, apiLevel android.ApiLevel) *android.ApiLevel {
|
|
|
|
apiLevels := append(ctx.Config().AllSupportedApiLevels(),
|
|
|
|
android.FutureApiLevel)
|
|
|
|
for _, api := range apiLevels {
|
|
|
|
if api.GreaterThan(apiLevel) {
|
|
|
|
return &api
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *stubDecorator) diffAbi(ctx ModuleContext) {
|
|
|
|
// Catch any ABI changes compared to the checked-in definition of this API
|
|
|
|
// level.
|
2023-07-01 00:28:15 +02:00
|
|
|
abiDiffPath := android.PathForModuleOut(ctx, "stgdiff.timestamp")
|
2020-07-30 23:32:55 +02:00
|
|
|
prebuiltAbiDump := this.findPrebuiltAbiDump(ctx, this.apiLevel)
|
2023-09-20 15:09:25 +02:00
|
|
|
missingPrebuiltErrorTemplate :=
|
|
|
|
"Did not find prebuilt ABI dump for %q (%q). Generate with " +
|
|
|
|
"//development/tools/ndk/update_ndk_abi.sh."
|
2022-11-29 18:20:16 +01:00
|
|
|
missingPrebuiltError := fmt.Sprintf(
|
2023-09-20 15:09:25 +02:00
|
|
|
missingPrebuiltErrorTemplate, this.libraryName(ctx),
|
2022-11-29 18:20:16 +01:00
|
|
|
prebuiltAbiDump.InvalidReason())
|
2020-07-30 23:32:55 +02:00
|
|
|
if !prebuiltAbiDump.Valid() {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.ErrorRule,
|
|
|
|
Output: abiDiffPath,
|
|
|
|
Args: map[string]string{
|
|
|
|
"error": missingPrebuiltError,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2023-07-01 00:28:15 +02:00
|
|
|
Rule: stgdiff,
|
|
|
|
Description: fmt.Sprintf("Comparing ABI %s %s", prebuiltAbiDump,
|
2020-07-30 23:32:55 +02:00
|
|
|
this.abiDumpPath),
|
|
|
|
Output: abiDiffPath,
|
|
|
|
Inputs: android.Paths{prebuiltAbiDump.Path(), this.abiDumpPath},
|
2023-07-01 00:28:15 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"args": "--format=small",
|
|
|
|
},
|
2020-07-30 23:32:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
this.abiDiffPaths = append(this.abiDiffPaths, abiDiffPath)
|
|
|
|
|
|
|
|
// Also ensure that the ABI of the next API level (if there is one) matches
|
|
|
|
// this API level. *New* ABI is allowed, but any changes to APIs that exist
|
|
|
|
// in this API level are disallowed.
|
2023-09-19 17:35:08 +02:00
|
|
|
if !this.apiLevel.IsCurrent() && prebuiltAbiDump.Valid() {
|
2020-07-30 23:32:55 +02:00
|
|
|
nextApiLevel := findNextApiLevel(ctx, this.apiLevel)
|
|
|
|
if nextApiLevel == nil {
|
|
|
|
panic(fmt.Errorf("could not determine which API level follows "+
|
|
|
|
"non-current API level %s", this.apiLevel))
|
|
|
|
}
|
|
|
|
nextAbiDiffPath := android.PathForModuleOut(ctx,
|
|
|
|
"abidiff_next.timestamp")
|
|
|
|
nextAbiDump := this.findPrebuiltAbiDump(ctx, *nextApiLevel)
|
2023-09-20 15:09:25 +02:00
|
|
|
missingNextPrebuiltError := fmt.Sprintf(
|
|
|
|
missingPrebuiltErrorTemplate, this.libraryName(ctx),
|
|
|
|
nextAbiDump.InvalidReason())
|
2020-07-30 23:32:55 +02:00
|
|
|
if !nextAbiDump.Valid() {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.ErrorRule,
|
|
|
|
Output: nextAbiDiffPath,
|
|
|
|
Args: map[string]string{
|
2023-09-20 15:09:25 +02:00
|
|
|
"error": missingNextPrebuiltError,
|
2020-07-30 23:32:55 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2023-07-01 00:28:15 +02:00
|
|
|
Rule: stgdiff,
|
2023-09-19 17:35:08 +02:00
|
|
|
Description: fmt.Sprintf(
|
|
|
|
"Comparing ABI to the next API level %s %s",
|
|
|
|
prebuiltAbiDump, nextAbiDump),
|
2020-07-30 23:32:55 +02:00
|
|
|
Output: nextAbiDiffPath,
|
2023-09-19 17:35:08 +02:00
|
|
|
Inputs: android.Paths{
|
|
|
|
prebuiltAbiDump.Path(), nextAbiDump.Path()},
|
2020-07-30 23:32:55 +02:00
|
|
|
Args: map[string]string{
|
2023-07-01 00:28:15 +02:00
|
|
|
"args": "--format=small --ignore=interface_addition",
|
2020-07-30 23:32:55 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.abiDiffPaths = append(this.abiDiffPaths, nextAbiDiffPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 21:44:32 +01:00
|
|
|
func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
2017-11-07 19:57:05 +01:00
|
|
|
if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
|
2017-06-14 00:14:56 +02:00
|
|
|
ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
|
|
|
|
}
|
|
|
|
|
2020-09-30 20:41:33 +02:00
|
|
|
if !c.buildStubs() {
|
|
|
|
// NDK libraries have no implementation variant, nothing to do
|
|
|
|
return Objects{}
|
|
|
|
}
|
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
if !c.initializeProperties(ctx) {
|
|
|
|
// Emits its own errors, so we don't need to.
|
|
|
|
return Objects{}
|
|
|
|
}
|
|
|
|
|
2020-05-29 22:37:12 +02:00
|
|
|
symbolFile := String(c.properties.Symbol_file)
|
2020-07-30 23:32:55 +02:00
|
|
|
nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, c.apiLevel, "")
|
|
|
|
objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
|
|
|
|
c.versionScriptPath = nativeAbiResult.versionScript
|
2022-04-15 01:08:51 +02:00
|
|
|
if canDumpAbi(ctx.Config()) {
|
2023-07-03 13:29:27 +02:00
|
|
|
c.dumpAbi(ctx, nativeAbiResult.symbolList)
|
2021-06-07 22:19:49 +02:00
|
|
|
if canDiffAbi() {
|
2020-07-30 23:32:55 +02:00
|
|
|
c.diffAbi(ctx)
|
|
|
|
}
|
|
|
|
}
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
if c.apiLevel.IsCurrent() && ctx.PrimaryArch() {
|
2021-08-17 07:54:00 +02:00
|
|
|
c.parsedCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
|
2020-05-29 22:37:12 +02:00
|
|
|
}
|
2017-03-19 21:44:32 +01:00
|
|
|
return objs
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-19 01:26:00 +02:00
|
|
|
// Add a dependency on the header modules of this ndk_library
|
2016-12-14 02:06:13 +01:00
|
|
|
func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2022-08-19 01:26:00 +02:00
|
|
|
return Deps{
|
|
|
|
HeaderLibs: linker.properties.Export_header_libs,
|
|
|
|
}
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 00:21:13 +02:00
|
|
|
func (linker *stubDecorator) Name(name string) string {
|
|
|
|
return name + ndkLibrarySuffix
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2017-04-08 00:21:13 +02:00
|
|
|
stub.libraryDecorator.libName = ctx.baseModuleName()
|
2016-07-30 02:28:03 +02:00
|
|
|
return stub.libraryDecorator.linkerFlags(ctx, flags)
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
|
2016-09-27 02:33:01 +02:00
|
|
|
objs Objects) android.Path {
|
2016-07-29 02:40:28 +02:00
|
|
|
|
2020-09-30 20:41:33 +02:00
|
|
|
if !stub.buildStubs() {
|
|
|
|
// NDK libraries have no implementation variant, nothing to do
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-06 23:49:35 +02:00
|
|
|
if shouldUseVersionScript(ctx, stub) {
|
2017-01-04 00:16:29 +01:00
|
|
|
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
|
2019-06-11 03:02:25 +02:00
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
|
2017-01-04 00:16:29 +01:00
|
|
|
}
|
|
|
|
|
2020-09-30 20:41:33 +02:00
|
|
|
stub.libraryDecorator.skipAPIDefine = true
|
2016-09-27 02:33:01 +02:00
|
|
|
return stub.libraryDecorator.link(ctx, flags, deps, objs)
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:31 +01:00
|
|
|
func (stub *stubDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-04-03 22:19:07 +02:00
|
|
|
// Returns the install path for unversioned NDK libraries (currently only static
|
|
|
|
// libraries).
|
|
|
|
func getUnversionedLibraryInstallPath(ctx ModuleContext) android.InstallPath {
|
|
|
|
return getNdkSysrootBase(ctx).Join(ctx, "usr/lib", config.NDKTriple(ctx.toolchain()))
|
|
|
|
}
|
2023-04-03 07:17:17 +02:00
|
|
|
|
2023-04-03 22:19:07 +02:00
|
|
|
// Returns the install path for versioned NDK libraries. These are most often
|
|
|
|
// stubs, but the same paths are used for CRT objects.
|
|
|
|
func getVersionedLibraryInstallPath(ctx ModuleContext, apiLevel android.ApiLevel) android.InstallPath {
|
|
|
|
return getUnversionedLibraryInstallPath(ctx).Join(ctx, apiLevel.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
|
|
|
|
installDir := getVersionedLibraryInstallPath(ctx, stub.apiLevel)
|
2017-11-29 02:34:01 +01:00
|
|
|
stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func newStubLibrary() *Module {
|
2016-12-09 23:46:15 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-06-18 01:45:24 +02:00
|
|
|
module.stl = nil
|
2016-07-30 02:28:03 +02:00
|
|
|
module.sanitize = nil
|
2020-08-19 14:53:01 +02:00
|
|
|
library.disableStripping()
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
stub := &stubDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = stub
|
|
|
|
module.linker = stub
|
|
|
|
module.installer = stub
|
2020-10-24 02:22:06 +02:00
|
|
|
module.library = stub
|
2016-06-18 01:45:24 +02:00
|
|
|
|
2020-04-07 18:50:32 +02:00
|
|
|
module.Properties.AlwaysSdk = true
|
|
|
|
module.Properties.Sdk_version = StringPtr("current")
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
module.AddProperties(&stub.properties, &library.MutatedProperties)
|
|
|
|
|
|
|
|
return module
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 23:19:06 +02:00
|
|
|
// ndk_library creates a library that exposes a stub implementation of functions
|
|
|
|
// and variables for use at build time only.
|
2019-12-09 10:21:48 +01:00
|
|
|
func NdkLibraryFactory() android.Module {
|
2017-06-24 00:06:31 +02:00
|
|
|
module := newStubLibrary()
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
2022-08-19 20:17:28 +02:00
|
|
|
android.InitBazelModule(module)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
2022-08-19 20:17:28 +02:00
|
|
|
|
|
|
|
type bazelCcApiContributionAttributes struct {
|
|
|
|
Api bazel.LabelAttribute
|
|
|
|
Api_surfaces bazel.StringListAttribute
|
|
|
|
Hdrs bazel.LabelListAttribute
|
|
|
|
Library_name string
|
|
|
|
}
|
|
|
|
|
2023-09-19 22:09:00 +02:00
|
|
|
func ndkLibraryBp2build(ctx android.Bp2buildMutatorContext, c *Module) {
|
2023-09-15 00:34:34 +02:00
|
|
|
ndk, _ := c.linker.(*stubDecorator)
|
|
|
|
props := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_stub_suite",
|
|
|
|
Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
|
|
|
|
}
|
|
|
|
sourceLibraryName := strings.TrimSuffix(c.Name(), ".ndk")
|
|
|
|
fromApiLevel, err := android.ApiLevelFromUser(ctx, proptools.String(ndk.properties.First_version))
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("first_version", "error converting first_version %v", proptools.String(ndk.properties.First_version))
|
|
|
|
}
|
|
|
|
symbolFileLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(ndk.properties.Symbol_file))
|
|
|
|
attrs := &bazelCcStubSuiteAttributes{
|
|
|
|
// TODO - b/300504837 Add ndk headers
|
|
|
|
Symbol_file: proptools.StringPtr(symbolFileLabel.Label),
|
|
|
|
Soname: proptools.StringPtr(sourceLibraryName + ".so"),
|
|
|
|
Api_surface: proptools.StringPtr(android.PublicApi.String()),
|
|
|
|
}
|
|
|
|
if sourceLibrary, exists := ctx.ModuleFromName(sourceLibraryName); exists {
|
|
|
|
// the source library might not exist in minimal/unbuildable branches like kernel-build-tools.
|
|
|
|
// check for its existence
|
|
|
|
attrs.Source_library_label = proptools.StringPtr(c.GetBazelLabel(ctx, sourceLibrary))
|
|
|
|
}
|
|
|
|
if ctx.Config().RawPlatformSdkVersion() != nil {
|
|
|
|
// This is a hack to populate `versions` only on branches that set a platform_sdk_version
|
|
|
|
// This prevents errors on branches such as kernel-build-tools
|
|
|
|
// This hack is acceptable since we are not required to support NDK Bazel builds on those branches
|
|
|
|
attrs.Versions = bazel.MakeStringListAttribute(ndkLibraryVersions(ctx, fromApiLevel))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
props,
|
|
|
|
android.CommonAttributes{Name: c.Name() + "_stub_libs"},
|
|
|
|
attrs,
|
|
|
|
)
|
|
|
|
}
|