Home | History | Annotate | Download | only in cc
      1 // Copyright 2015 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 	"fmt"
     19 	"regexp"
     20 	"strings"
     21 
     22 	"android/soong/android"
     23 )
     24 
     25 // Efficiently converts a list of include directories to a single string
     26 // of cflags with -I prepended to each directory.
     27 func includeDirsToFlags(dirs android.Paths) string {
     28 	return android.JoinWithPrefix(dirs.Strings(), "-I")
     29 }
     30 
     31 func includeFilesToFlags(files android.Paths) string {
     32 	return android.JoinWithPrefix(files.Strings(), "-include ")
     33 }
     34 
     35 func ldDirsToFlags(dirs []string) string {
     36 	return android.JoinWithPrefix(dirs, "-L")
     37 }
     38 
     39 func libNamesToFlags(names []string) string {
     40 	return android.JoinWithPrefix(names, "-l")
     41 }
     42 
     43 var indexList = android.IndexList
     44 var inList = android.InList
     45 var filterList = android.FilterList
     46 var removeListFromList = android.RemoveListFromList
     47 var removeFromList = android.RemoveFromList
     48 
     49 var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
     50 
     51 func moduleToLibName(module string) (string, error) {
     52 	matches := libNameRegexp.FindStringSubmatch(module)
     53 	if matches == nil {
     54 		return "", fmt.Errorf("Library module name %s does not start with lib", module)
     55 	}
     56 	return matches[1], nil
     57 }
     58 
     59 func flagsToBuilderFlags(in Flags) builderFlags {
     60 	return builderFlags{
     61 		globalFlags:    strings.Join(in.GlobalFlags, " "),
     62 		arFlags:        strings.Join(in.ArFlags, " "),
     63 		asFlags:        strings.Join(in.AsFlags, " "),
     64 		cFlags:         strings.Join(in.CFlags, " "),
     65 		toolingCFlags:  strings.Join(in.ToolingCFlags, " "),
     66 		conlyFlags:     strings.Join(in.ConlyFlags, " "),
     67 		cppFlags:       strings.Join(in.CppFlags, " "),
     68 		yaccFlags:      strings.Join(in.YaccFlags, " "),
     69 		protoFlags:     strings.Join(in.protoFlags, " "),
     70 		protoOutParams: strings.Join(in.protoOutParams, ","),
     71 		aidlFlags:      strings.Join(in.aidlFlags, " "),
     72 		rsFlags:        strings.Join(in.rsFlags, " "),
     73 		ldFlags:        strings.Join(in.LdFlags, " "),
     74 		libFlags:       strings.Join(in.libFlags, " "),
     75 		tidyFlags:      strings.Join(in.TidyFlags, " "),
     76 		sAbiFlags:      strings.Join(in.SAbiFlags, " "),
     77 		yasmFlags:      strings.Join(in.YasmFlags, " "),
     78 		toolchain:      in.Toolchain,
     79 		clang:          in.Clang,
     80 		coverage:       in.Coverage,
     81 		tidy:           in.Tidy,
     82 		sAbiDump:       in.SAbiDump,
     83 		protoRoot:      in.ProtoRoot,
     84 
     85 		systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
     86 
     87 		groupStaticLibs: in.GroupStaticLibs,
     88 		arGoldPlugin:    in.ArGoldPlugin,
     89 	}
     90 }
     91 
     92 func addPrefix(list []string, prefix string) []string {
     93 	for i := range list {
     94 		list[i] = prefix + list[i]
     95 	}
     96 	return list
     97 }
     98 
     99 func addSuffix(list []string, suffix string) []string {
    100 	for i := range list {
    101 		list[i] = list[i] + suffix
    102 	}
    103 	return list
    104 }
    105