Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 19 | "strings" |
Colin Cross | e8a67a7 | 2016-08-07 21:17:54 -0700 | [diff] [blame] | 20 | "sync" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
| 23 | |
| 24 | "android/soong/android" |
| 25 | ) |
| 26 | |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 27 | func init() { |
Dan Albert | 06f58af | 2020-06-22 15:10:31 -0700 | [diff] [blame] | 28 | pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen") |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 29 | pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser") |
| 30 | } |
| 31 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 32 | var ( |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 33 | genStubSrc = pctx.AndroidStaticRule("genStubSrc", |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 34 | blueprint.RuleParams{ |
Dan Albert | 06f58af | 2020-06-22 15:10:31 -0700 | [diff] [blame] | 35 | Command: "$ndkStubGenerator --arch $arch --api $apiLevel " + |
| 36 | "--api-map $apiMap $flags $in $out", |
| 37 | CommandDeps: []string{"$ndkStubGenerator"}, |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 38 | }, "arch", "apiLevel", "apiMap", "flags") |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 39 | |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 40 | parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule", |
| 41 | blueprint.RuleParams{ |
| 42 | Command: "$ndk_api_coverage_parser $in $out --api-map $apiMap", |
| 43 | CommandDeps: []string{"$ndk_api_coverage_parser"}, |
| 44 | }, "apiMap") |
| 45 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 46 | ndkLibrarySuffix = ".ndk" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 47 | |
Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 48 | // Added as a variation dependency via depsMutator. |
| 49 | ndkKnownLibs = []string{} |
| 50 | // protects ndkKnownLibs writes during parallel BeginMutator. |
| 51 | ndkKnownLibsLock sync.Mutex |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 52 | ) |
| 53 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 54 | // The First_version and Unversioned_until properties of this struct should not |
| 55 | // be used directly, but rather through the ApiLevel returning methods |
| 56 | // firstVersion() and unversionedUntil(). |
| 57 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 58 | // Creates a stub shared library based on the provided version file. |
| 59 | // |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 60 | // Example: |
| 61 | // |
| 62 | // ndk_library { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 63 | // name: "libfoo", |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 64 | // symbol_file: "libfoo.map.txt", |
| 65 | // first_version: "9", |
| 66 | // } |
| 67 | // |
| 68 | type libraryProperties struct { |
| 69 | // Relative path to the symbol map. |
| 70 | // An example file can be seen here: TODO(danalbert): Make an example. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 71 | Symbol_file *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 72 | |
| 73 | // The first API level a library was available. A library will be generated |
| 74 | // for every API level beginning with this one. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 75 | First_version *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 76 | |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 77 | // The first API level that library should have the version script applied. |
| 78 | // This defaults to the value of first_version, and should almost never be |
| 79 | // used. This is only needed to work around platform bugs like |
| 80 | // https://github.com/android-ndk/ndk/issues/265. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 81 | Unversioned_until *string |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 82 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 83 | // Use via apiLevel on the stubDecorator. |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 84 | ApiLevel string `blueprint:"mutated"` |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 85 | |
| 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 Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 92 | type stubDecorator struct { |
| 93 | *libraryDecorator |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 94 | |
| 95 | properties libraryProperties |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 96 | |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 97 | versionScriptPath android.ModuleGenPath |
| 98 | parsedCoverageXmlPath android.ModuleOutPath |
| 99 | installPath android.Path |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 100 | |
| 101 | apiLevel android.ApiLevel |
| 102 | firstVersion android.ApiLevel |
| 103 | unversionedUntil android.ApiLevel |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 106 | func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool { |
| 107 | return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil) |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 110 | func generatePerApiVariants(ctx android.BottomUpMutatorContext, m *Module, |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 111 | from android.ApiLevel, perSplit func(*Module, android.ApiLevel)) { |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 112 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 113 | var versions []android.ApiLevel |
| 114 | versionStrs := []string{} |
| 115 | for _, version := range ctx.Config().AllSupportedApiLevels() { |
| 116 | if version.GreaterThanOrEqualTo(from) { |
| 117 | versions = append(versions, version) |
| 118 | versionStrs = append(versionStrs, version.String()) |
| 119 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 120 | } |
Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame^] | 121 | versions = append(versions, android.FutureApiLevel) |
| 122 | versionStrs = append(versionStrs, android.FutureApiLevel.String()) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 123 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 124 | modules := ctx.CreateVariations(versionStrs...) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 125 | for i, module := range modules { |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 126 | perSplit(module.(*Module), versions[i]) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 130 | func NdkApiMutator(ctx android.BottomUpMutatorContext) { |
| 131 | if m, ok := ctx.Module().(*Module); ok { |
Colin Cross | d402582 | 2017-04-13 12:53:07 -0700 | [diff] [blame] | 132 | if m.Enabled() { |
| 133 | if compiler, ok := m.compiler.(*stubDecorator); ok { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 134 | if ctx.Os() != android.Android { |
| 135 | // These modules are always android.DeviceEnabled only, but |
| 136 | // those include Fuchsia devices, which we don't support. |
| 137 | ctx.Module().Disable() |
| 138 | return |
| 139 | } |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 140 | firstVersion, err := nativeApiLevelFromUser(ctx, |
| 141 | String(compiler.properties.First_version)) |
| 142 | if err != nil { |
| 143 | ctx.PropertyErrorf("first_version", err.Error()) |
| 144 | return |
| 145 | } |
| 146 | generatePerApiVariants(ctx, m, firstVersion, |
| 147 | func(m *Module, version android.ApiLevel) { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 148 | m.compiler.(*stubDecorator).properties.ApiLevel = |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 149 | version.String() |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 150 | }) |
| 151 | } else if m.SplitPerApiLevel() && m.IsSdkVariant() { |
| 152 | if ctx.Os() != android.Android { |
| 153 | return |
| 154 | } |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 155 | from, err := nativeApiLevelFromUser(ctx, m.MinSdkVersion()) |
| 156 | if err != nil { |
| 157 | ctx.PropertyErrorf("min_sdk_version", err.Error()) |
| 158 | return |
| 159 | } |
| 160 | generatePerApiVariants(ctx, m, from, |
| 161 | func(m *Module, version android.ApiLevel) { |
| 162 | m.Properties.Sdk_version = StringPtr(version.String()) |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 163 | }) |
Colin Cross | d402582 | 2017-04-13 12:53:07 -0700 | [diff] [blame] | 164 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 169 | func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool { |
| 170 | this.apiLevel = nativeApiLevelOrPanic(ctx, this.properties.ApiLevel) |
| 171 | |
| 172 | var err error |
| 173 | this.firstVersion, err = nativeApiLevelFromUser(ctx, |
| 174 | String(this.properties.First_version)) |
| 175 | if err != nil { |
| 176 | ctx.PropertyErrorf("first_version", err.Error()) |
| 177 | return false |
| 178 | } |
| 179 | |
| 180 | this.unversionedUntil, err = nativeApiLevelFromUserWithDefault(ctx, |
| 181 | String(this.properties.Unversioned_until), "minimum") |
| 182 | if err != nil { |
| 183 | ctx.PropertyErrorf("unversioned_until", err.Error()) |
| 184 | return false |
| 185 | } |
| 186 | |
| 187 | return true |
| 188 | } |
| 189 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 190 | func (c *stubDecorator) compilerInit(ctx BaseModuleContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 191 | c.baseCompiler.compilerInit(ctx) |
| 192 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 193 | name := ctx.baseModuleName() |
| 194 | if strings.HasSuffix(name, ndkLibrarySuffix) { |
| 195 | ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix) |
| 196 | } |
| 197 | |
Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 198 | ndkKnownLibsLock.Lock() |
| 199 | defer ndkKnownLibsLock.Unlock() |
| 200 | for _, lib := range ndkKnownLibs { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 201 | if lib == name { |
| 202 | return |
| 203 | } |
| 204 | } |
Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 205 | ndkKnownLibs = append(ndkKnownLibs, name) |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 208 | func addStubLibraryCompilerFlags(flags Flags) Flags { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 209 | flags.Global.CFlags = append(flags.Global.CFlags, |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 210 | // We're knowingly doing some otherwise unsightly things with builtin |
| 211 | // functions here. We're just generating stub libraries, so ignore it. |
| 212 | "-Wno-incompatible-library-redeclaration", |
Nick Desaulniers | eb20744 | 2019-12-12 10:15:42 -0800 | [diff] [blame] | 213 | "-Wno-incomplete-setjmp-declaration", |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 214 | "-Wno-builtin-requires-header", |
| 215 | "-Wno-invalid-noreturn", |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 216 | "-Wall", |
| 217 | "-Werror", |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 218 | // These libraries aren't actually used. Don't worry about unwinding |
| 219 | // (avoids the need to link an unwinder into a fake library). |
| 220 | "-fno-unwind-tables", |
| 221 | ) |
Jiyong Park | 48d75ef | 2019-11-21 15:11:49 +0900 | [diff] [blame] | 222 | // All symbols in the stubs library should be visible. |
| 223 | if inList("-fvisibility=hidden", flags.Local.CFlags) { |
| 224 | flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default") |
| 225 | } |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 226 | return flags |
| 227 | } |
| 228 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 229 | func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
| 230 | flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 231 | return addStubLibraryCompilerFlags(flags) |
| 232 | } |
| 233 | |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 234 | func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 235 | arch := ctx.Arch().ArchType.String() |
| 236 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 237 | stubSrcPath := android.PathForModuleGen(ctx, "stub.c") |
| 238 | versionScriptPath := android.PathForModuleGen(ctx, "stub.map") |
| 239 | symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) |
Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 240 | apiLevelsJson := android.GetApiLevelsJson(ctx) |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 241 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 242 | Rule: genStubSrc, |
| 243 | Description: "generate stubs " + symbolFilePath.Rel(), |
| 244 | Outputs: []android.WritablePath{stubSrcPath, versionScriptPath}, |
| 245 | Input: symbolFilePath, |
| 246 | Implicits: []android.Path{apiLevelsJson}, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 247 | Args: map[string]string{ |
| 248 | "arch": arch, |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 249 | "apiLevel": apiLevel, |
Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 250 | "apiMap": apiLevelsJson.String(), |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 251 | "flags": genstubFlags, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 252 | }, |
| 253 | }) |
| 254 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 255 | subdir := "" |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 256 | srcs := []android.Path{stubSrcPath} |
Pirama Arumuga Nainar | 70ba5a3 | 2017-12-19 15:11:01 -0800 | [diff] [blame] | 257 | return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 258 | } |
| 259 | |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 260 | func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath { |
| 261 | apiLevelsJson := android.GetApiLevelsJson(ctx) |
| 262 | symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) |
| 263 | outputFileName := strings.Split(symbolFilePath.Base(), ".")[0] |
| 264 | parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml") |
| 265 | ctx.Build(pctx, android.BuildParams{ |
| 266 | Rule: parseNdkApiRule, |
| 267 | Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(), |
| 268 | Outputs: []android.WritablePath{parsedApiCoveragePath}, |
| 269 | Input: symbolFilePath, |
sophiez | 148b317 | 2020-06-11 17:27:56 -0700 | [diff] [blame] | 270 | Implicits: []android.Path{apiLevelsJson}, |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 271 | Args: map[string]string{ |
| 272 | "apiMap": apiLevelsJson.String(), |
| 273 | }, |
| 274 | }) |
| 275 | return parsedApiCoveragePath |
| 276 | } |
| 277 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 278 | func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 279 | if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") { |
Dan Albert | 15be0c6 | 2017-06-13 15:14:56 -0700 | [diff] [blame] | 280 | ctx.PropertyErrorf("symbol_file", "must end with .map.txt") |
| 281 | } |
| 282 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 283 | if !c.initializeProperties(ctx) { |
| 284 | // Emits its own errors, so we don't need to. |
| 285 | return Objects{} |
| 286 | } |
| 287 | |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 288 | symbolFile := String(c.properties.Symbol_file) |
| 289 | objs, versionScript := compileStubLibrary(ctx, flags, symbolFile, |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 290 | c.apiLevel.String(), "") |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 291 | c.versionScriptPath = versionScript |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 292 | if c.apiLevel.IsCurrent() && ctx.PrimaryArch() { |
sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 293 | c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile) |
| 294 | } |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 295 | return objs |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 298 | func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 299 | return Deps{} |
| 300 | } |
| 301 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 302 | func (linker *stubDecorator) Name(name string) string { |
| 303 | return name + ndkLibrarySuffix |
| 304 | } |
| 305 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 306 | func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 307 | stub.libraryDecorator.libName = ctx.baseModuleName() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 308 | return stub.libraryDecorator.linkerFlags(ctx, flags) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 311 | func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 312 | objs Objects) android.Path { |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 313 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 314 | if shouldUseVersionScript(ctx, stub) { |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 315 | linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 316 | flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag) |
Dan Willemsen | 939408a | 2019-06-10 18:02:25 -0700 | [diff] [blame] | 317 | flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 320 | return stub.libraryDecorator.link(ctx, flags, deps, objs) |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 323 | func (stub *stubDecorator) nativeCoverage() bool { |
| 324 | return false |
| 325 | } |
| 326 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 327 | func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 328 | arch := ctx.Target().Arch.ArchType.Name |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 329 | // arm64 isn't actually a multilib toolchain, so unlike the other LP64 |
| 330 | // architectures it's just installed to lib. |
| 331 | libDir := "lib" |
| 332 | if ctx.toolchain().Is64Bit() && arch != "arm64" { |
| 333 | libDir = "lib64" |
| 334 | } |
| 335 | |
| 336 | installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf( |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 337 | "platforms/android-%s/arch-%s/usr/%s", stub.apiLevel, arch, libDir)) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 338 | stub.installPath = ctx.InstallFile(installDir, path.Base(), path) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 341 | func newStubLibrary() *Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 342 | module, library := NewLibrary(android.DeviceSupported) |
| 343 | library.BuildOnlyShared() |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 344 | module.stl = nil |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 345 | module.sanitize = nil |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 346 | library.disableStripping() |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 347 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 348 | stub := &stubDecorator{ |
| 349 | libraryDecorator: library, |
| 350 | } |
| 351 | module.compiler = stub |
| 352 | module.linker = stub |
| 353 | module.installer = stub |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 354 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 355 | module.Properties.AlwaysSdk = true |
| 356 | module.Properties.Sdk_version = StringPtr("current") |
| 357 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 358 | module.AddProperties(&stub.properties, &library.MutatedProperties) |
| 359 | |
| 360 | return module |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Dan Albert | f740ed0 | 2020-07-24 14:19:06 -0700 | [diff] [blame] | 363 | // ndk_library creates a library that exposes a stub implementation of functions |
| 364 | // and variables for use at build time only. |
Jooyung Han | b90e491 | 2019-12-09 18:21:48 +0900 | [diff] [blame] | 365 | func NdkLibraryFactory() android.Module { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 366 | module := newStubLibrary() |
| 367 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) |
dimitry | 03dc3f6 | 2019-05-09 14:07:34 +0200 | [diff] [blame] | 368 | module.ModuleBase.EnableNativeBridgeSupportByDefault() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 369 | return module |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 370 | } |