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 | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 22 | "path/filepath" |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 23 | "runtime" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | "strings" |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint" |
Josh Gao | 75a50a2 | 2019-06-07 17:58:59 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/pathtools" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
| 30 | "android/soong/cc/config" |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 31 | "android/soong/remoteexec" |
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 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 42 | // Rule to invoke gcc with given command, flags, and dependencies. Outputs a .d depfile. |
Ramy Medhat | 8ea054a | 2020-01-27 14:19:44 -0500 | [diff] [blame] | 43 | cc = pctx.AndroidRemoteStaticRule("cc", android.RemoteRuleSupports{Goma: true, RBE: true}, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 44 | blueprint.RuleParams{ |
| 45 | Depfile: "${out}.d", |
| 46 | Deps: blueprint.DepsGCC, |
Kousik Kumar | d207cbe | 2020-10-20 05:52:49 +0000 | [diff] [blame] | 47 | 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] | 48 | CommandDeps: []string{"$ccCmd"}, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 52 | // Rule to invoke gcc with given command and flags, but no dependencies. |
Kousik Kumar | 2976bfd | 2020-02-17 00:26:55 -0800 | [diff] [blame] | 53 | ccNoDeps = pctx.AndroidStaticRule("ccNoDeps", |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 54 | blueprint.RuleParams{ |
Kousik Kumar | d207cbe | 2020-10-20 05:52:49 +0000 | [diff] [blame] | 55 | Command: "$relPwd $ccCmd -c $cFlags -o $out $in", |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 56 | CommandDeps: []string{"$ccCmd"}, |
| 57 | }, |
| 58 | "ccCmd", "cFlags") |
| 59 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 60 | // Rules to invoke ld to link binaries. Uses a .rsp file to list dependencies, as there may |
| 61 | // be many. |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 62 | ld, ldRE = pctx.RemoteStaticRules("ld", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 63 | blueprint.RuleParams{ |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 64 | Command: "$reTemplate$ldCmd ${crtBegin} @${out}.rsp " + |
Pete Bentley | 99f2fc2 | 2019-08-02 14:02:20 +0100 | [diff] [blame] | 65 | "${libFlags} ${crtEnd} -o ${out} ${ldFlags} ${extraLibFlags}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 66 | CommandDeps: []string{"$ldCmd"}, |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 67 | Rspfile: "${out}.rsp", |
| 68 | RspfileContent: "${in}", |
Colin Cross | 36ae135 | 2019-03-29 15:55:30 -0700 | [diff] [blame] | 69 | // clang -Wl,--out-implib doesn't update its output file if it hasn't changed. |
| 70 | Restat: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 71 | }, |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 72 | &remoteexec.REParams{ |
| 73 | Labels: map[string]string{"type": "link", "tool": "clang"}, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 74 | ExecStrategy: "${config.RECXXLinksExecStrategy}", |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 75 | Inputs: []string{"${out}.rsp", "$implicitInputs"}, |
Colin Cross | a4eafdd | 2021-03-24 14:09:28 -0700 | [diff] [blame] | 76 | RSPFiles: []string{"${out}.rsp"}, |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 77 | OutputFiles: []string{"${out}", "$implicitOutputs"}, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 78 | ToolchainInputs: []string{"$ldCmd"}, |
| 79 | Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXLinksPool}"}, |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 80 | }, []string{"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags", "extraLibFlags"}, []string{"implicitInputs", "implicitOutputs"}) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 81 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 82 | // Rules for .o files to combine to other .o files, using ld partial linking. |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 83 | partialLd, partialLdRE = pctx.RemoteStaticRules("partialLd", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 84 | blueprint.RuleParams{ |
Chih-Hung Hsieh | 3ede294 | 2018-01-10 14:30:44 -0800 | [diff] [blame] | 85 | // Without -no-pie, clang 7.0 adds -pie to link Android files, |
| 86 | // but -r and -pie cannot be used together. |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 87 | Command: "$reTemplate$ldCmd -fuse-ld=lld -nostdlib -no-pie -Wl,-r ${in} -o ${out} ${ldFlags}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 88 | CommandDeps: []string{"$ldCmd"}, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 89 | }, &remoteexec.REParams{ |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 90 | Labels: map[string]string{"type": "link", "tool": "clang"}, |
| 91 | ExecStrategy: "${config.RECXXLinksExecStrategy}", |
| 92 | Inputs: []string{"$inCommaList", "$implicitInputs"}, |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 93 | OutputFiles: []string{"${out}", "$implicitOutputs"}, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 94 | ToolchainInputs: []string{"$ldCmd"}, |
| 95 | Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXLinksPool}"}, |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 96 | }, []string{"ldCmd", "ldFlags"}, []string{"implicitInputs", "inCommaList", "implicitOutputs"}) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 97 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 98 | // Rule to invoke `ar` with given cmd and flags, but no static library depenencies. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 99 | ar = pctx.AndroidStaticRule("ar", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 100 | blueprint.RuleParams{ |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 101 | Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 102 | CommandDeps: []string{"$arCmd"}, |
Colin Cross | 7d21c44 | 2015-03-30 17:47:53 -0700 | [diff] [blame] | 103 | Rspfile: "${out}.rsp", |
| 104 | RspfileContent: "${in}", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 105 | }, |
| 106 | "arCmd", "arFlags") |
| 107 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 108 | // Rule to invoke `ar` with given cmd, flags, and library dependencies. Generates a .a |
| 109 | // (archive) file from .o files. |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 110 | arWithLibs = pctx.AndroidStaticRule("arWithLibs", |
| 111 | blueprint.RuleParams{ |
| 112 | Command: "rm -f ${out} && $arCmd $arObjFlags $out @${out}.rsp && $arCmd $arLibFlags $out $arLibs", |
| 113 | CommandDeps: []string{"$arCmd"}, |
| 114 | Rspfile: "${out}.rsp", |
| 115 | RspfileContent: "${arObjs}", |
| 116 | }, |
| 117 | "arCmd", "arObjFlags", "arObjs", "arLibFlags", "arLibs") |
| 118 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 119 | // Rule to run objcopy --prefix-symbols (to prefix all symbols in a file with a given string). |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 120 | prefixSymbols = pctx.AndroidStaticRule("prefixSymbols", |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 121 | blueprint.RuleParams{ |
| 122 | Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 123 | CommandDeps: []string{"$objcopyCmd"}, |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 124 | }, |
| 125 | "objcopyCmd", "prefix") |
| 126 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 127 | _ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh") |
Dan Willemsen | 8fec83a | 2018-03-09 10:47:52 -0800 | [diff] [blame] | 128 | _ = pctx.SourcePathVariable("xzCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/xz") |
David Srbecky | 69315e4 | 2021-04-29 21:06:47 +0100 | [diff] [blame] | 129 | _ = pctx.SourcePathVariable("createMiniDebugInfo", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/create_minidebuginfo") |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 130 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 131 | // Rule to invoke `strip` (to discard symbols and data from object files). |
| 132 | strip = pctx.AndroidStaticRule("strip", |
| 133 | blueprint.RuleParams{ |
David Srbecky | 69315e4 | 2021-04-29 21:06:47 +0100 | [diff] [blame] | 134 | Depfile: "${out}.d", |
| 135 | Deps: blueprint.DepsGCC, |
| 136 | Command: "XZ=$xzCmd CREATE_MINIDEBUGINFO=$createMiniDebugInfo CLANG_BIN=${config.ClangBin} $stripPath ${args} -i ${in} -o ${out} -d ${out}.d", |
| 137 | CommandDeps: func() []string { |
| 138 | if runtime.GOOS != "darwin" { |
| 139 | return []string{"$stripPath", "$xzCmd", "$createMiniDebugInfo"} |
| 140 | } else { |
| 141 | return []string{"$stripPath", "$xzCmd"} |
| 142 | } |
| 143 | }(), |
| 144 | Pool: darwinStripPool, |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 145 | }, |
Elliott Hughes | afcd339 | 2021-05-05 13:54:11 -0700 | [diff] [blame] | 146 | "args") |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 147 | |
| 148 | // Rule to invoke `strip` (to discard symbols and data from object files) on darwin architecture. |
| 149 | darwinStrip = pctx.AndroidStaticRule("darwinStrip", |
| 150 | blueprint.RuleParams{ |
| 151 | Command: "${config.MacStripPath} -u -r -o $out $in", |
| 152 | CommandDeps: []string{"${config.MacStripPath}"}, |
| 153 | }) |
| 154 | |
Colin Cross | ee3ea31 | 2019-05-17 15:36:46 -0700 | [diff] [blame] | 155 | // b/132822437: objcopy uses a file descriptor per .o file when called on .a files, which runs the system out of |
Colin Cross | badf8d6 | 2019-05-22 13:25:50 -0700 | [diff] [blame] | 156 | // file descriptors on darwin. Limit concurrent calls to 5 on darwin. |
Colin Cross | ee3ea31 | 2019-05-17 15:36:46 -0700 | [diff] [blame] | 157 | darwinStripPool = func() blueprint.Pool { |
| 158 | if runtime.GOOS == "darwin" { |
| 159 | return pctx.StaticPool("darwinStripPool", blueprint.PoolParams{ |
Colin Cross | badf8d6 | 2019-05-22 13:25:50 -0700 | [diff] [blame] | 160 | Depth: 5, |
Colin Cross | ee3ea31 | 2019-05-17 15:36:46 -0700 | [diff] [blame] | 161 | }) |
| 162 | } else { |
| 163 | return nil |
| 164 | } |
| 165 | }() |
| 166 | |
Yi Kong | c49c393 | 2019-10-15 02:01:19 -0700 | [diff] [blame] | 167 | _ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh") |
| 168 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 169 | // Rule to repack an archive (.a) file with a subset of object files. |
Yi Kong | c49c393 | 2019-10-15 02:01:19 -0700 | [diff] [blame] | 170 | archiveRepack = pctx.AndroidStaticRule("archiveRepack", |
| 171 | blueprint.RuleParams{ |
| 172 | Depfile: "${out}.d", |
| 173 | Deps: blueprint.DepsGCC, |
| 174 | Command: "CLANG_BIN=${config.ClangBin} $archiveRepackPath -i ${in} -o ${out} -d ${out}.d ${objects}", |
| 175 | CommandDeps: []string{"$archiveRepackPath"}, |
| 176 | }, |
| 177 | "objects") |
| 178 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 179 | // Rule to create an empty file at a given path. |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 180 | emptyFile = pctx.AndroidStaticRule("emptyFile", |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 181 | blueprint.RuleParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 182 | Command: "rm -f $out && touch $out", |
Dan Willemsen | 9f0b550 | 2016-05-13 14:05:09 -0700 | [diff] [blame] | 183 | }) |
| 184 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 185 | _ = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh") |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 186 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 187 | // A rule for extracting a table of contents from a shared library (.so). |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 188 | toc = pctx.AndroidStaticRule("toc", |
| 189 | blueprint.RuleParams{ |
| 190 | Depfile: "${out}.d", |
| 191 | Deps: blueprint.DepsGCC, |
Yi Kong | 4ad44e7 | 2021-04-01 17:45:42 +0800 | [diff] [blame] | 192 | Command: "CLANG_BIN=$clangBin $tocPath $format -i ${in} -o ${out} -d ${out}.d", |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 193 | CommandDeps: []string{"$tocPath"}, |
| 194 | Restat: true, |
| 195 | }, |
Yi Kong | 4ad44e7 | 2021-04-01 17:45:42 +0800 | [diff] [blame] | 196 | "clangBin", "format") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 197 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 198 | // Rule for invoking clang-tidy (a clang-based linter). |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 199 | clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy", |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 200 | blueprint.RuleParams{ |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 201 | Command: "rm -f $out && $reTemplate${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && touch $out", |
George Burgess IV | c4624c0 | 2019-04-04 16:22:37 -0700 | [diff] [blame] | 202 | CommandDeps: []string{"${config.ClangBin}/clang-tidy"}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 203 | }, |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 204 | &remoteexec.REParams{ |
| 205 | Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"}, |
| 206 | ExecStrategy: "${config.REClangTidyExecStrategy}", |
| 207 | Inputs: []string{"$in"}, |
| 208 | // OutputFile here is $in for remote-execution since its possible that |
| 209 | // clang-tidy modifies the given input file itself and $out refers to the |
| 210 | // ".tidy" file generated for ninja-dependency reasons. |
Colin Cross | 053fca1 | 2020-08-19 13:51:47 -0700 | [diff] [blame] | 211 | OutputFiles: []string{"$in"}, |
| 212 | Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"}, |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 213 | }, []string{"cFlags", "tidyFlags"}, []string{}) |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 214 | |
Nan Zhang | 43a485c | 2017-03-27 14:27:58 -0700 | [diff] [blame] | 215 | _ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm") |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 216 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 217 | // Rule for invoking yasm to compile .asm assembly files. |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 218 | yasm = pctx.AndroidStaticRule("yasm", |
| 219 | blueprint.RuleParams{ |
Dan Willemsen | 1d3e545 | 2017-08-22 20:53:45 -0700 | [diff] [blame] | 220 | Command: "$yasmCmd $asFlags -o $out $in && $yasmCmd $asFlags -M $in >$out.d", |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 221 | CommandDeps: []string{"$yasmCmd"}, |
Dan Willemsen | 1d3e545 | 2017-08-22 20:53:45 -0700 | [diff] [blame] | 222 | Depfile: "$out.d", |
| 223 | Deps: blueprint.DepsGCC, |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 224 | }, |
| 225 | "asFlags") |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 226 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 227 | // Rule to invoke windres, for interaction with Windows resources. |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 228 | windres = pctx.AndroidStaticRule("windres", |
| 229 | blueprint.RuleParams{ |
Nick Desaulniers | 18eeffa | 2020-01-29 16:20:11 -0800 | [diff] [blame] | 230 | Command: "$windresCmd $flags -I$$(dirname $in) -i $in -o $out --preprocessor \"${config.ClangBin}/clang -E -xc-header -DRC_INVOKED\"", |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 231 | CommandDeps: []string{"$windresCmd"}, |
| 232 | }, |
| 233 | "windresCmd", "flags") |
| 234 | |
Jayant Chowdhary | a4c6df5 | 2018-02-20 12:36:51 -0800 | [diff] [blame] | 235 | _ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper") |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 236 | |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 237 | // -w has been added since header-abi-dumper does not need to produce any sort of diagnostic information. |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 238 | sAbiDump, sAbiDumpRE = pctx.RemoteStaticRules("sAbiDump", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 239 | blueprint.RuleParams{ |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 240 | Command: "rm -f $out && $reTemplate$sAbiDumper -o ${out} $in $exportDirs -- $cFlags -w -isystem prebuilts/clang-tools/${config.HostPrebuiltTag}/clang-headers", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 241 | CommandDeps: []string{"$sAbiDumper"}, |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 242 | }, &remoteexec.REParams{ |
| 243 | Labels: map[string]string{"type": "abi-dump", "tool": "header-abi-dumper"}, |
| 244 | ExecStrategy: "${config.REAbiDumperExecStrategy}", |
Ulf Adams | 1893176 | 2020-11-25 22:54:35 +0100 | [diff] [blame] | 245 | Inputs: []string{"$sAbiLinkerLibs"}, |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 246 | Platform: map[string]string{ |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 247 | remoteexec.PoolKey: "${config.RECXXPool}", |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 248 | }, |
| 249 | }, []string{"cFlags", "exportDirs"}, nil) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 250 | |
Jayant Chowdhary | a4c6df5 | 2018-02-20 12:36:51 -0800 | [diff] [blame] | 251 | _ = pctx.SourcePathVariable("sAbiLinker", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-linker") |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 252 | _ = pctx.SourcePathVariable("sAbiLinkerLibs", "prebuilts/clang-tools/${config.HostPrebuiltTag}/lib64") |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 253 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 254 | // Rule to combine .dump sAbi dump files from multiple source files into a single .ldump |
| 255 | // sAbi dump file. |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 256 | sAbiLink, sAbiLinkRE = pctx.RemoteStaticRules("sAbiLink", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 257 | blueprint.RuleParams{ |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 258 | Command: "$reTemplate$sAbiLinker -o ${out} $symbolFilter -arch $arch $exportedHeaderFlags @${out}.rsp ", |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 259 | CommandDeps: []string{"$sAbiLinker"}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 260 | Rspfile: "${out}.rsp", |
| 261 | RspfileContent: "${in}", |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 262 | }, &remoteexec.REParams{ |
| 263 | Labels: map[string]string{"type": "tool", "name": "abi-linker"}, |
| 264 | ExecStrategy: "${config.REAbiLinkerExecStrategy}", |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 265 | Inputs: []string{"$sAbiLinkerLibs", "${out}.rsp", "$implicitInputs"}, |
Colin Cross | a4eafdd | 2021-03-24 14:09:28 -0700 | [diff] [blame] | 266 | RSPFiles: []string{"${out}.rsp"}, |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 267 | OutputFiles: []string{"$out"}, |
| 268 | ToolchainInputs: []string{"$sAbiLinker"}, |
| 269 | Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXPool}"}, |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 270 | }, []string{"symbolFilter", "arch", "exportedHeaderFlags"}, []string{"implicitInputs"}) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 271 | |
Jayant Chowdhary | a4c6df5 | 2018-02-20 12:36:51 -0800 | [diff] [blame] | 272 | _ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff") |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 273 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 274 | // Rule to compare linked sAbi dump files (.ldump). |
Colin Cross | 2e2dbc2 | 2019-09-25 13:31:46 -0700 | [diff] [blame] | 275 | sAbiDiff = pctx.RuleFunc("sAbiDiff", |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 276 | func(ctx android.PackageRuleContext) blueprint.RuleParams { |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 277 | commandStr := "($sAbiDiffer ${extraFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})" |
Logan Chien | 6227fed | 2019-02-18 13:12:21 +0800 | [diff] [blame] | 278 | commandStr += "|| (echo 'error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py ${createReferenceDumpFlags} -l ${libName}'" |
Logan Chien | 8f74fe6 | 2019-01-28 12:14:54 +0800 | [diff] [blame] | 279 | commandStr += " && (mkdir -p $$DIST_DIR/abidiffs && cp ${out} $$DIST_DIR/abidiffs/)" |
Jayant Chowdhary | d8b70a3 | 2018-02-01 17:23:09 -0800 | [diff] [blame] | 280 | commandStr += " && exit 1)" |
Jayant Chowdhary | 219139d | 2017-11-27 14:52:21 -0800 | [diff] [blame] | 281 | return blueprint.RuleParams{ |
| 282 | Command: commandStr, |
| 283 | CommandDeps: []string{"$sAbiDiffer"}, |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 284 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 285 | }, |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 286 | "extraFlags", "referenceDump", "libName", "arch", "createReferenceDumpFlags") |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 287 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 288 | // Rule to unzip a reference abi dump. |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 289 | unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump", |
| 290 | blueprint.RuleParams{ |
| 291 | Command: "gunzip -c $in > $out", |
| 292 | }) |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 293 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 294 | // Rule to zip files. |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 295 | zip = pctx.AndroidStaticRule("zip", |
| 296 | blueprint.RuleParams{ |
Colin Cross | 053fca1 | 2020-08-19 13:51:47 -0700 | [diff] [blame] | 297 | Command: "${SoongZipCmd} -o ${out} -C $$OUT_DIR -r ${out}.rsp", |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 298 | CommandDeps: []string{"${SoongZipCmd}"}, |
Colin Cross | 053fca1 | 2020-08-19 13:51:47 -0700 | [diff] [blame] | 299 | Rspfile: "${out}.rsp", |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 300 | RspfileContent: "$in", |
| 301 | }) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 302 | |
| 303 | _ = pctx.SourcePathVariable("cxxExtractor", |
| 304 | "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/cxx_extractor") |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 305 | _ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json") |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 306 | _ = pctx.VariableFunc("kytheCorpus", |
| 307 | func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() }) |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 308 | _ = pctx.VariableFunc("kytheCuEncoding", |
| 309 | func(ctx android.PackageVarContext) string { return ctx.Config().XrefCuEncoding() }) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 310 | |
| 311 | // Rule to use kythe extractors to generate .kzip files, used to build code cross references. |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 312 | kytheExtract = pctx.StaticRule("kythe", |
| 313 | blueprint.RuleParams{ |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 314 | Command: `rm -f $out && ` + |
Sasha Smundak | a4ef83b | 2020-04-21 17:08:35 -0700 | [diff] [blame] | 315 | `KYTHE_CORPUS=${kytheCorpus} ` + |
| 316 | `KYTHE_OUTPUT_FILE=$out ` + |
| 317 | `KYTHE_VNAMES=$kytheVnames ` + |
| 318 | `KYTHE_KZIP_ENCODING=${kytheCuEncoding} ` + |
| 319 | `KYTHE_CANONICALIZE_VNAME_PATHS=prefer-relative ` + |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 320 | `$cxxExtractor $cFlags $in `, |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 321 | CommandDeps: []string{"$cxxExtractor", "$kytheVnames"}, |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 322 | }, |
| 323 | "cFlags") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 324 | ) |
| 325 | |
Ivan Lozano | f3717ee | 2020-05-20 09:03:20 -0400 | [diff] [blame] | 326 | func PwdPrefix() string { |
| 327 | // Darwin doesn't have /proc |
| 328 | if runtime.GOOS != "darwin" { |
| 329 | return "PWD=/proc/self/cwd" |
| 330 | } |
| 331 | return "" |
| 332 | } |
| 333 | |
Dan Willemsen | 322a0a6 | 2015-11-17 15:19:46 -0800 | [diff] [blame] | 334 | func init() { |
| 335 | // We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the |
| 336 | // debug output. That way two builds in two different directories will |
| 337 | // create the same output. |
Ivan Lozano | f3717ee | 2020-05-20 09:03:20 -0400 | [diff] [blame] | 338 | pctx.StaticVariable("relPwd", PwdPrefix()) |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 339 | |
| 340 | pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") |
Dan Willemsen | 322a0a6 | 2015-11-17 15:19:46 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 343 | // builderFlags contains various types of command line flags (and settings) for use in building |
| 344 | // build statements related to C++. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 345 | type builderFlags struct { |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 346 | // Global flags (which build system or toolchain is responsible for). These are separate from |
| 347 | // local flags because they should appear first (so that they may be overridden by local flags). |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 348 | globalCommonFlags string |
| 349 | globalAsFlags string |
| 350 | globalYasmFlags string |
| 351 | globalCFlags string |
| 352 | globalToolingCFlags string // A separate set of cFlags for clang LibTooling tools |
| 353 | globalToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools |
| 354 | globalConlyFlags string |
| 355 | globalCppFlags string |
| 356 | globalLdFlags string |
| 357 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 358 | // Local flags (which individual modules are responsible for). These may override global flags. |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 359 | localCommonFlags string |
| 360 | localAsFlags string |
| 361 | localYasmFlags string |
| 362 | localCFlags string |
| 363 | localToolingCFlags string // A separate set of cFlags for clang LibTooling tools |
| 364 | localToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools |
| 365 | localConlyFlags string |
| 366 | localCppFlags string |
| 367 | localLdFlags string |
| 368 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 369 | libFlags string // Flags to add to the linker directly after specifying libraries to link. |
| 370 | extraLibFlags string // Flags to add to the linker last. |
| 371 | tidyFlags string // Flags that apply to clang-tidy |
| 372 | sAbiFlags string // Flags that apply to header-abi-dumps |
| 373 | aidlFlags string // Flags that apply to aidl source files |
| 374 | rsFlags string // Flags that apply to renderscript source files |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 375 | toolchain config.Toolchain |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 376 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 377 | // True if these extra features are enabled. |
| 378 | tidy bool |
| 379 | gcovCoverage bool |
| 380 | sAbiDump bool |
| 381 | emitXrefs bool |
| 382 | |
| 383 | assemblerWithCpp bool // True if .s files should be processed with the c preprocessor. |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 384 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 385 | systemIncludeFlags string |
| 386 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 387 | // True if static libraries should be grouped (using `-Wl,--start-group` and `-Wl,--end-group`). |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 388 | groupStaticLibs bool |
| 389 | |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 390 | proto android.ProtoFlags |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 391 | protoC bool // If true, compile protos as `.c` files. Otherwise, output as `.cc`. |
| 392 | protoOptionsFile bool // If true, output a proto options file. |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 393 | |
| 394 | yacc *YaccProperties |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 395 | lex *LexProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 398 | // StripFlags represents flags related to stripping. This is separate from builderFlags, as these |
| 399 | // flags are useful outside of this package (such as for Rust). |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 400 | type StripFlags struct { |
| 401 | Toolchain config.Toolchain |
| 402 | StripKeepSymbols bool |
| 403 | StripKeepSymbolsList string |
| 404 | StripKeepSymbolsAndDebugFrame bool |
| 405 | StripKeepMiniDebugInfo bool |
| 406 | StripAddGnuDebuglink bool |
| 407 | StripUseGnuStrip bool |
| 408 | } |
| 409 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 410 | // Objects is a collection of file paths corresponding to outputs for C++ related build statements. |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 411 | type Objects struct { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 412 | objFiles android.Paths |
| 413 | tidyFiles android.Paths |
| 414 | coverageFiles android.Paths |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 415 | sAbiDumpFiles android.Paths |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 416 | kytheFiles android.Paths |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | func (a Objects) Copy() Objects { |
| 420 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 421 | objFiles: append(android.Paths{}, a.objFiles...), |
| 422 | tidyFiles: append(android.Paths{}, a.tidyFiles...), |
| 423 | coverageFiles: append(android.Paths{}, a.coverageFiles...), |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 424 | sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 425 | kytheFiles: append(android.Paths{}, a.kytheFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | func (a Objects) Append(b Objects) Objects { |
| 430 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 431 | objFiles: append(a.objFiles, b.objFiles...), |
| 432 | tidyFiles: append(a.tidyFiles, b.tidyFiles...), |
| 433 | coverageFiles: append(a.coverageFiles, b.coverageFiles...), |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 434 | sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 435 | kytheFiles: append(a.kytheFiles, b.kytheFiles...), |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 439 | // Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 440 | func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 441 | flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects { |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 442 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 443 | // Source files are one-to-one with tidy, coverage, or kythe files, if enabled. |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 444 | objFiles := make(android.Paths, len(srcFiles)) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 445 | var tidyFiles android.Paths |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 446 | if flags.tidy { |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 447 | tidyFiles = make(android.Paths, 0, len(srcFiles)) |
| 448 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 449 | var coverageFiles android.Paths |
Oliver Nguyen | 0452678 | 2020-04-21 12:40:27 -0700 | [diff] [blame] | 450 | if flags.gcovCoverage { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 451 | coverageFiles = make(android.Paths, 0, len(srcFiles)) |
| 452 | } |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 453 | var kytheFiles android.Paths |
| 454 | if flags.emitXrefs { |
| 455 | kytheFiles = make(android.Paths, 0, len(srcFiles)) |
| 456 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 457 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 458 | // Produce fully expanded flags for use by C tools, C compiles, C++ tools, C++ compiles, and asm compiles |
| 459 | // respectively. |
| 460 | toolingCflags := flags.globalCommonFlags + " " + |
| 461 | flags.globalToolingCFlags + " " + |
| 462 | flags.globalConlyFlags + " " + |
| 463 | flags.localCommonFlags + " " + |
| 464 | flags.localToolingCFlags + " " + |
| 465 | flags.localConlyFlags + " " + |
| 466 | flags.systemIncludeFlags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 467 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 468 | cflags := flags.globalCommonFlags + " " + |
| 469 | flags.globalCFlags + " " + |
| 470 | flags.globalConlyFlags + " " + |
| 471 | flags.localCommonFlags + " " + |
| 472 | flags.localCFlags + " " + |
| 473 | flags.localConlyFlags + " " + |
| 474 | flags.systemIncludeFlags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 475 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 476 | toolingCppflags := flags.globalCommonFlags + " " + |
| 477 | flags.globalToolingCFlags + " " + |
| 478 | flags.globalToolingCppFlags + " " + |
| 479 | flags.localCommonFlags + " " + |
| 480 | flags.localToolingCFlags + " " + |
| 481 | flags.localToolingCppFlags + " " + |
| 482 | flags.systemIncludeFlags |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 483 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 484 | cppflags := flags.globalCommonFlags + " " + |
| 485 | flags.globalCFlags + " " + |
| 486 | flags.globalCppFlags + " " + |
| 487 | flags.localCommonFlags + " " + |
| 488 | flags.localCFlags + " " + |
| 489 | flags.localCppFlags + " " + |
| 490 | flags.systemIncludeFlags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 491 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 492 | asflags := flags.globalCommonFlags + " " + |
| 493 | flags.globalAsFlags + " " + |
| 494 | flags.localCommonFlags + " " + |
| 495 | flags.localAsFlags + " " + |
| 496 | flags.systemIncludeFlags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 497 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 498 | var sAbiDumpFiles android.Paths |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 499 | if flags.sAbiDump { |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 500 | sAbiDumpFiles = make(android.Paths, 0, len(srcFiles)) |
| 501 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 502 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame^] | 503 | cflags += " ${config.NoOverrideGlobalCflags}" |
| 504 | toolingCflags += " ${config.NoOverrideGlobalCflags}" |
| 505 | cppflags += " ${config.NoOverrideGlobalCflags}" |
| 506 | toolingCppflags += " ${config.NoOverrideGlobalCflags}" |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 507 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 508 | for i, srcFile := range srcFiles { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 509 | objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 510 | |
| 511 | objFiles[i] = objFile |
| 512 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 513 | // Register compilation build statements. The actual rule used depends on the source file type. |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 514 | switch srcFile.Ext() { |
| 515 | case ".asm": |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 516 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 517 | Rule: yasm, |
| 518 | Description: "yasm " + srcFile.Rel(), |
| 519 | Output: objFile, |
| 520 | Input: srcFile, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 521 | Implicits: cFlagsDeps, |
| 522 | OrderOnly: pathDeps, |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 523 | Args: map[string]string{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 524 | "asFlags": flags.globalYasmFlags + " " + flags.localYasmFlags, |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 525 | }, |
| 526 | }) |
| 527 | continue |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 528 | case ".rc": |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 529 | ctx.Build(pctx, android.BuildParams{ |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 530 | Rule: windres, |
| 531 | Description: "windres " + srcFile.Rel(), |
| 532 | Output: objFile, |
| 533 | Input: srcFile, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 534 | Implicits: cFlagsDeps, |
| 535 | OrderOnly: pathDeps, |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 536 | Args: map[string]string{ |
Elliott Hughes | 5f314b1 | 2021-05-18 11:56:02 -0700 | [diff] [blame] | 537 | "windresCmd": mingwCmd(flags.toolchain, "windres"), |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 538 | "flags": flags.toolchain.WindresFlags(), |
| 539 | }, |
| 540 | }) |
| 541 | continue |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 542 | case ".o": |
| 543 | objFiles[i] = srcFile |
| 544 | continue |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 547 | var moduleFlags string |
| 548 | var moduleToolingFlags string |
| 549 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 550 | var ccCmd string |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 551 | tidy := flags.tidy |
Oliver Nguyen | 0452678 | 2020-04-21 12:40:27 -0700 | [diff] [blame] | 552 | coverage := flags.gcovCoverage |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 553 | dump := flags.sAbiDump |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 554 | rule := cc |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 555 | emitXref := flags.emitXrefs |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 556 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 557 | switch srcFile.Ext() { |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 558 | case ".s": |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 559 | if !flags.assemblerWithCpp { |
| 560 | rule = ccNoDeps |
| 561 | } |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 562 | fallthrough |
| 563 | case ".S": |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 564 | ccCmd = "clang" |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 565 | moduleFlags = asflags |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 566 | tidy = false |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 567 | coverage = false |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 568 | dump = false |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 569 | emitXref = false |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 570 | case ".c": |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 571 | ccCmd = "clang" |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 572 | moduleFlags = cflags |
| 573 | moduleToolingFlags = toolingCflags |
Colin Cross | d34ab7c | 2019-06-27 14:46:10 -0700 | [diff] [blame] | 574 | case ".cpp", ".cc", ".cxx", ".mm": |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 575 | ccCmd = "clang++" |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 576 | moduleFlags = cppflags |
| 577 | moduleToolingFlags = toolingCppflags |
Liz Kammer | e286113 | 2020-12-03 22:12:41 +0000 | [diff] [blame] | 578 | case ".h", ".hpp": |
| 579 | ctx.PropertyErrorf("srcs", "Header file %s is not supported, instead use export_include_dirs or local_include_dirs.", srcFile) |
| 580 | continue |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 581 | default: |
Liz Kammer | e286113 | 2020-12-03 22:12:41 +0000 | [diff] [blame] | 582 | ctx.PropertyErrorf("srcs", "File %s has unknown extension. Supported extensions: .s, .S, .c, .cpp, .cc, .cxx, .mm", srcFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 583 | continue |
| 584 | } |
| 585 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 586 | ccDesc := ccCmd |
| 587 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 588 | ccCmd = "${config.ClangBin}/" + ccCmd |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 589 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 590 | var implicitOutputs android.WritablePaths |
| 591 | if coverage { |
| 592 | gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno") |
| 593 | implicitOutputs = append(implicitOutputs, gcnoFile) |
| 594 | coverageFiles = append(coverageFiles, gcnoFile) |
| 595 | } |
| 596 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 597 | ctx.Build(pctx, android.BuildParams{ |
Dan Willemsen | fcabb1c | 2019-01-03 23:25:11 -0800 | [diff] [blame] | 598 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 599 | Description: ccDesc + " " + srcFile.Rel(), |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 600 | Output: objFile, |
| 601 | ImplicitOutputs: implicitOutputs, |
| 602 | Input: srcFile, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 603 | Implicits: cFlagsDeps, |
| 604 | OrderOnly: pathDeps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 605 | Args: map[string]string{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 606 | "cFlags": moduleFlags, |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 607 | "ccCmd": ccCmd, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 608 | }, |
| 609 | }) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 610 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 611 | // Register post-process build statements (such as for tidy or kythe). |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 612 | if emitXref { |
| 613 | kytheFile := android.ObjPathWithExt(ctx, subdir, srcFile, "kzip") |
| 614 | ctx.Build(pctx, android.BuildParams{ |
| 615 | Rule: kytheExtract, |
| 616 | Description: "Xref C++ extractor " + srcFile.Rel(), |
| 617 | Output: kytheFile, |
| 618 | Input: srcFile, |
| 619 | Implicits: cFlagsDeps, |
| 620 | OrderOnly: pathDeps, |
| 621 | Args: map[string]string{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 622 | "cFlags": moduleFlags, |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 623 | }, |
| 624 | }) |
| 625 | kytheFiles = append(kytheFiles, kytheFile) |
| 626 | } |
| 627 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 628 | if tidy { |
Dan Willemsen | 21ec490 | 2016-11-02 20:43:13 -0700 | [diff] [blame] | 629 | tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 630 | tidyFiles = append(tidyFiles, tidyFile) |
| 631 | |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 632 | rule := clangTidy |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 633 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CLANG_TIDY") { |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 634 | rule = clangTidyRE |
| 635 | } |
| 636 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 637 | ctx.Build(pctx, android.BuildParams{ |
Kousik Kumar | 4e30bba | 2020-06-18 09:17:51 -0700 | [diff] [blame] | 638 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 639 | Description: "clang-tidy " + srcFile.Rel(), |
| 640 | Output: tidyFile, |
| 641 | Input: srcFile, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 642 | // We must depend on objFile, since clang-tidy doesn't |
| 643 | // support exporting dependencies. |
Dan Willemsen | 6b4419c | 2019-08-09 12:45:53 -0700 | [diff] [blame] | 644 | Implicit: objFile, |
| 645 | Implicits: cFlagsDeps, |
| 646 | OrderOnly: pathDeps, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 647 | Args: map[string]string{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 648 | "cFlags": moduleToolingFlags, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 649 | "tidyFlags": flags.tidyFlags, |
| 650 | }, |
| 651 | }) |
| 652 | } |
| 653 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 654 | if dump { |
| 655 | sAbiDumpFile := android.ObjPathWithExt(ctx, subdir, srcFile, "sdump") |
| 656 | sAbiDumpFiles = append(sAbiDumpFiles, sAbiDumpFile) |
| 657 | |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 658 | dumpRule := sAbiDump |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 659 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ABI_DUMPER") { |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 660 | dumpRule = sAbiDumpRE |
| 661 | } |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 662 | ctx.Build(pctx, android.BuildParams{ |
Ramy Medhat | 31ec942 | 2020-04-17 15:03:58 -0400 | [diff] [blame] | 663 | Rule: dumpRule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 664 | Description: "header-abi-dumper " + srcFile.Rel(), |
| 665 | Output: sAbiDumpFile, |
| 666 | Input: srcFile, |
| 667 | Implicit: objFile, |
Dan Willemsen | 6b4419c | 2019-08-09 12:45:53 -0700 | [diff] [blame] | 668 | Implicits: cFlagsDeps, |
| 669 | OrderOnly: pathDeps, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 670 | Args: map[string]string{ |
Colin Cross | 6d88dba | 2019-11-06 07:06:58 -0800 | [diff] [blame] | 671 | "cFlags": moduleToolingFlags, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 672 | "exportDirs": flags.sAbiFlags, |
| 673 | }, |
| 674 | }) |
| 675 | } |
| 676 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 679 | return Objects{ |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 680 | objFiles: objFiles, |
| 681 | tidyFiles: tidyFiles, |
| 682 | coverageFiles: coverageFiles, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 683 | sAbiDumpFiles: sAbiDumpFiles, |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 684 | kytheFiles: kytheFiles, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 685 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // Generate a rule for compiling multiple .o files to a static library (.a) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 689 | func transformObjToStaticLib(ctx android.ModuleContext, |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 690 | objFiles android.Paths, wholeStaticLibs android.Paths, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 691 | flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 692 | |
Stephen Hines | f1addeb | 2018-01-09 23:29:04 -0800 | [diff] [blame] | 693 | arCmd := "${config.ClangBin}/llvm-ar" |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 694 | arFlags := "" |
Stephen Hines | f1addeb | 2018-01-09 23:29:04 -0800 | [diff] [blame] | 695 | if !ctx.Darwin() { |
| 696 | arFlags += " -format=gnu" |
| 697 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 698 | |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 699 | if len(wholeStaticLibs) == 0 { |
| 700 | ctx.Build(pctx, android.BuildParams{ |
| 701 | Rule: ar, |
| 702 | Description: "static link " + outputFile.Base(), |
| 703 | Output: outputFile, |
| 704 | Inputs: objFiles, |
| 705 | Implicits: deps, |
| 706 | Args: map[string]string{ |
| 707 | "arFlags": "crsPD" + arFlags, |
| 708 | "arCmd": arCmd, |
| 709 | }, |
| 710 | }) |
| 711 | |
| 712 | } else { |
| 713 | ctx.Build(pctx, android.BuildParams{ |
| 714 | Rule: arWithLibs, |
| 715 | Description: "static link " + outputFile.Base(), |
| 716 | Output: outputFile, |
| 717 | Inputs: append(objFiles, wholeStaticLibs...), |
| 718 | Implicits: deps, |
| 719 | Args: map[string]string{ |
| 720 | "arCmd": arCmd, |
| 721 | "arObjFlags": "crsPD" + arFlags, |
| 722 | "arObjs": strings.Join(objFiles.Strings(), " "), |
| 723 | "arLibFlags": "cqsL" + arFlags, |
| 724 | "arLibs": strings.Join(wholeStaticLibs.Strings(), " "), |
| 725 | }, |
| 726 | }) |
| 727 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | // Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries, |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 731 | // and shared libraries, to a shared library (.so) or dynamic executable |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 732 | func transformObjToDynamicBinary(ctx android.ModuleContext, |
Colin Cross | c465efd | 2021-06-11 18:00:04 -0700 | [diff] [blame] | 733 | objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps, crtBegin, crtEnd android.Paths, |
| 734 | groupLate bool, flags builderFlags, outputFile android.WritablePath, |
| 735 | implicitOutputs android.WritablePaths, validations android.WritablePaths) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 736 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 737 | ldCmd := "${config.ClangBin}/clang++" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 738 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 739 | var libFlagsList []string |
| 740 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 741 | if len(flags.libFlags) > 0 { |
| 742 | libFlagsList = append(libFlagsList, flags.libFlags) |
| 743 | } |
| 744 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 745 | if len(wholeStaticLibs) > 0 { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 746 | if ctx.Host() && ctx.Darwin() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 747 | libFlagsList = append(libFlagsList, android.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load ")) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 748 | } else { |
| 749 | libFlagsList = append(libFlagsList, "-Wl,--whole-archive ") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 750 | libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 751 | libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ") |
| 752 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 755 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 756 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 757 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 758 | libFlagsList = append(libFlagsList, staticLibs.Strings()...) |
Colin Cross | 7a7cf97 | 2016-12-05 18:47:39 -0800 | [diff] [blame] | 759 | if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 { |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 760 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 761 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 762 | |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 763 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 764 | libFlagsList = append(libFlagsList, "-Wl,--start-group") |
| 765 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 766 | libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...) |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 767 | if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 { |
Dan Willemsen | edc385f | 2015-07-08 13:02:23 -0700 | [diff] [blame] | 768 | libFlagsList = append(libFlagsList, "-Wl,--end-group") |
| 769 | } |
| 770 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 771 | for _, lib := range sharedLibs { |
Josh Gao | 75a50a2 | 2019-06-07 17:58:59 -0700 | [diff] [blame] | 772 | libFile := lib.String() |
| 773 | if ctx.Windows() { |
| 774 | libFile = pathtools.ReplaceExtension(libFile, "lib") |
| 775 | } |
| 776 | libFlagsList = append(libFlagsList, libFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 779 | deps = append(deps, staticLibs...) |
Colin Cross | 3075ad0 | 2015-03-17 10:47:08 -0700 | [diff] [blame] | 780 | deps = append(deps, lateStaticLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 781 | deps = append(deps, wholeStaticLibs...) |
Colin Cross | c465efd | 2021-06-11 18:00:04 -0700 | [diff] [blame] | 782 | deps = append(deps, crtBegin...) |
| 783 | deps = append(deps, crtEnd...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 784 | |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 785 | rule := ld |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 786 | args := map[string]string{ |
| 787 | "ldCmd": ldCmd, |
Colin Cross | c465efd | 2021-06-11 18:00:04 -0700 | [diff] [blame] | 788 | "crtBegin": strings.Join(crtBegin.Strings(), " "), |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 789 | "libFlags": strings.Join(libFlagsList, " "), |
| 790 | "extraLibFlags": flags.extraLibFlags, |
| 791 | "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, |
Colin Cross | c465efd | 2021-06-11 18:00:04 -0700 | [diff] [blame] | 792 | "crtEnd": strings.Join(crtEnd.Strings(), " "), |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 793 | } |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 794 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") { |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 795 | rule = ldRE |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 796 | args["implicitOutputs"] = strings.Join(implicitOutputs.Strings(), ",") |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 797 | args["implicitInputs"] = strings.Join(deps.Strings(), ",") |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 798 | } |
| 799 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 800 | ctx.Build(pctx, android.BuildParams{ |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 801 | Rule: rule, |
Josh Gao | 75a50a2 | 2019-06-07 17:58:59 -0700 | [diff] [blame] | 802 | Description: "link " + outputFile.Base(), |
| 803 | Output: outputFile, |
| 804 | ImplicitOutputs: implicitOutputs, |
| 805 | Inputs: objFiles, |
| 806 | Implicits: deps, |
Colin Cross | 58dd6a9 | 2021-05-13 17:45:36 -0700 | [diff] [blame] | 807 | OrderOnly: sharedLibs, |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 808 | Validations: validations.Paths(), |
Kousik Kumar | 3fb6126 | 2020-04-22 13:31:09 -0700 | [diff] [blame] | 809 | Args: args, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 810 | }) |
| 811 | } |
| 812 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 813 | // Generate a rule to combine .dump sAbi dump files from multiple source files |
| 814 | // into a single .ldump sAbi dump file |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 815 | func transformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path, |
Logan Chien | e3d7a0d | 2019-01-17 00:18:02 +0800 | [diff] [blame] | 816 | baseName, exportedHeaderFlags string, symbolFile android.OptionalPath, |
| 817 | excludedSymbolVersions, excludedSymbolTags []string) android.OptionalPath { |
| 818 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 819 | outputFile := android.PathForModuleOut(ctx, baseName+".lsdump") |
Logan Chien | e3d7a0d | 2019-01-17 00:18:02 +0800 | [diff] [blame] | 820 | |
| 821 | implicits := android.Paths{soFile} |
Jayant Chowdhary | df344d5 | 2018-01-17 11:11:42 -0800 | [diff] [blame] | 822 | symbolFilterStr := "-so " + soFile.String() |
Logan Chien | e3d7a0d | 2019-01-17 00:18:02 +0800 | [diff] [blame] | 823 | |
| 824 | if symbolFile.Valid() { |
| 825 | implicits = append(implicits, symbolFile.Path()) |
| 826 | symbolFilterStr += " -v " + symbolFile.String() |
| 827 | } |
| 828 | for _, ver := range excludedSymbolVersions { |
| 829 | symbolFilterStr += " --exclude-symbol-version " + ver |
| 830 | } |
| 831 | for _, tag := range excludedSymbolTags { |
| 832 | symbolFilterStr += " --exclude-symbol-tag " + tag |
| 833 | } |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 834 | rule := sAbiLink |
| 835 | args := map[string]string{ |
| 836 | "symbolFilter": symbolFilterStr, |
| 837 | "arch": ctx.Arch().ArchType.Name, |
| 838 | "exportedHeaderFlags": exportedHeaderFlags, |
| 839 | } |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 840 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ABI_LINKER") { |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 841 | rule = sAbiLinkRE |
| 842 | rbeImplicits := implicits.Strings() |
| 843 | for _, p := range strings.Split(exportedHeaderFlags, " ") { |
| 844 | if len(p) > 2 { |
| 845 | // Exclude the -I prefix. |
| 846 | rbeImplicits = append(rbeImplicits, p[2:]) |
| 847 | } |
| 848 | } |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 849 | args["implicitInputs"] = strings.Join(rbeImplicits, ",") |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 850 | } |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 851 | ctx.Build(pctx, android.BuildParams{ |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 852 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 853 | Description: "header-abi-linker " + outputFile.Base(), |
| 854 | Output: outputFile, |
| 855 | Inputs: sAbiDumps, |
Logan Chien | e3d7a0d | 2019-01-17 00:18:02 +0800 | [diff] [blame] | 856 | Implicits: implicits, |
Ramy Medhat | 808594c | 2020-05-07 06:56:47 -0400 | [diff] [blame] | 857 | Args: args, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 858 | }) |
| 859 | return android.OptionalPathForPath(outputFile) |
| 860 | } |
| 861 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 862 | // unzipRefDump registers a build statement to unzip a reference abi dump. |
| 863 | func unzipRefDump(ctx android.ModuleContext, zippedRefDump android.Path, baseName string) android.Path { |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 864 | outputFile := android.PathForModuleOut(ctx, baseName+"_ref.lsdump") |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 865 | ctx.Build(pctx, android.BuildParams{ |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 866 | Rule: unzipRefSAbiDump, |
| 867 | Description: "gunzip" + outputFile.Base(), |
| 868 | Output: outputFile, |
| 869 | Input: zippedRefDump, |
| 870 | }) |
| 871 | return outputFile |
| 872 | } |
| 873 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 874 | // sourceAbiDiff registers a build statement to compare linked sAbi dump files (.ldump). |
| 875 | func sourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path, |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 876 | baseName, exportedHeaderFlags string, checkAllApis, isLlndk, isNdk, isVndkExt bool) android.OptionalPath { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 877 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 878 | outputFile := android.PathForModuleOut(ctx, baseName+".abidiff") |
Jayant Chowdhary | c7434e2 | 2018-05-31 15:42:26 -0700 | [diff] [blame] | 879 | libName := strings.TrimSuffix(baseName, filepath.Ext(baseName)) |
Logan Chien | 6227fed | 2019-02-18 13:12:21 +0800 | [diff] [blame] | 880 | createReferenceDumpFlags := "" |
| 881 | |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 882 | var extraFlags []string |
| 883 | if checkAllApis { |
| 884 | extraFlags = append(extraFlags, "-check-all-apis") |
| 885 | } else { |
| 886 | extraFlags = append(extraFlags, |
| 887 | "-allow-unreferenced-changes", |
| 888 | "-allow-unreferenced-elf-symbol-changes") |
Jayant Chowdhary | e449950 | 2018-01-17 13:13:33 -0800 | [diff] [blame] | 889 | } |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 890 | |
| 891 | if exportedHeaderFlags == "" { |
| 892 | extraFlags = append(extraFlags, "-advice-only") |
| 893 | } |
| 894 | |
Logan Chien | 62f1f94 | 2019-02-18 15:40:42 +0800 | [diff] [blame] | 895 | if isLlndk || isNdk { |
Logan Chien | 6227fed | 2019-02-18 13:12:21 +0800 | [diff] [blame] | 896 | createReferenceDumpFlags = "--llndk" |
Logan Chien | 62f1f94 | 2019-02-18 15:40:42 +0800 | [diff] [blame] | 897 | if isLlndk { |
| 898 | // TODO(b/130324828): "-consider-opaque-types-different" should apply to |
| 899 | // both LLNDK and NDK shared libs. However, a known issue in header-abi-diff |
| 900 | // breaks libaaudio. Remove the if-guard after the issue is fixed. |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 901 | extraFlags = append(extraFlags, "-consider-opaque-types-different") |
Logan Chien | 62f1f94 | 2019-02-18 15:40:42 +0800 | [diff] [blame] | 902 | } |
Jayant Chowdhary | c7434e2 | 2018-05-31 15:42:26 -0700 | [diff] [blame] | 903 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 904 | if isVndkExt { |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 905 | extraFlags = append(extraFlags, "-allow-extensions") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 906 | } |
| 907 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 908 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 909 | Rule: sAbiDiff, |
| 910 | Description: "header-abi-diff " + outputFile.Base(), |
| 911 | Output: outputFile, |
| 912 | Input: inputDump, |
| 913 | Implicit: referenceDump, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 914 | Args: map[string]string{ |
Logan Chien | 6227fed | 2019-02-18 13:12:21 +0800 | [diff] [blame] | 915 | "referenceDump": referenceDump.String(), |
| 916 | "libName": libName, |
| 917 | "arch": ctx.Arch().ArchType.Name, |
Logan Chien | 2a65dda | 2019-10-01 15:58:07 -0700 | [diff] [blame] | 918 | "extraFlags": strings.Join(extraFlags, " "), |
Logan Chien | 6227fed | 2019-02-18 13:12:21 +0800 | [diff] [blame] | 919 | "createReferenceDumpFlags": createReferenceDumpFlags, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 920 | }, |
| 921 | }) |
| 922 | return android.OptionalPathForPath(outputFile) |
| 923 | } |
| 924 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 925 | // Generate a rule for extracting a table of contents from a shared library (.so) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 926 | func transformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path, |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 927 | outputFile android.WritablePath, flags builderFlags) { |
| 928 | |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 929 | var format string |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 930 | if ctx.Darwin() { |
| 931 | format = "--macho" |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 932 | } else if ctx.Windows() { |
| 933 | format = "--pe" |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 934 | } else { |
| 935 | format = "--elf" |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 936 | } |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 937 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 938 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 939 | Rule: toc, |
| 940 | Description: "generate toc " + inputFile.Base(), |
| 941 | Output: outputFile, |
| 942 | Input: inputFile, |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 943 | Args: map[string]string{ |
Yi Kong | 4ad44e7 | 2021-04-01 17:45:42 +0800 | [diff] [blame] | 944 | "clangBin": "${config.ClangBin}", |
| 945 | "format": format, |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 946 | }, |
| 947 | }) |
| 948 | } |
| 949 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 950 | // Generate a rule for compiling multiple .o files to a .o using ld partial linking |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 951 | func transformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, |
Dan Willemsen | 724ab5d | 2019-09-19 10:50:18 -0700 | [diff] [blame] | 952 | flags builderFlags, outputFile android.WritablePath, deps android.Paths) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 953 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 954 | ldCmd := "${config.ClangBin}/clang++" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 955 | |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 956 | rule := partialLd |
| 957 | args := map[string]string{ |
| 958 | "ldCmd": ldCmd, |
| 959 | "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, |
| 960 | } |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 961 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") { |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 962 | rule = partialLdRE |
| 963 | args["inCommaList"] = strings.Join(objFiles.Strings(), ",") |
Ramy Medhat | 6797edc | 2020-08-28 14:21:55 -0400 | [diff] [blame] | 964 | args["implicitInputs"] = strings.Join(deps.Strings(), ",") |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 965 | } |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 966 | ctx.Build(pctx, android.BuildParams{ |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 967 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 968 | Description: "link " + outputFile.Base(), |
| 969 | Output: outputFile, |
| 970 | Inputs: objFiles, |
Dan Willemsen | 724ab5d | 2019-09-19 10:50:18 -0700 | [diff] [blame] | 971 | Implicits: deps, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 972 | Args: args, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 973 | }) |
| 974 | } |
| 975 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 976 | // Generate a rule for running objcopy --prefix-symbols on a binary |
| 977 | func transformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inputFile android.Path, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 978 | flags builderFlags, outputFile android.WritablePath) { |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 979 | |
Elliott Hughes | 2e70f79 | 2021-04-19 12:58:43 -0700 | [diff] [blame] | 980 | objcopyCmd := "${config.ClangBin}/llvm-objcopy" |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 981 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 982 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 983 | Rule: prefixSymbols, |
| 984 | Description: "prefix symbols " + outputFile.Base(), |
| 985 | Output: outputFile, |
| 986 | Input: inputFile, |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 987 | Args: map[string]string{ |
| 988 | "objcopyCmd": objcopyCmd, |
| 989 | "prefix": prefix, |
| 990 | }, |
| 991 | }) |
| 992 | } |
| 993 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 994 | // Registers a build statement to invoke `strip` (to discard symbols and data from object files). |
| 995 | func transformStrip(ctx android.ModuleContext, inputFile android.Path, |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 996 | outputFile android.WritablePath, flags StripFlags) { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 997 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 998 | args := "" |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 999 | if flags.StripAddGnuDebuglink { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1000 | args += " --add-gnu-debuglink" |
| 1001 | } |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 1002 | if flags.StripKeepMiniDebugInfo { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1003 | args += " --keep-mini-debug-info" |
| 1004 | } |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 1005 | if flags.StripKeepSymbols { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1006 | args += " --keep-symbols" |
| 1007 | } |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 1008 | if flags.StripKeepSymbolsList != "" { |
| 1009 | args += " -k" + flags.StripKeepSymbolsList |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 1010 | } |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 1011 | if flags.StripKeepSymbolsAndDebugFrame { |
Christopher Ferris | b43fe7a | 2019-05-17 16:39:54 -0700 | [diff] [blame] | 1012 | args += " --keep-symbols-and-debug-frame" |
| 1013 | } |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1014 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 1015 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1016 | Rule: strip, |
| 1017 | Description: "strip " + outputFile.Base(), |
| 1018 | Output: outputFile, |
| 1019 | Input: inputFile, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1020 | Args: map[string]string{ |
Elliott Hughes | afcd339 | 2021-05-05 13:54:11 -0700 | [diff] [blame] | 1021 | "args": args, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1022 | }, |
| 1023 | }) |
| 1024 | } |
| 1025 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 1026 | // Registers build statement to invoke `strip` on darwin architecture. |
| 1027 | func transformDarwinStrip(ctx android.ModuleContext, inputFile android.Path, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1028 | outputFile android.WritablePath) { |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 1029 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 1030 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 1031 | Rule: darwinStrip, |
| 1032 | Description: "strip " + outputFile.Base(), |
| 1033 | Output: outputFile, |
| 1034 | Input: inputFile, |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 1035 | }) |
| 1036 | } |
| 1037 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 1038 | // Registers build statement to zip one or more coverage files. |
| 1039 | func transformCoverageFilesToZip(ctx android.ModuleContext, |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 1040 | inputs Objects, baseName string) android.OptionalPath { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1041 | |
| 1042 | if len(inputs.coverageFiles) > 0 { |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 1043 | outputFile := android.PathForModuleOut(ctx, baseName+".zip") |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1044 | |
Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 1045 | ctx.Build(pctx, android.BuildParams{ |
| 1046 | Rule: zip, |
| 1047 | Description: "zip " + outputFile.Base(), |
| 1048 | Inputs: inputs.coverageFiles, |
| 1049 | Output: outputFile, |
| 1050 | }) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1051 | |
| 1052 | return android.OptionalPathForPath(outputFile) |
| 1053 | } |
| 1054 | |
| 1055 | return android.OptionalPath{} |
| 1056 | } |
| 1057 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 1058 | // Rule to repack an archive (.a) file with a subset of object files. |
| 1059 | func transformArchiveRepack(ctx android.ModuleContext, inputFile android.Path, |
Yi Kong | c49c393 | 2019-10-15 02:01:19 -0700 | [diff] [blame] | 1060 | outputFile android.WritablePath, objects []string) { |
| 1061 | |
| 1062 | ctx.Build(pctx, android.BuildParams{ |
| 1063 | Rule: archiveRepack, |
| 1064 | Description: "Repack archive " + outputFile.Base(), |
| 1065 | Output: outputFile, |
| 1066 | Input: inputFile, |
| 1067 | Args: map[string]string{ |
| 1068 | "objects": strings.Join(objects, " "), |
| 1069 | }, |
| 1070 | }) |
| 1071 | } |
| 1072 | |
Elliott Hughes | 5f314b1 | 2021-05-18 11:56:02 -0700 | [diff] [blame] | 1073 | func mingwCmd(toolchain config.Toolchain, cmd string) string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1074 | return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd) |
| 1075 | } |