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