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" |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | "regexp" |
| 21 | "strings" |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 22 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // Efficiently converts a list of include directories to a single string |
| 27 | // of cflags with -I prepended to each directory. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 28 | func includeDirsToFlags(dirs android.Paths) string { |
| 29 | return android.JoinWithPrefix(dirs.Strings(), "-I") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | func ldDirsToFlags(dirs []string) string { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 33 | return android.JoinWithPrefix(dirs, "-L") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | func libNamesToFlags(names []string) string { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 37 | return android.JoinWithPrefix(names, "-l") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Colin Cross | b4330e2 | 2017-12-22 15:47:09 -0800 | [diff] [blame] | 40 | var indexList = android.IndexList |
| 41 | var inList = android.InList |
| 42 | var filterList = android.FilterList |
| 43 | var removeListFromList = android.RemoveListFromList |
| 44 | var removeFromList = android.RemoveFromList |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 45 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 46 | var libNameRegexp = regexp.MustCompile(`^lib(.*)$`) |
| 47 | |
| 48 | func moduleToLibName(module string) (string, error) { |
| 49 | matches := libNameRegexp.FindStringSubmatch(module) |
| 50 | if matches == nil { |
| 51 | return "", fmt.Errorf("Library module name %s does not start with lib", module) |
| 52 | } |
| 53 | return matches[1], nil |
| 54 | } |
| 55 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 56 | func flagsToBuilderFlags(in Flags) builderFlags { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 57 | return builderFlags{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 58 | globalCommonFlags: strings.Join(in.Global.CommonFlags, " "), |
| 59 | globalAsFlags: strings.Join(in.Global.AsFlags, " "), |
| 60 | globalYasmFlags: strings.Join(in.Global.YasmFlags, " "), |
| 61 | globalCFlags: strings.Join(in.Global.CFlags, " "), |
| 62 | globalToolingCFlags: strings.Join(in.Global.ToolingCFlags, " "), |
| 63 | globalToolingCppFlags: strings.Join(in.Global.ToolingCppFlags, " "), |
| 64 | globalConlyFlags: strings.Join(in.Global.ConlyFlags, " "), |
| 65 | globalCppFlags: strings.Join(in.Global.CppFlags, " "), |
| 66 | globalLdFlags: strings.Join(in.Global.LdFlags, " "), |
| 67 | |
| 68 | localCommonFlags: strings.Join(in.Local.CommonFlags, " "), |
| 69 | localAsFlags: strings.Join(in.Local.AsFlags, " "), |
| 70 | localYasmFlags: strings.Join(in.Local.YasmFlags, " "), |
| 71 | localCFlags: strings.Join(in.Local.CFlags, " "), |
| 72 | localToolingCFlags: strings.Join(in.Local.ToolingCFlags, " "), |
| 73 | localToolingCppFlags: strings.Join(in.Local.ToolingCppFlags, " "), |
| 74 | localConlyFlags: strings.Join(in.Local.ConlyFlags, " "), |
| 75 | localCppFlags: strings.Join(in.Local.CppFlags, " "), |
| 76 | localLdFlags: strings.Join(in.Local.LdFlags, " "), |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 77 | |
| 78 | aidlFlags: strings.Join(in.aidlFlags, " "), |
| 79 | rsFlags: strings.Join(in.rsFlags, " "), |
| 80 | libFlags: strings.Join(in.libFlags, " "), |
| 81 | extraLibFlags: strings.Join(in.extraLibFlags, " "), |
| 82 | tidyFlags: strings.Join(in.TidyFlags, " "), |
| 83 | sAbiFlags: strings.Join(in.SAbiFlags, " "), |
| 84 | toolchain: in.Toolchain, |
Oliver Nguyen | 0452678 | 2020-04-21 12:40:27 -0700 | [diff] [blame] | 85 | gcovCoverage: in.GcovCoverage, |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 86 | tidy: in.Tidy, |
| 87 | sAbiDump: in.SAbiDump, |
| 88 | emitXrefs: in.EmitXrefs, |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 89 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 90 | systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "), |
| 91 | |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 92 | assemblerWithCpp: in.AssemblerWithCpp, |
| 93 | groupStaticLibs: in.GroupStaticLibs, |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 94 | |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 95 | proto: in.proto, |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 96 | protoC: in.protoC, |
| 97 | protoOptionsFile: in.protoOptionsFile, |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 98 | |
| 99 | yacc: in.Yacc, |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 100 | lex: in.Lex, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | } |
| 102 | } |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 103 | |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 104 | func flagsToStripFlags(in Flags) StripFlags { |
| 105 | return StripFlags{Toolchain: in.Toolchain} |
| 106 | } |
| 107 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 108 | func addPrefix(list []string, prefix string) []string { |
| 109 | for i := range list { |
| 110 | list[i] = prefix + list[i] |
| 111 | } |
| 112 | return list |
| 113 | } |
Jiyong Park | ab0fd5f | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 114 | |
| 115 | func addSuffix(list []string, suffix string) []string { |
| 116 | for i := range list { |
| 117 | list[i] = list[i] + suffix |
| 118 | } |
| 119 | return list |
| 120 | } |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 121 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 122 | // linkDirOnDevice/linkName -> target |
| 123 | func makeSymlinkCmd(linkDirOnDevice string, linkName string, target string) string { |
| 124 | dir := filepath.Join("$(PRODUCT_OUT)", linkDirOnDevice) |
| 125 | return "mkdir -p " + dir + " && " + |
| 126 | "ln -sf " + target + " " + filepath.Join(dir, linkName) |
| 127 | } |