github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/sabi.go (about)

     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 (
    18  	"strings"
    19  	"sync"
    20  
    21  	"android/soong/android"
    22  	"android/soong/cc/config"
    23  )
    24  
    25  var (
    26  	lsdumpPaths []string
    27  	sabiLock    sync.Mutex
    28  )
    29  
    30  type SAbiProperties struct {
    31  	CreateSAbiDumps        bool `blueprint:"mutated"`
    32  	ReexportedIncludeFlags []string
    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  
    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  
    70  func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
    71  	// Assuming that the cflags which clang LibTooling tools cannot
    72  	// understand have not been converted to ninja variables yet.
    73  	flags.ToolingCFlags = filterOutWithPrefix(flags.CFlags, config.ClangLibToolingUnknownCflags)
    74  
    75  	// RSClang does not support recent mcpu option likes exynos-m2.
    76  	// So we need overriding mcpu option when we want to use it.
    77  	mappedArch := map[string]string{
    78  		"exynos-m2":  "cortex-a53",
    79  		"cortex-a55": "cortex-a53",
    80  		"cortex-a75": "cortex-a57",
    81  	}
    82  	if arch, ok := mappedArch[ctx.Arch().CpuVariant]; ok {
    83  		flags.ToolingCFlags = append(flags.ToolingCFlags, "-mcpu="+arch)
    84  	}
    85  
    86  	return flags
    87  }
    88  
    89  func sabiDepsMutator(mctx android.TopDownMutatorContext) {
    90  	if c, ok := mctx.Module().(*Module); ok &&
    91  		((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) ||
    92  			(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
    93  		mctx.VisitDirectDeps(func(m android.Module) {
    94  			tag := mctx.OtherModuleDependencyTag(m)
    95  			switch tag {
    96  			case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
    97  
    98  				cc, _ := m.(*Module)
    99  				if cc == nil {
   100  					return
   101  				}
   102  				cc.sabi.Properties.CreateSAbiDumps = true
   103  			}
   104  		})
   105  	}
   106  }