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 | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 18 | "strings" |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 19 | "sync" |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 20 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 21 | "android/soong/android" |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 22 | "android/soong/cc/config" |
| 23 | ) |
| 24 | |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 25 | var ( |
| 26 | lsdumpPaths []string |
| 27 | sabiLock sync.Mutex |
| 28 | ) |
| 29 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 30 | type SAbiProperties struct { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 31 | CreateSAbiDumps bool `blueprint:"mutated"` |
| 32 | ReexportedIncludes []string `blueprint:"mutated"` |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | type sabi struct { |
| 36 | Properties SAbiProperties |
| 37 | } |
| 38 | |
| 39 | func (sabimod *sabi) props() []interface{} { |
| 40 | return []interface{}{&sabimod.Properties} |
| 41 | } |
| 42 | |
| 43 | func (sabimod *sabi) begin(ctx BaseModuleContext) {} |
| 44 | |
| 45 | func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 46 | return deps |
| 47 | } |
| 48 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 49 | func 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 | |
| 60 | func 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 Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 70 | func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 71 | // Assuming that the cflags which clang LibTooling tools cannot |
| 72 | // understand have not been converted to ninja variables yet. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 73 | flags.Local.ToolingCFlags = filterOutWithPrefix(flags.Local.CFlags, config.ClangLibToolingUnknownCflags) |
| 74 | flags.Global.ToolingCFlags = filterOutWithPrefix(flags.Global.CFlags, config.ClangLibToolingUnknownCflags) |
| 75 | flags.Local.ToolingCppFlags = filterOutWithPrefix(flags.Local.CppFlags, config.ClangLibToolingUnknownCflags) |
| 76 | flags.Global.ToolingCppFlags = filterOutWithPrefix(flags.Global.CppFlags, config.ClangLibToolingUnknownCflags) |
Junmo Park | ccbd62e | 2017-07-20 13:29:24 +0900 | [diff] [blame] | 77 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 78 | return flags |
| 79 | } |
| 80 | |
| 81 | func sabiDepsMutator(mctx android.TopDownMutatorContext) { |
| 82 | if c, ok := mctx.Module().(*Module); ok && |
Lorenzo Colitti | 2973c11 | 2019-12-18 00:15:07 +0000 | [diff] [blame] | 83 | ((c.IsVndk() && c.UseVndk()) || c.isLlndk(mctx.Config()) || |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 84 | (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 85 | mctx.VisitDirectDeps(func(m android.Module) { |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 86 | tag := mctx.OtherModuleDependencyTag(m) |
| 87 | switch tag { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 88 | case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 89 | |
| 90 | cc, _ := m.(*Module) |
| 91 | if cc == nil { |
| 92 | return |
| 93 | } |
| 94 | cc.sabi.Properties.CreateSAbiDumps = true |
| 95 | } |
| 96 | }) |
| 97 | } |
| 98 | } |
Hsin-Yi Chen | 5348964 | 2019-07-31 17:10:45 +0800 | [diff] [blame] | 99 | |
| 100 | func addLsdumpPath(lsdumpPath string) { |
| 101 | sabiLock.Lock() |
| 102 | lsdumpPaths = append(lsdumpPaths, lsdumpPath) |
| 103 | sabiLock.Unlock() |
| 104 | } |