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