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