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 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 112 | stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh") |
| 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 | |
Colin Cross | 1474741 | 2016-04-27 16:10:38 -0700 | [diff] [blame] | 130 | copyGccLibPath = 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 | |
| 142 | tocPath = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh") |
| 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 | |
| 162 | yasmCmd = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm") |
| 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") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | ) |
| 172 | |
Dan Willemsen | 322a0a6 | 2015-11-17 15:19:46 -0800 | [diff] [blame] | 173 | func init() { |
| 174 | // We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the |
| 175 | // debug output. That way two builds in two different directories will |
| 176 | // create the same output. |
| 177 | if runtime.GOOS != "darwin" { |
| 178 | pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd") |
| 179 | } else { |
| 180 | // Darwin doesn't have /proc |
| 181 | pctx.StaticVariable("relPwd", "") |
| 182 | } |
| 183 | } |
| 184 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 185 | type builderFlags struct { |
| 186 | globalFlags string |
| 187 | asFlags string |
| 188 | cFlags string |
| 189 | conlyFlags string |
| 190 | cppFlags string |
| 191 | ldFlags string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 192 | libFlags string |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 193 | yaccFlags string |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 194 | protoFlags string |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 195 | tidyFlags string |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 196 | yasmFlags string |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 197 | aidlFlags string |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 198 | toolchain config.Toolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 199 | clang bool |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 200 | tidy bool |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 201 | coverage bool |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 202 | |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 203 | groupStaticLibs bool |
| 204 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 205 | stripKeepSymbols bool |
| 206 | stripKeepMiniDebugInfo bool |
| 207 | stripAddGnuDebuglink bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 210 | type Objects struct { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 211 | objFiles android.Paths |
| 212 | tidyFiles android.Paths |
| 213 | coverageFiles android.Paths |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | func (a Objects) Copy() Objects { |
| 217 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 218 | objFiles: append(android.Paths{}, a.objFiles...), |
| 219 | tidyFiles: append(android.Paths{}, a.tidyFiles...), |
| 220 | coverageFiles: append(android.Paths{}, a.coverageFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
| 224 | func (a Objects) Append(b Objects) Objects { |
| 225 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 226 | objFiles: append(a.objFiles, b.objFiles...), |
| 227 | tidyFiles: append(a.tidyFiles, b.tidyFiles...), |
| 228 | coverageFiles: append(a.coverageFiles, b.coverageFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 232 | // 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] | 233 | func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 234 | flags builderFlags, deps android.Paths) Objects { |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 235 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 236 | objFiles := make(android.Paths, len(srcFiles)) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 237 | var tidyFiles android.Paths |
| 238 | if flags.tidy && flags.clang { |
| 239 | tidyFiles = make(android.Paths, 0, len(srcFiles)) |
| 240 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 241 | var coverageFiles android.Paths |
| 242 | if flags.coverage { |
| 243 | coverageFiles = make(android.Paths, 0, len(srcFiles)) |
| 244 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 245 | |
| 246 | cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags |
| 247 | cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags |
| 248 | asflags := flags.globalFlags + " " + flags.asFlags |
| 249 | |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 250 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 251 | cflags += " ${config.NoOverrideClangGlobalCflags}" |
| 252 | cppflags += " ${config.NoOverrideClangGlobalCflags}" |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 253 | } else { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 254 | cflags += " ${config.NoOverrideGlobalCflags}" |
| 255 | cppflags += " ${config.NoOverrideGlobalCflags}" |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 258 | for i, srcFile := range srcFiles { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 259 | objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 260 | |
| 261 | objFiles[i] = objFile |
| 262 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 263 | if srcFile.Ext() == ".asm" { |
| 264 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 265 | Rule: yasm, |
| 266 | Output: objFile, |
| 267 | Input: srcFile, |
| 268 | OrderOnly: deps, |
| 269 | Args: map[string]string{ |
| 270 | "asFlags": flags.yasmFlags, |
| 271 | }, |
| 272 | }) |
| 273 | continue |
| 274 | } |
| 275 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 276 | var moduleCflags string |
| 277 | var ccCmd string |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 278 | tidy := flags.tidy && flags.clang |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 279 | coverage := flags.coverage |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 280 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 281 | switch srcFile.Ext() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 282 | case ".S", ".s": |
| 283 | ccCmd = "gcc" |
| 284 | moduleCflags = asflags |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 285 | tidy = false |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 286 | coverage = false |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 287 | case ".c": |
| 288 | ccCmd = "gcc" |
| 289 | moduleCflags = cflags |
Colin Cross | 9978ffe | 2016-12-01 15:31:22 -0800 | [diff] [blame] | 290 | case ".cpp", ".cc", ".mm": |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 291 | ccCmd = "g++" |
| 292 | moduleCflags = cppflags |
| 293 | default: |
| 294 | ctx.ModuleErrorf("File %s has unknown extension", srcFile) |
| 295 | continue |
| 296 | } |
| 297 | |
| 298 | if flags.clang { |
| 299 | switch ccCmd { |
| 300 | case "gcc": |
| 301 | ccCmd = "clang" |
| 302 | case "g++": |
| 303 | ccCmd = "clang++" |
| 304 | default: |
| 305 | panic("unrecoginzied ccCmd") |
| 306 | } |
| 307 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 308 | ccCmd = "${config.ClangBin}/" + ccCmd |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 309 | } else { |
| 310 | ccCmd = gccCmd(flags.toolchain, ccCmd) |
| 311 | } |
| 312 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 313 | var implicitOutputs android.WritablePaths |
| 314 | if coverage { |
| 315 | gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno") |
| 316 | implicitOutputs = append(implicitOutputs, gcnoFile) |
| 317 | coverageFiles = append(coverageFiles, gcnoFile) |
| 318 | } |
| 319 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 320 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 321 | Rule: cc, |
| 322 | Output: objFile, |
| 323 | ImplicitOutputs: implicitOutputs, |
| 324 | Input: srcFile, |
| 325 | OrderOnly: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 326 | Args: map[string]string{ |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 327 | "cFlags": moduleCflags, |
| 328 | "ccCmd": ccCmd, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 329 | }, |
| 330 | }) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 331 | |
| 332 | if tidy { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 333 | tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 334 | tidyFiles = append(tidyFiles, tidyFile) |
| 335 | |
| 336 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 337 | Rule: clangTidy, |
| 338 | Output: tidyFile, |
| 339 | Input: srcFile, |
| 340 | // We must depend on objFile, since clang-tidy doesn't |
| 341 | // support exporting dependencies. |
| 342 | Implicit: objFile, |
| 343 | Args: map[string]string{ |
| 344 | "cFlags": moduleCflags, |
| 345 | "tidyFlags": flags.tidyFlags, |
| 346 | }, |
| 347 | }) |
| 348 | } |
| 349 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 352 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 353 | objFiles: objFiles, |
| 354 | tidyFiles: tidyFiles, |
| 355 | coverageFiles: coverageFiles, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 356 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | // 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] | 360 | func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 361 | flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 362 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 363 | if ctx.Darwin() { |
| 364 | transformDarwinObjToStaticLib(ctx, objFiles, flags, outputFile, deps) |
| 365 | return |
| 366 | } |
| 367 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 368 | arCmd := gccCmd(flags.toolchain, "ar") |
| 369 | arFlags := "crsPD" |
| 370 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 371 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 372 | Rule: ar, |
| 373 | Output: outputFile, |
| 374 | Inputs: objFiles, |
| 375 | Implicits: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 376 | Args: map[string]string{ |
| 377 | "arFlags": arFlags, |
| 378 | "arCmd": arCmd, |
| 379 | }, |
| 380 | }) |
| 381 | } |
| 382 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 383 | // Generate a rule for compiling multiple .o files to a static library (.a) on |
| 384 | // darwin. The darwin ar tool doesn't support @file for list files, and has a |
| 385 | // very small command line length limit, so we have to split the ar into multiple |
| 386 | // steps, each appending to the previous one. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 387 | func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 388 | flags builderFlags, outputPath android.ModuleOutPath, deps android.Paths) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 389 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 390 | arFlags := "cqs" |
| 391 | |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 392 | if len(objFiles) == 0 { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 393 | dummy := android.PathForModuleOut(ctx, "dummy"+objectExtension) |
| 394 | dummyAr := android.PathForModuleOut(ctx, "dummy"+staticLibraryExtension) |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 395 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 396 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 397 | Rule: emptyFile, |
| 398 | Output: dummy, |
| 399 | Implicits: deps, |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 400 | }) |
| 401 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 402 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 403 | Rule: darwinAr, |
| 404 | Output: dummyAr, |
| 405 | Input: dummy, |
| 406 | Args: map[string]string{ |
| 407 | "arFlags": arFlags, |
| 408 | }, |
| 409 | }) |
| 410 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 411 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 412 | Rule: darwinAppendAr, |
| 413 | Output: outputPath, |
| 414 | Input: dummy, |
| 415 | Args: map[string]string{ |
| 416 | "arFlags": "d", |
| 417 | "inAr": dummyAr.String(), |
| 418 | }, |
| 419 | }) |
| 420 | |
| 421 | return |
| 422 | } |
| 423 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 424 | // ARG_MAX on darwin is 262144, use half that to be safe |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 425 | objFilesLists, err := splitListForSize(objFiles.Strings(), 131072) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 426 | if err != nil { |
| 427 | ctx.ModuleErrorf("%s", err.Error()) |
| 428 | } |
| 429 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 430 | outputFile := outputPath.String() |
| 431 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 432 | var in, out string |
| 433 | for i, l := range objFilesLists { |
| 434 | in = out |
| 435 | out = outputFile |
| 436 | if i != len(objFilesLists)-1 { |
| 437 | out += "." + strconv.Itoa(i) |
| 438 | } |
| 439 | |
| 440 | if in == "" { |
| 441 | ctx.Build(pctx, blueprint.BuildParams{ |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 442 | Rule: darwinAr, |
| 443 | Outputs: []string{out}, |
| 444 | Inputs: l, |
| 445 | Implicits: deps.Strings(), |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 446 | Args: map[string]string{ |
| 447 | "arFlags": arFlags, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 448 | }, |
| 449 | }) |
| 450 | } else { |
| 451 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 452 | Rule: darwinAppendAr, |
| 453 | Outputs: []string{out}, |
| 454 | Inputs: l, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 455 | Args: map[string]string{ |
| 456 | "arFlags": arFlags, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 457 | "inAr": in, |
| 458 | }, |
| 459 | }) |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 464 | // Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries, |
| 465 | // and shared libraires, to a shared library (.so) or dynamic executable |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 466 | func TransformObjToDynamicBinary(ctx android.ModuleContext, |
| 467 | objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths, |
| 468 | crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 469 | |
| 470 | var ldCmd string |
| 471 | if flags.clang { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 472 | ldCmd = "${config.ClangBin}/clang++" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 473 | } else { |
| 474 | ldCmd = gccCmd(flags.toolchain, "g++") |
| 475 | } |
| 476 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 477 | var libFlagsList []string |
| 478 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 479 | if len(flags.libFlags) > 0 { |
| 480 | libFlagsList = append(libFlagsList, flags.libFlags) |
| 481 | } |
| 482 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 483 | if len(wholeStaticLibs) > 0 { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 484 | if ctx.Host() && ctx.Darwin() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 485 | libFlagsList = append(libFlagsList, android.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load ")) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 486 | } else { |
| 487 | libFlagsList = append(libFlagsList, "-Wl,--whole-archive ") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 488 | libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 489 | libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ") |
| 490 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 493 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 494 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 495 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 496 | libFlagsList = append(libFlagsList, staticLibs.Strings()...) |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 497 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 498 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 499 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 500 | |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 501 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 502 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 503 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 504 | libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...) |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 505 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 506 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 507 | } |
| 508 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 509 | for _, lib := range sharedLibs { |
Dan Albert | 9840e1b | 2016-07-21 08:47:33 -0700 | [diff] [blame] | 510 | libFlagsList = append(libFlagsList, lib.String()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 513 | deps = append(deps, staticLibs...) |
Colin Cross | 3075ad0 | 2015-03-17 10:47:08 -0700 | [diff] [blame] | 514 | deps = append(deps, lateStaticLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 515 | deps = append(deps, wholeStaticLibs...) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 516 | if crtBegin.Valid() { |
| 517 | deps = append(deps, crtBegin.Path(), crtEnd.Path()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 520 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 521 | Rule: ld, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 522 | Output: outputFile, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 523 | Inputs: objFiles, |
| 524 | Implicits: deps, |
| 525 | Args: map[string]string{ |
Dan Albert | ce2b839 | 2016-07-21 13:16:49 -0700 | [diff] [blame] | 526 | "ldCmd": ldCmd, |
| 527 | "crtBegin": crtBegin.String(), |
| 528 | "libFlags": strings.Join(libFlagsList, " "), |
| 529 | "ldFlags": flags.ldFlags, |
| 530 | "crtEnd": crtEnd.String(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 531 | }, |
| 532 | }) |
| 533 | } |
| 534 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 535 | // Generate a rule for extract a table of contents from a shared library (.so) |
| 536 | func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.WritablePath, |
| 537 | outputFile android.WritablePath, flags builderFlags) { |
| 538 | |
| 539 | crossCompile := gccCmd(flags.toolchain, "") |
| 540 | |
| 541 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 542 | Rule: toc, |
| 543 | Output: outputFile, |
| 544 | Input: inputFile, |
| 545 | Args: map[string]string{ |
| 546 | "crossCompile": crossCompile, |
| 547 | }, |
| 548 | }) |
| 549 | } |
| 550 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 551 | // 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] | 552 | func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, |
| 553 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 554 | |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 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 | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 558 | } else { |
| 559 | ldCmd = gccCmd(flags.toolchain, "g++") |
| 560 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 561 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 562 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 563 | Rule: partialLd, |
| 564 | Output: outputFile, |
| 565 | Inputs: objFiles, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 566 | Args: map[string]string{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 567 | "ldCmd": ldCmd, |
Colin Cross | 41280a4 | 2015-11-23 14:01:42 -0800 | [diff] [blame] | 568 | "ldFlags": flags.ldFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 569 | }, |
| 570 | }) |
| 571 | } |
| 572 | |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 573 | // Generate a rule for runing objcopy --prefix-symbols on a binary |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 574 | func TransformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inputFile android.Path, |
| 575 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 576 | |
| 577 | objcopyCmd := gccCmd(flags.toolchain, "objcopy") |
| 578 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 579 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 580 | Rule: prefixSymbols, |
| 581 | Output: outputFile, |
| 582 | Input: inputFile, |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 583 | Args: map[string]string{ |
| 584 | "objcopyCmd": objcopyCmd, |
| 585 | "prefix": prefix, |
| 586 | }, |
| 587 | }) |
| 588 | } |
| 589 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 590 | func TransformStrip(ctx android.ModuleContext, inputFile android.Path, |
| 591 | outputFile android.WritablePath, flags builderFlags) { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 592 | |
| 593 | crossCompile := gccCmd(flags.toolchain, "") |
| 594 | args := "" |
| 595 | if flags.stripAddGnuDebuglink { |
| 596 | args += " --add-gnu-debuglink" |
| 597 | } |
| 598 | if flags.stripKeepMiniDebugInfo { |
| 599 | args += " --keep-mini-debug-info" |
| 600 | } |
| 601 | if flags.stripKeepSymbols { |
| 602 | args += " --keep-symbols" |
| 603 | } |
| 604 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 605 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 606 | Rule: strip, |
| 607 | Output: outputFile, |
| 608 | Input: inputFile, |
| 609 | Args: map[string]string{ |
| 610 | "crossCompile": crossCompile, |
| 611 | "args": args, |
| 612 | }, |
| 613 | }) |
| 614 | } |
| 615 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 616 | func TransformDarwinStrip(ctx android.ModuleContext, inputFile android.Path, |
| 617 | outputFile android.WritablePath) { |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 618 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 619 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 620 | Rule: darwinStrip, |
| 621 | Output: outputFile, |
| 622 | Input: inputFile, |
| 623 | }) |
| 624 | } |
| 625 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame^] | 626 | func TransformCoverageFilesToLib(ctx android.ModuleContext, |
| 627 | inputs Objects, flags builderFlags, baseName string) android.OptionalPath { |
| 628 | |
| 629 | if len(inputs.coverageFiles) > 0 { |
| 630 | outputFile := android.PathForModuleOut(ctx, baseName+".gcnodir") |
| 631 | |
| 632 | TransformObjToStaticLib(ctx, inputs.coverageFiles, flags, outputFile, nil) |
| 633 | |
| 634 | return android.OptionalPathForPath(outputFile) |
| 635 | } |
| 636 | |
| 637 | return android.OptionalPath{} |
| 638 | } |
| 639 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 640 | func CopyGccLib(ctx android.ModuleContext, libName string, |
| 641 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 642 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 643 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 644 | Rule: copyGccLib, |
| 645 | Output: outputFile, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 646 | Args: map[string]string{ |
| 647 | "ccCmd": gccCmd(flags.toolchain, "gcc"), |
| 648 | "cFlags": flags.globalFlags, |
| 649 | "libName": libName, |
| 650 | }, |
| 651 | }) |
| 652 | } |
| 653 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 654 | func gccCmd(toolchain config.Toolchain, cmd string) string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 655 | return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd) |
| 656 | } |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 657 | |
| 658 | func splitListForSize(list []string, limit int) (lists [][]string, err error) { |
| 659 | var i int |
| 660 | |
| 661 | start := 0 |
| 662 | bytes := 0 |
| 663 | for i = range list { |
| 664 | l := len(list[i]) |
| 665 | if l > limit { |
| 666 | return nil, fmt.Errorf("list element greater than size limit (%d)", limit) |
| 667 | } |
| 668 | if bytes+l > limit { |
| 669 | lists = append(lists, list[start:i]) |
| 670 | start = i |
| 671 | bytes = 0 |
| 672 | } |
| 673 | bytes += l + 1 // count a space between each list element |
| 674 | } |
| 675 | |
| 676 | lists = append(lists, list[start:]) |
| 677 | |
| 678 | totalLen := 0 |
| 679 | for _, l := range lists { |
| 680 | totalLen += len(l) |
| 681 | } |
| 682 | if totalLen != len(list) { |
| 683 | panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen)) |
| 684 | } |
| 685 | return lists, nil |
| 686 | } |