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