blob: ec1d2468a80455f72ecff1aba292df3efdf659a9 [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"
19
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
24type SAbiProperties struct {
Jayant Chowdhary715cac32017-04-20 06:53:59 -070025 CreateSAbiDumps bool `blueprint:"mutated"`
26 ReexportedIncludeFlags []string
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080027}
28
29type sabi struct {
30 Properties SAbiProperties
31}
32
33func (sabimod *sabi) props() []interface{} {
34 return []interface{}{&sabimod.Properties}
35}
36
37func (sabimod *sabi) begin(ctx BaseModuleContext) {}
38
39func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
40 return deps
41}
42
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070043func 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
54func 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 Chowdhary3e231fd2017-02-08 13:45:53 -080064func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070065 // 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 Parkccbd62e2017-07-20 13:29:24 +090068
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 Chowdhary3e231fd2017-02-08 13:45:53 -080075 return flags
76}
77
78func sabiDepsMutator(mctx android.TopDownMutatorContext) {
79 if c, ok := mctx.Module().(*Module); ok &&
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070080 ((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) ||
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
Colin Crossd11fcda2017-10-23 17:59:01 -070082 mctx.VisitDirectDeps(func(m android.Module) {
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 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}