blob: ae7b31d28822210bec0ddd9b50a70a7d10bce8fc [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 Chowdhary9677e8c2017-06-15 14:45:18 -070018 "strings"
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080019 "sync"
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070020
Colin Cross36242852017-06-23 15:06:31 -070021 "android/soong/android"
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080022 "android/soong/cc/config"
23)
24
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080025var (
26 lsdumpPaths []string
27 sabiLock sync.Mutex
28)
29
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080030type SAbiProperties struct {
Inseob Kim69378442019-06-03 19:10:47 +090031 CreateSAbiDumps bool `blueprint:"mutated"`
32 ReexportedIncludes []string `blueprint:"mutated"`
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080033}
34
35type sabi struct {
36 Properties SAbiProperties
37}
38
39func (sabimod *sabi) props() []interface{} {
40 return []interface{}{&sabimod.Properties}
41}
42
43func (sabimod *sabi) begin(ctx BaseModuleContext) {}
44
45func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
46 return deps
47}
48
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070049func inListWithPrefixSearch(flag string, filter []string) bool {
50 // Assuming the filter is small enough.
51 // If the suffix of a filter element is *, try matching prefixes as well.
52 for _, f := range filter {
53 if (f == flag) || (strings.HasSuffix(f, "*") && strings.HasPrefix(flag, strings.TrimSuffix(f, "*"))) {
54 return true
55 }
56 }
57 return false
58}
59
60func filterOutWithPrefix(list []string, filter []string) (remainder []string) {
61 // Go through the filter, matching and optionally doing a prefix search for list elements.
62 for _, l := range list {
63 if !inListWithPrefixSearch(l, filter) {
64 remainder = append(remainder, l)
65 }
66 }
67 return
68}
69
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080070func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070071 // Assuming that the cflags which clang LibTooling tools cannot
72 // understand have not been converted to ninja variables yet.
73 flags.ToolingCFlags = filterOutWithPrefix(flags.CFlags, config.ClangLibToolingUnknownCflags)
Chih-Hung Hsieh9e88ba92018-08-22 14:18:04 -070074 flags.ToolingCppFlags = filterOutWithPrefix(flags.CppFlags, config.ClangLibToolingUnknownCflags)
Junmo Parkccbd62e2017-07-20 13:29:24 +090075
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080076 return flags
77}
78
79func sabiDepsMutator(mctx android.TopDownMutatorContext) {
80 if c, ok := mctx.Module().(*Module); ok &&
Inseob Kim9516ee92019-05-09 10:56:13 +090081 ((c.isVndk() && c.useVndk()) || inList(c.Name(), *llndkLibraries(mctx.Config())) ||
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
Colin Crossd11fcda2017-10-23 17:59:01 -070083 mctx.VisitDirectDeps(func(m android.Module) {
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080084 tag := mctx.OtherModuleDependencyTag(m)
85 switch tag {
86 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
87
88 cc, _ := m.(*Module)
89 if cc == nil {
90 return
91 }
92 cc.sabi.Properties.CreateSAbiDumps = true
93 }
94 })
95 }
96}