blob: 119ca403d01f25a9e27d75d80c94b68e9f5e31b8 [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
28var (
29 toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/gen_stub_libs.py")
30
Colin Cross9d45bb72016-08-29 16:14:13 -070031 genStubSrc = pctx.AndroidStaticRule("genStubSrc",
Dan Albert914449f2016-06-17 16:45:24 -070032 blueprint.RuleParams{
Dan Albert49927d22017-03-28 15:00:46 -070033 Command: "$toolPath --arch $arch --api $apiLevel --api-map " +
Jiyong Park3fd0baf2018-12-07 16:25:39 +090034 "$apiMap $flags $in $out",
Dan Albert914449f2016-06-17 16:45:24 -070035 CommandDeps: []string{"$toolPath"},
Jiyong Park3fd0baf2018-12-07 16:25:39 +090036 }, "arch", "apiLevel", "apiMap", "flags")
Dan Albert914449f2016-06-17 16:45:24 -070037
38 ndkLibrarySuffix = ".ndk"
Colin Cross4d9c2d12016-07-29 12:48:20 -070039
40 ndkPrebuiltSharedLibs = []string{
Sasha Smundakb500ce52019-03-19 17:13:17 -070041 "aaudio",
42 "amidi",
Colin Cross4d9c2d12016-07-29 12:48:20 -070043 "android",
Steven Morelandfa287842018-08-29 20:14:18 -070044 "binder_ndk",
Colin Cross4d9c2d12016-07-29 12:48:20 -070045 "c",
Sasha Smundakb500ce52019-03-19 17:13:17 -070046 "camera2ndk",
Colin Cross4d9c2d12016-07-29 12:48:20 -070047 "dl",
48 "EGL",
49 "GLESv1_CM",
50 "GLESv2",
51 "GLESv3",
52 "jnigraphics",
53 "log",
54 "mediandk",
Sasha Smundakb500ce52019-03-19 17:13:17 -070055 "nativewindow",
Colin Cross4d9c2d12016-07-29 12:48:20 -070056 "m",
Slava Shklyaevaef0d6e2019-07-24 14:08:18 +010057 "neuralnetworks",
Colin Cross4d9c2d12016-07-29 12:48:20 -070058 "OpenMAXAL",
59 "OpenSLES",
60 "stdc++",
Dan Willemsen62b9cf92019-02-06 18:40:16 -080061 "sync",
Colin Cross4d9c2d12016-07-29 12:48:20 -070062 "vulkan",
63 "z",
64 }
65 ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib")
66
67 // These libraries have migrated over to the new ndk_library, which is added
68 // as a variation dependency via depsMutator.
Colin Crosse8a67a72016-08-07 21:17:54 -070069 ndkMigratedLibs = []string{}
Colin Crosse40b4ea2018-10-02 22:25:58 -070070 ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel BeginMutator
Dan Albert914449f2016-06-17 16:45:24 -070071)
72
73// Creates a stub shared library based on the provided version file.
74//
Dan Albert914449f2016-06-17 16:45:24 -070075// Example:
76//
77// ndk_library {
Dan Willemsen01a90592017-04-07 15:21:13 -070078// name: "libfoo",
Dan Albert914449f2016-06-17 16:45:24 -070079// symbol_file: "libfoo.map.txt",
80// first_version: "9",
81// }
82//
83type libraryProperties struct {
84 // Relative path to the symbol map.
85 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080086 Symbol_file *string
Dan Albert914449f2016-06-17 16:45:24 -070087
88 // The first API level a library was available. A library will be generated
89 // for every API level beginning with this one.
Nan Zhang0007d812017-11-07 10:57:05 -080090 First_version *string
Dan Albert914449f2016-06-17 16:45:24 -070091
Dan Albert98dbb3b2017-01-03 15:16:29 -080092 // The first API level that library should have the version script applied.
93 // This defaults to the value of first_version, and should almost never be
94 // used. This is only needed to work around platform bugs like
95 // https://github.com/android-ndk/ndk/issues/265.
Nan Zhang0007d812017-11-07 10:57:05 -080096 Unversioned_until *string
Dan Albert98dbb3b2017-01-03 15:16:29 -080097
Dan Albert914449f2016-06-17 16:45:24 -070098 // Private property for use by the mutator that splits per-API level.
Jooyung Han29e91d22020-04-02 01:41:41 +090099 // can be one of <number:sdk_version> or <codename> or "current"
100 // passed to "gen_stub_libs.py" as it is
Dan Albertfd86e9e2016-11-08 13:35:12 -0800101 ApiLevel string `blueprint:"mutated"`
Dan Albert23d37e02018-11-28 08:30:10 -0800102
103 // True if this API is not yet ready to be shipped in the NDK. It will be
104 // available in the platform for testing, but will be excluded from the
105 // sysroot provided to the NDK proper.
106 Draft bool
Dan Albert914449f2016-06-17 16:45:24 -0700107}
108
Colin Crossb916a382016-07-29 17:28:03 -0700109type stubDecorator struct {
110 *libraryDecorator
Dan Albert914449f2016-06-17 16:45:24 -0700111
112 properties libraryProperties
Dan Albert2bc91ba2016-07-28 17:40:28 -0700113
Colin Crossb916a382016-07-29 17:28:03 -0700114 versionScriptPath android.ModuleGenPath
Colin Cross0875c522017-11-28 17:34:01 -0800115 installPath android.Path
Dan Albert914449f2016-06-17 16:45:24 -0700116}
117
118// OMG GO
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700119func intMax(a int, b int) int {
120 if a > b {
Dan Albert914449f2016-06-17 16:45:24 -0700121 return a
122 } else {
123 return b
124 }
125}
126
Colin Cross0ea8ba82019-06-06 14:33:29 -0700127func normalizeNdkApiLevel(ctx android.BaseModuleContext, apiLevel string,
Dan Albertf5415d72017-08-17 16:19:59 -0700128 arch android.Arch) (string, error) {
129
Dan Albert90f7a4d2016-11-08 14:34:24 -0800130 if apiLevel == "current" {
131 return apiLevel, nil
132 }
133
Colin Cross6510f912017-11-29 00:27:14 -0800134 minVersion := ctx.Config().MinSupportedSdkVersion()
Colin Crossce87b802017-04-13 13:00:26 -0700135 firstArchVersions := map[android.ArchType]int{
Dan Albertf5415d72017-08-17 16:19:59 -0700136 android.Arm: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700137 android.Arm64: 21,
Dan Albertf5415d72017-08-17 16:19:59 -0700138 android.Mips: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700139 android.Mips64: 21,
Dan Albertf5415d72017-08-17 16:19:59 -0700140 android.X86: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700141 android.X86_64: 21,
Dan Albert914449f2016-06-17 16:45:24 -0700142 }
143
Colin Crossce87b802017-04-13 13:00:26 -0700144 firstArchVersion, ok := firstArchVersions[arch.ArchType]
Dan Albert2e5d7d42017-03-29 18:22:39 -0700145 if !ok {
Colin Crossce87b802017-04-13 13:00:26 -0700146 panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType))
Dan Albert2e5d7d42017-03-29 18:22:39 -0700147 }
148
149 if apiLevel == "minimum" {
150 return strconv.Itoa(firstArchVersion), nil
151 }
152
Dan Albert914449f2016-06-17 16:45:24 -0700153 // If the NDK drops support for a platform version, we don't want to have to
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700154 // fix up every module that was using it as its SDK version. Clip to the
Dan Albert914449f2016-06-17 16:45:24 -0700155 // supported version here instead.
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700156 version, err := strconv.Atoi(apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700157 if err != nil {
Dan Albert90f7a4d2016-11-08 14:34:24 -0800158 return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700159 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700160 version = intMax(version, minVersion)
161
Dan Albert90f7a4d2016-11-08 14:34:24 -0800162 return strconv.Itoa(intMax(version, firstArchVersion)), nil
163}
164
165func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) {
166 if firstSupportedVersion == "current" {
167 return platformVersion + 1, nil
168 }
169
170 return strconv.Atoi(firstSupportedVersion)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700171}
172
Colin Cross0ea8ba82019-06-06 14:33:29 -0700173func shouldUseVersionScript(ctx android.BaseModuleContext, stub *stubDecorator) (bool, error) {
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700174 // unversioned_until is normally empty, in which case we should use the version script.
175 if String(stub.properties.Unversioned_until) == "" {
176 return true, nil
177 }
Dan Albert98dbb3b2017-01-03 15:16:29 -0800178
Nan Zhang0007d812017-11-07 10:57:05 -0800179 if String(stub.properties.Unversioned_until) == "current" {
Dan Albert022e7a32017-01-05 15:49:09 -0800180 if stub.properties.ApiLevel == "current" {
181 return true, nil
182 } else {
183 return false, nil
184 }
185 }
186
Dan Albert98dbb3b2017-01-03 15:16:29 -0800187 if stub.properties.ApiLevel == "current" {
188 return true, nil
189 }
190
Dan Alberte67144e2018-05-03 15:42:34 -0700191 unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until))
Dan Albert98dbb3b2017-01-03 15:16:29 -0800192 if err != nil {
193 return true, err
194 }
195
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700196 version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
197 if err != nil {
198 return true, err
Dan Alberte67144e2018-05-03 15:42:34 -0700199 }
200
Dan Albert98dbb3b2017-01-03 15:16:29 -0800201 return version >= unversionedUntil, nil
202}
203
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700204func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
Colin Cross6510f912017-11-29 00:27:14 -0800205 platformVersion := mctx.Config().PlatformSdkVersionInt()
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700206
Nan Zhang0007d812017-11-07 10:57:05 -0800207 firstSupportedVersion, err := normalizeNdkApiLevel(mctx, String(c.properties.First_version),
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700208 mctx.Arch())
209 if err != nil {
210 mctx.PropertyErrorf("first_version", err.Error())
Dan Albert914449f2016-06-17 16:45:24 -0700211 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700212
Dan Albert90f7a4d2016-11-08 14:34:24 -0800213 firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion)
214 if err != nil {
215 // In theory this is impossible because we've already run this through
216 // normalizeNdkApiLevel above.
217 mctx.PropertyErrorf("first_version", err.Error())
218 }
219
Dan Albertfd86e9e2016-11-08 13:35:12 -0800220 var versionStrs []string
Dan Albert90f7a4d2016-11-08 14:34:24 -0800221 for version := firstGenVersion; version <= platformVersion; version++ {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800222 versionStrs = append(versionStrs, strconv.Itoa(version))
Dan Albert914449f2016-06-17 16:45:24 -0700223 }
Colin Cross6510f912017-11-29 00:27:14 -0800224 versionStrs = append(versionStrs, mctx.Config().PlatformVersionActiveCodenames()...)
Dan Albertfd86e9e2016-11-08 13:35:12 -0800225 versionStrs = append(versionStrs, "current")
Dan Albert914449f2016-06-17 16:45:24 -0700226
227 modules := mctx.CreateVariations(versionStrs...)
228 for i, module := range modules {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800229 module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i]
Dan Albert914449f2016-06-17 16:45:24 -0700230 }
231}
232
Jooyung Hanb90e4912019-12-09 18:21:48 +0900233func NdkApiMutator(mctx android.BottomUpMutatorContext) {
Dan Albert914449f2016-06-17 16:45:24 -0700234 if m, ok := mctx.Module().(*Module); ok {
Colin Crossd4025822017-04-13 12:53:07 -0700235 if m.Enabled() {
236 if compiler, ok := m.compiler.(*stubDecorator); ok {
237 generateStubApiVariants(mctx, compiler)
238 }
Dan Albert914449f2016-06-17 16:45:24 -0700239 }
240 }
241}
242
Colin Crossb916a382016-07-29 17:28:03 -0700243func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -0700244 c.baseCompiler.compilerInit(ctx)
245
Dan Willemsen01a90592017-04-07 15:21:13 -0700246 name := ctx.baseModuleName()
247 if strings.HasSuffix(name, ndkLibrarySuffix) {
248 ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
249 }
250
Colin Crosse8a67a72016-08-07 21:17:54 -0700251 ndkMigratedLibsLock.Lock()
252 defer ndkMigratedLibsLock.Unlock()
Dan Albert7e9d2952016-08-04 13:02:36 -0700253 for _, lib := range ndkMigratedLibs {
254 if lib == name {
255 return
256 }
257 }
258 ndkMigratedLibs = append(ndkMigratedLibs, name)
259}
260
George Burgess IVf5310e32017-07-19 11:39:53 -0700261func addStubLibraryCompilerFlags(flags Flags) Flags {
Colin Cross4af21ed2019-11-04 09:37:55 -0800262 flags.Global.CFlags = append(flags.Global.CFlags,
George Burgess IVf5310e32017-07-19 11:39:53 -0700263 // We're knowingly doing some otherwise unsightly things with builtin
264 // functions here. We're just generating stub libraries, so ignore it.
265 "-Wno-incompatible-library-redeclaration",
Nick Desaulnierseb207442019-12-12 10:15:42 -0800266 "-Wno-incomplete-setjmp-declaration",
George Burgess IVf5310e32017-07-19 11:39:53 -0700267 "-Wno-builtin-requires-header",
268 "-Wno-invalid-noreturn",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800269 "-Wall",
270 "-Werror",
George Burgess IVf5310e32017-07-19 11:39:53 -0700271 // These libraries aren't actually used. Don't worry about unwinding
272 // (avoids the need to link an unwinder into a fake library).
273 "-fno-unwind-tables",
274 )
Jiyong Park48d75ef2019-11-21 15:11:49 +0900275 // All symbols in the stubs library should be visible.
276 if inList("-fvisibility=hidden", flags.Local.CFlags) {
277 flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
278 }
George Burgess IVf5310e32017-07-19 11:39:53 -0700279 return flags
280}
281
Colin Crossf18e1102017-11-16 14:33:08 -0800282func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
283 flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
George Burgess IVf5310e32017-07-19 11:39:53 -0700284 return addStubLibraryCompilerFlags(flags)
285}
286
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900287func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
Dan Albert914449f2016-06-17 16:45:24 -0700288 arch := ctx.Arch().ArchType.String()
289
Dan Willemsenb916b802017-03-19 13:44:32 -0700290 stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
291 versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
292 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
Dan Albert49927d22017-03-28 15:00:46 -0700293 apiLevelsJson := android.GetApiLevelsJson(ctx)
Colin Crossae887032017-10-23 17:16:14 -0700294 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700295 Rule: genStubSrc,
296 Description: "generate stubs " + symbolFilePath.Rel(),
297 Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
298 Input: symbolFilePath,
299 Implicits: []android.Path{apiLevelsJson},
Dan Albert914449f2016-06-17 16:45:24 -0700300 Args: map[string]string{
301 "arch": arch,
Dan Willemsenb916b802017-03-19 13:44:32 -0700302 "apiLevel": apiLevel,
Dan Albert49927d22017-03-28 15:00:46 -0700303 "apiMap": apiLevelsJson.String(),
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900304 "flags": genstubFlags,
Dan Albert914449f2016-06-17 16:45:24 -0700305 },
306 })
307
Dan Albert914449f2016-06-17 16:45:24 -0700308 subdir := ""
Colin Cross2f336352016-10-26 10:03:47 -0700309 srcs := []android.Path{stubSrcPath}
Pirama Arumuga Nainar70ba5a32017-12-19 15:11:01 -0800310 return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath
Dan Willemsenb916b802017-03-19 13:44:32 -0700311}
312
313func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Nan Zhang0007d812017-11-07 10:57:05 -0800314 if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
Dan Albert15be0c62017-06-13 15:14:56 -0700315 ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
316 }
317
Nan Zhang0007d812017-11-07 10:57:05 -0800318 objs, versionScript := compileStubLibrary(ctx, flags, String(c.properties.Symbol_file),
319 c.properties.ApiLevel, "")
Dan Willemsenb916b802017-03-19 13:44:32 -0700320 c.versionScriptPath = versionScript
321 return objs
Dan Albert914449f2016-06-17 16:45:24 -0700322}
323
Colin Cross37047f12016-12-13 17:06:13 -0800324func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Dan Albert914449f2016-06-17 16:45:24 -0700325 return Deps{}
326}
327
Dan Willemsen01a90592017-04-07 15:21:13 -0700328func (linker *stubDecorator) Name(name string) string {
329 return name + ndkLibrarySuffix
330}
331
Colin Crossb916a382016-07-29 17:28:03 -0700332func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Dan Willemsen01a90592017-04-07 15:21:13 -0700333 stub.libraryDecorator.libName = ctx.baseModuleName()
Colin Crossb916a382016-07-29 17:28:03 -0700334 return stub.libraryDecorator.linkerFlags(ctx, flags)
Dan Albert914449f2016-06-17 16:45:24 -0700335}
336
Colin Crossb916a382016-07-29 17:28:03 -0700337func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700338 objs Objects) android.Path {
Dan Albert2bc91ba2016-07-28 17:40:28 -0700339
Dan Alberte67144e2018-05-03 15:42:34 -0700340 useVersionScript, err := shouldUseVersionScript(ctx, stub)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800341 if err != nil {
342 ctx.ModuleErrorf(err.Error())
343 }
344
345 if useVersionScript {
346 linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
Colin Cross4af21ed2019-11-04 09:37:55 -0800347 flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
Dan Willemsen939408a2019-06-10 18:02:25 -0700348 flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800349 }
350
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700351 return stub.libraryDecorator.link(ctx, flags, deps, objs)
Dan Albert2bc91ba2016-07-28 17:40:28 -0700352}
353
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700354func (stub *stubDecorator) nativeCoverage() bool {
355 return false
356}
357
Colin Crossb916a382016-07-29 17:28:03 -0700358func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
Dan Albert914449f2016-06-17 16:45:24 -0700359 arch := ctx.Target().Arch.ArchType.Name
Colin Crossb916a382016-07-29 17:28:03 -0700360 apiLevel := stub.properties.ApiLevel
Dan Albert914449f2016-06-17 16:45:24 -0700361
362 // arm64 isn't actually a multilib toolchain, so unlike the other LP64
363 // architectures it's just installed to lib.
364 libDir := "lib"
365 if ctx.toolchain().Is64Bit() && arch != "arm64" {
366 libDir = "lib64"
367 }
368
369 installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
Dan Albertfd86e9e2016-11-08 13:35:12 -0800370 "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir))
Colin Cross0875c522017-11-28 17:34:01 -0800371 stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
Dan Albert914449f2016-06-17 16:45:24 -0700372}
373
Colin Cross36242852017-06-23 15:06:31 -0700374func newStubLibrary() *Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800375 module, library := NewLibrary(android.DeviceSupported)
376 library.BuildOnlyShared()
Dan Albert914449f2016-06-17 16:45:24 -0700377 module.stl = nil
Colin Crossb916a382016-07-29 17:28:03 -0700378 module.sanitize = nil
Nan Zhang0007d812017-11-07 10:57:05 -0800379 library.StripProperties.Strip.None = BoolPtr(true)
Dan Albert914449f2016-06-17 16:45:24 -0700380
Colin Crossb916a382016-07-29 17:28:03 -0700381 stub := &stubDecorator{
382 libraryDecorator: library,
383 }
384 module.compiler = stub
385 module.linker = stub
386 module.installer = stub
Dan Albert914449f2016-06-17 16:45:24 -0700387
Colin Cross01fd7cc2020-02-19 16:54:04 -0800388 module.Properties.AlwaysSdk = true
389 module.Properties.Sdk_version = StringPtr("current")
390
Colin Cross36242852017-06-23 15:06:31 -0700391 module.AddProperties(&stub.properties, &library.MutatedProperties)
392
393 return module
Dan Albert914449f2016-06-17 16:45:24 -0700394}
395
Patrice Arruda6ea42112019-04-03 08:43:30 -0700396// ndk_library creates a stub library that exposes dummy implementation
397// of functions and variables for use at build time only.
Jooyung Hanb90e4912019-12-09 18:21:48 +0900398func NdkLibraryFactory() android.Module {
Colin Cross36242852017-06-23 15:06:31 -0700399 module := newStubLibrary()
400 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
dimitry03dc3f62019-05-09 14:07:34 +0200401 module.ModuleBase.EnableNativeBridgeSupportByDefault()
Colin Cross36242852017-06-23 15:06:31 -0700402 return module
Dan Albert914449f2016-06-17 16:45:24 -0700403}