| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
|  | 21 | func init() { | 
| LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 22 | android.RegisterParallelSingletonType("ndk_abi_dump", NdkAbiDumpSingleton) | 
|  | 23 | android.RegisterParallelSingletonType("ndk_abi_diff", NdkAbiDiffSingleton) | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 24 | } | 
|  | 25 |  | 
|  | 26 | func getNdkAbiDumpInstallBase(ctx android.PathContext) android.OutputPath { | 
|  | 27 | return android.PathForOutput(ctx).Join(ctx, "abi-dumps/ndk") | 
|  | 28 | } | 
|  | 29 |  | 
|  | 30 | func getNdkAbiDumpTimestampFile(ctx android.PathContext) android.OutputPath { | 
|  | 31 | return android.PathForOutput(ctx, "ndk_abi_dump.timestamp") | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | func NdkAbiDumpSingleton() android.Singleton { | 
|  | 35 | return &ndkAbiDumpSingleton{} | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | type ndkAbiDumpSingleton struct{} | 
|  | 39 |  | 
|  | 40 | func (n *ndkAbiDumpSingleton) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 41 | var depPaths android.Paths | 
|  | 42 | ctx.VisitAllModules(func(module android.Module) { | 
| Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 43 | if !module.Enabled(ctx) { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 44 | return | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | if m, ok := module.(*Module); ok { | 
|  | 48 | if installer, ok := m.installer.(*stubDecorator); ok { | 
| Dan Albert | fbe5780 | 2024-08-09 20:39:39 +0000 | [diff] [blame] | 49 | if canDumpAbi(ctx.Config(), ctx.ModuleDir(module)) { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 50 | depPaths = append(depPaths, installer.abiDumpPath) | 
|  | 51 | } | 
|  | 52 | } | 
|  | 53 | } | 
|  | 54 | }) | 
|  | 55 |  | 
|  | 56 | // `m dump-ndk-abi` will dump the NDK ABI. | 
|  | 57 | // `development/tools/ndk/update_ndk_abi.sh` will dump the NDK ABI and | 
|  | 58 | // update the golden copies in prebuilts/abi-dumps/ndk. | 
|  | 59 | ctx.Build(pctx, android.BuildParams{ | 
|  | 60 | Rule:      android.Touch, | 
|  | 61 | Output:    getNdkAbiDumpTimestampFile(ctx), | 
|  | 62 | Implicits: depPaths, | 
|  | 63 | }) | 
|  | 64 |  | 
|  | 65 | ctx.Phony("dump-ndk-abi", getNdkAbiDumpTimestampFile(ctx)) | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | func getNdkAbiDiffTimestampFile(ctx android.PathContext) android.WritablePath { | 
|  | 69 | return android.PathForOutput(ctx, "ndk_abi_diff.timestamp") | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | func NdkAbiDiffSingleton() android.Singleton { | 
|  | 73 | return &ndkAbiDiffSingleton{} | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | type ndkAbiDiffSingleton struct{} | 
|  | 77 |  | 
|  | 78 | func (n *ndkAbiDiffSingleton) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 79 | var depPaths android.Paths | 
|  | 80 | ctx.VisitAllModules(func(module android.Module) { | 
| Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 81 | if m, ok := module.(android.Module); ok && !m.Enabled(ctx) { | 
| Dan Albert | f1d14c7 | 2020-07-30 14:32:55 -0700 | [diff] [blame] | 82 | return | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | if m, ok := module.(*Module); ok { | 
|  | 86 | if installer, ok := m.installer.(*stubDecorator); ok { | 
|  | 87 | depPaths = append(depPaths, installer.abiDiffPaths...) | 
|  | 88 | } | 
|  | 89 | } | 
|  | 90 | }) | 
|  | 91 |  | 
|  | 92 | depPaths = append(depPaths, getNdkAbiDumpTimestampFile(ctx)) | 
|  | 93 |  | 
|  | 94 | // `m diff-ndk-abi` will diff the NDK ABI. | 
|  | 95 | ctx.Build(pctx, android.BuildParams{ | 
|  | 96 | Rule:      android.Touch, | 
|  | 97 | Output:    getNdkAbiDiffTimestampFile(ctx), | 
|  | 98 | Implicits: depPaths, | 
|  | 99 | }) | 
|  | 100 |  | 
|  | 101 | ctx.Phony("diff-ndk-abi", getNdkAbiDiffTimestampFile(ctx)) | 
|  | 102 | } |