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