Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 ( |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 18 | "sync" |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 19 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 21 | "android/soong/cc/config" |
| 22 | ) |
| 23 | |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 24 | var ( |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 25 | lsdumpPaths []string |
| 26 | lsdumpPathsLock sync.Mutex |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 29 | type SAbiProperties struct { |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 30 | // True if need to generate ABI dump. |
| 31 | CreateSAbiDumps bool `blueprint:"mutated"` |
| 32 | |
| 33 | // Include directories that may contain ABI information exported by a library. |
| 34 | // These directories are passed to the header-abi-dumper. |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 35 | ReexportedIncludes []string `blueprint:"mutated"` |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | type sabi struct { |
| 39 | Properties SAbiProperties |
| 40 | } |
| 41 | |
| 42 | func (sabimod *sabi) props() []interface{} { |
| 43 | return []interface{}{&sabimod.Properties} |
| 44 | } |
| 45 | |
| 46 | func (sabimod *sabi) begin(ctx BaseModuleContext) {} |
| 47 | |
| 48 | func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 49 | return deps |
| 50 | } |
| 51 | |
| 52 | func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags { |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 53 | // Filter out flags which libTooling don't understand. |
| 54 | // This is here for legacy reasons and future-proof, in case the version of libTooling and clang |
| 55 | // diverge. |
| 56 | flags.Local.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CFlags) |
| 57 | flags.Global.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CFlags) |
| 58 | flags.Local.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CppFlags) |
| 59 | flags.Global.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CppFlags) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 60 | return flags |
| 61 | } |
| 62 | |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 63 | func shouldSkipSabiDepsMutator(mctx android.TopDownMutatorContext, m *Module) bool { |
| 64 | if m.sabi != nil && m.sabi.Properties.CreateSAbiDumps { |
| 65 | return false |
| 66 | } |
| 67 | if library, ok := m.linker.(*libraryDecorator); ok { |
| 68 | ctx := &baseModuleContext{ |
| 69 | BaseModuleContext: mctx, |
| 70 | moduleContextImpl: moduleContextImpl{ |
| 71 | mod: m, |
| 72 | }, |
| 73 | } |
| 74 | ctx.ctx = ctx |
| 75 | return !library.shouldCreateSourceAbiDump(ctx) |
| 76 | } |
| 77 | return true |
| 78 | } |
| 79 | |
| 80 | // Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps |
| 81 | // of their dependencies would be generated. |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 82 | func sabiDepsMutator(mctx android.TopDownMutatorContext) { |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 83 | if c, ok := mctx.Module().(*Module); ok { |
| 84 | if shouldSkipSabiDepsMutator(mctx, c) { |
| 85 | return |
| 86 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 87 | mctx.VisitDirectDeps(func(m android.Module) { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 88 | if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() { |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 89 | if cc, ok := m.(*Module); ok { |
| 90 | cc.sabi.Properties.CreateSAbiDumps = true |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 91 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 92 | } |
| 93 | }) |
| 94 | } |
| 95 | } |
Hsin-Yi Chen | 5348964 | 2019-07-31 17:10:45 +0800 | [diff] [blame] | 96 | |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 97 | // Add an entry to the global list of lsdump. The list is exported to a Make variable by |
| 98 | // `cc.makeVarsProvider`. |
Hsin-Yi Chen | 5348964 | 2019-07-31 17:10:45 +0800 | [diff] [blame] | 99 | func addLsdumpPath(lsdumpPath string) { |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame^] | 100 | lsdumpPathsLock.Lock() |
| 101 | defer lsdumpPathsLock.Unlock() |
Hsin-Yi Chen | 5348964 | 2019-07-31 17:10:45 +0800 | [diff] [blame] | 102 | lsdumpPaths = append(lsdumpPaths, lsdumpPath) |
Hsin-Yi Chen | 5348964 | 2019-07-31 17:10:45 +0800 | [diff] [blame] | 103 | } |