2016-06-18 07:45:24 +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 (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2016-08-08 12:17:54 +08:00
|
|
|
"sync"
|
2016-06-18 07:45:24 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
2020-05-30 04:37:12 +08:00
|
|
|
func init() {
|
2020-06-23 06:10:31 +08:00
|
|
|
pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen")
|
2020-05-30 04:37:12 +08:00
|
|
|
pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
|
|
|
|
}
|
|
|
|
|
2016-06-18 07:45:24 +08:00
|
|
|
var (
|
2016-08-30 07:14:13 +08:00
|
|
|
genStubSrc = pctx.AndroidStaticRule("genStubSrc",
|
2016-06-18 07:45:24 +08:00
|
|
|
blueprint.RuleParams{
|
2020-06-23 06:10:31 +08:00
|
|
|
Command: "$ndkStubGenerator --arch $arch --api $apiLevel " +
|
|
|
|
"--api-map $apiMap $flags $in $out",
|
|
|
|
CommandDeps: []string{"$ndkStubGenerator"},
|
2018-12-07 15:25:39 +08:00
|
|
|
}, "arch", "apiLevel", "apiMap", "flags")
|
2016-06-18 07:45:24 +08:00
|
|
|
|
2020-05-30 04:37:12 +08:00
|
|
|
parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$ndk_api_coverage_parser $in $out --api-map $apiMap",
|
|
|
|
CommandDeps: []string{"$ndk_api_coverage_parser"},
|
|
|
|
}, "apiMap")
|
|
|
|
|
2016-06-18 07:45:24 +08:00
|
|
|
ndkLibrarySuffix = ".ndk"
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2020-07-01 03:32:51 +08:00
|
|
|
// Added as a variation dependency via depsMutator.
|
|
|
|
ndkKnownLibs = []string{}
|
|
|
|
// protects ndkKnownLibs writes during parallel BeginMutator.
|
|
|
|
ndkKnownLibsLock sync.Mutex
|
2016-06-18 07:45:24 +08: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-07 05:49:35 +08: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 07:45:24 +08:00
|
|
|
// Creates a stub shared library based on the provided version file.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// ndk_library {
|
2017-04-08 06:21:13 +08:00
|
|
|
// name: "libfoo",
|
2016-06-18 07:45:24 +08:00
|
|
|
// symbol_file: "libfoo.map.txt",
|
|
|
|
// first_version: "9",
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
type libraryProperties struct {
|
|
|
|
// Relative path to the symbol map.
|
|
|
|
// An example file can be seen here: TODO(danalbert): Make an example.
|
2017-11-08 02:57:05 +08:00
|
|
|
Symbol_file *string
|
2016-06-18 07:45:24 +08:00
|
|
|
|
|
|
|
// The first API level a library was available. A library will be generated
|
|
|
|
// for every API level beginning with this one.
|
2017-11-08 02:57:05 +08:00
|
|
|
First_version *string
|
2016-06-18 07:45:24 +08:00
|
|
|
|
2017-01-04 07:16:29 +08: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-08 02:57:05 +08:00
|
|
|
Unversioned_until *string
|
2017-01-04 07:16:29 +08: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-07 05:49:35 +08:00
|
|
|
// Use via apiLevel on the stubDecorator.
|
2016-11-09 05:35:12 +08:00
|
|
|
ApiLevel string `blueprint:"mutated"`
|
2018-11-29 00:30:10 +08:00
|
|
|
|
|
|
|
// True if this API is not yet ready to be shipped in the NDK. It will be
|
|
|
|
// available in the platform for testing, but will be excluded from the
|
|
|
|
// sysroot provided to the NDK proper.
|
|
|
|
Draft bool
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type stubDecorator struct {
|
|
|
|
*libraryDecorator
|
2016-06-18 07:45:24 +08:00
|
|
|
|
|
|
|
properties libraryProperties
|
2016-07-29 08:40:28 +08:00
|
|
|
|
2020-05-30 04:37:12 +08:00
|
|
|
versionScriptPath android.ModuleGenPath
|
|
|
|
parsedCoverageXmlPath android.ModuleOutPath
|
|
|
|
installPath android.Path
|
2017-03-30 09:22:39 +08: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-07 05:49:35 +08:00
|
|
|
apiLevel android.ApiLevel
|
|
|
|
firstVersion android.ApiLevel
|
|
|
|
unversionedUntil android.ApiLevel
|
2016-11-09 06:34:24 +08: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-07 05:49:35 +08:00
|
|
|
func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool {
|
|
|
|
return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil)
|
2017-01-04 07:16:29 +08:00
|
|
|
}
|
|
|
|
|
2020-07-16 04:33:30 +08:00
|
|
|
func generatePerApiVariants(ctx android.BottomUpMutatorContext, m *Module,
|
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-07 05:49:35 +08:00
|
|
|
from android.ApiLevel, perSplit func(*Module, android.ApiLevel)) {
|
|
|
|
|
|
|
|
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 07:45:24 +08:00
|
|
|
}
|
2020-07-24 07:43:25 +08:00
|
|
|
versions = append(versions, android.FutureApiLevel)
|
|
|
|
versionStrs = append(versionStrs, android.FutureApiLevel.String())
|
2016-06-18 07:45:24 +08:00
|
|
|
|
2020-07-16 04:33:30 +08:00
|
|
|
modules := ctx.CreateVariations(versionStrs...)
|
2016-06-18 07:45:24 +08:00
|
|
|
for i, module := range modules {
|
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-07 05:49:35 +08:00
|
|
|
perSplit(module.(*Module), versions[i])
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 04:33:30 +08:00
|
|
|
func NdkApiMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*Module); ok {
|
2017-04-14 03:53:07 +08:00
|
|
|
if m.Enabled() {
|
|
|
|
if compiler, ok := m.compiler.(*stubDecorator); ok {
|
2020-07-16 04:33:30 +08:00
|
|
|
if ctx.Os() != android.Android {
|
|
|
|
// These modules are always android.DeviceEnabled only, but
|
|
|
|
// those include Fuchsia devices, which we don't support.
|
|
|
|
ctx.Module().Disable()
|
|
|
|
return
|
|
|
|
}
|
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-07 05:49:35 +08:00
|
|
|
firstVersion, err := nativeApiLevelFromUser(ctx,
|
|
|
|
String(compiler.properties.First_version))
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("first_version", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
generatePerApiVariants(ctx, m, firstVersion,
|
|
|
|
func(m *Module, version android.ApiLevel) {
|
2020-07-16 04:33:30 +08:00
|
|
|
m.compiler.(*stubDecorator).properties.ApiLevel =
|
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-07 05:49:35 +08:00
|
|
|
version.String()
|
2020-07-16 04:33:30 +08:00
|
|
|
})
|
|
|
|
} else if m.SplitPerApiLevel() && m.IsSdkVariant() {
|
|
|
|
if ctx.Os() != android.Android {
|
|
|
|
return
|
|
|
|
}
|
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-07 05:49:35 +08:00
|
|
|
from, err := nativeApiLevelFromUser(ctx, m.MinSdkVersion())
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("min_sdk_version", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
generatePerApiVariants(ctx, m, from,
|
|
|
|
func(m *Module, version android.ApiLevel) {
|
|
|
|
m.Properties.Sdk_version = StringPtr(version.String())
|
2020-07-16 04:33:30 +08:00
|
|
|
})
|
2017-04-14 03:53:07 +08:00
|
|
|
}
|
2016-06-18 07:45:24 +08: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-07 05:49:35 +08:00
|
|
|
func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
|
|
|
|
this.apiLevel = nativeApiLevelOrPanic(ctx, this.properties.ApiLevel)
|
|
|
|
|
|
|
|
var err error
|
|
|
|
this.firstVersion, err = nativeApiLevelFromUser(ctx,
|
|
|
|
String(this.properties.First_version))
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("first_version", err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
this.unversionedUntil, err = nativeApiLevelFromUserWithDefault(ctx,
|
|
|
|
String(this.properties.Unversioned_until), "minimum")
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("unversioned_until", err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
|
2016-08-05 04:02:36 +08:00
|
|
|
c.baseCompiler.compilerInit(ctx)
|
|
|
|
|
2017-04-08 06:21:13 +08:00
|
|
|
name := ctx.baseModuleName()
|
|
|
|
if strings.HasSuffix(name, ndkLibrarySuffix) {
|
|
|
|
ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
|
|
|
|
}
|
|
|
|
|
2020-07-01 03:32:51 +08:00
|
|
|
ndkKnownLibsLock.Lock()
|
|
|
|
defer ndkKnownLibsLock.Unlock()
|
|
|
|
for _, lib := range ndkKnownLibs {
|
2016-08-05 04:02:36 +08:00
|
|
|
if lib == name {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 03:32:51 +08:00
|
|
|
ndkKnownLibs = append(ndkKnownLibs, name)
|
2016-08-05 04:02:36 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 02:39:53 +08:00
|
|
|
func addStubLibraryCompilerFlags(flags Flags) Flags {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.CFlags = append(flags.Global.CFlags,
|
2017-07-20 02:39:53 +08:00
|
|
|
// 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",
|
2019-12-13 02:15:42 +08:00
|
|
|
"-Wno-incomplete-setjmp-declaration",
|
2017-07-20 02:39:53 +08:00
|
|
|
"-Wno-builtin-requires-header",
|
|
|
|
"-Wno-invalid-noreturn",
|
2017-11-15 06:09:14 +08:00
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
2017-07-20 02:39:53 +08:00
|
|
|
// 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",
|
|
|
|
)
|
2019-11-21 14:11:49 +08: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-20 02:39:53 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2017-11-17 06:33:08 +08:00
|
|
|
func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
|
|
|
|
flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
|
2017-07-20 02:39:53 +08:00
|
|
|
return addStubLibraryCompilerFlags(flags)
|
|
|
|
}
|
|
|
|
|
2018-12-07 15:25:39 +08:00
|
|
|
func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
|
2016-06-18 07:45:24 +08:00
|
|
|
arch := ctx.Arch().ArchType.String()
|
|
|
|
|
2017-03-20 04:44:32 +08:00
|
|
|
stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
|
|
|
|
versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
|
|
|
|
symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
|
2017-03-29 06:00:46 +08:00
|
|
|
apiLevelsJson := android.GetApiLevelsJson(ctx)
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: genStubSrc,
|
|
|
|
Description: "generate stubs " + symbolFilePath.Rel(),
|
|
|
|
Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
|
|
|
|
Input: symbolFilePath,
|
|
|
|
Implicits: []android.Path{apiLevelsJson},
|
2016-06-18 07:45:24 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arch": arch,
|
2017-03-20 04:44:32 +08:00
|
|
|
"apiLevel": apiLevel,
|
2017-03-29 06:00:46 +08:00
|
|
|
"apiMap": apiLevelsJson.String(),
|
2018-12-07 15:25:39 +08:00
|
|
|
"flags": genstubFlags,
|
2016-06-18 07:45:24 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
subdir := ""
|
2016-10-27 01:03:47 +08:00
|
|
|
srcs := []android.Path{stubSrcPath}
|
2017-12-20 07:11:01 +08:00
|
|
|
return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath
|
2017-03-20 04:44:32 +08:00
|
|
|
}
|
|
|
|
|
2020-05-30 04:37:12 +08:00
|
|
|
func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath {
|
|
|
|
apiLevelsJson := android.GetApiLevelsJson(ctx)
|
|
|
|
symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
|
|
|
|
outputFileName := strings.Split(symbolFilePath.Base(), ".")[0]
|
|
|
|
parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: parseNdkApiRule,
|
|
|
|
Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(),
|
|
|
|
Outputs: []android.WritablePath{parsedApiCoveragePath},
|
|
|
|
Input: symbolFilePath,
|
2020-06-12 08:27:56 +08:00
|
|
|
Implicits: []android.Path{apiLevelsJson},
|
2020-05-30 04:37:12 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"apiMap": apiLevelsJson.String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return parsedApiCoveragePath
|
|
|
|
}
|
|
|
|
|
2017-03-20 04:44:32 +08:00
|
|
|
func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
2017-11-08 02:57:05 +08:00
|
|
|
if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
|
2017-06-14 06:14:56 +08:00
|
|
|
ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
|
|
|
|
}
|
|
|
|
|
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-07 05:49:35 +08:00
|
|
|
if !c.initializeProperties(ctx) {
|
|
|
|
// Emits its own errors, so we don't need to.
|
|
|
|
return Objects{}
|
|
|
|
}
|
|
|
|
|
2020-05-30 04:37:12 +08:00
|
|
|
symbolFile := String(c.properties.Symbol_file)
|
|
|
|
objs, versionScript := compileStubLibrary(ctx, flags, symbolFile,
|
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-07 05:49:35 +08:00
|
|
|
c.apiLevel.String(), "")
|
2017-03-20 04:44:32 +08:00
|
|
|
c.versionScriptPath = versionScript
|
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-07 05:49:35 +08:00
|
|
|
if c.apiLevel.IsCurrent() && ctx.PrimaryArch() {
|
2020-05-30 04:37:12 +08:00
|
|
|
c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
|
|
|
|
}
|
2017-03-20 04:44:32 +08:00
|
|
|
return objs
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-06-18 07:45:24 +08:00
|
|
|
return Deps{}
|
|
|
|
}
|
|
|
|
|
2017-04-08 06:21:13 +08:00
|
|
|
func (linker *stubDecorator) Name(name string) string {
|
|
|
|
return name + ndkLibrarySuffix
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2017-04-08 06:21:13 +08:00
|
|
|
stub.libraryDecorator.libName = ctx.baseModuleName()
|
2016-07-30 08:28:03 +08:00
|
|
|
return stub.libraryDecorator.linkerFlags(ctx, flags)
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
|
2016-09-27 08:33:01 +08:00
|
|
|
objs Objects) android.Path {
|
2016-07-29 08:40:28 +08: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-07 05:49:35 +08:00
|
|
|
if shouldUseVersionScript(ctx, stub) {
|
2017-01-04 07:16:29 +08:00
|
|
|
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
|
2019-06-11 09:02:25 +08:00
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
|
2017-01-04 07:16:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
return stub.libraryDecorator.link(ctx, flags, deps, objs)
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 01:21:31 +08:00
|
|
|
func (stub *stubDecorator) nativeCoverage() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
|
2016-06-18 07:45:24 +08:00
|
|
|
arch := ctx.Target().Arch.ArchType.Name
|
|
|
|
// arm64 isn't actually a multilib toolchain, so unlike the other LP64
|
|
|
|
// architectures it's just installed to lib.
|
|
|
|
libDir := "lib"
|
|
|
|
if ctx.toolchain().Is64Bit() && arch != "arm64" {
|
|
|
|
libDir = "lib64"
|
|
|
|
}
|
|
|
|
|
|
|
|
installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
|
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-07 05:49:35 +08:00
|
|
|
"platforms/android-%s/arch-%s/usr/%s", stub.apiLevel, arch, libDir))
|
2017-11-29 09:34:01 +08:00
|
|
|
stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
func newStubLibrary() *Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-06-18 07:45:24 +08:00
|
|
|
module.stl = nil
|
2016-07-30 08:28:03 +08:00
|
|
|
module.sanitize = nil
|
2020-08-19 20:53:01 +08:00
|
|
|
library.disableStripping()
|
2016-06-18 07:45:24 +08:00
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
stub := &stubDecorator{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = stub
|
|
|
|
module.linker = stub
|
|
|
|
module.installer = stub
|
2016-06-18 07:45:24 +08:00
|
|
|
|
2020-04-08 00:50:32 +08:00
|
|
|
module.Properties.AlwaysSdk = true
|
|
|
|
module.Properties.Sdk_version = StringPtr("current")
|
|
|
|
|
2017-06-24 06:06:31 +08:00
|
|
|
module.AddProperties(&stub.properties, &library.MutatedProperties)
|
|
|
|
|
|
|
|
return module
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2020-07-25 05:19:06 +08:00
|
|
|
// ndk_library creates a library that exposes a stub implementation of functions
|
|
|
|
// and variables for use at build time only.
|
2019-12-09 17:21:48 +08:00
|
|
|
func NdkLibraryFactory() android.Module {
|
2017-06-24 06:06:31 +08:00
|
|
|
module := newStubLibrary()
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
2019-05-09 20:07:34 +08:00
|
|
|
module.ModuleBase.EnableNativeBridgeSupportByDefault()
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2016-06-18 07:45:24 +08:00
|
|
|
}
|