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" |
| 19 | "strconv" |
| 20 | "strings" |
Colin Cross | e8a67a7 | 2016-08-07 21:17:54 -0700 | [diff] [blame] | 21 | "sync" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/gen_stub_libs.py") |
| 30 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 31 | genStubSrc = pctx.AndroidStaticRule("genStubSrc", |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 32 | blueprint.RuleParams{ |
Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 33 | Command: "$toolPath --arch $arch --api $apiLevel --api-map " + |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 34 | "$apiMap $flags $in $out", |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 35 | CommandDeps: []string{"$toolPath"}, |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 36 | }, "arch", "apiLevel", "apiMap", "flags") |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 37 | |
| 38 | ndkLibrarySuffix = ".ndk" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 39 | |
| 40 | ndkPrebuiltSharedLibs = []string{ |
Sasha Smundak | b500ce5 | 2019-03-19 17:13:17 -0700 | [diff] [blame] | 41 | "aaudio", |
| 42 | "amidi", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 43 | "android", |
Steven Moreland | fa28784 | 2018-08-29 20:14:18 -0700 | [diff] [blame] | 44 | "binder_ndk", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 45 | "c", |
Sasha Smundak | b500ce5 | 2019-03-19 17:13:17 -0700 | [diff] [blame] | 46 | "camera2ndk", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 47 | "dl", |
| 48 | "EGL", |
| 49 | "GLESv1_CM", |
| 50 | "GLESv2", |
| 51 | "GLESv3", |
| 52 | "jnigraphics", |
| 53 | "log", |
| 54 | "mediandk", |
Sasha Smundak | b500ce5 | 2019-03-19 17:13:17 -0700 | [diff] [blame] | 55 | "nativewindow", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 56 | "m", |
| 57 | "OpenMAXAL", |
| 58 | "OpenSLES", |
| 59 | "stdc++", |
Dan Willemsen | 62b9cf9 | 2019-02-06 18:40:16 -0800 | [diff] [blame] | 60 | "sync", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 61 | "vulkan", |
| 62 | "z", |
| 63 | } |
| 64 | ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib") |
| 65 | |
| 66 | // These libraries have migrated over to the new ndk_library, which is added |
| 67 | // as a variation dependency via depsMutator. |
Colin Cross | e8a67a7 | 2016-08-07 21:17:54 -0700 | [diff] [blame] | 68 | ndkMigratedLibs = []string{} |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 69 | ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel BeginMutator |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | // Creates a stub shared library based on the provided version file. |
| 73 | // |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 74 | // Example: |
| 75 | // |
| 76 | // ndk_library { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 77 | // name: "libfoo", |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 78 | // symbol_file: "libfoo.map.txt", |
| 79 | // first_version: "9", |
| 80 | // } |
| 81 | // |
| 82 | type libraryProperties struct { |
| 83 | // Relative path to the symbol map. |
| 84 | // An example file can be seen here: TODO(danalbert): Make an example. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 85 | Symbol_file *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 86 | |
| 87 | // The first API level a library was available. A library will be generated |
| 88 | // for every API level beginning with this one. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 89 | First_version *string |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 90 | |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 91 | // The first API level that library should have the version script applied. |
| 92 | // This defaults to the value of first_version, and should almost never be |
| 93 | // used. This is only needed to work around platform bugs like |
| 94 | // https://github.com/android-ndk/ndk/issues/265. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 95 | Unversioned_until *string |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 96 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 97 | // Private property for use by the mutator that splits per-API level. |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 98 | ApiLevel string `blueprint:"mutated"` |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 99 | |
| 100 | // True if this API is not yet ready to be shipped in the NDK. It will be |
| 101 | // available in the platform for testing, but will be excluded from the |
| 102 | // sysroot provided to the NDK proper. |
| 103 | Draft bool |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 106 | type stubDecorator struct { |
| 107 | *libraryDecorator |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 108 | |
| 109 | properties libraryProperties |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 110 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 111 | versionScriptPath android.ModuleGenPath |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 112 | installPath android.Path |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // OMG GO |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 116 | func intMax(a int, b int) int { |
| 117 | if a > b { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 118 | return a |
| 119 | } else { |
| 120 | return b |
| 121 | } |
| 122 | } |
| 123 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 124 | func normalizeNdkApiLevel(ctx android.BaseModuleContext, apiLevel string, |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 125 | arch android.Arch) (string, error) { |
| 126 | |
Dan Albert | 90f7a4d | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 127 | if apiLevel == "current" { |
| 128 | return apiLevel, nil |
| 129 | } |
| 130 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 131 | minVersion := ctx.Config().MinSupportedSdkVersion() |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 132 | firstArchVersions := map[android.ArchType]int{ |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 133 | android.Arm: minVersion, |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 134 | android.Arm64: 21, |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 135 | android.Mips: minVersion, |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 136 | android.Mips64: 21, |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 137 | android.X86: minVersion, |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 138 | android.X86_64: 21, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 141 | firstArchVersion, ok := firstArchVersions[arch.ArchType] |
Dan Albert | 2e5d7d4 | 2017-03-29 18:22:39 -0700 | [diff] [blame] | 142 | if !ok { |
Colin Cross | ce87b80 | 2017-04-13 13:00:26 -0700 | [diff] [blame] | 143 | panic(fmt.Errorf("Arch %q not found in firstArchVersions", arch.ArchType)) |
Dan Albert | 2e5d7d4 | 2017-03-29 18:22:39 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if apiLevel == "minimum" { |
| 147 | return strconv.Itoa(firstArchVersion), nil |
| 148 | } |
| 149 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 150 | // If the NDK drops support for a platform version, we don't want to have to |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 151 | // fix up every module that was using it as its SDK version. Clip to the |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 152 | // supported version here instead. |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 153 | version, err := strconv.Atoi(apiLevel) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 154 | if err != nil { |
Dan Albert | 90f7a4d | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 155 | return "", fmt.Errorf("API level must be an integer (is %q)", apiLevel) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 156 | } |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 157 | version = intMax(version, minVersion) |
| 158 | |
Dan Albert | 90f7a4d | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 159 | return strconv.Itoa(intMax(version, firstArchVersion)), nil |
| 160 | } |
| 161 | |
| 162 | func getFirstGeneratedVersion(firstSupportedVersion string, platformVersion int) (int, error) { |
| 163 | if firstSupportedVersion == "current" { |
| 164 | return platformVersion + 1, nil |
| 165 | } |
| 166 | |
| 167 | return strconv.Atoi(firstSupportedVersion) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 170 | func shouldUseVersionScript(ctx android.BaseModuleContext, stub *stubDecorator) (bool, error) { |
Ryan Prichard | 37ebbde | 2018-07-24 12:37:24 -0700 | [diff] [blame] | 171 | // unversioned_until is normally empty, in which case we should use the version script. |
| 172 | if String(stub.properties.Unversioned_until) == "" { |
| 173 | return true, nil |
| 174 | } |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 175 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 176 | if String(stub.properties.Unversioned_until) == "current" { |
Dan Albert | 022e7a3 | 2017-01-05 15:49:09 -0800 | [diff] [blame] | 177 | if stub.properties.ApiLevel == "current" { |
| 178 | return true, nil |
| 179 | } else { |
| 180 | return false, nil |
| 181 | } |
| 182 | } |
| 183 | |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 184 | if stub.properties.ApiLevel == "current" { |
| 185 | return true, nil |
| 186 | } |
| 187 | |
Dan Albert | e67144e | 2018-05-03 15:42:34 -0700 | [diff] [blame] | 188 | unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until)) |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 189 | if err != nil { |
| 190 | return true, err |
| 191 | } |
| 192 | |
Ryan Prichard | 37ebbde | 2018-07-24 12:37:24 -0700 | [diff] [blame] | 193 | version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel) |
| 194 | if err != nil { |
| 195 | return true, err |
Dan Albert | e67144e | 2018-05-03 15:42:34 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 198 | return version >= unversionedUntil, nil |
| 199 | } |
| 200 | |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 201 | func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 202 | platformVersion := mctx.Config().PlatformSdkVersionInt() |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 203 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 204 | firstSupportedVersion, err := normalizeNdkApiLevel(mctx, String(c.properties.First_version), |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 205 | mctx.Arch()) |
| 206 | if err != nil { |
| 207 | mctx.PropertyErrorf("first_version", err.Error()) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 208 | } |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 209 | |
Dan Albert | 90f7a4d | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 210 | firstGenVersion, err := getFirstGeneratedVersion(firstSupportedVersion, platformVersion) |
| 211 | if err != nil { |
| 212 | // In theory this is impossible because we've already run this through |
| 213 | // normalizeNdkApiLevel above. |
| 214 | mctx.PropertyErrorf("first_version", err.Error()) |
| 215 | } |
| 216 | |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 217 | var versionStrs []string |
Dan Albert | 90f7a4d | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 218 | for version := firstGenVersion; version <= platformVersion; version++ { |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 219 | versionStrs = append(versionStrs, strconv.Itoa(version)) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 220 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 221 | versionStrs = append(versionStrs, mctx.Config().PlatformVersionActiveCodenames()...) |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 222 | versionStrs = append(versionStrs, "current") |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 223 | |
| 224 | modules := mctx.CreateVariations(versionStrs...) |
| 225 | for i, module := range modules { |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 226 | module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i] |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | func ndkApiMutator(mctx android.BottomUpMutatorContext) { |
| 231 | if m, ok := mctx.Module().(*Module); ok { |
Colin Cross | d402582 | 2017-04-13 12:53:07 -0700 | [diff] [blame] | 232 | if m.Enabled() { |
| 233 | if compiler, ok := m.compiler.(*stubDecorator); ok { |
| 234 | generateStubApiVariants(mctx, compiler) |
| 235 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 240 | func (c *stubDecorator) compilerInit(ctx BaseModuleContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 241 | c.baseCompiler.compilerInit(ctx) |
| 242 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 243 | name := ctx.baseModuleName() |
| 244 | if strings.HasSuffix(name, ndkLibrarySuffix) { |
| 245 | ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix) |
| 246 | } |
| 247 | |
Colin Cross | e8a67a7 | 2016-08-07 21:17:54 -0700 | [diff] [blame] | 248 | ndkMigratedLibsLock.Lock() |
| 249 | defer ndkMigratedLibsLock.Unlock() |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 250 | for _, lib := range ndkMigratedLibs { |
| 251 | if lib == name { |
| 252 | return |
| 253 | } |
| 254 | } |
| 255 | ndkMigratedLibs = append(ndkMigratedLibs, name) |
| 256 | } |
| 257 | |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 258 | func addStubLibraryCompilerFlags(flags Flags) Flags { |
| 259 | flags.CFlags = append(flags.CFlags, |
| 260 | // We're knowingly doing some otherwise unsightly things with builtin |
| 261 | // functions here. We're just generating stub libraries, so ignore it. |
| 262 | "-Wno-incompatible-library-redeclaration", |
| 263 | "-Wno-builtin-requires-header", |
| 264 | "-Wno-invalid-noreturn", |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 265 | "-Wall", |
| 266 | "-Werror", |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 267 | // These libraries aren't actually used. Don't worry about unwinding |
| 268 | // (avoids the need to link an unwinder into a fake library). |
| 269 | "-fno-unwind-tables", |
| 270 | ) |
| 271 | return flags |
| 272 | } |
| 273 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 274 | func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
| 275 | flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 276 | return addStubLibraryCompilerFlags(flags) |
| 277 | } |
| 278 | |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 279 | 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] | 280 | arch := ctx.Arch().ArchType.String() |
| 281 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 282 | stubSrcPath := android.PathForModuleGen(ctx, "stub.c") |
| 283 | versionScriptPath := android.PathForModuleGen(ctx, "stub.map") |
| 284 | symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) |
Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 285 | apiLevelsJson := android.GetApiLevelsJson(ctx) |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 286 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 287 | Rule: genStubSrc, |
| 288 | Description: "generate stubs " + symbolFilePath.Rel(), |
| 289 | Outputs: []android.WritablePath{stubSrcPath, versionScriptPath}, |
| 290 | Input: symbolFilePath, |
| 291 | Implicits: []android.Path{apiLevelsJson}, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 292 | Args: map[string]string{ |
| 293 | "arch": arch, |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 294 | "apiLevel": apiLevel, |
Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 295 | "apiMap": apiLevelsJson.String(), |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 296 | "flags": genstubFlags, |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 297 | }, |
| 298 | }) |
| 299 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 300 | subdir := "" |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 301 | srcs := []android.Path{stubSrcPath} |
Pirama Arumuga Nainar | 70ba5a3 | 2017-12-19 15:11:01 -0800 | [diff] [blame] | 302 | return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 306 | if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") { |
Dan Albert | 15be0c6 | 2017-06-13 15:14:56 -0700 | [diff] [blame] | 307 | ctx.PropertyErrorf("symbol_file", "must end with .map.txt") |
| 308 | } |
| 309 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 310 | objs, versionScript := compileStubLibrary(ctx, flags, String(c.properties.Symbol_file), |
| 311 | c.properties.ApiLevel, "") |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 312 | c.versionScriptPath = versionScript |
| 313 | return objs |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 316 | func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 317 | return Deps{} |
| 318 | } |
| 319 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 320 | func (linker *stubDecorator) Name(name string) string { |
| 321 | return name + ndkLibrarySuffix |
| 322 | } |
| 323 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 324 | func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 325 | stub.libraryDecorator.libName = ctx.baseModuleName() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 326 | return stub.libraryDecorator.linkerFlags(ctx, flags) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 329 | func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 330 | objs Objects) android.Path { |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 331 | |
Dan Albert | e67144e | 2018-05-03 15:42:34 -0700 | [diff] [blame] | 332 | useVersionScript, err := shouldUseVersionScript(ctx, stub) |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 333 | if err != nil { |
| 334 | ctx.ModuleErrorf(err.Error()) |
| 335 | } |
| 336 | |
| 337 | if useVersionScript { |
| 338 | linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() |
| 339 | flags.LdFlags = append(flags.LdFlags, linkerScriptFlag) |
Dan Willemsen | 939408a | 2019-06-10 18:02:25 -0700 | [diff] [blame^] | 340 | flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) |
Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 343 | return stub.libraryDecorator.link(ctx, flags, deps, objs) |
Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 346 | func (stub *stubDecorator) nativeCoverage() bool { |
| 347 | return false |
| 348 | } |
| 349 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 350 | func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 351 | arch := ctx.Target().Arch.ArchType.Name |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 352 | apiLevel := stub.properties.ApiLevel |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 353 | |
| 354 | // arm64 isn't actually a multilib toolchain, so unlike the other LP64 |
| 355 | // architectures it's just installed to lib. |
| 356 | libDir := "lib" |
| 357 | if ctx.toolchain().Is64Bit() && arch != "arm64" { |
| 358 | libDir = "lib64" |
| 359 | } |
| 360 | |
| 361 | installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf( |
Dan Albert | fd86e9e | 2016-11-08 13:35:12 -0800 | [diff] [blame] | 362 | "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir)) |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 363 | stub.installPath = ctx.InstallFile(installDir, path.Base(), path) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 366 | func newStubLibrary() *Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 367 | module, library := NewLibrary(android.DeviceSupported) |
| 368 | library.BuildOnlyShared() |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 369 | module.stl = nil |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 370 | module.sanitize = nil |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 371 | library.StripProperties.Strip.None = BoolPtr(true) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 372 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 373 | stub := &stubDecorator{ |
| 374 | libraryDecorator: library, |
| 375 | } |
| 376 | module.compiler = stub |
| 377 | module.linker = stub |
| 378 | module.installer = stub |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 379 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 380 | module.AddProperties(&stub.properties, &library.MutatedProperties) |
| 381 | |
| 382 | return module |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Patrice Arruda | 6ea4211 | 2019-04-03 08:43:30 -0700 | [diff] [blame] | 385 | // ndk_library creates a stub library that exposes dummy implementation |
| 386 | // of functions and variables for use at build time only. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 387 | func ndkLibraryFactory() android.Module { |
| 388 | module := newStubLibrary() |
| 389 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) |
dimitry | 03dc3f6 | 2019-05-09 14:07:34 +0200 | [diff] [blame] | 390 | module.ModuleBase.EnableNativeBridgeSupportByDefault() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 391 | return module |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 392 | } |