blob: 6299b009e12b766805805d6b10287e8164b8401c [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
Dan Albertde5aade2020-06-30 12:32:51 -070050 // Added as a variation dependency via depsMutator.
51 ndkKnownLibs = []string{}
52 // protects ndkKnownLibs writes during parallel BeginMutator.
53 ndkKnownLibsLock sync.Mutex
Dan Albert914449f2016-06-17 16:45:24 -070054)
55
56// Creates a stub shared library based on the provided version file.
57//
Dan Albert914449f2016-06-17 16:45:24 -070058// Example:
59//
60// ndk_library {
Dan Willemsen01a90592017-04-07 15:21:13 -070061// name: "libfoo",
Dan Albert914449f2016-06-17 16:45:24 -070062// symbol_file: "libfoo.map.txt",
63// first_version: "9",
64// }
65//
66type libraryProperties struct {
67 // Relative path to the symbol map.
68 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080069 Symbol_file *string
Dan Albert914449f2016-06-17 16:45:24 -070070
71 // The first API level a library was available. A library will be generated
72 // for every API level beginning with this one.
Nan Zhang0007d812017-11-07 10:57:05 -080073 First_version *string
Dan Albert914449f2016-06-17 16:45:24 -070074
Dan Albert98dbb3b2017-01-03 15:16:29 -080075 // The first API level that library should have the version script applied.
76 // This defaults to the value of first_version, and should almost never be
77 // used. This is only needed to work around platform bugs like
78 // https://github.com/android-ndk/ndk/issues/265.
Nan Zhang0007d812017-11-07 10:57:05 -080079 Unversioned_until *string
Dan Albert98dbb3b2017-01-03 15:16:29 -080080
Dan Albert914449f2016-06-17 16:45:24 -070081 // Private property for use by the mutator that splits per-API level.
Jooyung Hanaed150d2020-04-02 01:41:41 +090082 // can be one of <number:sdk_version> or <codename> or "current"
83 // passed to "gen_stub_libs.py" as it is
Dan Albertfd86e9e2016-11-08 13:35:12 -080084 ApiLevel string `blueprint:"mutated"`
Dan Albert23d37e02018-11-28 08:30:10 -080085
86 // True if this API is not yet ready to be shipped in the NDK. It will be
87 // available in the platform for testing, but will be excluded from the
88 // sysroot provided to the NDK proper.
89 Draft bool
Dan Albert914449f2016-06-17 16:45:24 -070090}
91
Colin Crossb916a382016-07-29 17:28:03 -070092type stubDecorator struct {
93 *libraryDecorator
Dan Albert914449f2016-06-17 16:45:24 -070094
95 properties libraryProperties
Dan Albert2bc91ba2016-07-28 17:40:28 -070096
sophiez58cabb72020-05-29 13:37:12 -070097 versionScriptPath android.ModuleGenPath
98 parsedCoverageXmlPath android.ModuleOutPath
99 installPath android.Path
Dan Albert914449f2016-06-17 16:45:24 -0700100}
101
102// OMG GO
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700103func intMax(a int, b int) int {
104 if a > b {
Dan Albert914449f2016-06-17 16:45:24 -0700105 return a
106 } else {
107 return b
108 }
109}
110
Colin Cross0ea8ba82019-06-06 14:33:29 -0700111func normalizeNdkApiLevel(ctx android.BaseModuleContext, apiLevel string,
Dan Albertf5415d72017-08-17 16:19:59 -0700112 arch android.Arch) (string, error) {
113
Dan Albert90f7a4d2016-11-08 14:34:24 -0800114 if apiLevel == "current" {
115 return apiLevel, nil
116 }
117
Colin Cross6510f912017-11-29 00:27:14 -0800118 minVersion := ctx.Config().MinSupportedSdkVersion()
Colin Crossce87b802017-04-13 13:00:26 -0700119 firstArchVersions := map[android.ArchType]int{
Dan Albertf5415d72017-08-17 16:19:59 -0700120 android.Arm: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700121 android.Arm64: 21,
Dan Albertf5415d72017-08-17 16:19:59 -0700122 android.X86: minVersion,
Colin Crossce87b802017-04-13 13:00:26 -0700123 android.X86_64: 21,
Dan Albert914449f2016-06-17 16:45:24 -0700124 }
125
Colin Crossce87b802017-04-13 13:00:26 -0700126 firstArchVersion, ok := firstArchVersions[arch.ArchType]
Dan Albert2e5d7d42017-03-29 18:22:39 -0700127 if !ok {
Colin Crossce87b802017-04-13 13:00:26 -0700128 panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType))
Dan Albert2e5d7d42017-03-29 18:22:39 -0700129 }
130
131 if apiLevel == "minimum" {
132 return strconv.Itoa(firstArchVersion), nil
133 }
134
Dan Albert914449f2016-06-17 16:45:24 -0700135 // If the NDK drops support for a platform version, we don't want to have to
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700136 // fix up every module that was using it as its SDK version. Clip to the
Dan Albert914449f2016-06-17 16:45:24 -0700137 // supported version here instead.
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700138 version, err := strconv.Atoi(apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700139 if err != nil {
Dan Albert90f7a4d2016-11-08 14:34:24 -0800140 return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel)
Dan Albert914449f2016-06-17 16:45:24 -0700141 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700142 version = intMax(version, minVersion)
143
Dan Albert90f7a4d2016-11-08 14:34:24 -0800144 return strconv.Itoa(intMax(version, firstArchVersion)), nil
145}
146
147func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) {
148 if firstSupportedVersion == "current" {
149 return platformVersion + 1, nil
150 }
151
152 return strconv.Atoi(firstSupportedVersion)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700153}
154
Colin Cross0ea8ba82019-06-06 14:33:29 -0700155func shouldUseVersionScript(ctx android.BaseModuleContext, stub *stubDecorator) (bool, error) {
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700156 // unversioned_until is normally empty, in which case we should use the version script.
157 if String(stub.properties.Unversioned_until) == "" {
158 return true, nil
159 }
Dan Albert98dbb3b2017-01-03 15:16:29 -0800160
Nan Zhang0007d812017-11-07 10:57:05 -0800161 if String(stub.properties.Unversioned_until) == "current" {
Dan Albert022e7a32017-01-05 15:49:09 -0800162 if stub.properties.ApiLevel == "current" {
163 return true, nil
164 } else {
165 return false, nil
166 }
167 }
168
Dan Albert98dbb3b2017-01-03 15:16:29 -0800169 if stub.properties.ApiLevel == "current" {
170 return true, nil
171 }
172
Dan Alberte67144e2018-05-03 15:42:34 -0700173 unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until))
Dan Albert98dbb3b2017-01-03 15:16:29 -0800174 if err != nil {
175 return true, err
176 }
177
Ryan Prichard37ebbde2018-07-24 12:37:24 -0700178 version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
179 if err != nil {
180 return true, err
Dan Alberte67144e2018-05-03 15:42:34 -0700181 }
182
Dan Albert98dbb3b2017-01-03 15:16:29 -0800183 return version >= unversionedUntil, nil
184}
185
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700186func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
Colin Cross6510f912017-11-29 00:27:14 -0800187 platformVersion := mctx.Config().PlatformSdkVersionInt()
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700188
Nan Zhang0007d812017-11-07 10:57:05 -0800189 firstSupportedVersion, err := normalizeNdkApiLevel(mctx, String(c.properties.First_version),
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700190 mctx.Arch())
191 if err != nil {
192 mctx.PropertyErrorf("first_version", err.Error())
Dan Albert914449f2016-06-17 16:45:24 -0700193 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700194
Dan Albert90f7a4d2016-11-08 14:34:24 -0800195 firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion)
196 if err != nil {
197 // In theory this is impossible because we've already run this through
198 // normalizeNdkApiLevel above.
199 mctx.PropertyErrorf("first_version", err.Error())
200 }
201
Dan Albertfd86e9e2016-11-08 13:35:12 -0800202 var versionStrs []string
Dan Albert90f7a4d2016-11-08 14:34:24 -0800203 for version := firstGenVersion; version <= platformVersion; version++ {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800204 versionStrs = append(versionStrs, strconv.Itoa(version))
Dan Albert914449f2016-06-17 16:45:24 -0700205 }
Colin Cross6510f912017-11-29 00:27:14 -0800206 versionStrs = append(versionStrs, mctx.Config().PlatformVersionActiveCodenames()...)
Dan Albertfd86e9e2016-11-08 13:35:12 -0800207 versionStrs = append(versionStrs, "current")
Dan Albert914449f2016-06-17 16:45:24 -0700208
209 modules := mctx.CreateVariations(versionStrs...)
210 for i, module := range modules {
Dan Albertfd86e9e2016-11-08 13:35:12 -0800211 module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i]
Dan Albert914449f2016-06-17 16:45:24 -0700212 }
213}
214
Jooyung Hanb90e4912019-12-09 18:21:48 +0900215func NdkApiMutator(mctx android.BottomUpMutatorContext) {
Dan Albert914449f2016-06-17 16:45:24 -0700216 if m, ok := mctx.Module().(*Module); ok {
Colin Crossd4025822017-04-13 12:53:07 -0700217 if m.Enabled() {
218 if compiler, ok := m.compiler.(*stubDecorator); ok {
219 generateStubApiVariants(mctx, compiler)
220 }
Dan Albert914449f2016-06-17 16:45:24 -0700221 }
222 }
223}
224
Colin Crossb916a382016-07-29 17:28:03 -0700225func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -0700226 c.baseCompiler.compilerInit(ctx)
227
Dan Willemsen01a90592017-04-07 15:21:13 -0700228 name := ctx.baseModuleName()
229 if strings.HasSuffix(name, ndkLibrarySuffix) {
230 ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix)
231 }
232
Dan Albertde5aade2020-06-30 12:32:51 -0700233 ndkKnownLibsLock.Lock()
234 defer ndkKnownLibsLock.Unlock()
235 for _, lib := range ndkKnownLibs {
Dan Albert7e9d2952016-08-04 13:02:36 -0700236 if lib == name {
237 return
238 }
239 }
Dan Albertde5aade2020-06-30 12:32:51 -0700240 ndkKnownLibs = append(ndkKnownLibs, name)
Dan Albert7e9d2952016-08-04 13:02:36 -0700241}
242
George Burgess IVf5310e32017-07-19 11:39:53 -0700243func addStubLibraryCompilerFlags(flags Flags) Flags {
Colin Cross4af21ed2019-11-04 09:37:55 -0800244 flags.Global.CFlags = append(flags.Global.CFlags,
George Burgess IVf5310e32017-07-19 11:39:53 -0700245 // We're knowingly doing some otherwise unsightly things with builtin
246 // functions here. We're just generating stub libraries, so ignore it.
247 "-Wno-incompatible-library-redeclaration",
Nick Desaulnierseb207442019-12-12 10:15:42 -0800248 "-Wno-incomplete-setjmp-declaration",
George Burgess IVf5310e32017-07-19 11:39:53 -0700249 "-Wno-builtin-requires-header",
250 "-Wno-invalid-noreturn",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800251 "-Wall",
252 "-Werror",
George Burgess IVf5310e32017-07-19 11:39:53 -0700253 // These libraries aren't actually used. Don't worry about unwinding
254 // (avoids the need to link an unwinder into a fake library).
255 "-fno-unwind-tables",
256 )
Jiyong Park48d75ef2019-11-21 15:11:49 +0900257 // All symbols in the stubs library should be visible.
258 if inList("-fvisibility=hidden", flags.Local.CFlags) {
259 flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
260 }
George Burgess IVf5310e32017-07-19 11:39:53 -0700261 return flags
262}
263
Colin Crossf18e1102017-11-16 14:33:08 -0800264func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
265 flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
George Burgess IVf5310e32017-07-19 11:39:53 -0700266 return addStubLibraryCompilerFlags(flags)
267}
268
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900269func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
Dan Albert914449f2016-06-17 16:45:24 -0700270 arch := ctx.Arch().ArchType.String()
271
Dan Willemsenb916b802017-03-19 13:44:32 -0700272 stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
273 versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
274 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
Dan Albert49927d22017-03-28 15:00:46 -0700275 apiLevelsJson := android.GetApiLevelsJson(ctx)
Colin Crossae887032017-10-23 17:16:14 -0700276 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700277 Rule: genStubSrc,
278 Description: "generate stubs " + symbolFilePath.Rel(),
279 Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
280 Input: symbolFilePath,
281 Implicits: []android.Path{apiLevelsJson},
Dan Albert914449f2016-06-17 16:45:24 -0700282 Args: map[string]string{
283 "arch": arch,
Dan Willemsenb916b802017-03-19 13:44:32 -0700284 "apiLevel": apiLevel,
Dan Albert49927d22017-03-28 15:00:46 -0700285 "apiMap": apiLevelsJson.String(),
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900286 "flags": genstubFlags,
Dan Albert914449f2016-06-17 16:45:24 -0700287 },
288 })
289
Dan Albert914449f2016-06-17 16:45:24 -0700290 subdir := ""
Colin Cross2f336352016-10-26 10:03:47 -0700291 srcs := []android.Path{stubSrcPath}
Pirama Arumuga Nainar70ba5a32017-12-19 15:11:01 -0800292 return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath
Dan Willemsenb916b802017-03-19 13:44:32 -0700293}
294
sophiez58cabb72020-05-29 13:37:12 -0700295func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath {
296 apiLevelsJson := android.GetApiLevelsJson(ctx)
297 symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
298 outputFileName := strings.Split(symbolFilePath.Base(), ".")[0]
299 parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml")
300 ctx.Build(pctx, android.BuildParams{
301 Rule: parseNdkApiRule,
302 Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(),
303 Outputs: []android.WritablePath{parsedApiCoveragePath},
304 Input: symbolFilePath,
sophiez148b3172020-06-11 17:27:56 -0700305 Implicits: []android.Path{apiLevelsJson},
sophiez58cabb72020-05-29 13:37:12 -0700306 Args: map[string]string{
307 "apiMap": apiLevelsJson.String(),
308 },
309 })
310 return parsedApiCoveragePath
311}
312
Dan Willemsenb916b802017-03-19 13:44:32 -0700313func (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
sophiez58cabb72020-05-29 13:37:12 -0700318 symbolFile := String(c.properties.Symbol_file)
319 objs, versionScript := compileStubLibrary(ctx, flags, symbolFile,
Nan Zhang0007d812017-11-07 10:57:05 -0800320 c.properties.ApiLevel, "")
Dan Willemsenb916b802017-03-19 13:44:32 -0700321 c.versionScriptPath = versionScript
sophiez58cabb72020-05-29 13:37:12 -0700322 if c.properties.ApiLevel == "current" && ctx.PrimaryArch() {
323 c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
324 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700325 return objs
Dan Albert914449f2016-06-17 16:45:24 -0700326}
327
Colin Cross37047f12016-12-13 17:06:13 -0800328func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Dan Albert914449f2016-06-17 16:45:24 -0700329 return Deps{}
330}
331
Dan Willemsen01a90592017-04-07 15:21:13 -0700332func (linker *stubDecorator) Name(name string) string {
333 return name + ndkLibrarySuffix
334}
335
Colin Crossb916a382016-07-29 17:28:03 -0700336func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Dan Willemsen01a90592017-04-07 15:21:13 -0700337 stub.libraryDecorator.libName = ctx.baseModuleName()
Colin Crossb916a382016-07-29 17:28:03 -0700338 return stub.libraryDecorator.linkerFlags(ctx, flags)
Dan Albert914449f2016-06-17 16:45:24 -0700339}
340
Colin Crossb916a382016-07-29 17:28:03 -0700341func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700342 objs Objects) android.Path {
Dan Albert2bc91ba2016-07-28 17:40:28 -0700343
Dan Alberte67144e2018-05-03 15:42:34 -0700344 useVersionScript, err := shouldUseVersionScript(ctx, stub)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800345 if err != nil {
346 ctx.ModuleErrorf(err.Error())
347 }
348
349 if useVersionScript {
350 linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
Colin Cross4af21ed2019-11-04 09:37:55 -0800351 flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
Dan Willemsen939408a2019-06-10 18:02:25 -0700352 flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
Dan Albert98dbb3b2017-01-03 15:16:29 -0800353 }
354
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700355 return stub.libraryDecorator.link(ctx, flags, deps, objs)
Dan Albert2bc91ba2016-07-28 17:40:28 -0700356}
357
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700358func (stub *stubDecorator) nativeCoverage() bool {
359 return false
360}
361
Colin Crossb916a382016-07-29 17:28:03 -0700362func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
Dan Albert914449f2016-06-17 16:45:24 -0700363 arch := ctx.Target().Arch.ArchType.Name
Colin Crossb916a382016-07-29 17:28:03 -0700364 apiLevel := stub.properties.ApiLevel
Dan Albert914449f2016-06-17 16:45:24 -0700365
366 // arm64 isn't actually a multilib toolchain, so unlike the other LP64
367 // architectures it's just installed to lib.
368 libDir := "lib"
369 if ctx.toolchain().Is64Bit() && arch != "arm64" {
370 libDir = "lib64"
371 }
372
373 installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
Dan Albertfd86e9e2016-11-08 13:35:12 -0800374 "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir))
Colin Cross0875c522017-11-28 17:34:01 -0800375 stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
Dan Albert914449f2016-06-17 16:45:24 -0700376}
377
Colin Cross36242852017-06-23 15:06:31 -0700378func newStubLibrary() *Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800379 module, library := NewLibrary(android.DeviceSupported)
380 library.BuildOnlyShared()
Dan Albert914449f2016-06-17 16:45:24 -0700381 module.stl = nil
Colin Crossb916a382016-07-29 17:28:03 -0700382 module.sanitize = nil
Nan Zhang0007d812017-11-07 10:57:05 -0800383 library.StripProperties.Strip.None = BoolPtr(true)
Dan Albert914449f2016-06-17 16:45:24 -0700384
Colin Crossb916a382016-07-29 17:28:03 -0700385 stub := &stubDecorator{
386 libraryDecorator: library,
387 }
388 module.compiler = stub
389 module.linker = stub
390 module.installer = stub
Dan Albert914449f2016-06-17 16:45:24 -0700391
Colin Crossc511bc52020-04-07 16:50:32 +0000392 module.Properties.AlwaysSdk = true
393 module.Properties.Sdk_version = StringPtr("current")
394
Colin Cross36242852017-06-23 15:06:31 -0700395 module.AddProperties(&stub.properties, &library.MutatedProperties)
396
397 return module
Dan Albert914449f2016-06-17 16:45:24 -0700398}
399
Patrice Arruda6ea42112019-04-03 08:43:30 -0700400// ndk_library creates a stub library that exposes dummy implementation
401// of functions and variables for use at build time only.
Jooyung Hanb90e4912019-12-09 18:21:48 +0900402func NdkLibraryFactory() android.Module {
Colin Cross36242852017-06-23 15:06:31 -0700403 module := newStubLibrary()
404 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
dimitry03dc3f62019-05-09 14:07:34 +0200405 module.ModuleBase.EnableNativeBridgeSupportByDefault()
Colin Cross36242852017-06-23 15:06:31 -0700406 return module
Dan Albert914449f2016-06-17 16:45:24 -0700407}