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 | // This file generates the final rules for compiling all C/C++. All properties related to |
| 18 | // compiling should have been translated into builderFlags or another argument to the Transform* |
| 19 | // functions. |
| 20 | |
| 21 | import ( |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 22 | "fmt" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 23 | "path/filepath" |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 24 | "runtime" |
| 25 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | "strings" |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 29 | |
| 30 | "android/soong/android" |
| 31 | "android/soong/cc/config" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | const ( |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 35 | objectExtension = ".o" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 36 | staticLibraryExtension = ".a" |
| 37 | ) |
| 38 | |
| 39 | var ( |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 40 | pctx = android.NewPackageContext("android/soong/cc") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 42 | cc = pctx.AndroidGomaStaticRule("cc", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 43 | blueprint.RuleParams{ |
| 44 | Depfile: "${out}.d", |
| 45 | Deps: blueprint.DepsGCC, |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 46 | Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 47 | CommandDeps: []string{"$ccCmd"}, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 48 | }, |
Dan Willemsen | 322a0a6 | 2015-11-17 15:19:46 -0800 | [diff] [blame] | 49 | "ccCmd", "cFlags") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 50 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 51 | ld = pctx.AndroidStaticRule("ld", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 52 | blueprint.RuleParams{ |
Dan Albert | ce2b839 | 2016-07-21 13:16:49 -0700 | [diff] [blame] | 53 | Command: "$ldCmd ${crtBegin} @${out}.rsp " + |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 54 | "${libFlags} ${crtEnd} -o ${out} ${ldFlags}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 55 | CommandDeps: []string{"$ldCmd"}, |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 56 | Rspfile: "${out}.rsp", |
| 57 | RspfileContent: "${in}", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 58 | }, |
Dan Albert | ce2b839 | 2016-07-21 13:16:49 -0700 | [diff] [blame] | 59 | "ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 60 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 61 | partialLd = pctx.AndroidStaticRule("partialLd", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 62 | blueprint.RuleParams{ |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 63 | Command: "$ldCmd -nostdlib -Wl,-r ${in} -o ${out} ${ldFlags}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 64 | CommandDeps: []string{"$ldCmd"}, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 65 | }, |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 66 | "ldCmd", "ldFlags") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 67 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 68 | ar = pctx.AndroidStaticRule("ar", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 69 | blueprint.RuleParams{ |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 70 | Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 71 | CommandDeps: []string{"$arCmd"}, |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 72 | Rspfile: "${out}.rsp", |
| 73 | RspfileContent: "${in}", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 74 | }, |
| 75 | "arCmd", "arFlags") |
| 76 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 77 | darwinAr = pctx.AndroidStaticRule("darwinAr", |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 78 | blueprint.RuleParams{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 79 | Command: "rm -f ${out} && ${config.MacArPath} $arFlags $out $in", |
| 80 | CommandDeps: []string{"${config.MacArPath}"}, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 81 | }, |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 82 | "arFlags") |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 83 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 84 | darwinAppendAr = pctx.AndroidStaticRule("darwinAppendAr", |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 85 | blueprint.RuleParams{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 86 | Command: "cp -f ${inAr} ${out}.tmp && ${config.MacArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}", |
| 87 | CommandDeps: []string{"${config.MacArPath}", "${inAr}"}, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 88 | }, |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 89 | "arFlags", "inAr") |
| 90 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 91 | darwinStrip = pctx.AndroidStaticRule("darwinStrip", |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 92 | blueprint.RuleParams{ |
Colin Cross | a24166b | 2016-08-01 15:42:38 -0700 | [diff] [blame] | 93 | Command: "${config.MacStripPath} -u -r -o $out $in", |
| 94 | CommandDeps: []string{"${config.MacStripPath}"}, |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 95 | }) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 96 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 97 | prefixSymbols = pctx.AndroidStaticRule("prefixSymbols", |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 98 | blueprint.RuleParams{ |
| 99 | Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 100 | CommandDeps: []string{"$objcopyCmd"}, |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 101 | }, |
| 102 | "objcopyCmd", "prefix") |
| 103 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 104 | _ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh") |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 105 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 106 | strip = pctx.AndroidStaticRule("strip", |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 107 | blueprint.RuleParams{ |
| 108 | Depfile: "${out}.d", |
| 109 | Deps: blueprint.DepsGCC, |
| 110 | Command: "CROSS_COMPILE=$crossCompile $stripPath ${args} -i ${in} -o ${out} -d ${out}.d", |
| 111 | CommandDeps: []string{"$stripPath"}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 112 | }, |
| 113 | "args", "crossCompile") |
| 114 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 115 | emptyFile = pctx.AndroidStaticRule("emptyFile", |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 116 | blueprint.RuleParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 117 | Command: "rm -f $out && touch $out", |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 118 | }) |
| 119 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 120 | _ = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 121 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 122 | copyGccLib = pctx.AndroidStaticRule("copyGccLib", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 123 | blueprint.RuleParams{ |
| 124 | Depfile: "${out}.d", |
| 125 | Deps: blueprint.DepsGCC, |
| 126 | Command: "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 127 | CommandDeps: []string{"$copyGccLibPath", "$ccCmd"}, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 128 | }, |
| 129 | "ccCmd", "cFlags", "libName") |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 130 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 131 | _ = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh") |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 132 | |
| 133 | toc = pctx.AndroidStaticRule("toc", |
| 134 | blueprint.RuleParams{ |
| 135 | Depfile: "${out}.d", |
| 136 | Deps: blueprint.DepsGCC, |
| 137 | Command: "CROSS_COMPILE=$crossCompile $tocPath -i ${in} -o ${out} -d ${out}.d", |
| 138 | CommandDeps: []string{"$tocPath"}, |
| 139 | Restat: true, |
| 140 | }, |
| 141 | "crossCompile") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 142 | |
| 143 | clangTidy = pctx.AndroidStaticRule("clangTidy", |
| 144 | blueprint.RuleParams{ |
| 145 | Command: "rm -f $out && ${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && touch $out", |
| 146 | CommandDeps: []string{"${config.ClangBin}/clang-tidy"}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 147 | }, |
| 148 | "cFlags", "tidyFlags") |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 149 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 150 | _ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm") |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 151 | |
| 152 | yasm = pctx.AndroidStaticRule("yasm", |
| 153 | blueprint.RuleParams{ |
Dan Willemsen | 1d3e545 | 2017-08-22 20:53:45 -0700 | [diff] [blame^] | 154 | Command: "$yasmCmd $asFlags -o $out $in && $yasmCmd $asFlags -M $in >$out.d", |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 155 | CommandDeps: []string{"$yasmCmd"}, |
Dan Willemsen | 1d3e545 | 2017-08-22 20:53:45 -0700 | [diff] [blame^] | 156 | Depfile: "$out.d", |
| 157 | Deps: blueprint.DepsGCC, |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 158 | }, |
| 159 | "asFlags") |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 160 | |
| 161 | _ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper") |
| 162 | |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 163 | // -w has been added since header-abi-dumper does not need to produce any sort of diagnostic information. |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 164 | sAbiDump = pctx.AndroidStaticRule("sAbiDump", |
| 165 | blueprint.RuleParams{ |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 166 | Command: "rm -f $out && $sAbiDumper -o ${out} $in $exportDirs -- $cFlags -w -isystem ${config.RSIncludePath}", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 167 | CommandDeps: []string{"$sAbiDumper"}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 168 | }, |
| 169 | "cFlags", "exportDirs") |
| 170 | |
| 171 | _ = pctx.SourcePathVariable("sAbiLinker", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-linker") |
| 172 | |
| 173 | sAbiLink = pctx.AndroidStaticRule("sAbiLink", |
| 174 | blueprint.RuleParams{ |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 175 | Command: "$sAbiLinker -o ${out} $symbolFilter -arch $arch -api $api $exportedHeaderFlags @${out}.rsp ", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 176 | CommandDeps: []string{"$sAbiLinker"}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 177 | Rspfile: "${out}.rsp", |
| 178 | RspfileContent: "${in}", |
| 179 | }, |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 180 | "symbolFilter", "arch", "api", "exportedHeaderFlags") |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 181 | |
| 182 | _ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-diff") |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 183 | |
Jayant Chowdhary | 918b1d9 | 2017-04-18 10:44:00 -0700 | [diff] [blame] | 184 | // Abidiff check turned on in advice-only mode. Builds will not fail on abi incompatibilties / extensions. |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 185 | sAbiDiff = pctx.AndroidStaticRule("sAbiDiff", |
| 186 | blueprint.RuleParams{ |
Jayant Chowdhary | f54e0a7 | 2017-05-22 10:53:24 -0700 | [diff] [blame] | 187 | Command: "$sAbiDiffer -lib $libName -arch $arch -advice-only -o ${out} -new $in -old $referenceDump", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 188 | CommandDeps: []string{"$sAbiDiffer"}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 189 | }, |
Jayant Chowdhary | f54e0a7 | 2017-05-22 10:53:24 -0700 | [diff] [blame] | 190 | "referenceDump", "libName", "arch") |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 191 | |
| 192 | unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump", |
| 193 | blueprint.RuleParams{ |
| 194 | Command: "gunzip -c $in > $out", |
| 195 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 196 | ) |
| 197 | |
Dan Willemsen | 322a0a6 | 2015-11-17 15:19:46 -0800 | [diff] [blame] | 198 | func init() { |
| 199 | // We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the |
| 200 | // debug output. That way two builds in two different directories will |
| 201 | // create the same output. |
| 202 | if runtime.GOOS != "darwin" { |
| 203 | pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd") |
| 204 | } else { |
| 205 | // Darwin doesn't have /proc |
| 206 | pctx.StaticVariable("relPwd", "") |
| 207 | } |
| 208 | } |
| 209 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 210 | type builderFlags struct { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 211 | globalFlags string |
| 212 | arFlags string |
| 213 | asFlags string |
| 214 | cFlags string |
| 215 | toolingCFlags string // Seperate set of Cflags for clang LibTooling tools |
| 216 | conlyFlags string |
| 217 | cppFlags string |
| 218 | ldFlags string |
| 219 | libFlags string |
| 220 | yaccFlags string |
| 221 | protoFlags string |
| 222 | tidyFlags string |
| 223 | sAbiFlags string |
| 224 | yasmFlags string |
| 225 | aidlFlags string |
| 226 | rsFlags string |
| 227 | toolchain config.Toolchain |
| 228 | clang bool |
| 229 | tidy bool |
| 230 | coverage bool |
| 231 | sAbiDump bool |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 232 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 233 | systemIncludeFlags string |
| 234 | |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 235 | groupStaticLibs bool |
| 236 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 237 | stripKeepSymbols bool |
| 238 | stripKeepMiniDebugInfo bool |
| 239 | stripAddGnuDebuglink bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 242 | type Objects struct { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 243 | objFiles android.Paths |
| 244 | tidyFiles android.Paths |
| 245 | coverageFiles android.Paths |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 246 | sAbiDumpFiles android.Paths |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | func (a Objects) Copy() Objects { |
| 250 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 251 | objFiles: append(android.Paths{}, a.objFiles...), |
| 252 | tidyFiles: append(android.Paths{}, a.tidyFiles...), |
| 253 | coverageFiles: append(android.Paths{}, a.coverageFiles...), |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 254 | sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | func (a Objects) Append(b Objects) Objects { |
| 259 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 260 | objFiles: append(a.objFiles, b.objFiles...), |
| 261 | tidyFiles: append(a.tidyFiles, b.tidyFiles...), |
| 262 | coverageFiles: append(a.coverageFiles, b.coverageFiles...), |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 263 | sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 267 | // Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 268 | func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 269 | flags builderFlags, deps android.Paths) Objects { |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 270 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 271 | objFiles := make(android.Paths, len(srcFiles)) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 272 | var tidyFiles android.Paths |
| 273 | if flags.tidy && flags.clang { |
| 274 | tidyFiles = make(android.Paths, 0, len(srcFiles)) |
| 275 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 276 | var coverageFiles android.Paths |
| 277 | if flags.coverage { |
| 278 | coverageFiles = make(android.Paths, 0, len(srcFiles)) |
| 279 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 280 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 281 | commonFlags := strings.Join([]string{ |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 282 | flags.globalFlags, |
| 283 | flags.systemIncludeFlags, |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 284 | }, " ") |
| 285 | |
| 286 | toolingCflags := strings.Join([]string{ |
| 287 | commonFlags, |
| 288 | flags.toolingCFlags, |
| 289 | flags.conlyFlags, |
| 290 | }, " ") |
| 291 | |
| 292 | cflags := strings.Join([]string{ |
| 293 | commonFlags, |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 294 | flags.cFlags, |
| 295 | flags.conlyFlags, |
| 296 | }, " ") |
| 297 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 298 | toolingCppflags := strings.Join([]string{ |
| 299 | commonFlags, |
| 300 | flags.toolingCFlags, |
| 301 | flags.cppFlags, |
| 302 | }, " ") |
| 303 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 304 | cppflags := strings.Join([]string{ |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 305 | commonFlags, |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 306 | flags.cFlags, |
| 307 | flags.cppFlags, |
| 308 | }, " ") |
| 309 | |
| 310 | asflags := strings.Join([]string{ |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 311 | commonFlags, |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 312 | flags.asFlags, |
| 313 | }, " ") |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 314 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 315 | var sAbiDumpFiles android.Paths |
| 316 | if flags.sAbiDump && flags.clang { |
| 317 | sAbiDumpFiles = make(android.Paths, 0, len(srcFiles)) |
| 318 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 319 | |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 320 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 321 | cflags += " ${config.NoOverrideClangGlobalCflags}" |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 322 | toolingCflags += " ${config.NoOverrideClangGlobalCflags}" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 323 | cppflags += " ${config.NoOverrideClangGlobalCflags}" |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 324 | toolingCppflags += " ${config.NoOverrideClangGlobalCflags}" |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 325 | } else { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 326 | cflags += " ${config.NoOverrideGlobalCflags}" |
| 327 | cppflags += " ${config.NoOverrideGlobalCflags}" |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 330 | for i, srcFile := range srcFiles { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 331 | objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 332 | |
| 333 | objFiles[i] = objFile |
| 334 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 335 | if srcFile.Ext() == ".asm" { |
| 336 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 337 | Rule: yasm, |
| 338 | Description: "yasm " + srcFile.Rel(), |
| 339 | Output: objFile, |
| 340 | Input: srcFile, |
| 341 | OrderOnly: deps, |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 342 | Args: map[string]string{ |
| 343 | "asFlags": flags.yasmFlags, |
| 344 | }, |
| 345 | }) |
| 346 | continue |
| 347 | } |
| 348 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 349 | var moduleCflags string |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 350 | var moduleToolingCflags string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 351 | var ccCmd string |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 352 | tidy := flags.tidy && flags.clang |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 353 | coverage := flags.coverage |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 354 | dump := flags.sAbiDump && flags.clang |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 355 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 356 | switch srcFile.Ext() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 357 | case ".S", ".s": |
| 358 | ccCmd = "gcc" |
| 359 | moduleCflags = asflags |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 360 | tidy = false |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 361 | coverage = false |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 362 | dump = false |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 363 | case ".c": |
| 364 | ccCmd = "gcc" |
| 365 | moduleCflags = cflags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 366 | moduleToolingCflags = toolingCflags |
Colin Cross | 9978ffe | 2016-12-01 15:31:22 -0800 | [diff] [blame] | 367 | case ".cpp", ".cc", ".mm": |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 368 | ccCmd = "g++" |
| 369 | moduleCflags = cppflags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 370 | moduleToolingCflags = toolingCppflags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 371 | default: |
| 372 | ctx.ModuleErrorf("File %s has unknown extension", srcFile) |
| 373 | continue |
| 374 | } |
| 375 | |
| 376 | if flags.clang { |
| 377 | switch ccCmd { |
| 378 | case "gcc": |
| 379 | ccCmd = "clang" |
| 380 | case "g++": |
| 381 | ccCmd = "clang++" |
| 382 | default: |
| 383 | panic("unrecoginzied ccCmd") |
| 384 | } |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 385 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 386 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 387 | ccDesc := ccCmd |
| 388 | |
| 389 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 390 | ccCmd = "${config.ClangBin}/" + ccCmd |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 391 | } else { |
| 392 | ccCmd = gccCmd(flags.toolchain, ccCmd) |
| 393 | } |
| 394 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 395 | var implicitOutputs android.WritablePaths |
| 396 | if coverage { |
| 397 | gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno") |
| 398 | implicitOutputs = append(implicitOutputs, gcnoFile) |
| 399 | coverageFiles = append(coverageFiles, gcnoFile) |
| 400 | } |
| 401 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 402 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 403 | Rule: cc, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 404 | Description: ccDesc + " " + srcFile.Rel(), |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 405 | Output: objFile, |
| 406 | ImplicitOutputs: implicitOutputs, |
| 407 | Input: srcFile, |
| 408 | OrderOnly: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 409 | Args: map[string]string{ |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 410 | "cFlags": moduleCflags, |
| 411 | "ccCmd": ccCmd, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 412 | }, |
| 413 | }) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 414 | |
| 415 | if tidy { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 416 | tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 417 | tidyFiles = append(tidyFiles, tidyFile) |
| 418 | |
| 419 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 420 | Rule: clangTidy, |
| 421 | Description: "clang-tidy " + srcFile.Rel(), |
| 422 | Output: tidyFile, |
| 423 | Input: srcFile, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 424 | // We must depend on objFile, since clang-tidy doesn't |
| 425 | // support exporting dependencies. |
| 426 | Implicit: objFile, |
| 427 | Args: map[string]string{ |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 428 | "cFlags": moduleToolingCflags, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 429 | "tidyFlags": flags.tidyFlags, |
| 430 | }, |
| 431 | }) |
| 432 | } |
| 433 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 434 | if dump { |
| 435 | sAbiDumpFile := android.ObjPathWithExt(ctx, subdir, srcFile, "sdump") |
| 436 | sAbiDumpFiles = append(sAbiDumpFiles, sAbiDumpFile) |
| 437 | |
| 438 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 439 | Rule: sAbiDump, |
| 440 | Description: "header-abi-dumper " + srcFile.Rel(), |
| 441 | Output: sAbiDumpFile, |
| 442 | Input: srcFile, |
| 443 | Implicit: objFile, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 444 | Args: map[string]string{ |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 445 | "cFlags": moduleToolingCflags, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 446 | "exportDirs": flags.sAbiFlags, |
| 447 | }, |
| 448 | }) |
| 449 | } |
| 450 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 453 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 454 | objFiles: objFiles, |
| 455 | tidyFiles: tidyFiles, |
| 456 | coverageFiles: coverageFiles, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 457 | sAbiDumpFiles: sAbiDumpFiles, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 458 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | // Generate a rule for compiling multiple .o files to a static library (.a) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 462 | func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 463 | flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 464 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 465 | if ctx.Darwin() { |
| 466 | transformDarwinObjToStaticLib(ctx, objFiles, flags, outputFile, deps) |
| 467 | return |
| 468 | } |
| 469 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 470 | arCmd := gccCmd(flags.toolchain, "ar") |
| 471 | arFlags := "crsPD" |
Vishwath Mohan | 83d9f71 | 2017-03-16 11:01:23 -0700 | [diff] [blame] | 472 | if flags.arFlags != "" { |
| 473 | arFlags += " " + flags.arFlags |
| 474 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 475 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 476 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 477 | Rule: ar, |
| 478 | Description: "static link " + outputFile.Base(), |
| 479 | Output: outputFile, |
| 480 | Inputs: objFiles, |
| 481 | Implicits: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 482 | Args: map[string]string{ |
| 483 | "arFlags": arFlags, |
| 484 | "arCmd": arCmd, |
| 485 | }, |
| 486 | }) |
| 487 | } |
| 488 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 489 | // Generate a rule for compiling multiple .o files to a static library (.a) on |
| 490 | // darwin. The darwin ar tool doesn't support @file for list files, and has a |
| 491 | // very small command line length limit, so we have to split the ar into multiple |
| 492 | // steps, each appending to the previous one. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 493 | func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 494 | flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 495 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 496 | arFlags := "cqs" |
| 497 | |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 498 | if len(objFiles) == 0 { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 499 | dummy := android.PathForModuleOut(ctx, "dummy"+objectExtension) |
| 500 | dummyAr := android.PathForModuleOut(ctx, "dummy"+staticLibraryExtension) |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 501 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 502 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 503 | Rule: emptyFile, |
| 504 | Description: "empty object file", |
| 505 | Output: dummy, |
| 506 | Implicits: deps, |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 507 | }) |
| 508 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 509 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 510 | Rule: darwinAr, |
| 511 | Description: "empty static archive", |
| 512 | Output: dummyAr, |
| 513 | Input: dummy, |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 514 | Args: map[string]string{ |
| 515 | "arFlags": arFlags, |
| 516 | }, |
| 517 | }) |
| 518 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 519 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 520 | Rule: darwinAppendAr, |
| 521 | Description: "static link " + outputFile.Base(), |
| 522 | Output: outputFile, |
| 523 | Input: dummy, |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 524 | Args: map[string]string{ |
| 525 | "arFlags": "d", |
| 526 | "inAr": dummyAr.String(), |
| 527 | }, |
| 528 | }) |
| 529 | |
| 530 | return |
| 531 | } |
| 532 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 533 | // ARG_MAX on darwin is 262144, use half that to be safe |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 534 | objFilesLists, err := splitListForSize(objFiles, 131072) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 535 | if err != nil { |
| 536 | ctx.ModuleErrorf("%s", err.Error()) |
| 537 | } |
| 538 | |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 539 | var in, out android.WritablePath |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 540 | for i, l := range objFilesLists { |
| 541 | in = out |
| 542 | out = outputFile |
| 543 | if i != len(objFilesLists)-1 { |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 544 | out = android.PathForModuleOut(ctx, outputFile.Base()+strconv.Itoa(i)) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 547 | build := android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 548 | Rule: darwinAr, |
| 549 | Description: "static link " + out.Base(), |
| 550 | Output: out, |
| 551 | Inputs: l, |
| 552 | Implicits: deps, |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 553 | Args: map[string]string{ |
| 554 | "arFlags": arFlags, |
| 555 | }, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 556 | } |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 557 | if i != 0 { |
| 558 | build.Rule = darwinAppendAr |
| 559 | build.Args["inAr"] = in.String() |
| 560 | } |
| 561 | ctx.ModuleBuild(pctx, build) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 565 | // Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries, |
| 566 | // and shared libraires, to a shared library (.so) or dynamic executable |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 567 | func TransformObjToDynamicBinary(ctx android.ModuleContext, |
| 568 | objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths, |
| 569 | crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 570 | |
| 571 | var ldCmd string |
| 572 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 573 | ldCmd = "${config.ClangBin}/clang++" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 574 | } else { |
| 575 | ldCmd = gccCmd(flags.toolchain, "g++") |
| 576 | } |
| 577 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 578 | var libFlagsList []string |
| 579 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 580 | if len(flags.libFlags) > 0 { |
| 581 | libFlagsList = append(libFlagsList, flags.libFlags) |
| 582 | } |
| 583 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 584 | if len(wholeStaticLibs) > 0 { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 585 | if ctx.Host() && ctx.Darwin() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 586 | libFlagsList = append(libFlagsList, android.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load ")) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 587 | } else { |
| 588 | libFlagsList = append(libFlagsList, "-Wl,--whole-archive ") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 589 | libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 590 | libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ") |
| 591 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 594 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 595 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 596 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 597 | libFlagsList = append(libFlagsList, staticLibs.Strings()...) |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 598 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 599 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 600 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 601 | |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 602 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 603 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 604 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 605 | libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...) |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 606 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 607 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 608 | } |
| 609 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 610 | for _, lib := range sharedLibs { |
Dan Albert | 9840e1b | 2016-07-21 08:47:33 -0700 | [diff] [blame] | 611 | libFlagsList = append(libFlagsList, lib.String()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 614 | deps = append(deps, staticLibs...) |
Colin Cross | 3075ad0 | 2015-03-17 10:47:08 -0700 | [diff] [blame] | 615 | deps = append(deps, lateStaticLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 616 | deps = append(deps, wholeStaticLibs...) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 617 | if crtBegin.Valid() { |
| 618 | deps = append(deps, crtBegin.Path(), crtEnd.Path()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 621 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 622 | Rule: ld, |
| 623 | Description: "link " + outputFile.Base(), |
| 624 | Output: outputFile, |
| 625 | Inputs: objFiles, |
| 626 | Implicits: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 627 | Args: map[string]string{ |
Dan Albert | ce2b839 | 2016-07-21 13:16:49 -0700 | [diff] [blame] | 628 | "ldCmd": ldCmd, |
| 629 | "crtBegin": crtBegin.String(), |
| 630 | "libFlags": strings.Join(libFlagsList, " "), |
| 631 | "ldFlags": flags.ldFlags, |
| 632 | "crtEnd": crtEnd.String(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 633 | }, |
| 634 | }) |
| 635 | } |
| 636 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 637 | // Generate a rule to combine .dump sAbi dump files from multiple source files |
| 638 | // into a single .ldump sAbi dump file |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 639 | func TransformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 640 | symbolFile android.OptionalPath, apiLevel, baseName, exportedHeaderFlags string) android.OptionalPath { |
| 641 | outputFile := android.PathForModuleOut(ctx, baseName+".lsdump") |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 642 | var symbolFilterStr string |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 643 | var linkedDumpDep android.Path |
| 644 | if symbolFile.Valid() { |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 645 | symbolFilterStr = "-v " + symbolFile.Path().String() |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 646 | linkedDumpDep = symbolFile.Path() |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 647 | } else { |
| 648 | linkedDumpDep = soFile |
| 649 | symbolFilterStr = "-so " + soFile.String() |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 650 | } |
| 651 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 652 | Rule: sAbiLink, |
| 653 | Description: "header-abi-linker " + outputFile.Base(), |
| 654 | Output: outputFile, |
| 655 | Inputs: sAbiDumps, |
| 656 | Implicit: linkedDumpDep, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 657 | Args: map[string]string{ |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 658 | "symbolFilter": symbolFilterStr, |
| 659 | "arch": ctx.Arch().ArchType.Name, |
| 660 | "api": apiLevel, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 661 | "exportedHeaderFlags": exportedHeaderFlags, |
| 662 | }, |
| 663 | }) |
| 664 | return android.OptionalPathForPath(outputFile) |
| 665 | } |
| 666 | |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 667 | func UnzipRefDump(ctx android.ModuleContext, zippedRefDump android.Path, baseName string) android.Path { |
| 668 | outputFile := android.PathForModuleOut(ctx, baseName+"_ref.lsdump") |
| 669 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 670 | Rule: unzipRefSAbiDump, |
| 671 | Description: "gunzip" + outputFile.Base(), |
| 672 | Output: outputFile, |
| 673 | Input: zippedRefDump, |
| 674 | }) |
| 675 | return outputFile |
| 676 | } |
| 677 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 678 | func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path, |
| 679 | baseName string) android.OptionalPath { |
| 680 | outputFile := android.PathForModuleOut(ctx, baseName+".abidiff") |
| 681 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 682 | Rule: sAbiDiff, |
| 683 | Description: "header-abi-diff " + outputFile.Base(), |
| 684 | Output: outputFile, |
| 685 | Input: inputDump, |
| 686 | Implicit: referenceDump, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 687 | Args: map[string]string{ |
| 688 | "referenceDump": referenceDump.String(), |
Jayant Chowdhary | f54e0a7 | 2017-05-22 10:53:24 -0700 | [diff] [blame] | 689 | "libName": baseName, |
| 690 | "arch": ctx.Arch().ArchType.Name, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 691 | }, |
| 692 | }) |
| 693 | return android.OptionalPathForPath(outputFile) |
| 694 | } |
| 695 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 696 | // Generate a rule for extract a table of contents from a shared library (.so) |
| 697 | func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.WritablePath, |
| 698 | outputFile android.WritablePath, flags builderFlags) { |
| 699 | |
| 700 | crossCompile := gccCmd(flags.toolchain, "") |
| 701 | |
| 702 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 703 | Rule: toc, |
| 704 | Description: "generate toc " + inputFile.Base(), |
| 705 | Output: outputFile, |
| 706 | Input: inputFile, |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 707 | Args: map[string]string{ |
| 708 | "crossCompile": crossCompile, |
| 709 | }, |
| 710 | }) |
| 711 | } |
| 712 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 713 | // Generate a rule for compiling multiple .o files to a .o using ld partial linking |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 714 | func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, |
| 715 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 716 | |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 717 | var ldCmd string |
| 718 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 719 | ldCmd = "${config.ClangBin}/clang++" |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 720 | } else { |
| 721 | ldCmd = gccCmd(flags.toolchain, "g++") |
| 722 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 723 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 724 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 725 | Rule: partialLd, |
| 726 | Description: "link " + outputFile.Base(), |
| 727 | Output: outputFile, |
| 728 | Inputs: objFiles, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 729 | Args: map[string]string{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 730 | "ldCmd": ldCmd, |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 731 | "ldFlags": flags.ldFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 732 | }, |
| 733 | }) |
| 734 | } |
| 735 | |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 736 | // Generate a rule for runing objcopy --prefix-symbols on a binary |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 737 | func TransformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inputFile android.Path, |
| 738 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 739 | |
| 740 | objcopyCmd := gccCmd(flags.toolchain, "objcopy") |
| 741 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 742 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 743 | Rule: prefixSymbols, |
| 744 | Description: "prefix symbols " + outputFile.Base(), |
| 745 | Output: outputFile, |
| 746 | Input: inputFile, |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 747 | Args: map[string]string{ |
| 748 | "objcopyCmd": objcopyCmd, |
| 749 | "prefix": prefix, |
| 750 | }, |
| 751 | }) |
| 752 | } |
| 753 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 754 | func TransformStrip(ctx android.ModuleContext, inputFile android.Path, |
| 755 | outputFile android.WritablePath, flags builderFlags) { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 756 | |
| 757 | crossCompile := gccCmd(flags.toolchain, "") |
| 758 | args := "" |
| 759 | if flags.stripAddGnuDebuglink { |
| 760 | args += " --add-gnu-debuglink" |
| 761 | } |
| 762 | if flags.stripKeepMiniDebugInfo { |
| 763 | args += " --keep-mini-debug-info" |
| 764 | } |
| 765 | if flags.stripKeepSymbols { |
| 766 | args += " --keep-symbols" |
| 767 | } |
| 768 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 769 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 770 | Rule: strip, |
| 771 | Description: "strip " + outputFile.Base(), |
| 772 | Output: outputFile, |
| 773 | Input: inputFile, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 774 | Args: map[string]string{ |
| 775 | "crossCompile": crossCompile, |
| 776 | "args": args, |
| 777 | }, |
| 778 | }) |
| 779 | } |
| 780 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 781 | func TransformDarwinStrip(ctx android.ModuleContext, inputFile android.Path, |
| 782 | outputFile android.WritablePath) { |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 783 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 784 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 785 | Rule: darwinStrip, |
| 786 | Description: "strip " + outputFile.Base(), |
| 787 | Output: outputFile, |
| 788 | Input: inputFile, |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 789 | }) |
| 790 | } |
| 791 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 792 | func TransformCoverageFilesToLib(ctx android.ModuleContext, |
| 793 | inputs Objects, flags builderFlags, baseName string) android.OptionalPath { |
| 794 | |
| 795 | if len(inputs.coverageFiles) > 0 { |
| 796 | outputFile := android.PathForModuleOut(ctx, baseName+".gcnodir") |
| 797 | |
| 798 | TransformObjToStaticLib(ctx, inputs.coverageFiles, flags, outputFile, nil) |
| 799 | |
| 800 | return android.OptionalPathForPath(outputFile) |
| 801 | } |
| 802 | |
| 803 | return android.OptionalPath{} |
| 804 | } |
| 805 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 806 | func CopyGccLib(ctx android.ModuleContext, libName string, |
| 807 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 808 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 809 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 810 | Rule: copyGccLib, |
| 811 | Description: "copy gcc library " + libName, |
| 812 | Output: outputFile, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 813 | Args: map[string]string{ |
| 814 | "ccCmd": gccCmd(flags.toolchain, "gcc"), |
| 815 | "cFlags": flags.globalFlags, |
| 816 | "libName": libName, |
| 817 | }, |
| 818 | }) |
| 819 | } |
| 820 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 821 | func gccCmd(toolchain config.Toolchain, cmd string) string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 822 | return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd) |
| 823 | } |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 824 | |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 825 | func splitListForSize(list android.Paths, limit int) (lists []android.Paths, err error) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 826 | var i int |
| 827 | |
| 828 | start := 0 |
| 829 | bytes := 0 |
| 830 | for i = range list { |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 831 | l := len(list[i].String()) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 832 | if l > limit { |
| 833 | return nil, fmt.Errorf("list element greater than size limit (%d)", limit) |
| 834 | } |
| 835 | if bytes+l > limit { |
| 836 | lists = append(lists, list[start:i]) |
| 837 | start = i |
| 838 | bytes = 0 |
| 839 | } |
| 840 | bytes += l + 1 // count a space between each list element |
| 841 | } |
| 842 | |
| 843 | lists = append(lists, list[start:]) |
| 844 | |
| 845 | totalLen := 0 |
| 846 | for _, l := range lists { |
| 847 | totalLen += len(l) |
| 848 | } |
| 849 | if totalLen != len(list) { |
| 850 | panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen)) |
| 851 | } |
| 852 | return lists, nil |
| 853 | } |