blob: 8086f5b6a4d6026e2fea4163e23f9f1c0108e258 [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
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080020 "github.com/google/blueprint"
21
Colin Cross36242852017-06-23 15:06:31 -070022 "android/soong/android"
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080023 "android/soong/cc/config"
24)
25
26type SAbiProperties struct {
Jayant Chowdhary715cac32017-04-20 06:53:59 -070027 CreateSAbiDumps bool `blueprint:"mutated"`
28 ReexportedIncludeFlags []string
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080029}
30
31type sabi struct {
32 Properties SAbiProperties
33}
34
35func (sabimod *sabi) props() []interface{} {
36 return []interface{}{&sabimod.Properties}
37}
38
39func (sabimod *sabi) begin(ctx BaseModuleContext) {}
40
41func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
42 return deps
43}
44
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070045func 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
56func 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 Chowdhary3e231fd2017-02-08 13:45:53 -080066func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070067 // 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)
Junmo Parkccbd62e2017-07-20 13:29:24 +090070
71 // RSClang does not support recent mcpu option likes exynos-m2.
72 // So we need overriding mcpu option when we want to use it.
73 if ctx.Arch().CpuVariant == "exynos-m2" {
74 flags.ToolingCFlags = append(flags.ToolingCFlags, "-mcpu=cortex-a53")
75 }
76
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080077 return flags
78}
79
80func sabiDepsMutator(mctx android.TopDownMutatorContext) {
81 if c, ok := mctx.Module().(*Module); ok &&
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070082 ((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) ||
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 (c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
84 mctx.VisitDirectDeps(func(m blueprint.Module) {
85 tag := mctx.OtherModuleDependencyTag(m)
86 switch tag {
87 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
88
89 cc, _ := m.(*Module)
90 if cc == nil {
91 return
92 }
93 cc.sabi.Properties.CreateSAbiDumps = true
94 }
95 })
96 }
97}