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