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" |
| 19 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 20 | "github.com/google/blueprint" |
| 21 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame^] | 22 | "android/soong/android" |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 23 | "android/soong/cc/config" |
| 24 | ) |
| 25 | |
| 26 | type SAbiProperties struct { |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 27 | CreateSAbiDumps bool `blueprint:"mutated"` |
| 28 | ReexportedIncludeFlags []string |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | type sabi struct { |
| 32 | Properties SAbiProperties |
| 33 | } |
| 34 | |
| 35 | func (sabimod *sabi) props() []interface{} { |
| 36 | return []interface{}{&sabimod.Properties} |
| 37 | } |
| 38 | |
| 39 | func (sabimod *sabi) begin(ctx BaseModuleContext) {} |
| 40 | |
| 41 | func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 42 | return deps |
| 43 | } |
| 44 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 45 | func inListWithPrefixSearch(flag string, filter []string) bool { |
| 46 | // Assuming the filter is small enough. |
| 47 | // If the suffix of a filter element is *, try matching prefixes as well. |
| 48 | for _, f := range filter { |
| 49 | if (f == flag) || (strings.HasSuffix(f, "*") && strings.HasPrefix(flag, strings.TrimSuffix(f, "*"))) { |
| 50 | return true |
| 51 | } |
| 52 | } |
| 53 | return false |
| 54 | } |
| 55 | |
| 56 | func filterOutWithPrefix(list []string, filter []string) (remainder []string) { |
| 57 | // Go through the filter, matching and optionally doing a prefix search for list elements. |
| 58 | for _, l := range list { |
| 59 | if !inListWithPrefixSearch(l, filter) { |
| 60 | remainder = append(remainder, l) |
| 61 | } |
| 62 | } |
| 63 | return |
| 64 | } |
| 65 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 66 | func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 67 | // Assuming that the cflags which clang LibTooling tools cannot |
| 68 | // understand have not been converted to ninja variables yet. |
| 69 | flags.ToolingCFlags = filterOutWithPrefix(flags.CFlags, config.ClangLibToolingUnknownCflags) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 70 | return flags |
| 71 | } |
| 72 | |
| 73 | func sabiDepsMutator(mctx android.TopDownMutatorContext) { |
| 74 | if c, ok := mctx.Module().(*Module); ok && |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 75 | (Bool(c.Properties.Vendor_available) || (inList(c.Name(), config.LLndkLibraries())) || |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 76 | (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) { |
| 77 | mctx.VisitDirectDeps(func(m blueprint.Module) { |
| 78 | tag := mctx.OtherModuleDependencyTag(m) |
| 79 | switch tag { |
| 80 | case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: |
| 81 | |
| 82 | cc, _ := m.(*Module) |
| 83 | if cc == nil { |
| 84 | return |
| 85 | } |
| 86 | cc.sabi.Properties.CreateSAbiDumps = true |
| 87 | } |
| 88 | }) |
| 89 | } |
| 90 | } |