| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 |  | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | import ( | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 18 | "runtime" | 
| Colin Cross | bcf5370 | 2024-01-17 11:11:03 -0800 | [diff] [blame] | 19 | "slices" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | "strings" | 
|  | 21 |  | 
|  | 22 | "android/soong/android" | 
| Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 23 | "android/soong/remoteexec" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | ) | 
|  | 25 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 26 | var ( | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 27 | pctx = android.NewPackageContext("android/soong/cc/config") | 
| Sam Delmerico | 7f88956 | 2022-03-25 14:55:40 +0000 | [diff] [blame] | 28 |  | 
| Leo Li | 8756b37 | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 29 | // Flags used by lots of devices.  Putting them in package static variables | 
|  | 30 | // will save bytes in build.ninja so they aren't repeated for every file | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 31 | commonGlobalCflags = []string{ | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 32 | // Enable some optimization by default. | 
|  | 33 | "-O2", | 
|  | 34 |  | 
|  | 35 | // Warnings enabled by default. Reference: | 
|  | 36 | // https://clang.llvm.org/docs/DiagnosticsReference.html | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 37 | "-Wall", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 38 | "-Wextra", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 39 | "-Winit-self", | 
|  | 40 | "-Wpointer-arith", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 41 | "-Wunguarded-availability", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 42 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 43 | // Warnings treated as errors by default. | 
|  | 44 | // See also noOverrideGlobalCflags for errors that cannot be disabled | 
|  | 45 | // from Android.bp files. | 
| Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 46 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 47 | // Using __DATE__/__TIME__ causes build nondeterminism. | 
| Dan Willemsen | 5d980c8 | 2019-08-27 19:37:10 -0700 | [diff] [blame] | 48 | "-Werror=date-time", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 49 | // Detects forgotten */& that usually cause a crash | 
|  | 50 | "-Werror=int-conversion", | 
|  | 51 | // Detects unterminated alignment modification pragmas, which often lead | 
|  | 52 | // to ABI mismatch between modules and hard-to-debug crashes. | 
| Elliott Hughes | 2cdbdf1 | 2019-12-03 18:13:00 -0800 | [diff] [blame] | 53 | "-Werror=pragma-pack", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 54 | // Same as above, but detects alignment pragmas around a header | 
|  | 55 | // inclusion. | 
| Elliott Hughes | 2cdbdf1 | 2019-12-03 18:13:00 -0800 | [diff] [blame] | 56 | "-Werror=pragma-pack-suspicious-include", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 57 | // Detects dividing an array size by itself, which is a common typo that | 
|  | 58 | // leads to bugs. | 
|  | 59 | "-Werror=sizeof-array-div", | 
|  | 60 | // Detects a typo that cuts off a prefix from a string literal. | 
| Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 61 | "-Werror=string-plus-int", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 62 | // Detects for loops that will never execute more than once (for example | 
|  | 63 | // due to unconditional break), but have a non-empty loop increment | 
|  | 64 | // clause. Often a mistake/bug. | 
| George Burgess IV | fb81db2 | 2020-02-22 19:28:56 -0800 | [diff] [blame] | 65 | "-Werror=unreachable-code-loop-increment", | 
| Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 66 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 67 | // Warnings that should not be errors even for modules with -Werror. | 
| Krzysztof Kosiński | 6934b0e | 2022-08-07 06:56:54 +0000 | [diff] [blame] | 68 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 69 | // Making deprecated usages an error causes extreme pain when trying to | 
|  | 70 | // deprecate anything. | 
|  | 71 | "-Wno-error=deprecated-declarations", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 72 |  | 
|  | 73 | // Warnings disabled by default. | 
|  | 74 |  | 
|  | 75 | // Designated initializer syntax is recommended by the Google C++ style | 
|  | 76 | // and is OK to use even if not formally supported by the chosen C++ | 
|  | 77 | // version. | 
|  | 78 | "-Wno-c99-designator", | 
|  | 79 | // Detects uses of a GNU C extension equivalent to a limited form of | 
|  | 80 | // constexpr. Enabling this would require replacing many constants with | 
|  | 81 | // macros, which is not a good trade-off. | 
|  | 82 | "-Wno-gnu-folding-constant", | 
|  | 83 | // AIDL generated code redeclares pure virtual methods in each | 
|  | 84 | // subsequent version of an interface, so this warning is currently | 
|  | 85 | // infeasible to enable. | 
|  | 86 | "-Wno-inconsistent-missing-override", | 
| Krzysztof Kosiński | 8f8cc16 | 2023-10-20 01:02:58 +0000 | [diff] [blame] | 87 | // Detects designated initializers that are in a different order than | 
|  | 88 | // the fields in the initialized type, which causes the side effects | 
|  | 89 | // of initializers to occur out of order with the source code. | 
|  | 90 | // In practice, this warning has extremely poor signal to noise ratio, | 
|  | 91 | // because it is triggered even for initializers with no side effects. | 
|  | 92 | // Individual modules can still opt into it via cflags. | 
|  | 93 | "-Wno-error=reorder-init-list", | 
|  | 94 | "-Wno-reorder-init-list", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 95 | // Incompatible with the Google C++ style guidance to use 'int' for loop | 
|  | 96 | // indices; poor signal to noise ratio. | 
|  | 97 | "-Wno-sign-compare", | 
|  | 98 | // Poor signal to noise ratio. | 
|  | 99 | "-Wno-unused", | 
|  | 100 |  | 
|  | 101 | // Global preprocessor constants. | 
|  | 102 |  | 
|  | 103 | "-DANDROID", | 
|  | 104 | "-DNDEBUG", | 
|  | 105 | "-UDEBUG", | 
| Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 106 | "-D__compiler_offsetof=__builtin_offsetof", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 107 | // Allows the bionic versioning.h to indirectly determine whether the | 
|  | 108 | // option -Wunguarded-availability is on or not. | 
|  | 109 | "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", | 
|  | 110 |  | 
|  | 111 | // -f and -g options. | 
| Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | // Emit address-significance table which allows linker to perform safe ICF. Clang does | 
|  | 114 | // not emit the table by default on Android since NDK still uses GNU binutils. | 
|  | 115 | "-faddrsig", | 
|  | 116 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 117 | // Emit debugging data in a modern format (DWARF v5). | 
|  | 118 | "-fdebug-default-version=5", | 
| Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 119 |  | 
| Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 120 | // Force clang to always output color diagnostics. Ninja will strip the ANSI | 
|  | 121 | // color codes if it is not running in a terminal. | 
|  | 122 | "-fcolor-diagnostics", | 
|  | 123 |  | 
| Pirama Arumuga Nainar | 8a4804f | 2022-02-14 11:19:26 -0800 | [diff] [blame] | 124 | // Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949) | 
|  | 125 | "-ffp-contract=off", | 
| AdityaK | 423e4ce | 2023-05-26 12:08:05 -0700 | [diff] [blame] | 126 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 127 | // Google C++ style does not allow exceptions, turn them off by default. | 
|  | 128 | "-fno-exceptions", | 
|  | 129 |  | 
|  | 130 | // Disable optimizations based on strict aliasing by default. | 
|  | 131 | // The performance benefit of enabling them currently does not outweigh | 
|  | 132 | // the risk of hard-to-reproduce bugs. | 
|  | 133 | "-fno-strict-aliasing", | 
|  | 134 |  | 
|  | 135 | // Disable line wrapping for error messages - it interferes with | 
|  | 136 | // displaying logs in web browsers. | 
|  | 137 | "-fmessage-length=0", | 
|  | 138 |  | 
| AdityaK | 423e4ce | 2023-05-26 12:08:05 -0700 | [diff] [blame] | 139 | // Using simple template names reduces the size of debug builds. | 
|  | 140 | "-gsimple-template-names", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 141 |  | 
| Eric Rahm | 5571ab8 | 2023-10-20 15:56:17 +0000 | [diff] [blame] | 142 | // Use zstd to compress debug data. | 
|  | 143 | "-gz=zstd", | 
|  | 144 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 145 | // Make paths in deps files relative. | 
|  | 146 | "-no-canonical-prefixes", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
| Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 149 | commonGlobalConlyflags = []string{} | 
| Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 150 |  | 
| Liz Kammer | e4d1bda | 2022-06-22 21:02:08 +0000 | [diff] [blame] | 151 | commonGlobalAsflags = []string{ | 
|  | 152 | "-D__ASSEMBLY__", | 
|  | 153 | // TODO(b/235105792): override global -fdebug-default-version=5, it is causing $TMPDIR to | 
|  | 154 | // end up in the dwarf data for crtend_so.S. | 
|  | 155 | "-fdebug-default-version=4", | 
|  | 156 | } | 
|  | 157 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 158 | // Compilation flags for device code; not applied to host code. | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 159 | deviceGlobalCflags = []string{ | 
| Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 160 | "-ffunction-sections", | 
| Colin Cross | ea3141d | 2017-11-06 14:02:02 -0800 | [diff] [blame] | 161 | "-fdata-sections", | 
|  | 162 | "-fno-short-enums", | 
| Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 163 | "-funwind-tables", | 
|  | 164 | "-fstack-protector-strong", | 
|  | 165 | "-Wa,--noexecstack", | 
|  | 166 | "-D_FORTIFY_SOURCE=2", | 
|  | 167 |  | 
|  | 168 | "-Wstrict-aliasing=2", | 
|  | 169 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 170 | "-Werror=return-type", | 
|  | 171 | "-Werror=non-virtual-dtor", | 
|  | 172 | "-Werror=address", | 
|  | 173 | "-Werror=sequence-point", | 
| Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 174 | "-Werror=format-security", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 175 | "-nostdlibinc", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 176 | } | 
|  | 177 |  | 
| Yi Kong | a9e1df1 | 2022-10-20 14:45:52 +0900 | [diff] [blame] | 178 | commonGlobalLldflags = []string{ | 
|  | 179 | "-fuse-ld=lld", | 
|  | 180 | "-Wl,--icf=safe", | 
| Steven Moreland | 8fe37e4 | 2023-07-22 00:14:55 +0000 | [diff] [blame] | 181 | "-Wl,--no-demangle", | 
| Yi Kong | a9e1df1 | 2022-10-20 14:45:52 +0900 | [diff] [blame] | 182 | } | 
|  | 183 |  | 
| Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 184 | deviceGlobalCppflags = []string{ | 
|  | 185 | "-fvisibility-inlines-hidden", | 
|  | 186 | } | 
|  | 187 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 188 | // Linking flags for device code; not applied to host binaries. | 
| Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 189 | deviceGlobalLdflags = []string{ | 
|  | 190 | "-Wl,-z,noexecstack", | 
|  | 191 | "-Wl,-z,relro", | 
|  | 192 | "-Wl,-z,now", | 
|  | 193 | "-Wl,--build-id=md5", | 
| Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 194 | "-Wl,--fatal-warnings", | 
|  | 195 | "-Wl,--no-undefined-version", | 
| Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 196 | // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these | 
|  | 197 | // --exclude-libs arguments can be removed. | 
| Christopher Ferris | c3a1e22 | 2019-04-10 17:57:50 -0700 | [diff] [blame] | 198 | "-Wl,--exclude-libs,libgcc.a", | 
| Yi Kong | 3d8792f | 2019-05-06 16:18:33 -0700 | [diff] [blame] | 199 | "-Wl,--exclude-libs,libgcc_stripped.a", | 
| Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 200 | "-Wl,--exclude-libs,libunwind_llvm.a", | 
| Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 201 | "-Wl,--exclude-libs,libunwind.a", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 202 | } | 
|  | 203 |  | 
| Eric Rahm | 1952471 | 2023-10-20 15:56:27 +0000 | [diff] [blame] | 204 | deviceGlobalLldflags = append(append(deviceGlobalLdflags, commonGlobalLldflags...), | 
|  | 205 | "-Wl,--compress-debug-sections=zstd", | 
|  | 206 | ) | 
| Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 207 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 208 | hostGlobalCflags = []string{} | 
|  | 209 |  | 
| Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 210 | hostGlobalCppflags = []string{} | 
|  | 211 |  | 
| Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 212 | hostGlobalLdflags = []string{} | 
|  | 213 |  | 
| Yi Kong | a9e1df1 | 2022-10-20 14:45:52 +0900 | [diff] [blame] | 214 | hostGlobalLldflags = commonGlobalLldflags | 
| Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 215 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 216 | commonGlobalCppflags = []string{ | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 217 | // -Wimplicit-fallthrough is not enabled by -Wall. | 
|  | 218 | "-Wimplicit-fallthrough", | 
|  | 219 |  | 
|  | 220 | // Enable clang's thread-safety annotations in libcxx. | 
|  | 221 | "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS", | 
|  | 222 |  | 
|  | 223 | // libc++'s math.h has an #include_next outside of system_headers. | 
|  | 224 | "-Wno-gnu-include-next", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 225 | } | 
|  | 226 |  | 
| Krzysztof Kosiński | 982c588 | 2023-08-18 18:56:45 +0000 | [diff] [blame] | 227 | // These flags are appended after the module's cflags, so they cannot be | 
|  | 228 | // overridden from Android.bp files. | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 229 | // | 
|  | 230 | // NOTE: if you need to disable a warning to unblock a compiler upgrade | 
|  | 231 | // and it is only triggered by third party code, add it to | 
|  | 232 | // extraExternalCflags (if possible) or noOverrideExternalGlobalCflags | 
|  | 233 | // (if the former doesn't work). If the new warning also occurs in first | 
|  | 234 | // party code, try adding it to commonGlobalCflags first. Adding it here | 
|  | 235 | // should be the last resort, because it prevents all code in Android from | 
|  | 236 | // opting into the warning. | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 237 | noOverrideGlobalCflags = []string{ | 
| Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 238 | "-Werror=bool-operation", | 
| Zijun Zhao | d156908 | 2023-03-08 23:48:45 +0000 | [diff] [blame] | 239 | "-Werror=format-insufficient-args", | 
| Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 240 | "-Werror=implicit-int-float-conversion", | 
|  | 241 | "-Werror=int-in-bool-context", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 242 | "-Werror=int-to-pointer-cast", | 
|  | 243 | "-Werror=pointer-to-int-cast", | 
| Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 244 | "-Werror=xor-used-as-pow", | 
| Stephen Hines | 2210e72 | 2020-07-15 11:11:57 -0700 | [diff] [blame] | 245 | // http://b/161386391 for -Wno-void-pointer-to-enum-cast | 
|  | 246 | "-Wno-void-pointer-to-enum-cast", | 
|  | 247 | // http://b/161386391 for -Wno-void-pointer-to-int-cast | 
|  | 248 | "-Wno-void-pointer-to-int-cast", | 
|  | 249 | // http://b/161386391 for -Wno-pointer-to-int-cast | 
|  | 250 | "-Wno-pointer-to-int-cast", | 
| George Burgess IV | 6c69164 | 2019-09-18 17:52:05 -0700 | [diff] [blame] | 251 | "-Werror=fortify-source", | 
| Aditya Kumar | ef7c121 | 2024-02-02 17:22:03 +0000 | [diff] [blame] | 252 | // http://b/315246135 temporarily disabled | 
| AdityaK | 94688b5 | 2024-02-08 13:50:18 -0800 | [diff] [blame] | 253 | "-Wno-unused-variable", | 
| Aditya Kumar | ef7c121 | 2024-02-02 17:22:03 +0000 | [diff] [blame] | 254 | // Disabled because it produces many false positives. http://b/323050926 | 
|  | 255 | "-Wno-missing-field-initializers", | 
|  | 256 | // http://b/323050889 | 
|  | 257 | "-Wno-packed-non-pod", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 258 |  | 
|  | 259 | "-Werror=address-of-temporary", | 
| Krzysztof Kosiński | 83199b5 | 2023-10-26 07:16:29 +0000 | [diff] [blame] | 260 | "-Werror=incompatible-function-pointer-types", | 
| zijunzhao | 2863c0a | 2023-02-06 21:28:30 +0000 | [diff] [blame] | 261 | "-Werror=null-dereference", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 262 | "-Werror=return-type", | 
|  | 263 |  | 
|  | 264 | // http://b/72331526 Disable -Wtautological-* until the instances detected by these | 
|  | 265 | // new warnings are fixed. | 
|  | 266 | "-Wno-tautological-constant-compare", | 
|  | 267 | "-Wno-tautological-type-limit-compare", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 268 | // http://b/145211066 | 
|  | 269 | "-Wno-implicit-int-float-conversion", | 
|  | 270 | // New warnings to be fixed after clang-r377782. | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 271 | "-Wno-tautological-overlap-compare", // http://b/148815696 | 
|  | 272 | // New warnings to be fixed after clang-r383902. | 
|  | 273 | "-Wno-deprecated-copy",                      // http://b/153746672 | 
|  | 274 | "-Wno-range-loop-construct",                 // http://b/153747076 | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 275 | "-Wno-zero-as-null-pointer-constant",        // http://b/68236239 | 
|  | 276 | "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485 | 
| Elliott Hughes | 2ced4b5 | 2024-01-22 15:27:24 -0800 | [diff] [blame] | 277 | "-Wno-deprecated-enum-enum-conversion", | 
| Yi Kong | fd50d17 | 2024-08-12 14:41:09 +0800 | [diff] [blame] | 278 | "-Wno-error=pessimizing-move", // http://b/154270751 | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 279 | // New warnings to be fixed after clang-r399163 | 
|  | 280 | "-Wno-non-c-typedef-for-linkage", // http://b/161304145 | 
| Yabin Cui | 10bf3b8 | 2021-08-10 15:42:10 +0000 | [diff] [blame] | 281 | // New warnings to be fixed after clang-r428724 | 
|  | 282 | "-Wno-align-mismatch", // http://b/193679946 | 
| Yi Kong | e827329 | 2021-08-31 14:04:18 +0800 | [diff] [blame] | 283 | // New warnings to be fixed after clang-r433403 | 
|  | 284 | "-Wno-error=unused-but-set-variable",  // http://b/197240255 | 
|  | 285 | "-Wno-error=unused-but-set-parameter", // http://b/197240255 | 
| Chih-hung Hsieh | 5c40a92 | 2022-09-27 07:19:03 +0000 | [diff] [blame] | 286 | // New warnings to be fixed after clang-r468909 | 
| Chih-hung Hsieh | 5c40a92 | 2022-09-27 07:19:03 +0000 | [diff] [blame] | 287 | "-Wno-error=deprecated-builtins", // http://b/241601211 | 
|  | 288 | "-Wno-error=deprecated",          // in external/googletest/googletest | 
| Aditya Kumar | 2c6b4ac | 2024-09-12 18:40:17 +0000 | [diff] [blame] | 289 | // Disabling until the warning is fixed in libc++abi header files b/366180429 | 
|  | 290 | "-Wno-deprecated-dynamic-exception-spec", | 
| Yabin Cui | 29f248b | 2022-11-30 13:32:10 -0800 | [diff] [blame] | 291 | // New warnings to be fixed after clang-r475365 | 
| Pirama Arumuga Nainar | 65087c3 | 2024-08-29 16:44:10 +0000 | [diff] [blame] | 292 | "-Wno-error=enum-constexpr-conversion", // http://b/243964282 | 
| Chris Wailes | ffebc5b | 2024-06-10 18:06:52 +0000 | [diff] [blame] | 293 | // New warnings to be fixed after clang-r522817 | 
|  | 294 | "-Wno-error=invalid-offsetof", | 
|  | 295 | "-Wno-error=thread-safety-reference-return", | 
| Elliott Hughes | 2ced4b5 | 2024-01-22 15:27:24 -0800 | [diff] [blame] | 296 |  | 
| Chris Wailes | ffebc5b | 2024-06-10 18:06:52 +0000 | [diff] [blame] | 297 | // Allow using VLA CXX extension. | 
|  | 298 | "-Wno-vla-cxx-extension", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 299 | } | 
|  | 300 |  | 
| zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 301 | noOverride64GlobalCflags = []string{} | 
|  | 302 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 303 | // Extra cflags applied to third-party code (anything for which | 
|  | 304 | // IsThirdPartyPath() in build/soong/android/paths.go returns true; | 
|  | 305 | // includes external/, most of vendor/ and most of hardware/) | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 306 | extraExternalCflags = []string{ | 
|  | 307 | "-Wno-enum-compare", | 
|  | 308 | "-Wno-enum-compare-switch", | 
|  | 309 |  | 
|  | 310 | // http://b/72331524 Allow null pointer arithmetic until the instances detected by | 
|  | 311 | // this new warning are fixed. | 
|  | 312 | "-Wno-null-pointer-arithmetic", | 
|  | 313 |  | 
|  | 314 | // Bug: http://b/29823425 Disable -Wnull-dereference until the | 
|  | 315 | // new instances detected by this warning are fixed. | 
|  | 316 | "-Wno-null-dereference", | 
|  | 317 |  | 
|  | 318 | // http://b/145211477 | 
|  | 319 | "-Wno-pointer-compare", | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 320 | "-Wno-final-dtor-non-final-class", | 
|  | 321 |  | 
|  | 322 | // http://b/165945989 | 
|  | 323 | "-Wno-psabi", | 
| Yi Kong | e827329 | 2021-08-31 14:04:18 +0800 | [diff] [blame] | 324 |  | 
|  | 325 | // http://b/199369603 | 
|  | 326 | "-Wno-null-pointer-subtraction", | 
| Yi Kong | 9feb029 | 2021-12-15 13:20:27 +0800 | [diff] [blame] | 327 |  | 
|  | 328 | // http://b/175068488 | 
|  | 329 | "-Wno-string-concatenation", | 
| Yi Kong | eb8d04e | 2022-07-08 13:47:09 +0800 | [diff] [blame] | 330 |  | 
|  | 331 | // http://b/239661264 | 
|  | 332 | "-Wno-deprecated-non-prototype", | 
| Elliott Hughes | 2ced4b5 | 2024-01-22 15:27:24 -0800 | [diff] [blame] | 333 |  | 
|  | 334 | "-Wno-unused", | 
|  | 335 | "-Wno-deprecated", | 
| Yi Kong | 2e2d753 | 2024-08-09 14:56:58 +0900 | [diff] [blame] | 336 |  | 
|  | 337 | // http://b/315250603 temporarily disabled | 
|  | 338 | "-Wno-error=format", | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 341 | // Similar to noOverrideGlobalCflags, but applies only to third-party code | 
|  | 342 | // (see extraExternalCflags). | 
|  | 343 | // This section can unblock compiler upgrades when a third party module that | 
|  | 344 | // enables -Werror and some group of warnings explicitly triggers newly | 
|  | 345 | // added warnings. | 
|  | 346 | noOverrideExternalGlobalCflags = []string{ | 
|  | 347 | // http://b/151457797 | 
|  | 348 | "-fcommon", | 
|  | 349 | // http://b/191699019 | 
|  | 350 | "-Wno-format-insufficient-args", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 351 | // http://b/296321508 | 
|  | 352 | // Introduced in response to a critical security vulnerability and | 
|  | 353 | // should be a hard error - it requires only whitespace changes to fix. | 
|  | 354 | "-Wno-misleading-indentation", | 
|  | 355 | // Triggered by old LLVM code in external/llvm. Likely not worth | 
|  | 356 | // enabling since it's a cosmetic issue. | 
|  | 357 | "-Wno-bitwise-instead-of-logical", | 
|  | 358 |  | 
| Prashanth Swaminathan | 13b0637 | 2024-01-22 19:41:52 -0800 | [diff] [blame] | 359 | "-Wno-unused", | 
|  | 360 | "-Wno-unused-parameter", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 361 | "-Wno-unused-but-set-parameter", | 
|  | 362 | "-Wno-unqualified-std-cast-call", | 
|  | 363 | "-Wno-array-parameter", | 
|  | 364 | "-Wno-gnu-offsetof-extensions", | 
| Yi Kong | fd50d17 | 2024-08-12 14:41:09 +0800 | [diff] [blame] | 365 | "-Wno-pessimizing-move", | 
| Priyanka Advani (xWF) | 435c4ed | 2024-09-05 18:24:53 +0000 | [diff] [blame] | 366 | // TODO: Enable this warning http://b/315245071 | 
|  | 367 | "-Wno-fortify-source", | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 368 | } | 
|  | 369 |  | 
| Chih-Hung Hsieh | ec450d9 | 2022-08-02 12:03:50 -0700 | [diff] [blame] | 370 | llvmNextExtraCommonGlobalCflags = []string{ | 
| Yi Kong | a8b0bfb | 2022-12-26 16:02:50 +0900 | [diff] [blame] | 371 | // Do not report warnings when testing with the top of trunk LLVM. | 
| AdityaK | e7b6067 | 2023-10-27 11:26:00 -0700 | [diff] [blame] | 372 | "-Wno-everything", | 
| Chih-Hung Hsieh | ec450d9 | 2022-08-02 12:03:50 -0700 | [diff] [blame] | 373 | } | 
| Yi Kong | b79fc58 | 2022-07-13 14:50:33 +0800 | [diff] [blame] | 374 |  | 
| Krzysztof Kosiński | 1a4572e | 2023-09-02 01:08:37 +0000 | [diff] [blame] | 375 | // Flags that must not appear in any command line. | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 376 | IllegalFlags = []string{ | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 377 | "-w", | 
|  | 378 | } | 
| Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 379 |  | 
| Elliott Hughes | fb294e3 | 2023-06-14 10:42:45 -0700 | [diff] [blame] | 380 | CStdVersion               = "gnu17" | 
| Elliott Hughes | c79d9e3 | 2022-01-13 14:56:02 -0800 | [diff] [blame] | 381 | CppStdVersion             = "gnu++20" | 
| Elliott Hughes | fb294e3 | 2023-06-14 10:42:45 -0700 | [diff] [blame] | 382 | ExperimentalCStdVersion   = "gnu2x" | 
| Tomasz Wasilczyk | e149616 | 2023-11-15 11:46:26 -0800 | [diff] [blame] | 383 | ExperimentalCppStdVersion = "gnu++2b" | 
| Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 384 |  | 
| Leo Li | 8756b37 | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 385 | // prebuilts/clang default settings. | 
|  | 386 | ClangDefaultBase         = "prebuilts/clang/host" | 
| Yabin Cui | 8c69b78 | 2024-07-13 23:38:11 -0700 | [diff] [blame] | 387 | ClangDefaultVersion      = "clang-r530567" | 
|  | 388 | ClangDefaultShortVersion = "19" | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 389 |  | 
| Chih-Hung Hsieh | 775edde | 2017-12-24 22:24:47 -0800 | [diff] [blame] | 390 | // Directories with warnings from Android.bp files. | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 391 | WarningAllowedProjects = []string{ | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 392 | "device/", | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 393 | "vendor/", | 
|  | 394 | } | 
| Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 395 |  | 
|  | 396 | VersionScriptFlagPrefix = "-Wl,--version-script," | 
| Trevor Radcliffe | a772d65 | 2023-04-11 13:41:17 +0000 | [diff] [blame] | 397 |  | 
|  | 398 | VisibilityHiddenFlag  = "-fvisibility=hidden" | 
|  | 399 | VisibilityDefaultFlag = "-fvisibility=default" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 400 | ) | 
|  | 401 |  | 
|  | 402 | func init() { | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 403 | if runtime.GOOS == "linux" { | 
| Kousik Kumar | d207cbe | 2020-10-20 05:52:49 +0000 | [diff] [blame] | 404 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") | 
|  | 405 | } | 
|  | 406 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 407 | pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " ")) | 
|  | 408 | pctx.StaticVariable("CommonGlobalAsflags", strings.Join(commonGlobalAsflags, " ")) | 
|  | 409 | pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " ")) | 
|  | 410 | pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " ")) | 
|  | 411 | pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " ")) | 
|  | 412 | pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " ")) | 
|  | 413 | pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " ")) | 
|  | 414 | pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " ")) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 415 |  | 
| Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 416 | pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string { | 
| Colin Cross | bcf5370 | 2024-01-17 11:11:03 -0800 | [diff] [blame] | 417 | flags := slices.Clone(commonGlobalCflags) | 
| Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 418 |  | 
|  | 419 | // http://b/131390872 | 
|  | 420 | // Automatically initialize any uninitialized stack variables. | 
| Stephen Hines | 5c873ac | 2020-05-14 00:59:09 +0000 | [diff] [blame] | 421 | // Prefer zero-init if multiple options are set. | 
| Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 422 | if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") { | 
| Pirama Arumuga Nainar | 4026558 | 2023-05-11 00:01:25 +0000 | [diff] [blame] | 423 | flags = append(flags, "-ftrivial-auto-var-init=zero") | 
| Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 424 | } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") { | 
|  | 425 | flags = append(flags, "-ftrivial-auto-var-init=pattern") | 
| Stephen Hines | 797e195 | 2020-01-28 14:43:11 -0800 | [diff] [blame] | 426 | } else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") { | 
|  | 427 | flags = append(flags, "-ftrivial-auto-var-init=uninitialized") | 
| Stephen Hines | 0e1d5d8 | 2020-01-30 15:06:00 -0800 | [diff] [blame] | 428 | } else { | 
| Stephen Hines | 5c873ac | 2020-05-14 00:59:09 +0000 | [diff] [blame] | 429 | // Default to zero initialization. | 
| Pirama Arumuga Nainar | 4026558 | 2023-05-11 00:01:25 +0000 | [diff] [blame] | 430 | flags = append(flags, "-ftrivial-auto-var-init=zero") | 
| Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 431 | } | 
| Yi Kong | 62e75f5 | 2021-08-18 15:38:20 +0800 | [diff] [blame] | 432 |  | 
|  | 433 | // Workaround for ccache with clang. | 
|  | 434 | // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. | 
|  | 435 | if ctx.Config().IsEnvTrue("USE_CCACHE") { | 
|  | 436 | flags = append(flags, "-Wno-unused-command-line-argument") | 
|  | 437 | } | 
| Yi Kong | b79fc58 | 2022-07-13 14:50:33 +0800 | [diff] [blame] | 438 |  | 
| Yi Kong | f7f69e4 | 2022-07-21 15:49:05 +0800 | [diff] [blame] | 439 | if ctx.Config().IsEnvTrue("ALLOW_UNKNOWN_WARNING_OPTION") { | 
|  | 440 | flags = append(flags, "-Wno-error=unknown-warning-option") | 
|  | 441 | } | 
|  | 442 |  | 
| Fabián Cañas | bc10544 | 2023-06-30 17:53:06 +0000 | [diff] [blame] | 443 | switch ctx.Config().Getenv("CLANG_DEFAULT_DEBUG_LEVEL") { | 
|  | 444 | case "debug_level_0": | 
|  | 445 | flags = append(flags, "-g0") | 
|  | 446 | case "debug_level_1": | 
|  | 447 | flags = append(flags, "-g1") | 
|  | 448 | case "debug_level_2": | 
|  | 449 | flags = append(flags, "-g2") | 
|  | 450 | case "debug_level_3": | 
|  | 451 | flags = append(flags, "-g3") | 
|  | 452 | case "debug_level_g": | 
|  | 453 | flags = append(flags, "-g") | 
|  | 454 | default: | 
|  | 455 | flags = append(flags, "-g") | 
|  | 456 | } | 
|  | 457 |  | 
| Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 458 | return strings.Join(flags, " ") | 
|  | 459 | }) | 
|  | 460 |  | 
| Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 461 | pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string { | 
| Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 462 | return strings.Join(deviceGlobalCflags, " ") | 
| Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 463 | }) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 464 |  | 
| Yi Kong | 60a2010 | 2023-01-13 04:40:18 +0900 | [diff] [blame] | 465 | pctx.VariableFunc("NoOverrideGlobalCflags", func(ctx android.PackageVarContext) string { | 
|  | 466 | flags := noOverrideGlobalCflags | 
|  | 467 | if ctx.Config().IsEnvTrue("LLVM_NEXT") { | 
|  | 468 | flags = append(noOverrideGlobalCflags, llvmNextExtraCommonGlobalCflags...) | 
| AdityaK | e7b6067 | 2023-10-27 11:26:00 -0700 | [diff] [blame] | 469 | IllegalFlags = []string{} // Don't fail build while testing a new compiler. | 
| zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 470 | } | 
|  | 471 | return strings.Join(flags, " ") | 
|  | 472 | }) | 
|  | 473 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 474 | pctx.StaticVariable("NoOverride64GlobalCflags", strings.Join(noOverride64GlobalCflags, " ")) | 
|  | 475 | pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) | 
|  | 476 | pctx.StaticVariable("NoOverrideExternalGlobalCflags", strings.Join(noOverrideExternalGlobalCflags, " ")) | 
|  | 477 | pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) | 
|  | 478 | pctx.StaticVariable("ExternalCflags", strings.Join(extraExternalCflags, " ")) | 
| Trevor Radcliffe | a772d65 | 2023-04-11 13:41:17 +0000 | [diff] [blame] | 479 |  | 
| Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 480 | // Everything in these lists is a crime against abstraction and dependency tracking. | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 481 | // Do not add anything to this list. | 
| Jingwen Chen | 2199995 | 2021-05-19 05:53:51 +0000 | [diff] [blame] | 482 | commonGlobalIncludes := []string{ | 
|  | 483 | "system/core/include", | 
|  | 484 | "system/logging/liblog/include", | 
|  | 485 | "system/media/audio/include", | 
|  | 486 | "hardware/libhardware/include", | 
|  | 487 | "hardware/libhardware_legacy/include", | 
|  | 488 | "hardware/ril/include", | 
|  | 489 | "frameworks/native/include", | 
|  | 490 | "frameworks/native/opengl/include", | 
|  | 491 | "frameworks/av/include", | 
|  | 492 | } | 
| Jingwen Chen | 2199995 | 2021-05-19 05:53:51 +0000 | [diff] [blame] | 493 | pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 494 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 495 | pctx.StaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion) | 
|  | 496 | pctx.StaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion) | 
| Sam Delmerico | 3eda019 | 2023-04-14 18:07:25 +0000 | [diff] [blame] | 497 |  | 
| Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 498 | pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase) | 
| Sam Delmerico | 3eda019 | 2023-04-14 18:07:25 +0000 | [diff] [blame] | 499 | pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion) | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 500 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") | 
|  | 501 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") | 
|  | 502 |  | 
| Sam Delmerico | 3eda019 | 2023-04-14 18:07:25 +0000 | [diff] [blame] | 503 | pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion) | 
| Yi Kong | bd18881 | 2023-02-08 19:51:59 +0900 | [diff] [blame] | 504 | pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib/clang/${ClangShortVersion}/lib/linux") | 
| Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 505 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 506 | pctx.StaticVariable("WarningAllowedProjects", strings.Join(WarningAllowedProjects, " ")) | 
| Sam Delmerico | 036afab | 2023-05-04 16:43:36 -0400 | [diff] [blame] | 507 |  | 
| Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 508 | // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts | 
|  | 509 | // being used for the rest of the build process. | 
|  | 510 | pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host") | 
|  | 511 | pctx.SourcePathVariable("RSClangVersion", "clang-3289846") | 
|  | 512 | pctx.SourcePathVariable("RSReleaseVersion", "3.8") | 
|  | 513 | pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin") | 
|  | 514 | pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include") | 
|  | 515 |  | 
| Alix | e266787 | 2023-04-24 14:57:32 +0000 | [diff] [blame] | 516 | rsGlobalIncludes := []string{ | 
|  | 517 | "external/clang/lib/Headers", | 
|  | 518 | "frameworks/rs/script_api/include", | 
|  | 519 | } | 
|  | 520 | pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I", rsGlobalIncludes) | 
| Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 521 |  | 
| Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 522 | pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string { | 
|  | 523 | if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" { | 
|  | 524 | return override + " " | 
| Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 525 | } | 
| Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 526 | return "" | 
| Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 527 | }) | 
| Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 528 |  | 
| Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 529 | pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool) | 
|  | 530 | pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool) | 
|  | 531 | pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool) | 
|  | 532 | pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy) | 
|  | 533 | pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy) | 
|  | 534 | pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy) | 
|  | 535 | pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 536 | } | 
|  | 537 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 538 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) | 
| Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 539 |  | 
|  | 540 | func ClangPath(ctx android.PathContext, file string) android.SourcePath { | 
|  | 541 | type clangToolKey string | 
|  | 542 |  | 
|  | 543 | key := android.NewCustomOnceKey(clangToolKey(file)) | 
|  | 544 |  | 
|  | 545 | return ctx.Config().OnceSourcePath(key, func() android.SourcePath { | 
|  | 546 | return clangPath(ctx).Join(ctx, file) | 
|  | 547 | }) | 
|  | 548 | } | 
|  | 549 |  | 
|  | 550 | var clangPathKey = android.NewOnceKey("clangPath") | 
|  | 551 |  | 
|  | 552 | func clangPath(ctx android.PathContext) android.SourcePath { | 
|  | 553 | return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath { | 
|  | 554 | clangBase := ClangDefaultBase | 
|  | 555 | if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" { | 
|  | 556 | clangBase = override | 
|  | 557 | } | 
|  | 558 | clangVersion := ClangDefaultVersion | 
|  | 559 | if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" { | 
|  | 560 | clangVersion = override | 
|  | 561 | } | 
|  | 562 | return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion) | 
|  | 563 | }) | 
|  | 564 | } |