blob: 4578fd329376b86ad2bb862b7ff40a9ab6405605 [file] [log] [blame]
Dan Albert914449f2016-06-17 16:45:24 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "fmt"
19 "strconv"
20 "strings"
Colin Crosse8a67a72016-08-07 21:17:54 -070021 "sync"
Dan Albert914449f2016-06-17 16:45:24 -070022
23 "github.com/google/blueprint"
24
25 "android/soong/android"
26)
27
sophiez58cabb72020-05-29 13:37:12 -070028func init() {
Dan Albert06f58af2020-06-22 15:10:31 -070029 pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen")
sophiez58cabb72020-05-29 13:37:12 -070030 pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
31}
32
Dan Albert914449f2016-06-17 16:45:24 -070033var (
Colin Cross9d45bb72016-08-29 16:14:13 -070034 genStubSrc = pctx.AndroidStaticRule("genStubSrc",
Dan Albert914449f2016-06-17 16:45:24 -070035 blueprint.RuleParams{
Dan Albert06f58af2020-06-22 15:10:31 -070036 Command: "$ndkStubGenerator --arch $arch --api $apiLevel " +
37 "--api-map $apiMap $flags $in $out",
38 CommandDeps: []string{"$ndkStubGenerator"},
Jiyong Park3fd0baf2018-12-07 16:25:39 +090039 }, "arch", "apiLevel", "apiMap", "flags")
Dan Albert914449f2016-06-17 16:45:24 -070040
sophiez58cabb72020-05-29 13:37:12 -070041 parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule",
42 blueprint.RuleParams{
43 Command: "$ndk_api_coverage_parser $in $out --api-map $apiMap",
44 CommandDeps: []string{"$ndk_api_coverage_parser"},
45 }, "apiMap")
46
Dan Albert914449f2016-06-17 16:45:24 -070047 ndkLibrarySuffix = ".ndk"
Colin Cross4d9c2d12016-07-29 12:48:20 -070048
Dan Albertde5aade2020-06-30 12:32:51 -070049 // Added as a variation dependency via depsMutator.
50 ndkKnownLibs = []string{}
51 // protects ndkKnownLibs writes during parallel BeginMutator.
52 ndkKnownLibsLock sync.Mutex
Dan Albert914449f2016-06-17 16:45:24 -070053)
54
55// Creates a stub shared library based on the provided version file.
56//
Dan Albert914449f2016-06-17 16:45:24 -070057// Example:
58//
59// ndk_library {
Dan Willemsen01a90592017-04-07 15:21:13 -070060// name: "libfoo",
Dan Albert914449f2016-06-17 16:45:24 -070061// symbol_file: "libfoo.map.txt",
62// first_version: "9",
63// }
64//
65type libraryProperties struct {
66 // Relative path to the symbol map.
67 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080068 Symbol_file *string
Dan Albert914449f2016-06-17 16:45:24 -070069
70 // The first API level a library was available. A library will be generated
71 // for every API level beginning with this one.
Nan Zhang0007d812017-11-07 10:57:05 -080072 First_version *string
Dan Albert914449f2016-06-17 16:45:24 -070073
Dan Albert98dbb3b2017-01-03 15:16:29 -080074 // The first API level that library should have the version script applied.
75 // This defaults to the value of first_version, and should almost never be
76 // used. This is only needed to work around platform bugs like
77 // https://github.com/android-ndk/ndk/issues/265.
Nan Zhang0007d812017-11-07 10:57:05 -080078 Unversioned_until *string
Dan Albert98dbb3b2017-01-03 15:16:29 -080079
Dan Albert06f58af2020-06-22 15:10:31 -070080 // Private property for use by the mutator that splits per-API level. Can be
81 // one of <number:sdk_version> or <codename> or "current" passed to
82 // "ndkstubgen.py" as it is
Dan Albertfd86e9e2016-11-08 13:35:12 -080083 ApiLevel string `blueprint:"mutated"`
Dan Albert23d37e02018-11-28 08:30:10 -080084
85 // True if this API is not yet ready to be shipped in the NDK. It will be
86 // available in the platform for testing, but will be excluded from the
87 // sysroot provided to the NDK proper.
88 Draft bool
Dan Albert914449f2016-06-17 16:45:24 -070089}
90
Colin Crossb916a382016-07-29 17:28:03 -070091type stubDecorator struct {
92 *libraryDecorator
Dan Albert914449f2016-06-17 16:45:24 -070093
94 properties libraryProperties
Dan Albert2bc91ba2016-07-28 17:40:28 -070095
sophiez58cabb72020-05-29 13:37:12 -070096 versionScriptPath android.ModuleGenPath
97 parsedCoverageXmlPath android.ModuleOutPath
98 installPath android.Path
Dan Albert914449f2016-06-17 16:45:24 -070099}
100
101// OMG GO
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700102func intMax(a int, b int) int {
103 if a > b {
Dan Albert914449f2016-06-17 16:45:24 -0700104 return a
105 } else {
106 return b
107 }
108}
109
Colin Cross0ea8ba82019-06-06 14:33:29 -0700110func normalizeNdkApiLevel(ctx android.BaseModuleContext, apiLevel string,
Dan Albertf5415d72017-08-17 16:19:59 -0700111 arch android.Arch) (string, error) {
112
Dan Albert90f7a4d2016-11-08 14:34:24 -0800113 if apiLevel == "current" {
114 return apiLevel, nil
115 }
116
Colin Cross6510f912017-11-29 00:27:14 -0800117 minVersion := ctx.Config().MinSupportedSdkVersion()
Colin Crossce87b802017-04-13 13:00:26 -0700118 firstArchVersions := map[android.ArchType]int{
Dan Albertf5415d72017-08-17 16:19:59 -0700119 android.Arm: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700120 android.Arm64: 21,
Dan Albertf5415d72017-08-17 16:19:59 -0700121 android.X86: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700122 android.X86_64: 21,
Dan Albert914449f2016-06-17 16:45:24 -0700123 }
124
Colin Crossce87b802017-04-13 13:00:26 -0700125 firstArchVersion, ok := firstArchVersions[arch.ArchType]
Dan Albert2e5d7d42017-03-29 18:22:39 -0700126 if !ok {
Colin Crossce87b802017-04-13 13:00:26 -0700127 panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType))
Dan Albert2e5d7d42017-03-29 18:22:39 -0700128 }
129
130 if apiLevel == "minimum" {
131 return strconv.Itoa(firstArchVersion), nil
132 }
133
Dan Albert914449f2016-06-17 16:45:24 -0700134 // If the NDK drops support for a platform version, we don't want to have to
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700135 // fix up every module that was using it as its SDK version. Clip to the
Dan Albert914449f2016-06-17 16:45:24 -0700136 // supported version here instead.
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700137 version, err := strconv.Atoi(apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700138 if err != nil {
Dan Albert90f7a4d2016-11-08 14:34:24 -0800139 return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700140 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700141 version = intMax(version, minVersion)
142
Dan Albert90f7a4d2016-11-08 14:34:24 -0800143 return strconv.Itoa(intMax(version, firstArchVersion)), nil
144}
145
146func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) {
147 if firstSupportedVersion == "current" {
148 return platformVersion + 1, nil
149 }
150
151 return strconv.Atoi(firstSupportedVersion)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700152}
153
Colin Cross0ea8ba82019-06-06 14:33:29 -0700154func shouldUseVersionScript(ctx android.BaseModuleContext, stub *stubDecorator) (bool, error) {
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700155 // unversioned_until is normally empty, in which case we should use the version script.
156 if String(stub.properties.Unversioned_until) == "" {
157 return true, nil
158 }
Dan Albert98dbb3b2017-01-03 15:16:29 -0800159
Nan Zhang0007d812017-11-07 10:57:05 -0800160 if String(stub.properties.Unversioned_until) == "current" {
Dan Albert022e7a32017-01-05 15:49:09 -0800161 if stub.properties.ApiLevel == "current" {
162 return true, nil
163 } else {
164 return false, nil
165 }
166 }
167
Dan Albert98dbb3b2017-01-03 15:16:29 -0800168 if stub.properties.ApiLevel == "current" {
169 return true, nil
170 }
171
Dan Alberte67144e2018-05-03 15:42:34 -0700172 unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until))
Dan Albert98dbb3b2017-01-03 15:16:29 -0800173 if err != nil {
174 return true, err
175 }
176
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700177 version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
178 if err != nil {
179 return true, err
Dan Alberte67144e2018-05-03 15:42:34 -0700180 }
181
Dan Albert98dbb3b2017-01-03 15:16:29 -0800182 return version >= unversionedUntil, nil
183}
184
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700185func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
Colin Cross6510f912017-11-29 00:27:14 -0800186 platformVersion := mctx.Config().PlatformSdkVersionInt()
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700187
Nan Zhang0007d812017-11-07 10:57:05 -0800188 firstSupportedVersion, err := normalizeNdkApiLevel(mctx, String(c.properties.First_version),
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700189 mctx.Arch())
190 if err != nil {
191 mctx.PropertyErrorf("first_version", err.Error())
Dan Albert914449f2016-06-17 16:45:24 -0700192 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700193
Dan Albert90f7a4d2016-11-08 14:34:24 -0800194 firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion)
195 if err != nil {
196 // In theory this is impossible because we've already run this through
197 // normalizeNdkApiLevel above.
198 mctx.PropertyErrorf("first_version", err.Error())
199 }
200
Dan Albertfd86e9e2016-11-08 13:35:12 -0800201 var versionStrs []string
Dan Albert90f7a4d2016-11-08 14:34:24 -0800202 for version := firstGenVersion; version <= platformVersion; version++ {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800203 versionStrs = append(versionStrs, strconv.Itoa(version))
Dan Albert914449f2016-06-17 16:45:24 -0700204 }
Colin Cross6510f912017-11-29 00:27:14 -0800205 versionStrs = append(versionStrs, mctx.Config().PlatformVersionActiveCodenames()...)
Dan Albertfd86e9e2016-11-08 13:35:12 -0800206 versionStrs = append(versionStrs, "current")
Dan Albert914449f2016-06-17 16:45:24 -0700207
208 modules := mctx.CreateVariations(versionStrs...)
209 for i, module := range modules {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800210 module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i]
Dan Albert914449f2016-06-17 16:45:24 -0700211 }
212}
213
Jooyung Hanb90e4912019-12-09 18:21:48 +0900214func NdkApiMutator(mctx android.BottomUpMutatorContext) {
Dan Albert914449f2016-06-17 16:45:24 -0700215 if m, ok := mctx.Module().(*Module); ok {
Colin Crossd4025822017-04-13 12:53:07 -0700216 if m.Enabled() {
217 if compiler, ok := m.compiler.(*stubDecorator); ok {
218 generateStubApiVariants(mctx, compiler)
219 }
Dan Albert914449f2016-06-17 16:45:24 -0700220 }
221 }
222}
223
Colin Crossb916a382016-07-29 17:28:03 -0700224func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -0700225 c.baseCompiler.compilerInit(ctx)
226
Dan Willemsen01a90592017-04-07 15:21:13 -0700227 name := ctx.baseModuleName()
228 if strings.HasSuffix(name, ndkLibrarySuffix) {
229 ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
230 }
231
Dan Albertde5aade2020-06-30 12:32:51 -0700232 ndkKnownLibsLock.Lock()
233 defer ndkKnownLibsLock.Unlock()
234 for _, lib := range ndkKnownLibs {
Dan Albert7e9d2952016-08-04 13:02:36 -0700235 if lib == name {
236 return
237 }
238 }
Dan Albertde5aade2020-06-30 12:32:51 -0700239 ndkKnownLibs = append(ndkKnownLibs, name)
Dan Albert7e9d2952016-08-04 13:02:36 -0700240}
241
George Burgess IVf5310e32017-07-19 11:39:53 -0700242func addStubLibraryCompilerFlags(flags Flags) Flags {
Colin Cross4af21ed2019-11-04 09:37:55 -0800243 flags.Global.CFlags = append(flags.Global.CFlags,
George Burgess IVf5310e32017-07-19 11:39:53 -0700244 // We're knowingly doing some otherwise unsightly things with builtin
245 // functions here. We're just generating stub libraries, so ignore it.
246 "-Wno-incompatible-library-redeclaration",
Nick Desaulnierseb207442019-12-12 10:15:42 -0800247 "-Wno-incomplete-setjmp-declaration",
George Burgess IVf5310e32017-07-19 11:39:53 -0700248 "-Wno-builtin-requires-header",
249 "-Wno-invalid-noreturn",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800250 "-Wall",
251 "-Werror",
George Burgess IVf5310e32017-07-19 11:39:53 -0700252 // These libraries aren't actually used. Don't worry about unwinding
253 // (avoids the need to link an unwinder into a fake library).
254 "-fno-unwind-tables",
255 )
Jiyong Park48d75ef2019-11-21 15:11:49 +0900256 // All symbols in the stubs library should be visible.
257 if inList("-fvisibility=hidden", flags.Local.CFlags) {
258 flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
259 }
George Burgess IVf5310e32017-07-19 11:39:53 -0700260 return flags
261}
262
Colin Crossf18e1102017-11-16 14:33:08 -0800263func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
264 flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
George Burgess IVf5310e32017-07-19 11:39:53 -0700265 return addStubLibraryCompilerFlags(flags)
266}
267
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900268func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
Dan Albert914449f2016-06-17 16:45:24 -0700269 arch := ctx.Arch().ArchType.String()
270
Dan Willemsenb916b802017-03-19 13:44:32 -0700271 stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
272 versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
273 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
Dan Albert49927d22017-03-28 15:00:46 -0700274 apiLevelsJson := android.GetApiLevelsJson(ctx)
Colin Crossae887032017-10-23 17:16:14 -0700275 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700276 Rule: genStubSrc,
277 Description: "generate stubs " + symbolFilePath.Rel(),
278 Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
279 Input: symbolFilePath,
280 Implicits: []android.Path{apiLevelsJson},
Dan Albert914449f2016-06-17 16:45:24 -0700281 Args: map[string]string{
282 "arch": arch,
Dan Willemsenb916b802017-03-19 13:44:32 -0700283 "apiLevel": apiLevel,
Dan Albert49927d22017-03-28 15:00:46 -0700284 "apiMap": apiLevelsJson.String(),
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900285 "flags": genstubFlags,
Dan Albert914449f2016-06-17 16:45:24 -0700286 },
287 })
288
Dan Albert914449f2016-06-17 16:45:24 -0700289 subdir := ""
Colin Cross2f336352016-10-26 10:03:47 -0700290 srcs := []android.Path{stubSrcPath}
Pirama Arumuga Nainar70ba5a32017-12-19 15:11:01 -0800291 return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath
Dan Willemsenb916b802017-03-19 13:44:32 -0700292}
293
sophiez58cabb72020-05-29 13:37:12 -0700294func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath {
295 apiLevelsJson := android.GetApiLevelsJson(ctx)
296 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
297 outputFileName := strings.Split(symbolFilePath.Base(), ".")[0]
298 parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml")
299 ctx.Build(pctx, android.BuildParams{
300 Rule: parseNdkApiRule,
301 Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(),
302 Outputs: []android.WritablePath{parsedApiCoveragePath},
303 Input: symbolFilePath,
sophiez148b3172020-06-11 17:27:56 -0700304 Implicits: []android.Path{apiLevelsJson},
sophiez58cabb72020-05-29 13:37:12 -0700305 Args: map[string]string{
306 "apiMap": apiLevelsJson.String(),
307 },
308 })
309 return parsedApiCoveragePath
310}
311
Dan Willemsenb916b802017-03-19 13:44:32 -0700312func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Nan Zhang0007d812017-11-07 10:57:05 -0800313 if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
Dan Albert15be0c62017-06-13 15:14:56 -0700314 ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
315 }
316
sophiez58cabb72020-05-29 13:37:12 -0700317 symbolFile := String(c.properties.Symbol_file)
318 objs, versionScript := compileStubLibrary(ctx, flags, symbolFile,
Nan Zhang0007d812017-11-07 10:57:05 -0800319 c.properties.ApiLevel, "")
Dan Willemsenb916b802017-03-19 13:44:32 -0700320 c.versionScriptPath = versionScript
sophiez58cabb72020-05-29 13:37:12 -0700321 if c.properties.ApiLevel == "current" && ctx.PrimaryArch() {
322 c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
323 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700324 return objs
Dan Albert914449f2016-06-17 16:45:24 -0700325}
326
Colin Cross37047f12016-12-13 17:06:13 -0800327func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Dan Albert914449f2016-06-17 16:45:24 -0700328 return Deps{}
329}
330
Dan Willemsen01a90592017-04-07 15:21:13 -0700331func (linker *stubDecorator) Name(name string) string {
332 return name + ndkLibrarySuffix
333}
334
Colin Crossb916a382016-07-29 17:28:03 -0700335func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Dan Willemsen01a90592017-04-07 15:21:13 -0700336 stub.libraryDecorator.libName = ctx.baseModuleName()
Colin Crossb916a382016-07-29 17:28:03 -0700337 return stub.libraryDecorator.linkerFlags(ctx, flags)
Dan Albert914449f2016-06-17 16:45:24 -0700338}
339
Colin Crossb916a382016-07-29 17:28:03 -0700340func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700341 objs Objects) android.Path {
Dan Albert2bc91ba2016-07-28 17:40:28 -0700342
Dan Alberte67144e2018-05-03 15:42:34 -0700343 useVersionScript, err := shouldUseVersionScript(ctx, stub)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800344 if err != nil {
345 ctx.ModuleErrorf(err.Error())
346 }
347
348 if useVersionScript {
349 linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
Colin Cross4af21ed2019-11-04 09:37:55 -0800350 flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
Dan Willemsen939408a2019-06-10 18:02:25 -0700351 flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800352 }
353
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700354 return stub.libraryDecorator.link(ctx, flags, deps, objs)
Dan Albert2bc91ba2016-07-28 17:40:28 -0700355}
356
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700357func (stub *stubDecorator) nativeCoverage() bool {
358 return false
359}
360
Colin Crossb916a382016-07-29 17:28:03 -0700361func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
Dan Albert914449f2016-06-17 16:45:24 -0700362 arch := ctx.Target().Arch.ArchType.Name
Colin Crossb916a382016-07-29 17:28:03 -0700363 apiLevel := stub.properties.ApiLevel
Dan Albert914449f2016-06-17 16:45:24 -0700364
365 // arm64 isn't actually a multilib toolchain, so unlike the other LP64
366 // architectures it's just installed to lib.
367 libDir := "lib"
368 if ctx.toolchain().Is64Bit() && arch != "arm64" {
369 libDir = "lib64"
370 }
371
372 installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
Dan Albertfd86e9e2016-11-08 13:35:12 -0800373 "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir))
Colin Cross0875c522017-11-28 17:34:01 -0800374 stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
Dan Albert914449f2016-06-17 16:45:24 -0700375}
376
Colin Cross36242852017-06-23 15:06:31 -0700377func newStubLibrary() *Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800378 module, library := NewLibrary(android.DeviceSupported)
379 library.BuildOnlyShared()
Dan Albert914449f2016-06-17 16:45:24 -0700380 module.stl = nil
Colin Crossb916a382016-07-29 17:28:03 -0700381 module.sanitize = nil
Nan Zhang0007d812017-11-07 10:57:05 -0800382 library.StripProperties.Strip.None = BoolPtr(true)
Dan Albert914449f2016-06-17 16:45:24 -0700383
Colin Crossb916a382016-07-29 17:28:03 -0700384 stub := &stubDecorator{
385 libraryDecorator: library,
386 }
387 module.compiler = stub
388 module.linker = stub
389 module.installer = stub
Dan Albert914449f2016-06-17 16:45:24 -0700390
Colin Crossc511bc52020-04-07 16:50:32 +0000391 module.Properties.AlwaysSdk = true
392 module.Properties.Sdk_version = StringPtr("current")
393
Colin Cross36242852017-06-23 15:06:31 -0700394 module.AddProperties(&stub.properties, &library.MutatedProperties)
395
396 return module
Dan Albert914449f2016-06-17 16:45:24 -0700397}
398
Patrice Arruda6ea42112019-04-03 08:43:30 -0700399// ndk_library creates a stub library that exposes dummy implementation
400// of functions and variables for use at build time only.
Jooyung Hanb90e4912019-12-09 18:21:48 +0900401func NdkLibraryFactory() android.Module {
Colin Cross36242852017-06-23 15:06:31 -0700402 module := newStubLibrary()
403 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
dimitry03dc3f62019-05-09 14:07:34 +0200404 module.ModuleBase.EnableNativeBridgeSupportByDefault()
Colin Cross36242852017-06-23 15:06:31 -0700405 return module
Dan Albert914449f2016-06-17 16:45:24 -0700406}