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