blob: b4c31e5e13fc0148dc7d5ff23e425200532f0ddf [file] [log] [blame]
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001// 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
15package cc
16
17import (
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080018 "sync"
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070019
Colin Cross36242852017-06-23 15:06:31 -070020 "android/soong/android"
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080021 "android/soong/cc/config"
22)
23
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080024var (
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080025 lsdumpPaths []string
26 lsdumpPathsLock sync.Mutex
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080027)
28
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080029type SAbiProperties struct {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080030 // 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 Kim69378442019-06-03 19:10:47 +090035 ReexportedIncludes []string `blueprint:"mutated"`
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080036}
37
38type sabi struct {
39 Properties SAbiProperties
40}
41
42func (sabimod *sabi) props() []interface{} {
43 return []interface{}{&sabimod.Properties}
44}
45
46func (sabimod *sabi) begin(ctx BaseModuleContext) {}
47
48func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
49 return deps
50}
51
52func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080053 // 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 Chowdhary3e231fd2017-02-08 13:45:53 -080060 return flags
61}
62
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080063func 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 Chowdhary3e231fd2017-02-08 13:45:53 -080082func sabiDepsMutator(mctx android.TopDownMutatorContext) {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080083 if c, ok := mctx.Module().(*Module); ok {
84 if shouldSkipSabiDepsMutator(mctx, c) {
85 return
86 }
Colin Crossd11fcda2017-10-23 17:59:01 -070087 mctx.VisitDirectDeps(func(m android.Module) {
Colin Cross6e511a92020-07-27 21:26:48 -070088 if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080089 if cc, ok := m.(*Module); ok {
90 cc.sabi.Properties.CreateSAbiDumps = true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080091 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080092 }
93 })
94 }
95}
Hsin-Yi Chen53489642019-07-31 17:10:45 +080096
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080097// Add an entry to the global list of lsdump. The list is exported to a Make variable by
98// `cc.makeVarsProvider`.
Hsin-Yi Chen53489642019-07-31 17:10:45 +080099func addLsdumpPath(lsdumpPath string) {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800100 lsdumpPathsLock.Lock()
101 defer lsdumpPathsLock.Unlock()
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800102 lsdumpPaths = append(lsdumpPaths, lsdumpPath)
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800103}