blob: 5ef9a7838bb825bc158863e3994dfd9964368ee8 [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() {
29 pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
30}
31
Dan Albert914449f2016-06-17 16:45:24 -070032var (
sophiezb858c6d2020-05-06 15:57:32 -070033 toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/scriptlib/gen_stub_libs.py")
Dan Albert914449f2016-06-17 16:45:24 -070034
Colin Cross9d45bb72016-08-29 16:14:13 -070035 genStubSrc = pctx.AndroidStaticRule("genStubSrc",
Dan Albert914449f2016-06-17 16:45:24 -070036 blueprint.RuleParams{
Dan Albert49927d22017-03-28 15:00:46 -070037 Command: "$toolPath --arch $arch --api $apiLevel --api-map " +
Jiyong Park3fd0baf2018-12-07 16:25:39 +090038 "$apiMap $flags $in $out",
Dan Albert914449f2016-06-17 16:45:24 -070039 CommandDeps: []string{"$toolPath"},
Jiyong Park3fd0baf2018-12-07 16:25:39 +090040 }, "arch", "apiLevel", "apiMap", "flags")
Dan Albert914449f2016-06-17 16:45:24 -070041
sophiez58cabb72020-05-29 13:37:12 -070042 parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule",
43 blueprint.RuleParams{
44 Command: "$ndk_api_coverage_parser $in $out --api-map $apiMap",
45 CommandDeps: []string{"$ndk_api_coverage_parser"},
46 }, "apiMap")
47
Dan Albert914449f2016-06-17 16:45:24 -070048 ndkLibrarySuffix = ".ndk"
Colin Cross4d9c2d12016-07-29 12:48:20 -070049
50 ndkPrebuiltSharedLibs = []string{
Sasha Smundakb500ce52019-03-19 17:13:17 -070051 "aaudio",
52 "amidi",
Colin Cross4d9c2d12016-07-29 12:48:20 -070053 "android",
Steven Morelandfa287842018-08-29 20:14:18 -070054 "binder_ndk",
Colin Cross4d9c2d12016-07-29 12:48:20 -070055 "c",
Sasha Smundakb500ce52019-03-19 17:13:17 -070056 "camera2ndk",
Colin Cross4d9c2d12016-07-29 12:48:20 -070057 "dl",
58 "EGL",
59 "GLESv1_CM",
60 "GLESv2",
61 "GLESv3",
62 "jnigraphics",
63 "log",
64 "mediandk",
Sasha Smundakb500ce52019-03-19 17:13:17 -070065 "nativewindow",
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 "m",
Slava Shklyaevaef0d6e2019-07-24 14:08:18 +010067 "neuralnetworks",
Colin Cross4d9c2d12016-07-29 12:48:20 -070068 "OpenMAXAL",
69 "OpenSLES",
70 "stdc++",
Dan Willemsen62b9cf92019-02-06 18:40:16 -080071 "sync",
Colin Cross4d9c2d12016-07-29 12:48:20 -070072 "vulkan",
73 "z",
74 }
75 ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib")
76
77 // These libraries have migrated over to the new ndk_library, which is added
78 // as a variation dependency via depsMutator.
Colin Crosse8a67a72016-08-07 21:17:54 -070079 ndkMigratedLibs = []string{}
Colin Crosse40b4ea2018-10-02 22:25:58 -070080 ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel BeginMutator
Dan Albert914449f2016-06-17 16:45:24 -070081)
82
83// Creates a stub shared library based on the provided version file.
84//
Dan Albert914449f2016-06-17 16:45:24 -070085// Example:
86//
87// ndk_library {
Dan Willemsen01a90592017-04-07 15:21:13 -070088// name: "libfoo",
Dan Albert914449f2016-06-17 16:45:24 -070089// symbol_file: "libfoo.map.txt",
90// first_version: "9",
91// }
92//
93type libraryProperties struct {
94 // Relative path to the symbol map.
95 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080096 Symbol_file *string
Dan Albert914449f2016-06-17 16:45:24 -070097
98 // The first API level a library was available. A library will be generated
99 // for every API level beginning with this one.
Nan Zhang0007d812017-11-07 10:57:05 -0800100 First_version *string
Dan Albert914449f2016-06-17 16:45:24 -0700101
Dan Albert98dbb3b2017-01-03 15:16:29 -0800102 // The first API level that library should have the version script applied.
103 // This defaults to the value of first_version, and should almost never be
104 // used. This is only needed to work around platform bugs like
105 // https://github.com/android-ndk/ndk/issues/265.
Nan Zhang0007d812017-11-07 10:57:05 -0800106 Unversioned_until *string
Dan Albert98dbb3b2017-01-03 15:16:29 -0800107
Dan Albert914449f2016-06-17 16:45:24 -0700108 // Private property for use by the mutator that splits per-API level.
Jooyung Hanaed150d2020-04-02 01:41:41 +0900109 // can be one of <number:sdk_version> or <codename> or "current"
110 // passed to "gen_stub_libs.py" as it is
Dan Albertfd86e9e2016-11-08 13:35:12 -0800111 ApiLevel string `blueprint:"mutated"`
Dan Albert23d37e02018-11-28 08:30:10 -0800112
113 // True if this API is not yet ready to be shipped in the NDK. It will be
114 // available in the platform for testing, but will be excluded from the
115 // sysroot provided to the NDK proper.
116 Draft bool
Dan Albert914449f2016-06-17 16:45:24 -0700117}
118
Colin Crossb916a382016-07-29 17:28:03 -0700119type stubDecorator struct {
120 *libraryDecorator
Dan Albert914449f2016-06-17 16:45:24 -0700121
122 properties libraryProperties
Dan Albert2bc91ba2016-07-28 17:40:28 -0700123
sophiez58cabb72020-05-29 13:37:12 -0700124 versionScriptPath android.ModuleGenPath
125 parsedCoverageXmlPath android.ModuleOutPath
126 installPath android.Path
Dan Albert914449f2016-06-17 16:45:24 -0700127}
128
129// OMG GO
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700130func intMax(a int, b int) int {
131 if a > b {
Dan Albert914449f2016-06-17 16:45:24 -0700132 return a
133 } else {
134 return b
135 }
136}
137
Colin Cross0ea8ba82019-06-06 14:33:29 -0700138func normalizeNdkApiLevel(ctx android.BaseModuleContext, apiLevel string,
Dan Albertf5415d72017-08-17 16:19:59 -0700139 arch android.Arch) (string, error) {
140
Dan Albert90f7a4d2016-11-08 14:34:24 -0800141 if apiLevel == "current" {
142 return apiLevel, nil
143 }
144
Colin Cross6510f912017-11-29 00:27:14 -0800145 minVersion := ctx.Config().MinSupportedSdkVersion()
Colin Crossce87b802017-04-13 13:00:26 -0700146 firstArchVersions := map[android.ArchType]int{
Dan Albertf5415d72017-08-17 16:19:59 -0700147 android.Arm: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700148 android.Arm64: 21,
Dan Albertf5415d72017-08-17 16:19:59 -0700149 android.X86: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700150 android.X86_64: 21,
Dan Albert914449f2016-06-17 16:45:24 -0700151 }
152
Colin Crossce87b802017-04-13 13:00:26 -0700153 firstArchVersion, ok := firstArchVersions[arch.ArchType]
Dan Albert2e5d7d42017-03-29 18:22:39 -0700154 if !ok {
Colin Crossce87b802017-04-13 13:00:26 -0700155 panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType))
Dan Albert2e5d7d42017-03-29 18:22:39 -0700156 }
157
158 if apiLevel == "minimum" {
159 return strconv.Itoa(firstArchVersion), nil
160 }
161
Dan Albert914449f2016-06-17 16:45:24 -0700162 // If the NDK drops support for a platform version, we don't want to have to
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700163 // fix up every module that was using it as its SDK version. Clip to the
Dan Albert914449f2016-06-17 16:45:24 -0700164 // supported version here instead.
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700165 version, err := strconv.Atoi(apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700166 if err != nil {
Dan Albert90f7a4d2016-11-08 14:34:24 -0800167 return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700168 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700169 version = intMax(version, minVersion)
170
Dan Albert90f7a4d2016-11-08 14:34:24 -0800171 return strconv.Itoa(intMax(version, firstArchVersion)), nil
172}
173
174func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) {
175 if firstSupportedVersion == "current" {
176 return platformVersion + 1, nil
177 }
178
179 return strconv.Atoi(firstSupportedVersion)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700180}
181
Colin Cross0ea8ba82019-06-06 14:33:29 -0700182func shouldUseVersionScript(ctx android.BaseModuleContext, stub *stubDecorator) (bool, error) {
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700183 // unversioned_until is normally empty, in which case we should use the version script.
184 if String(stub.properties.Unversioned_until) == "" {
185 return true, nil
186 }
Dan Albert98dbb3b2017-01-03 15:16:29 -0800187
Nan Zhang0007d812017-11-07 10:57:05 -0800188 if String(stub.properties.Unversioned_until) == "current" {
Dan Albert022e7a32017-01-05 15:49:09 -0800189 if stub.properties.ApiLevel == "current" {
190 return true, nil
191 } else {
192 return false, nil
193 }
194 }
195
Dan Albert98dbb3b2017-01-03 15:16:29 -0800196 if stub.properties.ApiLevel == "current" {
197 return true, nil
198 }
199
Dan Alberte67144e2018-05-03 15:42:34 -0700200 unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until))
Dan Albert98dbb3b2017-01-03 15:16:29 -0800201 if err != nil {
202 return true, err
203 }
204
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700205 version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
206 if err != nil {
207 return true, err
Dan Alberte67144e2018-05-03 15:42:34 -0700208 }
209
Dan Albert98dbb3b2017-01-03 15:16:29 -0800210 return version >= unversionedUntil, nil
211}
212
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700213func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
Colin Cross6510f912017-11-29 00:27:14 -0800214 platformVersion := mctx.Config().PlatformSdkVersionInt()
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700215
Nan Zhang0007d812017-11-07 10:57:05 -0800216 firstSupportedVersion, err := normalizeNdkApiLevel(mctx, String(c.properties.First_version),
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700217 mctx.Arch())
218 if err != nil {
219 mctx.PropertyErrorf("first_version", err.Error())
Dan Albert914449f2016-06-17 16:45:24 -0700220 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700221
Dan Albert90f7a4d2016-11-08 14:34:24 -0800222 firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion)
223 if err != nil {
224 // In theory this is impossible because we've already run this through
225 // normalizeNdkApiLevel above.
226 mctx.PropertyErrorf("first_version", err.Error())
227 }
228
Dan Albertfd86e9e2016-11-08 13:35:12 -0800229 var versionStrs []string
Dan Albert90f7a4d2016-11-08 14:34:24 -0800230 for version := firstGenVersion; version <= platformVersion; version++ {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800231 versionStrs = append(versionStrs, strconv.Itoa(version))
Dan Albert914449f2016-06-17 16:45:24 -0700232 }
Colin Cross6510f912017-11-29 00:27:14 -0800233 versionStrs = append(versionStrs, mctx.Config().PlatformVersionActiveCodenames()...)
Dan Albertfd86e9e2016-11-08 13:35:12 -0800234 versionStrs = append(versionStrs, "current")
Dan Albert914449f2016-06-17 16:45:24 -0700235
236 modules := mctx.CreateVariations(versionStrs...)
237 for i, module := range modules {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800238 module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i]
Dan Albert914449f2016-06-17 16:45:24 -0700239 }
240}
241
Jooyung Hanb90e4912019-12-09 18:21:48 +0900242func NdkApiMutator(mctx android.BottomUpMutatorContext) {
Dan Albert914449f2016-06-17 16:45:24 -0700243 if m, ok := mctx.Module().(*Module); ok {
Colin Crossd4025822017-04-13 12:53:07 -0700244 if m.Enabled() {
245 if compiler, ok := m.compiler.(*stubDecorator); ok {
246 generateStubApiVariants(mctx, compiler)
247 }
Dan Albert914449f2016-06-17 16:45:24 -0700248 }
249 }
250}
251
Colin Crossb916a382016-07-29 17:28:03 -0700252func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -0700253 c.baseCompiler.compilerInit(ctx)
254
Dan Willemsen01a90592017-04-07 15:21:13 -0700255 name := ctx.baseModuleName()
256 if strings.HasSuffix(name, ndkLibrarySuffix) {
257 ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
258 }
259
Colin Crosse8a67a72016-08-07 21:17:54 -0700260 ndkMigratedLibsLock.Lock()
261 defer ndkMigratedLibsLock.Unlock()
Dan Albert7e9d2952016-08-04 13:02:36 -0700262 for _, lib := range ndkMigratedLibs {
263 if lib == name {
264 return
265 }
266 }
267 ndkMigratedLibs = append(ndkMigratedLibs, name)
268}
269
George Burgess IVf5310e32017-07-19 11:39:53 -0700270func addStubLibraryCompilerFlags(flags Flags) Flags {
Colin Cross4af21ed2019-11-04 09:37:55 -0800271 flags.Global.CFlags = append(flags.Global.CFlags,
George Burgess IVf5310e32017-07-19 11:39:53 -0700272 // We're knowingly doing some otherwise unsightly things with builtin
273 // functions here. We're just generating stub libraries, so ignore it.
274 "-Wno-incompatible-library-redeclaration",
Nick Desaulnierseb207442019-12-12 10:15:42 -0800275 "-Wno-incomplete-setjmp-declaration",
George Burgess IVf5310e32017-07-19 11:39:53 -0700276 "-Wno-builtin-requires-header",
277 "-Wno-invalid-noreturn",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800278 "-Wall",
279 "-Werror",
George Burgess IVf5310e32017-07-19 11:39:53 -0700280 // These libraries aren't actually used. Don't worry about unwinding
281 // (avoids the need to link an unwinder into a fake library).
282 "-fno-unwind-tables",
283 )
Jiyong Park48d75ef2019-11-21 15:11:49 +0900284 // All symbols in the stubs library should be visible.
285 if inList("-fvisibility=hidden", flags.Local.CFlags) {
286 flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
287 }
George Burgess IVf5310e32017-07-19 11:39:53 -0700288 return flags
289}
290
Colin Crossf18e1102017-11-16 14:33:08 -0800291func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
292 flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
George Burgess IVf5310e32017-07-19 11:39:53 -0700293 return addStubLibraryCompilerFlags(flags)
294}
295
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900296func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
Dan Albert914449f2016-06-17 16:45:24 -0700297 arch := ctx.Arch().ArchType.String()
298
Dan Willemsenb916b802017-03-19 13:44:32 -0700299 stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
300 versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
301 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
Dan Albert49927d22017-03-28 15:00:46 -0700302 apiLevelsJson := android.GetApiLevelsJson(ctx)
Colin Crossae887032017-10-23 17:16:14 -0700303 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700304 Rule: genStubSrc,
305 Description: "generate stubs " + symbolFilePath.Rel(),
306 Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
307 Input: symbolFilePath,
308 Implicits: []android.Path{apiLevelsJson},
Dan Albert914449f2016-06-17 16:45:24 -0700309 Args: map[string]string{
310 "arch": arch,
Dan Willemsenb916b802017-03-19 13:44:32 -0700311 "apiLevel": apiLevel,
Dan Albert49927d22017-03-28 15:00:46 -0700312 "apiMap": apiLevelsJson.String(),
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900313 "flags": genstubFlags,
Dan Albert914449f2016-06-17 16:45:24 -0700314 },
315 })
316
Dan Albert914449f2016-06-17 16:45:24 -0700317 subdir := ""
Colin Cross2f336352016-10-26 10:03:47 -0700318 srcs := []android.Path{stubSrcPath}
Pirama Arumuga Nainar70ba5a32017-12-19 15:11:01 -0800319 return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath
Dan Willemsenb916b802017-03-19 13:44:32 -0700320}
321
sophiez58cabb72020-05-29 13:37:12 -0700322func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath {
323 apiLevelsJson := android.GetApiLevelsJson(ctx)
324 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
325 outputFileName := strings.Split(symbolFilePath.Base(), ".")[0]
326 parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml")
327 ctx.Build(pctx, android.BuildParams{
328 Rule: parseNdkApiRule,
329 Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(),
330 Outputs: []android.WritablePath{parsedApiCoveragePath},
331 Input: symbolFilePath,
sophiez148b3172020-06-11 17:27:56 -0700332 Implicits: []android.Path{apiLevelsJson},
sophiez58cabb72020-05-29 13:37:12 -0700333 Args: map[string]string{
334 "apiMap": apiLevelsJson.String(),
335 },
336 })
337 return parsedApiCoveragePath
338}
339
Dan Willemsenb916b802017-03-19 13:44:32 -0700340func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Nan Zhang0007d812017-11-07 10:57:05 -0800341 if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
Dan Albert15be0c62017-06-13 15:14:56 -0700342 ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
343 }
344
sophiez58cabb72020-05-29 13:37:12 -0700345 symbolFile := String(c.properties.Symbol_file)
346 objs, versionScript := compileStubLibrary(ctx, flags, symbolFile,
Nan Zhang0007d812017-11-07 10:57:05 -0800347 c.properties.ApiLevel, "")
Dan Willemsenb916b802017-03-19 13:44:32 -0700348 c.versionScriptPath = versionScript
sophiez58cabb72020-05-29 13:37:12 -0700349 if c.properties.ApiLevel == "current" && ctx.PrimaryArch() {
350 c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
351 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700352 return objs
Dan Albert914449f2016-06-17 16:45:24 -0700353}
354
Colin Cross37047f12016-12-13 17:06:13 -0800355func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Dan Albert914449f2016-06-17 16:45:24 -0700356 return Deps{}
357}
358
Dan Willemsen01a90592017-04-07 15:21:13 -0700359func (linker *stubDecorator) Name(name string) string {
360 return name + ndkLibrarySuffix
361}
362
Colin Crossb916a382016-07-29 17:28:03 -0700363func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Dan Willemsen01a90592017-04-07 15:21:13 -0700364 stub.libraryDecorator.libName = ctx.baseModuleName()
Colin Crossb916a382016-07-29 17:28:03 -0700365 return stub.libraryDecorator.linkerFlags(ctx, flags)
Dan Albert914449f2016-06-17 16:45:24 -0700366}
367
Colin Crossb916a382016-07-29 17:28:03 -0700368func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700369 objs Objects) android.Path {
Dan Albert2bc91ba2016-07-28 17:40:28 -0700370
Dan Alberte67144e2018-05-03 15:42:34 -0700371 useVersionScript, err := shouldUseVersionScript(ctx, stub)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800372 if err != nil {
373 ctx.ModuleErrorf(err.Error())
374 }
375
376 if useVersionScript {
377 linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
Colin Cross4af21ed2019-11-04 09:37:55 -0800378 flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
Dan Willemsen939408a2019-06-10 18:02:25 -0700379 flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800380 }
381
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700382 return stub.libraryDecorator.link(ctx, flags, deps, objs)
Dan Albert2bc91ba2016-07-28 17:40:28 -0700383}
384
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700385func (stub *stubDecorator) nativeCoverage() bool {
386 return false
387}
388
Colin Crossb916a382016-07-29 17:28:03 -0700389func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
Dan Albert914449f2016-06-17 16:45:24 -0700390 arch := ctx.Target().Arch.ArchType.Name
Colin Crossb916a382016-07-29 17:28:03 -0700391 apiLevel := stub.properties.ApiLevel
Dan Albert914449f2016-06-17 16:45:24 -0700392
393 // arm64 isn't actually a multilib toolchain, so unlike the other LP64
394 // architectures it's just installed to lib.
395 libDir := "lib"
396 if ctx.toolchain().Is64Bit() && arch != "arm64" {
397 libDir = "lib64"
398 }
399
400 installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
Dan Albertfd86e9e2016-11-08 13:35:12 -0800401 "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir))
Colin Cross0875c522017-11-28 17:34:01 -0800402 stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
Dan Albert914449f2016-06-17 16:45:24 -0700403}
404
Colin Cross36242852017-06-23 15:06:31 -0700405func newStubLibrary() *Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800406 module, library := NewLibrary(android.DeviceSupported)
407 library.BuildOnlyShared()
Dan Albert914449f2016-06-17 16:45:24 -0700408 module.stl = nil
Colin Crossb916a382016-07-29 17:28:03 -0700409 module.sanitize = nil
Nan Zhang0007d812017-11-07 10:57:05 -0800410 library.StripProperties.Strip.None = BoolPtr(true)
Dan Albert914449f2016-06-17 16:45:24 -0700411
Colin Crossb916a382016-07-29 17:28:03 -0700412 stub := &stubDecorator{
413 libraryDecorator: library,
414 }
415 module.compiler = stub
416 module.linker = stub
417 module.installer = stub
Dan Albert914449f2016-06-17 16:45:24 -0700418
Colin Crossc511bc52020-04-07 16:50:32 +0000419 module.Properties.AlwaysSdk = true
420 module.Properties.Sdk_version = StringPtr("current")
421
Colin Cross36242852017-06-23 15:06:31 -0700422 module.AddProperties(&stub.properties, &library.MutatedProperties)
423
424 return module
Dan Albert914449f2016-06-17 16:45:24 -0700425}
426
Patrice Arruda6ea42112019-04-03 08:43:30 -0700427// ndk_library creates a stub library that exposes dummy implementation
428// of functions and variables for use at build time only.
Jooyung Hanb90e4912019-12-09 18:21:48 +0900429func NdkLibraryFactory() android.Module {
Colin Cross36242852017-06-23 15:06:31 -0700430 module := newStubLibrary()
431 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
dimitry03dc3f62019-05-09 14:07:34 +0200432 module.ModuleBase.EnableNativeBridgeSupportByDefault()
Colin Cross36242852017-06-23 15:06:31 -0700433 return module
Dan Albert914449f2016-06-17 16:45:24 -0700434}