Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 21 | |
| 22 | "android/soong/common" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // Efficiently converts a list of include directories to a single string |
| 26 | // of cflags with -I prepended to each directory. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 27 | func includeDirsToFlags(dirs common.Paths) string { |
| 28 | return common.JoinWithPrefix(dirs.Strings(), "-I") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 31 | func includeFilesToFlags(files common.Paths) string { |
| 32 | return common.JoinWithPrefix(files.Strings(), "-include ") |
Colin Cross | 39d97f2 | 2015-09-14 12:30:50 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 35 | func ldDirsToFlags(dirs []string) string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 36 | return common.JoinWithPrefix(dirs, "-L") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func libNamesToFlags(names []string) string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 40 | return common.JoinWithPrefix(names, "-l") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | func inList(s string, list []string) bool { |
| 44 | for _, l := range list { |
| 45 | if l == s { |
| 46 | return true |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return false |
| 51 | } |
| 52 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 53 | func filterList(list []string, filter []string) (remainder []string, filtered []string) { |
| 54 | for _, l := range list { |
| 55 | if inList(l, filter) { |
| 56 | filtered = append(filtered, l) |
| 57 | } else { |
| 58 | remainder = append(remainder, l) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return |
| 63 | } |
| 64 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 65 | var libNameRegexp = regexp.MustCompile(`^lib(.*)$`) |
| 66 | |
| 67 | func moduleToLibName(module string) (string, error) { |
| 68 | matches := libNameRegexp.FindStringSubmatch(module) |
| 69 | if matches == nil { |
| 70 | return "", fmt.Errorf("Library module name %s does not start with lib", module) |
| 71 | } |
| 72 | return matches[1], nil |
| 73 | } |
| 74 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame^] | 75 | func flagsToBuilderFlags(in Flags) builderFlags { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 76 | return builderFlags{ |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 77 | globalFlags: strings.Join(in.GlobalFlags, " "), |
| 78 | asFlags: strings.Join(in.AsFlags, " "), |
| 79 | cFlags: strings.Join(in.CFlags, " "), |
| 80 | conlyFlags: strings.Join(in.ConlyFlags, " "), |
| 81 | cppFlags: strings.Join(in.CppFlags, " "), |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 82 | yaccFlags: strings.Join(in.YaccFlags, " "), |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 83 | ldFlags: strings.Join(in.LdFlags, " "), |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 84 | nocrt: in.Nocrt, |
| 85 | toolchain: in.Toolchain, |
| 86 | clang: in.Clang, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 87 | } |
| 88 | } |