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