| 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 | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 19 | "path/filepath" | 
| Dan Albert | ad66593 | 2021-06-07 13:19:49 -0700 | [diff] [blame] | 20 | "runtime" | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 21 | "strings" | 
| Colin Cross | e8a67a7 | 2016-08-07 21:17:54 -0700 | [diff] [blame] | 22 | "sync" | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 23 |  | 
|  | 24 | "github.com/google/blueprint" | 
| Jiyong Park | ee9b117 | 2021-04-06 17:40:32 +0900 | [diff] [blame] | 25 | "github.com/google/blueprint/proptools" | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | "android/soong/android" | 
| Jingwen Chen | 341f735 | 2022-01-11 05:42:49 +0000 | [diff] [blame] | 28 | "android/soong/cc/config" | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 29 | ) | 
|  | 30 |  | 
| sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 31 | func init() { | 
| Dan Albert | 06f58af | 2020-06-22 15:10:31 -0700 | [diff] [blame] | 32 | pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen") | 
| Matthias Maennich | ca8ae65 | 2023-06-30 21:52:17 +0100 | [diff] [blame] | 33 | pctx.HostBinToolVariable("stg", "stg") | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 34 | pctx.HostBinToolVariable("stgdiff", "stgdiff") | 
| sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 37 | var ( | 
| Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 38 | genStubSrc = pctx.AndroidStaticRule("genStubSrc", | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 39 | blueprint.RuleParams{ | 
| Dan Albert | 06f58af | 2020-06-22 15:10:31 -0700 | [diff] [blame] | 40 | Command: "$ndkStubGenerator --arch $arch --api $apiLevel " + | 
|  | 41 | "--api-map $apiMap $flags $in $out", | 
|  | 42 | CommandDeps: []string{"$ndkStubGenerator"}, | 
| Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 43 | }, "arch", "apiLevel", "apiMap", "flags") | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 44 |  | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 45 | // $headersList should include paths to public headers. All types | 
|  | 46 | // that are defined outside of public headers will be excluded from | 
|  | 47 | // ABI monitoring. | 
|  | 48 | // | 
|  | 49 | // STG tool doesn't access content of files listed in $headersList, | 
|  | 50 | // so there is no need to add them to dependencies. | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 51 | stg = pctx.AndroidStaticRule("stg", | 
|  | 52 | blueprint.RuleParams{ | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 53 | Command:     "$stg -S :$symbolList --file-filter :$headersList --elf $in -o $out", | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 54 | CommandDeps: []string{"$stg"}, | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 55 | }, "symbolList", "headersList") | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 56 |  | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 57 | stgdiff = pctx.AndroidStaticRule("stgdiff", | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 58 | blueprint.RuleParams{ | 
|  | 59 | // Need to create *some* output for ninja. We don't want to use tee | 
|  | 60 | // because we don't want to spam the build output with "nothing | 
|  | 61 | // changed" messages, so redirect output message to $out, and if | 
|  | 62 | // changes were detected print the output and fail. | 
| Dan Albert | 5b2fd58 | 2023-10-05 21:43:41 +0000 | [diff] [blame] | 63 | Command:     "$stgdiff $args --stg $in -o $out || (cat $out && echo 'Run $$ANDROID_BUILD_TOP/development/tools/ndk/update_ndk_abi.sh to update the ABI dumps.' && false)", | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 64 | CommandDeps: []string{"$stgdiff"}, | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 65 | }, "args") | 
|  | 66 |  | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 67 | ndkLibrarySuffix = ".ndk" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 68 |  | 
| Colin Cross | 95f1ca0 | 2020-10-29 20:47:22 -0700 | [diff] [blame] | 69 | ndkKnownLibsKey = android.NewOnceKey("ndkKnownLibsKey") | 
| Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 70 | // protects ndkKnownLibs writes during parallel BeginMutator. | 
|  | 71 | ndkKnownLibsLock sync.Mutex | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 72 |  | 
|  | 73 | stubImplementation = dependencyTag{name: "stubImplementation"} | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 74 | ) | 
|  | 75 |  | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 76 | // The First_version and Unversioned_until properties of this struct should not | 
|  | 77 | // be used directly, but rather through the ApiLevel returning methods | 
|  | 78 | // firstVersion() and unversionedUntil(). | 
|  | 79 |  | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 80 | // Creates a stub shared library based on the provided version file. | 
|  | 81 | // | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 82 | // Example: | 
|  | 83 | // | 
| Spandan Das | 73bcafc | 2022-08-18 23:26:00 +0000 | [diff] [blame] | 84 | // ndk_library { | 
|  | 85 | // | 
|  | 86 | //	name: "libfoo", | 
|  | 87 | //	symbol_file: "libfoo.map.txt", | 
|  | 88 | //	first_version: "9", | 
|  | 89 | // | 
|  | 90 | // } | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 91 | type libraryProperties struct { | 
|  | 92 | // Relative path to the symbol map. | 
|  | 93 | // An example file can be seen here: TODO(danalbert): Make an example. | 
| Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 94 | Symbol_file *string `android:"path"` | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 95 |  | 
|  | 96 | // The first API level a library was available. A library will be generated | 
|  | 97 | // for every API level beginning with this one. | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 98 | First_version *string | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 99 |  | 
| Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 100 | // The first API level that library should have the version script applied. | 
|  | 101 | // This defaults to the value of first_version, and should almost never be | 
|  | 102 | // used. This is only needed to work around platform bugs like | 
|  | 103 | // https://github.com/android-ndk/ndk/issues/265. | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 104 | Unversioned_until *string | 
| Dan Albert | 604086f | 2021-06-15 13:23:44 -0700 | [diff] [blame] | 105 |  | 
| Colin Cross | a158a71 | 2024-09-04 15:33:04 +0000 | [diff] [blame] | 106 | // DO NOT USE THIS | 
|  | 107 | // NDK libraries should not export their headers. Headers belonging to NDK | 
|  | 108 | // libraries should be added to the NDK with an ndk_headers module. | 
| Spandan Das | 73bcafc | 2022-08-18 23:26:00 +0000 | [diff] [blame] | 109 | Export_header_libs []string | 
| Colin Cross | a158a71 | 2024-09-04 15:33:04 +0000 | [diff] [blame] | 110 |  | 
|  | 111 | // Do not add other export_* properties without consulting with danalbert@. | 
|  | 112 | // Consumers of ndk_library modules should emulate the typical NDK build | 
|  | 113 | // behavior as closely as possible (that is, all NDK APIs are exposed to | 
|  | 114 | // builds via --sysroot). Export behaviors used in Soong will not be present | 
|  | 115 | // for app developers as they don't use Soong, and reliance on these export | 
|  | 116 | // behaviors can mask issues with the NDK sysroot. | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 117 | } | 
|  | 118 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 119 | type stubDecorator struct { | 
|  | 120 | *libraryDecorator | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 121 |  | 
|  | 122 | properties libraryProperties | 
| Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 123 |  | 
| sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 124 | versionScriptPath     android.ModuleGenPath | 
|  | 125 | parsedCoverageXmlPath android.ModuleOutPath | 
|  | 126 | installPath           android.Path | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 127 | abiDumpPath           android.OutputPath | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 128 | hasAbiDump            bool | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 129 | abiDiffPaths          android.Paths | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | apiLevel         android.ApiLevel | 
|  | 132 | firstVersion     android.ApiLevel | 
|  | 133 | unversionedUntil android.ApiLevel | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 134 | } | 
|  | 135 |  | 
| Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 136 | var _ versionedInterface = (*stubDecorator)(nil) | 
|  | 137 |  | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 138 | func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool { | 
|  | 139 | return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil) | 
| Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 140 | } | 
|  | 141 |  | 
| Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 142 | func (stub *stubDecorator) implementationModuleName(name string) string { | 
|  | 143 | return strings.TrimSuffix(name, ndkLibrarySuffix) | 
|  | 144 | } | 
|  | 145 |  | 
| Colin Cross | add04a8 | 2024-05-22 09:57:59 -0700 | [diff] [blame] | 146 | func ndkLibraryVersions(ctx android.BaseModuleContext, from android.ApiLevel) []string { | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 147 | var versions []android.ApiLevel | 
|  | 148 | versionStrs := []string{} | 
|  | 149 | for _, version := range ctx.Config().AllSupportedApiLevels() { | 
|  | 150 | if version.GreaterThanOrEqualTo(from) { | 
|  | 151 | versions = append(versions, version) | 
|  | 152 | versionStrs = append(versionStrs, version.String()) | 
|  | 153 | } | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 154 | } | 
| Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame] | 155 | versionStrs = append(versionStrs, android.FutureApiLevel.String()) | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 156 |  | 
| Colin Cross | 5ec407b | 2020-09-30 11:41:33 -0700 | [diff] [blame] | 157 | return versionStrs | 
|  | 158 | } | 
|  | 159 |  | 
| Colin Cross | add04a8 | 2024-05-22 09:57:59 -0700 | [diff] [blame] | 160 | func (this *stubDecorator) stubsVersions(ctx android.BaseModuleContext) []string { | 
| Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 161 | if !ctx.Module().Enabled(ctx) { | 
| Colin Cross | 3572cf7 | 2020-10-01 15:58:11 -0700 | [diff] [blame] | 162 | return nil | 
|  | 163 | } | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 164 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { | 
|  | 165 | ctx.Module().Disable() | 
|  | 166 | return nil | 
|  | 167 | } | 
| Colin Cross | 3572cf7 | 2020-10-01 15:58:11 -0700 | [diff] [blame] | 168 | firstVersion, err := nativeApiLevelFromUser(ctx, | 
|  | 169 | String(this.properties.First_version)) | 
|  | 170 | if err != nil { | 
|  | 171 | ctx.PropertyErrorf("first_version", err.Error()) | 
|  | 172 | return nil | 
|  | 173 | } | 
|  | 174 | return ndkLibraryVersions(ctx, firstVersion) | 
|  | 175 | } | 
|  | 176 |  | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 177 | func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool { | 
| Colin Cross | 5ec407b | 2020-09-30 11:41:33 -0700 | [diff] [blame] | 178 | this.apiLevel = nativeApiLevelOrPanic(ctx, this.stubsVersion()) | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 179 |  | 
|  | 180 | var err error | 
|  | 181 | this.firstVersion, err = nativeApiLevelFromUser(ctx, | 
|  | 182 | String(this.properties.First_version)) | 
|  | 183 | if err != nil { | 
|  | 184 | ctx.PropertyErrorf("first_version", err.Error()) | 
|  | 185 | return false | 
|  | 186 | } | 
|  | 187 |  | 
| Jiyong Park | ee9b117 | 2021-04-06 17:40:32 +0900 | [diff] [blame] | 188 | str := proptools.StringDefault(this.properties.Unversioned_until, "minimum") | 
|  | 189 | this.unversionedUntil, err = nativeApiLevelFromUser(ctx, str) | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 190 | if err != nil { | 
|  | 191 | ctx.PropertyErrorf("unversioned_until", err.Error()) | 
|  | 192 | return false | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | return true | 
|  | 196 | } | 
|  | 197 |  | 
| Colin Cross | 95f1ca0 | 2020-10-29 20:47:22 -0700 | [diff] [blame] | 198 | func getNDKKnownLibs(config android.Config) *[]string { | 
|  | 199 | return config.Once(ndkKnownLibsKey, func() interface{} { | 
|  | 200 | return &[]string{} | 
|  | 201 | }).(*[]string) | 
|  | 202 | } | 
|  | 203 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 204 | func (c *stubDecorator) compilerInit(ctx BaseModuleContext) { | 
| Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 205 | c.baseCompiler.compilerInit(ctx) | 
|  | 206 |  | 
| Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 207 | name := ctx.baseModuleName() | 
|  | 208 | if strings.HasSuffix(name, ndkLibrarySuffix) { | 
|  | 209 | ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix) | 
|  | 210 | } | 
|  | 211 |  | 
| Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 212 | ndkKnownLibsLock.Lock() | 
|  | 213 | defer ndkKnownLibsLock.Unlock() | 
| Colin Cross | 95f1ca0 | 2020-10-29 20:47:22 -0700 | [diff] [blame] | 214 | ndkKnownLibs := getNDKKnownLibs(ctx.Config()) | 
|  | 215 | for _, lib := range *ndkKnownLibs { | 
| Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 216 | if lib == name { | 
|  | 217 | return | 
|  | 218 | } | 
|  | 219 | } | 
| Colin Cross | 95f1ca0 | 2020-10-29 20:47:22 -0700 | [diff] [blame] | 220 | *ndkKnownLibs = append(*ndkKnownLibs, name) | 
| Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 221 | } | 
|  | 222 |  | 
| Jingwen Chen | 341f735 | 2022-01-11 05:42:49 +0000 | [diff] [blame] | 223 | var stubLibraryCompilerFlags = []string{ | 
|  | 224 | // We're knowingly doing some otherwise unsightly things with builtin | 
|  | 225 | // functions here. We're just generating stub libraries, so ignore it. | 
|  | 226 | "-Wno-incompatible-library-redeclaration", | 
|  | 227 | "-Wno-incomplete-setjmp-declaration", | 
|  | 228 | "-Wno-builtin-requires-header", | 
|  | 229 | "-Wno-invalid-noreturn", | 
|  | 230 | "-Wall", | 
|  | 231 | "-Werror", | 
|  | 232 | // These libraries aren't actually used. Don't worry about unwinding | 
|  | 233 | // (avoids the need to link an unwinder into a fake library). | 
|  | 234 | "-fno-unwind-tables", | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | func init() { | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 238 | pctx.StaticVariable("StubLibraryCompilerFlags", strings.Join(stubLibraryCompilerFlags, " ")) | 
| Jingwen Chen | 341f735 | 2022-01-11 05:42:49 +0000 | [diff] [blame] | 239 | } | 
|  | 240 |  | 
| George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 241 | func addStubLibraryCompilerFlags(flags Flags) Flags { | 
| Jingwen Chen | 341f735 | 2022-01-11 05:42:49 +0000 | [diff] [blame] | 242 | flags.Global.CFlags = append(flags.Global.CFlags, stubLibraryCompilerFlags...) | 
| Jiyong Park | 48d75ef | 2019-11-21 15:11:49 +0900 | [diff] [blame] | 243 | // All symbols in the stubs library should be visible. | 
|  | 244 | if inList("-fvisibility=hidden", flags.Local.CFlags) { | 
|  | 245 | flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default") | 
|  | 246 | } | 
| George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 247 | return flags | 
|  | 248 | } | 
|  | 249 |  | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 250 | func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { | 
|  | 251 | flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) | 
| George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 252 | return addStubLibraryCompilerFlags(flags) | 
|  | 253 | } | 
|  | 254 |  | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 255 | type ndkApiOutputs struct { | 
|  | 256 | stubSrc       android.ModuleGenPath | 
|  | 257 | versionScript android.ModuleGenPath | 
|  | 258 | symbolList    android.ModuleGenPath | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | func parseNativeAbiDefinition(ctx ModuleContext, symbolFile string, | 
|  | 262 | apiLevel android.ApiLevel, genstubFlags string) ndkApiOutputs { | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 263 |  | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 264 | stubSrcPath := android.PathForModuleGen(ctx, "stub.c") | 
|  | 265 | versionScriptPath := android.PathForModuleGen(ctx, "stub.map") | 
|  | 266 | symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 267 | symbolListPath := android.PathForModuleGen(ctx, "abi_symbol_list.txt") | 
| Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 268 | apiLevelsJson := android.GetApiLevelsJson(ctx) | 
| Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 269 | ctx.Build(pctx, android.BuildParams{ | 
| Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 270 | Rule:        genStubSrc, | 
|  | 271 | Description: "generate stubs " + symbolFilePath.Rel(), | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 272 | Outputs: []android.WritablePath{stubSrcPath, versionScriptPath, | 
|  | 273 | symbolListPath}, | 
|  | 274 | Input:     symbolFilePath, | 
|  | 275 | Implicits: []android.Path{apiLevelsJson}, | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 276 | Args: map[string]string{ | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 277 | "arch":     ctx.Arch().ArchType.String(), | 
|  | 278 | "apiLevel": apiLevel.String(), | 
| Dan Albert | 49927d2 | 2017-03-28 15:00:46 -0700 | [diff] [blame] | 279 | "apiMap":   apiLevelsJson.String(), | 
| Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 280 | "flags":    genstubFlags, | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 281 | }, | 
|  | 282 | }) | 
|  | 283 |  | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 284 | return ndkApiOutputs{ | 
|  | 285 | stubSrc:       stubSrcPath, | 
|  | 286 | versionScript: versionScriptPath, | 
|  | 287 | symbolList:    symbolListPath, | 
|  | 288 | } | 
|  | 289 | } | 
|  | 290 |  | 
|  | 291 | func compileStubLibrary(ctx ModuleContext, flags Flags, src android.Path) Objects { | 
| Mitch Phillips | 4e5f9a1 | 2022-04-29 13:12:28 -0700 | [diff] [blame] | 292 | // libc/libm stubs libraries end up mismatching with clang's internal definition of these | 
|  | 293 | // functions (which have noreturn attributes and other things). Because we just want to create a | 
|  | 294 | // stub with symbol definitions, and types aren't important in C, ignore the mismatch. | 
|  | 295 | flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, "-fno-builtin") | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 296 | return compileObjs(ctx, flagsToBuilderFlags(flags), "", | 
| Chih-Hung Hsieh | 9db8a0c | 2022-02-17 12:54:45 -0800 | [diff] [blame] | 297 | android.Paths{src}, nil, nil, nil, nil) | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 298 | } | 
|  | 299 |  | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 300 | func (this *stubDecorator) findImplementationLibrary(ctx ModuleContext) android.Path { | 
|  | 301 | dep := ctx.GetDirectDepWithTag(strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix), | 
|  | 302 | stubImplementation) | 
|  | 303 | if dep == nil { | 
|  | 304 | ctx.ModuleErrorf("Could not find implementation for stub") | 
|  | 305 | return nil | 
|  | 306 | } | 
|  | 307 | impl, ok := dep.(*Module) | 
|  | 308 | if !ok { | 
|  | 309 | ctx.ModuleErrorf("Implementation for stub is not correct module type") | 
| Alan Stokes | 73d3245 | 2022-11-01 14:05:08 +0000 | [diff] [blame] | 310 | return nil | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 311 | } | 
|  | 312 | output := impl.UnstrippedOutputFile() | 
|  | 313 | if output == nil { | 
|  | 314 | ctx.ModuleErrorf("implementation module (%s) has no output", impl) | 
|  | 315 | return nil | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | return output | 
|  | 319 | } | 
|  | 320 |  | 
|  | 321 | func (this *stubDecorator) libraryName(ctx ModuleContext) string { | 
|  | 322 | return strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix) | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | func (this *stubDecorator) findPrebuiltAbiDump(ctx ModuleContext, | 
|  | 326 | apiLevel android.ApiLevel) android.OptionalPath { | 
|  | 327 |  | 
|  | 328 | subpath := filepath.Join("prebuilts/abi-dumps/ndk", apiLevel.String(), | 
| Matthias Maennich | ca8ae65 | 2023-06-30 21:52:17 +0100 | [diff] [blame] | 329 | ctx.Arch().ArchType.String(), this.libraryName(ctx), "abi.stg") | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 330 | return android.ExistentPathForSource(ctx, subpath) | 
|  | 331 | } | 
|  | 332 |  | 
|  | 333 | // Feature flag. | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 334 | func (this *stubDecorator) canDumpAbi(ctx ModuleContext) bool { | 
| Dan Albert | f71006a | 2022-04-14 23:08:51 +0000 | [diff] [blame] | 335 | if runtime.GOOS == "darwin" { | 
|  | 336 | return false | 
|  | 337 | } | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 338 | if strings.HasPrefix(ctx.ModuleDir(), "bionic/") { | 
| Dan Albert | fbe5780 | 2024-08-09 20:39:39 +0000 | [diff] [blame] | 339 | // Bionic has enough uncommon implementation details like ifuncs and asm | 
|  | 340 | // code that the ABI tracking here has a ton of false positives. That's | 
|  | 341 | // causing pretty extreme friction for development there, so disabling | 
|  | 342 | // it until the workflow can be improved. | 
|  | 343 | // | 
|  | 344 | // http://b/358653811 | 
|  | 345 | return false | 
|  | 346 | } | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 347 |  | 
|  | 348 | if this.apiLevel.IsCurrent() { | 
|  | 349 | // "current" (AKA 10000) is not tracked. | 
|  | 350 | return false | 
|  | 351 | } | 
|  | 352 |  | 
| Dan Albert | 326ab24 | 2023-04-20 17:38:29 +0000 | [diff] [blame] | 353 | // http://b/156513478 | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 354 | return ctx.Config().ReleaseNdkAbiMonitored() | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 355 | } | 
|  | 356 |  | 
|  | 357 | // Feature flag to disable diffing against prebuilts. | 
| Aleksei Vetrov | 146e982 | 2023-11-24 19:54:26 +0000 | [diff] [blame] | 358 | func canDiffAbi(config android.Config) bool { | 
|  | 359 | return config.ReleaseNdkAbiMonitored() | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 360 | } | 
|  | 361 |  | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 362 | func (this *stubDecorator) dumpAbi(ctx ModuleContext, symbolList android.Path) { | 
|  | 363 | implementationLibrary := this.findImplementationLibrary(ctx) | 
|  | 364 | this.abiDumpPath = getNdkAbiDumpInstallBase(ctx).Join(ctx, | 
|  | 365 | this.apiLevel.String(), ctx.Arch().ArchType.String(), | 
|  | 366 | this.libraryName(ctx), "abi.stg") | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 367 | this.hasAbiDump = true | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 368 | headersList := getNdkABIHeadersFile(ctx) | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 369 | ctx.Build(pctx, android.BuildParams{ | 
|  | 370 | Rule:        stg, | 
|  | 371 | Description: fmt.Sprintf("stg %s", implementationLibrary), | 
|  | 372 | Input:       implementationLibrary, | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 373 | Implicits: []android.Path{ | 
|  | 374 | symbolList, | 
|  | 375 | headersList, | 
|  | 376 | }, | 
|  | 377 | Output: this.abiDumpPath, | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 378 | Args: map[string]string{ | 
| Aleksei Vetrov | 262ed1a | 2023-08-23 10:06:35 +0000 | [diff] [blame] | 379 | "symbolList":  symbolList.String(), | 
|  | 380 | "headersList": headersList.String(), | 
| Matthias Maennich | 55486f8 | 2023-07-03 12:25:27 +0100 | [diff] [blame] | 381 | }, | 
|  | 382 | }) | 
|  | 383 | } | 
|  | 384 |  | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 385 | func findNextApiLevel(ctx ModuleContext, apiLevel android.ApiLevel) *android.ApiLevel { | 
|  | 386 | apiLevels := append(ctx.Config().AllSupportedApiLevels(), | 
|  | 387 | android.FutureApiLevel) | 
|  | 388 | for _, api := range apiLevels { | 
|  | 389 | if api.GreaterThan(apiLevel) { | 
|  | 390 | return &api | 
|  | 391 | } | 
|  | 392 | } | 
|  | 393 | return nil | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | func (this *stubDecorator) diffAbi(ctx ModuleContext) { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 397 | // Catch any ABI changes compared to the checked-in definition of this API | 
|  | 398 | // level. | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 399 | abiDiffPath := android.PathForModuleOut(ctx, "stgdiff.timestamp") | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 400 | prebuiltAbiDump := this.findPrebuiltAbiDump(ctx, this.apiLevel) | 
| Aleksei Vetrov | 9c8c5ab | 2023-09-20 13:09:25 +0000 | [diff] [blame] | 401 | missingPrebuiltErrorTemplate := | 
|  | 402 | "Did not find prebuilt ABI dump for %q (%q). Generate with " + | 
|  | 403 | "//development/tools/ndk/update_ndk_abi.sh." | 
| Dan Albert | f7cb563 | 2022-11-29 17:20:16 +0000 | [diff] [blame] | 404 | missingPrebuiltError := fmt.Sprintf( | 
| Aleksei Vetrov | 9c8c5ab | 2023-09-20 13:09:25 +0000 | [diff] [blame] | 405 | missingPrebuiltErrorTemplate, this.libraryName(ctx), | 
| Dan Albert | f7cb563 | 2022-11-29 17:20:16 +0000 | [diff] [blame] | 406 | prebuiltAbiDump.InvalidReason()) | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 407 | if !prebuiltAbiDump.Valid() { | 
|  | 408 | ctx.Build(pctx, android.BuildParams{ | 
|  | 409 | Rule:   android.ErrorRule, | 
|  | 410 | Output: abiDiffPath, | 
|  | 411 | Args: map[string]string{ | 
|  | 412 | "error": missingPrebuiltError, | 
|  | 413 | }, | 
|  | 414 | }) | 
|  | 415 | } else { | 
|  | 416 | ctx.Build(pctx, android.BuildParams{ | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 417 | Rule: stgdiff, | 
|  | 418 | Description: fmt.Sprintf("Comparing ABI %s %s", prebuiltAbiDump, | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 419 | this.abiDumpPath), | 
|  | 420 | Output: abiDiffPath, | 
|  | 421 | Inputs: android.Paths{prebuiltAbiDump.Path(), this.abiDumpPath}, | 
| Matthias Maennich | 658bb4d | 2023-06-30 23:28:15 +0100 | [diff] [blame] | 422 | Args: map[string]string{ | 
|  | 423 | "args": "--format=small", | 
|  | 424 | }, | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 425 | }) | 
|  | 426 | } | 
|  | 427 | this.abiDiffPaths = append(this.abiDiffPaths, abiDiffPath) | 
|  | 428 |  | 
|  | 429 | // Also ensure that the ABI of the next API level (if there is one) matches | 
|  | 430 | // this API level. *New* ABI is allowed, but any changes to APIs that exist | 
|  | 431 | // in this API level are disallowed. | 
| Dan Albert | 9c8e0c4 | 2024-09-18 20:45:44 +0000 | [diff] [blame] | 432 | if prebuiltAbiDump.Valid() { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 433 | nextApiLevel := findNextApiLevel(ctx, this.apiLevel) | 
|  | 434 | if nextApiLevel == nil { | 
|  | 435 | panic(fmt.Errorf("could not determine which API level follows "+ | 
|  | 436 | "non-current API level %s", this.apiLevel)) | 
|  | 437 | } | 
| Dan Albert | 9c8e0c4 | 2024-09-18 20:45:44 +0000 | [diff] [blame] | 438 |  | 
|  | 439 | // "current" ABI is not tracked. | 
|  | 440 | if !nextApiLevel.IsCurrent() { | 
|  | 441 | nextAbiDiffPath := android.PathForModuleOut(ctx, | 
|  | 442 | "abidiff_next.timestamp") | 
|  | 443 | nextAbiDump := this.findPrebuiltAbiDump(ctx, *nextApiLevel) | 
|  | 444 | missingNextPrebuiltError := fmt.Sprintf( | 
|  | 445 | missingPrebuiltErrorTemplate, this.libraryName(ctx), | 
|  | 446 | nextAbiDump.InvalidReason()) | 
|  | 447 | if !nextAbiDump.Valid() { | 
|  | 448 | ctx.Build(pctx, android.BuildParams{ | 
|  | 449 | Rule:   android.ErrorRule, | 
|  | 450 | Output: nextAbiDiffPath, | 
|  | 451 | Args: map[string]string{ | 
|  | 452 | "error": missingNextPrebuiltError, | 
|  | 453 | }, | 
|  | 454 | }) | 
|  | 455 | } else { | 
|  | 456 | ctx.Build(pctx, android.BuildParams{ | 
|  | 457 | Rule: stgdiff, | 
|  | 458 | Description: fmt.Sprintf( | 
|  | 459 | "Comparing ABI to the next API level %s %s", | 
|  | 460 | prebuiltAbiDump, nextAbiDump), | 
|  | 461 | Output: nextAbiDiffPath, | 
|  | 462 | Inputs: android.Paths{ | 
|  | 463 | prebuiltAbiDump.Path(), nextAbiDump.Path()}, | 
|  | 464 | Args: map[string]string{ | 
|  | 465 | "args": "--format=small --ignore=interface_addition", | 
|  | 466 | }, | 
|  | 467 | }) | 
|  | 468 | } | 
|  | 469 | this.abiDiffPaths = append(this.abiDiffPaths, nextAbiDiffPath) | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 470 | } | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 471 | } | 
|  | 472 | } | 
|  | 473 |  | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 474 | func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 475 | if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") { | 
| Dan Albert | 15be0c6 | 2017-06-13 15:14:56 -0700 | [diff] [blame] | 476 | ctx.PropertyErrorf("symbol_file", "must end with .map.txt") | 
|  | 477 | } | 
|  | 478 |  | 
| Colin Cross | 5ec407b | 2020-09-30 11:41:33 -0700 | [diff] [blame] | 479 | if !c.buildStubs() { | 
|  | 480 | // NDK libraries have no implementation variant, nothing to do | 
|  | 481 | return Objects{} | 
|  | 482 | } | 
|  | 483 |  | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 484 | if !c.initializeProperties(ctx) { | 
|  | 485 | // Emits its own errors, so we don't need to. | 
|  | 486 | return Objects{} | 
|  | 487 | } | 
|  | 488 |  | 
| sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 489 | symbolFile := String(c.properties.Symbol_file) | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 490 | nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, c.apiLevel, "") | 
|  | 491 | objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) | 
|  | 492 | c.versionScriptPath = nativeAbiResult.versionScript | 
| Dan Albert | 2d0dce1 | 2024-09-18 19:34:32 +0000 | [diff] [blame] | 493 | if c.canDumpAbi(ctx) { | 
| Matthias Maennich | e914f2d | 2023-07-03 12:29:27 +0100 | [diff] [blame] | 494 | c.dumpAbi(ctx, nativeAbiResult.symbolList) | 
| Aleksei Vetrov | 146e982 | 2023-11-24 19:54:26 +0000 | [diff] [blame] | 495 | if canDiffAbi(ctx.Config()) { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 496 | c.diffAbi(ctx) | 
|  | 497 | } | 
|  | 498 | } | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 499 | if c.apiLevel.IsCurrent() && ctx.PrimaryArch() { | 
| sophiez | 4c4f803 | 2021-08-16 22:54:00 -0700 | [diff] [blame] | 500 | c.parsedCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile) | 
| sophiez | 58cabb7 | 2020-05-29 13:37:12 -0700 | [diff] [blame] | 501 | } | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 502 | return objs | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 503 | } | 
|  | 504 |  | 
| Spandan Das | 73bcafc | 2022-08-18 23:26:00 +0000 | [diff] [blame] | 505 | // Add a dependency on the header modules of this ndk_library | 
| Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 506 | func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { | 
| Spandan Das | 73bcafc | 2022-08-18 23:26:00 +0000 | [diff] [blame] | 507 | return Deps{ | 
| Steven Moreland | bedc997 | 2024-09-03 21:46:14 +0000 | [diff] [blame] | 508 | ReexportHeaderLibHeaders: linker.properties.Export_header_libs, | 
|  | 509 | HeaderLibs:               linker.properties.Export_header_libs, | 
| Spandan Das | 73bcafc | 2022-08-18 23:26:00 +0000 | [diff] [blame] | 510 | } | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 511 | } | 
|  | 512 |  | 
| Colin Cross | 4a9e6ec | 2023-12-18 15:29:41 -0800 | [diff] [blame] | 513 | func (linker *stubDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { | 
|  | 514 | linker.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON) | 
|  | 515 | // Overwrites the SubName computed by libraryDecorator | 
|  | 516 | moduleInfoJSON.SubName = ndkLibrarySuffix + "." + linker.apiLevel.String() | 
|  | 517 | } | 
|  | 518 |  | 
| Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 519 | func (linker *stubDecorator) Name(name string) string { | 
|  | 520 | return name + ndkLibrarySuffix | 
|  | 521 | } | 
|  | 522 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 523 | func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { | 
| Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 524 | stub.libraryDecorator.libName = ctx.baseModuleName() | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 525 | return stub.libraryDecorator.linkerFlags(ctx, flags) | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 526 | } | 
|  | 527 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 528 | func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 529 | objs Objects) android.Path { | 
| Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 530 |  | 
| Colin Cross | 5ec407b | 2020-09-30 11:41:33 -0700 | [diff] [blame] | 531 | if !stub.buildStubs() { | 
|  | 532 | // NDK libraries have no implementation variant, nothing to do | 
|  | 533 | return nil | 
|  | 534 | } | 
|  | 535 |  | 
| Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 536 | if shouldUseVersionScript(ctx, stub) { | 
| Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 537 | linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 538 | flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag) | 
| Dan Willemsen | 939408a | 2019-06-10 18:02:25 -0700 | [diff] [blame] | 539 | flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) | 
| Dan Albert | 98dbb3b | 2017-01-03 15:16:29 -0800 | [diff] [blame] | 540 | } | 
|  | 541 |  | 
| Colin Cross | 5ec407b | 2020-09-30 11:41:33 -0700 | [diff] [blame] | 542 | stub.libraryDecorator.skipAPIDefine = true | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 543 | return stub.libraryDecorator.link(ctx, flags, deps, objs) | 
| Dan Albert | 2bc91ba | 2016-07-28 17:40:28 -0700 | [diff] [blame] | 544 | } | 
|  | 545 |  | 
| Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 546 | func (stub *stubDecorator) nativeCoverage() bool { | 
|  | 547 | return false | 
|  | 548 | } | 
|  | 549 |  | 
| Dan Albert | 4048bb0 | 2023-04-03 20:19:07 +0000 | [diff] [blame] | 550 | // Returns the install path for unversioned NDK libraries (currently only static | 
|  | 551 | // libraries). | 
| Spandan Das | f280b23 | 2024-04-04 21:25:51 +0000 | [diff] [blame] | 552 | func getUnversionedLibraryInstallPath(ctx ModuleContext) android.OutputPath { | 
| Dan Albert | 4048bb0 | 2023-04-03 20:19:07 +0000 | [diff] [blame] | 553 | return getNdkSysrootBase(ctx).Join(ctx, "usr/lib", config.NDKTriple(ctx.toolchain())) | 
|  | 554 | } | 
| Rebecca Chyung | 961cf1c | 2023-04-03 05:17:17 +0000 | [diff] [blame] | 555 |  | 
| Dan Albert | 4048bb0 | 2023-04-03 20:19:07 +0000 | [diff] [blame] | 556 | // Returns the install path for versioned NDK libraries. These are most often | 
|  | 557 | // stubs, but the same paths are used for CRT objects. | 
| Spandan Das | f280b23 | 2024-04-04 21:25:51 +0000 | [diff] [blame] | 558 | func getVersionedLibraryInstallPath(ctx ModuleContext, apiLevel android.ApiLevel) android.OutputPath { | 
| Dan Albert | 4048bb0 | 2023-04-03 20:19:07 +0000 | [diff] [blame] | 559 | return getUnversionedLibraryInstallPath(ctx).Join(ctx, apiLevel.String()) | 
|  | 560 | } | 
|  | 561 |  | 
|  | 562 | func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) { | 
|  | 563 | installDir := getVersionedLibraryInstallPath(ctx, stub.apiLevel) | 
| Spandan Das | f280b23 | 2024-04-04 21:25:51 +0000 | [diff] [blame] | 564 | out := installDir.Join(ctx, path.Base()) | 
|  | 565 | ctx.Build(pctx, android.BuildParams{ | 
|  | 566 | Rule:   android.Cp, | 
|  | 567 | Input:  path, | 
|  | 568 | Output: out, | 
|  | 569 | }) | 
|  | 570 | stub.installPath = out | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 571 | } | 
|  | 572 |  | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 573 | func newStubLibrary() *Module { | 
| Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 574 | module, library := NewLibrary(android.DeviceSupported) | 
|  | 575 | library.BuildOnlyShared() | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 576 | module.stl = nil | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 577 | module.sanitize = nil | 
| ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 578 | library.disableStripping() | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 579 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 580 | stub := &stubDecorator{ | 
|  | 581 | libraryDecorator: library, | 
|  | 582 | } | 
|  | 583 | module.compiler = stub | 
|  | 584 | module.linker = stub | 
|  | 585 | module.installer = stub | 
| Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 586 | module.library = stub | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 587 |  | 
| Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 588 | module.Properties.AlwaysSdk = true | 
|  | 589 | module.Properties.Sdk_version = StringPtr("current") | 
|  | 590 |  | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 591 | module.AddProperties(&stub.properties, &library.MutatedProperties) | 
|  | 592 |  | 
|  | 593 | return module | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
| Dan Albert | f740ed0 | 2020-07-24 14:19:06 -0700 | [diff] [blame] | 596 | // ndk_library creates a library that exposes a stub implementation of functions | 
|  | 597 | // and variables for use at build time only. | 
| Jooyung Han | b90e491 | 2019-12-09 18:21:48 +0900 | [diff] [blame] | 598 | func NdkLibraryFactory() android.Module { | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 599 | module := newStubLibrary() | 
|  | 600 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) | 
|  | 601 | return module | 
| Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 602 | } |