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 15package cc 16 17import ( 18 "android/soong/android" 19) 20 21func init() { 22 android.RegisterSingletonType("ndk_abi_dump", NdkAbiDumpSingleton) 23 android.RegisterSingletonType("ndk_abi_diff", NdkAbiDiffSingleton) 24} 25 26func getNdkAbiDumpInstallBase(ctx android.PathContext) android.OutputPath { 27 return android.PathForOutput(ctx).Join(ctx, "abi-dumps/ndk") 28} 29 30func getNdkAbiDumpTimestampFile(ctx android.PathContext) android.OutputPath { 31 return android.PathForOutput(ctx, "ndk_abi_dump.timestamp") 32} 33 34func NdkAbiDumpSingleton() android.Singleton { 35 return &ndkAbiDumpSingleton{} 36} 37 38type ndkAbiDumpSingleton struct{} 39 40func (n *ndkAbiDumpSingleton) GenerateBuildActions(ctx android.SingletonContext) { 41 var depPaths android.Paths 42 ctx.VisitAllModules(func(module android.Module) { 43 if !module.Enabled() { 44 return 45 } 46 47 if m, ok := module.(*Module); ok { 48 if installer, ok := m.installer.(*stubDecorator); ok { 49 if canDumpAbi(ctx.Config()) { 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 68func getNdkAbiDiffTimestampFile(ctx android.PathContext) android.WritablePath { 69 return android.PathForOutput(ctx, "ndk_abi_diff.timestamp") 70} 71 72func NdkAbiDiffSingleton() android.Singleton { 73 return &ndkAbiDiffSingleton{} 74} 75 76type ndkAbiDiffSingleton struct{} 77 78func (n *ndkAbiDiffSingleton) GenerateBuildActions(ctx android.SingletonContext) { 79 var depPaths android.Paths 80 ctx.VisitAllModules(func(module android.Module) { 81 if m, ok := module.(android.Module); ok && !m.Enabled() { 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} 103