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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "path/filepath" |
Peter Collingbourne | b0e6143 | 2019-07-22 16:36:06 -0700 | [diff] [blame] | 20 | "strconv" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
| 24 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 25 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 26 | "android/soong/cc/config" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | // This file contains the basic C/C++/assembly to .o compliation steps |
| 30 | |
| 31 | type BaseCompilerProperties struct { |
| 32 | // list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files. |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 33 | // srcs may reference the outputs of other modules that produce source files like genrule |
| 34 | // or filegroup using the syntax ":module". |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 35 | Srcs []string `android:"path,arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 36 | |
| 37 | // list of source files that should not be used to build the C/C++ module. |
| 38 | // This is most useful in the arch/multilib variants to remove non-common files |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 39 | Exclude_srcs []string `android:"path,arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 40 | |
| 41 | // list of module-specific flags that will be used for C and C++ compiles. |
| 42 | Cflags []string `android:"arch_variant"` |
| 43 | |
| 44 | // list of module-specific flags that will be used for C++ compiles |
| 45 | Cppflags []string `android:"arch_variant"` |
| 46 | |
| 47 | // list of module-specific flags that will be used for C compiles |
| 48 | Conlyflags []string `android:"arch_variant"` |
| 49 | |
| 50 | // list of module-specific flags that will be used for .S compiles |
| 51 | Asflags []string `android:"arch_variant"` |
| 52 | |
| 53 | // list of module-specific flags that will be used for C and C++ compiles when |
| 54 | // compiling with clang |
| 55 | Clang_cflags []string `android:"arch_variant"` |
| 56 | |
| 57 | // list of module-specific flags that will be used for .S compiles when |
| 58 | // compiling with clang |
| 59 | Clang_asflags []string `android:"arch_variant"` |
| 60 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 61 | // the instruction set architecture to use to compile the C/C++ |
| 62 | // module. |
Dan Willemsen | 5922f3c | 2017-10-25 15:20:50 -0700 | [diff] [blame] | 63 | Instruction_set *string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 64 | |
| 65 | // list of directories relative to the root of the source tree that will |
| 66 | // be added to the include path using -I. |
| 67 | // If possible, don't use this. If adding paths from the current directory use |
| 68 | // local_include_dirs, if adding paths from other modules use export_include_dirs in |
| 69 | // that module. |
Colin Cross | ccf01e7 | 2017-04-26 17:01:07 -0700 | [diff] [blame] | 70 | Include_dirs []string `android:"arch_variant,variant_prepend"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 71 | |
| 72 | // list of directories relative to the Blueprints file that will |
| 73 | // be added to the include path using -I |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 74 | Local_include_dirs []string `android:"arch_variant,variant_prepend"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 75 | |
Dan Albert | 899c23e | 2018-12-06 11:04:03 -0800 | [diff] [blame] | 76 | // Add the directory containing the Android.bp file to the list of include |
| 77 | // directories. Defaults to true. |
| 78 | Include_build_directory *bool |
| 79 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 80 | // list of generated sources to compile. These are the names of gensrcs or |
| 81 | // genrule modules. |
| 82 | Generated_sources []string `android:"arch_variant"` |
| 83 | |
| 84 | // list of generated headers to add to the include path. These are the names |
| 85 | // of genrule modules. |
| 86 | Generated_headers []string `android:"arch_variant"` |
| 87 | |
| 88 | // pass -frtti instead of -fno-rtti |
| 89 | Rtti *bool |
| 90 | |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 91 | // C standard version to use. Can be a specific version (such as "gnu11"), |
| 92 | // "experimental" (which will use draft versions like C1x when available), |
| 93 | // or the empty string (which will use the default). |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 94 | C_std *string |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 95 | |
| 96 | // C++ standard version to use. Can be a specific version (such as |
| 97 | // "gnu++11"), "experimental" (which will use draft versions like C++1z when |
| 98 | // available), or the empty string (which will use the default). |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 99 | Cpp_std *string |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 100 | |
Colin Cross | 948f0cb | 2016-10-17 14:24:56 -0700 | [diff] [blame] | 101 | // if set to false, use -std=c++* instead of -std=gnu++* |
| 102 | Gnu_extensions *bool |
| 103 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 104 | Yacc *YaccProperties |
| 105 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 106 | Aidl struct { |
| 107 | // list of directories that will be added to the aidl include paths. |
| 108 | Include_dirs []string |
| 109 | |
| 110 | // list of directories relative to the Blueprints file that will |
| 111 | // be added to the aidl include paths. |
| 112 | Local_include_dirs []string |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 113 | |
| 114 | // whether to generate traces (for systrace) for this interface |
| 115 | Generate_traces *bool |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 118 | Renderscript struct { |
| 119 | // list of directories that will be added to the llvm-rs-cc include paths |
| 120 | Include_dirs []string |
| 121 | |
| 122 | // list of flags that will be passed to llvm-rs-cc |
| 123 | Flags []string |
| 124 | |
| 125 | // Renderscript API level to target |
| 126 | Target_api *string |
| 127 | } |
| 128 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 129 | Debug, Release struct { |
| 130 | // list of module-specific flags that will be used for C and C++ compiles in debug or |
| 131 | // release builds |
| 132 | Cflags []string `android:"arch_variant"` |
| 133 | } `android:"arch_variant"` |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 134 | |
| 135 | Target struct { |
| 136 | Vendor struct { |
| 137 | // list of source files that should only be used in the |
| 138 | // vendor variant of the C/C++ module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 139 | Srcs []string `android:"path"` |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 140 | |
| 141 | // list of source files that should not be used to |
| 142 | // build the vendor variant of the C/C++ module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 143 | Exclude_srcs []string `android:"path"` |
Jiyong Park | a622de8 | 2017-08-10 13:33:27 +0900 | [diff] [blame] | 144 | |
| 145 | // List of additional cflags that should be used to build the vendor |
| 146 | // variant of the C/C++ module. |
| 147 | Cflags []string |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 148 | } |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 149 | Recovery struct { |
| 150 | // list of source files that should only be used in the |
| 151 | // recovery variant of the C/C++ module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 152 | Srcs []string `android:"path"` |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 153 | |
| 154 | // list of source files that should not be used to |
| 155 | // build the recovery variant of the C/C++ module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 156 | Exclude_srcs []string `android:"path"` |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 157 | |
| 158 | // List of additional cflags that should be used to build the recovery |
| 159 | // variant of the C/C++ module. |
| 160 | Cflags []string |
| 161 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 162 | } |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 163 | |
Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 164 | Proto struct { |
| 165 | // Link statically against the protobuf runtime |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 166 | Static *bool `android:"arch_variant"` |
Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 167 | } `android:"arch_variant"` |
| 168 | |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 169 | // Stores the original list of source files before being cleared by library reuse |
| 170 | OriginalSrcs []string `blueprint:"mutated"` |
Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 171 | |
| 172 | // Build and link with OpenMP |
| 173 | Openmp *bool `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 176 | func NewBaseCompiler() *baseCompiler { |
| 177 | return &baseCompiler{} |
| 178 | } |
| 179 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 180 | type baseCompiler struct { |
| 181 | Properties BaseCompilerProperties |
Colin Cross | 38f794e | 2017-09-07 10:53:07 -0700 | [diff] [blame] | 182 | Proto android.ProtoProperties |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 183 | cFlagsDeps android.Paths |
Pirama Arumuga Nainar | 70ba5a3 | 2017-12-19 15:11:01 -0800 | [diff] [blame] | 184 | pathDeps android.Paths |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 185 | flags builderFlags |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 186 | |
| 187 | // Sources that were passed to the C/C++ compiler |
| 188 | srcs android.Paths |
| 189 | |
| 190 | // Sources that were passed in the Android.bp file, including generated sources generated by |
| 191 | // other modules and filegroups. May include source files that have not yet been translated to |
| 192 | // C/C++ (.aidl, .proto, etc.) |
| 193 | srcsBeforeGen android.Paths |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | var _ compiler = (*baseCompiler)(nil) |
| 197 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 198 | type CompiledInterface interface { |
| 199 | Srcs() android.Paths |
| 200 | } |
| 201 | |
| 202 | func (compiler *baseCompiler) Srcs() android.Paths { |
Nan Zhang | e42777a | 2018-03-27 16:19:42 -0700 | [diff] [blame] | 203 | return append(android.Paths{}, compiler.srcs...) |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 206 | func (compiler *baseCompiler) appendCflags(flags []string) { |
| 207 | compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...) |
| 208 | } |
| 209 | |
| 210 | func (compiler *baseCompiler) appendAsflags(flags []string) { |
| 211 | compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...) |
| 212 | } |
| 213 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 214 | func (compiler *baseCompiler) compilerProps() []interface{} { |
Colin Cross | 0feb169 | 2016-11-03 14:38:52 -0700 | [diff] [blame] | 215 | return []interface{}{&compiler.Properties, &compiler.Proto} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 218 | func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 219 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 220 | func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 221 | deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...) |
| 222 | deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...) |
| 223 | |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 224 | android.ProtoDeps(ctx, &compiler.Proto) |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 225 | if compiler.hasSrcExt(".proto") { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 226 | deps = protoDeps(ctx, deps, &compiler.Proto, Bool(compiler.Properties.Proto.Static)) |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 229 | if Bool(compiler.Properties.Openmp) { |
| 230 | deps.StaticLibs = append(deps.StaticLibs, "libomp") |
| 231 | } |
| 232 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 233 | return deps |
| 234 | } |
| 235 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 236 | // Return true if the module is in the WarningAllowedProjects. |
| 237 | func warningsAreAllowed(subdir string) bool { |
| 238 | subdir += "/" |
| 239 | for _, prefix := range config.WarningAllowedProjects { |
| 240 | if strings.HasPrefix(subdir, prefix) { |
| 241 | return true |
| 242 | } |
| 243 | } |
| 244 | return false |
| 245 | } |
| 246 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 247 | func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) { |
| 248 | getNamedMapForConfig(ctx.Config(), key).Store(module, true) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 251 | // Create a Flags struct that collects the compile flags from global values, |
| 252 | // per-target values, module type values, and per-module Blueprints properties |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 253 | func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 254 | tc := ctx.toolchain() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 255 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 256 | compiler.srcsBeforeGen = android.PathsForModuleSrcExcludes(ctx, compiler.Properties.Srcs, compiler.Properties.Exclude_srcs) |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 257 | compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...) |
| 258 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 259 | CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags) |
| 260 | CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags) |
| 261 | CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags) |
| 262 | CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags) |
Jiyong Park | 4a2dcb5 | 2018-05-24 16:44:14 +0900 | [diff] [blame] | 263 | CheckBadCompilerFlags(ctx, "vendor.cflags", compiler.Properties.Target.Vendor.Cflags) |
| 264 | CheckBadCompilerFlags(ctx, "recovery.cflags", compiler.Properties.Target.Recovery.Cflags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 265 | |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 266 | esc := proptools.NinjaAndShellEscapeList |
Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 267 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 268 | flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Cflags)...) |
| 269 | flags.Local.CppFlags = append(flags.Local.CppFlags, esc(compiler.Properties.Cppflags)...) |
| 270 | flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, esc(compiler.Properties.Conlyflags)...) |
| 271 | flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Asflags)...) |
| 272 | flags.Local.YasmFlags = append(flags.Local.YasmFlags, esc(compiler.Properties.Asflags)...) |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 273 | |
| 274 | flags.Yacc = compiler.Properties.Yacc |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 275 | |
| 276 | // Include dir cflags |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 277 | localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 278 | if len(localIncludeDirs) > 0 { |
Colin Cross | dad8c95 | 2017-04-26 14:55:27 -0700 | [diff] [blame] | 279 | f := includeDirsToFlags(localIncludeDirs) |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 280 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, f) |
| 281 | flags.Local.YasmFlags = append(flags.Local.YasmFlags, f) |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 282 | } |
| 283 | rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) |
| 284 | if len(rootIncludeDirs) > 0 { |
Colin Cross | dad8c95 | 2017-04-26 14:55:27 -0700 | [diff] [blame] | 285 | f := includeDirsToFlags(rootIncludeDirs) |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 286 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, f) |
| 287 | flags.Local.YasmFlags = append(flags.Local.YasmFlags, f) |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 288 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 289 | |
Dan Albert | 899c23e | 2018-12-06 11:04:03 -0800 | [diff] [blame] | 290 | if compiler.Properties.Include_build_directory == nil || |
| 291 | *compiler.Properties.Include_build_directory { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 292 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 293 | flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) |
Dan Albert | 899c23e | 2018-12-06 11:04:03 -0800 | [diff] [blame] | 294 | } |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 295 | |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 296 | if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { |
| 297 | flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, |
| 298 | "${config.CommonGlobalIncludes}", |
| 299 | tc.IncludeFlags(), |
| 300 | "${config.CommonNativehelperInclude}") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 303 | if ctx.useSdk() { |
Dan Albert | fac114b | 2018-11-14 21:22:00 -0800 | [diff] [blame] | 304 | // TODO: Switch to --sysroot. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 305 | // The NDK headers are installed to a common sysroot. While a more |
| 306 | // typical Soong approach would be to only make the headers for the |
| 307 | // library you're using available, we're trying to emulate the NDK |
| 308 | // behavior here, and the NDK always has all the NDK headers available. |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 309 | flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 310 | "-isystem "+getCurrentIncludePath(ctx).String(), |
Chih-Hung Hsieh | 1e7d1bf | 2018-03-15 18:44:57 -0700 | [diff] [blame] | 311 | "-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String()) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 314 | if ctx.useVndk() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 315 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__") |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Jiyong Park | d54aee5 | 2018-06-09 01:32:54 +0900 | [diff] [blame] | 318 | if ctx.inRecovery() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 319 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_RECOVERY__") |
Jiyong Park | d54aee5 | 2018-06-09 01:32:54 +0900 | [diff] [blame] | 320 | } |
| 321 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 322 | if ctx.apexName() != "" { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 323 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, |
| 324 | "-D__ANDROID_APEX__", |
| 325 | "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 326 | } |
| 327 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 328 | instructionSet := String(compiler.Properties.Instruction_set) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 329 | if flags.RequiredInstructionSet != "" { |
| 330 | instructionSet = flags.RequiredInstructionSet |
| 331 | } |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 332 | instructionSetFlags, err := tc.ClangInstructionSetFlags(instructionSet) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 333 | if err != nil { |
| 334 | ctx.ModuleErrorf("%s", err) |
| 335 | } |
| 336 | |
| 337 | CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) |
| 338 | |
| 339 | // TODO: debug |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 340 | flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 341 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 342 | CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) |
| 343 | CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 344 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 345 | flags.Local.CFlags = config.ClangFilterUnknownCflags(flags.Local.CFlags) |
| 346 | flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Clang_cflags)...) |
| 347 | flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Clang_asflags)...) |
| 348 | flags.Local.CppFlags = config.ClangFilterUnknownCflags(flags.Local.CppFlags) |
| 349 | flags.Local.ConlyFlags = config.ClangFilterUnknownCflags(flags.Local.ConlyFlags) |
| 350 | flags.Local.LdFlags = config.ClangFilterUnknownCflags(flags.Local.LdFlags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 351 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 352 | target := "-target " + tc.ClangTriple() |
Peter Collingbourne | b0e6143 | 2019-07-22 16:36:06 -0700 | [diff] [blame] | 353 | if ctx.Os().Class == android.Device { |
| 354 | version := ctx.sdkVersion() |
| 355 | if version == "" || version == "current" { |
| 356 | target += strconv.Itoa(android.FutureApiLevel) |
| 357 | } else { |
| 358 | target += version |
| 359 | } |
| 360 | } |
| 361 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 362 | gccPrefix := "-B" + config.ToolPath(tc) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 363 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 364 | flags.Global.CFlags = append(flags.Global.CFlags, target, gccPrefix) |
| 365 | flags.Global.AsFlags = append(flags.Global.AsFlags, target, gccPrefix) |
| 366 | flags.Global.LdFlags = append(flags.Global.LdFlags, target, gccPrefix) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 367 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 368 | hod := "Host" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 369 | if ctx.Os().Class == android.Device { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 370 | hod = "Device" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 373 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, instructionSetFlags) |
| 374 | flags.Global.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.Global.ConlyFlags...) |
| 375 | flags.Global.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.Global.CppFlags...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 376 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 377 | flags.Global.AsFlags = append(flags.Global.AsFlags, tc.ClangAsflags()) |
| 378 | flags.Global.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.Global.CppFlags...) |
| 379 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 380 | tc.ClangCflags(), |
| 381 | "${config.CommonClangGlobalCflags}", |
| 382 | fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 383 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 384 | if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 385 | flags.Global.CommonFlags = append([]string{"${config.ClangExternalCflags}"}, flags.Global.CommonFlags...) |
Yi Kong | cc80f8d | 2018-06-06 14:42:44 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Dan Willemsen | 10db384 | 2018-10-21 18:42:46 -0700 | [diff] [blame] | 388 | if tc.Bionic() { |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 389 | if Bool(compiler.Properties.Rtti) { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 390 | flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti") |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 391 | } else { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 392 | flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti") |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 396 | flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__") |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 397 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 398 | flags.Global.CppFlags = append(flags.Global.CppFlags, tc.ClangCppflags()) |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 399 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 400 | flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags()) |
Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 401 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 402 | flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainClangCflags()) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 403 | |
Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 404 | cStd := config.CStdVersion |
| 405 | if String(compiler.Properties.C_std) == "experimental" { |
| 406 | cStd = config.ExperimentalCStdVersion |
| 407 | } else if String(compiler.Properties.C_std) != "" { |
| 408 | cStd = String(compiler.Properties.C_std) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 411 | cppStd := String(compiler.Properties.Cpp_std) |
| 412 | switch String(compiler.Properties.Cpp_std) { |
| 413 | case "": |
| 414 | cppStd = config.CppStdVersion |
| 415 | case "experimental": |
| 416 | cppStd = config.ExperimentalCppStdVersion |
Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 419 | if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false { |
| 420 | cStd = gnuToCReplacer.Replace(cStd) |
| 421 | cppStd = gnuToCReplacer.Replace(cppStd) |
| 422 | } |
| 423 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 424 | flags.Local.ConlyFlags = append([]string{"-std=" + cStd}, flags.Local.ConlyFlags...) |
| 425 | flags.Local.CppFlags = append([]string{"-std=" + cppStd}, flags.Local.CppFlags...) |
Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 426 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 427 | if ctx.useVndk() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 428 | flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) |
Jiyong Park | a622de8 | 2017-08-10 13:33:27 +0900 | [diff] [blame] | 429 | } |
| 430 | |
Jiyong Park | 4a2dcb5 | 2018-05-24 16:44:14 +0900 | [diff] [blame] | 431 | if ctx.inRecovery() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 432 | flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...) |
Jiyong Park | 4a2dcb5 | 2018-05-24 16:44:14 +0900 | [diff] [blame] | 433 | } |
| 434 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 435 | // We can enforce some rules more strictly in the code we own. strict |
| 436 | // indicates if this is code that we can be stricter with. If we have |
| 437 | // rules that we want to apply to *our* code (but maybe can't for |
| 438 | // vendor/device specific things), we could extend this to be a ternary |
| 439 | // value. |
| 440 | strict := true |
| 441 | if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { |
| 442 | strict = false |
| 443 | } |
| 444 | |
| 445 | // Can be used to make some annotations stricter for code we can fix |
| 446 | // (such as when we mark functions as deprecated). |
| 447 | if strict { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 448 | flags.Global.CFlags = append(flags.Global.CFlags, "-DANDROID_STRICT") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 451 | if compiler.hasSrcExt(".proto") { |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 452 | flags = protoFlags(ctx, flags, &compiler.Proto) |
| 453 | } |
| 454 | |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 455 | if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 456 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 457 | "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) |
| 458 | } |
| 459 | |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 460 | if compiler.hasSrcExt(".mc") { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 461 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, |
Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 462 | "-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String()) |
| 463 | } |
| 464 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 465 | if compiler.hasSrcExt(".aidl") { |
| 466 | if len(compiler.Properties.Aidl.Local_include_dirs) > 0 { |
| 467 | localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs) |
| 468 | flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(localAidlIncludeDirs)) |
| 469 | } |
| 470 | if len(compiler.Properties.Aidl.Include_dirs) > 0 { |
| 471 | rootAidlIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Aidl.Include_dirs) |
| 472 | flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs)) |
| 473 | } |
| 474 | |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 475 | if Bool(compiler.Properties.Aidl.Generate_traces) { |
| 476 | flags.aidlFlags = append(flags.aidlFlags, "-t") |
| 477 | } |
| 478 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 479 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 480 | "-I"+android.PathForModuleGen(ctx, "aidl").String()) |
| 481 | } |
| 482 | |
Jeff Vander Stoep | d612627 | 2019-07-15 19:08:37 -0700 | [diff] [blame] | 483 | if compiler.hasSrcExt(".rscript") || compiler.hasSrcExt(".fs") { |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 484 | flags = rsFlags(ctx, flags, &compiler.Properties) |
| 485 | } |
| 486 | |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 487 | if compiler.hasSrcExt(".sysprop") { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 488 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 489 | "-I"+android.PathForModuleGen(ctx, "sysprop", "include").String()) |
| 490 | } |
| 491 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 492 | if len(compiler.Properties.Srcs) > 0 { |
| 493 | module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName() |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 494 | if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 495 | addToModuleList(ctx, modulesUsingWnoErrorKey, module) |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 496 | } else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) { |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 497 | if warningsAreAllowed(ctx.ModuleDir()) { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 498 | addToModuleList(ctx, modulesAddedWallKey, module) |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 499 | flags.Local.CFlags = append([]string{"-Wall"}, flags.Local.CFlags...) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 500 | } else { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 501 | flags.Local.CFlags = append([]string{"-Wall", "-Werror"}, flags.Local.CFlags...) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 506 | if Bool(compiler.Properties.Openmp) { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 507 | flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp") |
Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 510 | return flags |
| 511 | } |
| 512 | |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 513 | func (compiler *baseCompiler) hasSrcExt(ext string) bool { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 514 | for _, src := range compiler.srcsBeforeGen { |
| 515 | if src.Ext() == ext { |
| 516 | return true |
| 517 | } |
| 518 | } |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 519 | for _, src := range compiler.Properties.Srcs { |
Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 520 | if filepath.Ext(src) == ext { |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 521 | return true |
| 522 | } |
| 523 | } |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 524 | for _, src := range compiler.Properties.OriginalSrcs { |
| 525 | if filepath.Ext(src) == ext { |
| 526 | return true |
| 527 | } |
| 528 | } |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 529 | |
| 530 | return false |
| 531 | } |
| 532 | |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 533 | // makeDefineString transforms a name of an APEX module into a value to be used as value for C define |
| 534 | // For example, com.android.foo => COM_ANDROID_FOO |
| 535 | func makeDefineString(name string) string { |
| 536 | return strings.ReplaceAll(strings.ToUpper(name), ".", "_") |
| 537 | } |
| 538 | |
Colin Cross | 948f0cb | 2016-10-17 14:24:56 -0700 | [diff] [blame] | 539 | var gnuToCReplacer = strings.NewReplacer("gnu", "c") |
| 540 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 541 | func ndkPathDeps(ctx ModuleContext) android.Paths { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 542 | if ctx.useSdk() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 543 | // The NDK sysroot timestamp file depends on all the NDK sysroot files |
| 544 | // (headers and libraries). |
Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame] | 545 | return android.Paths{getNdkBaseTimestampFile(ctx)} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 546 | } |
| 547 | return nil |
| 548 | } |
| 549 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 550 | func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 551 | pathDeps := deps.GeneratedHeaders |
| 552 | pathDeps = append(pathDeps, ndkPathDeps(ctx)...) |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 553 | |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 554 | buildFlags := flagsToBuilderFlags(flags) |
| 555 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 556 | srcs := append(android.Paths(nil), compiler.srcsBeforeGen...) |
| 557 | |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 558 | srcs, genDeps := genSources(ctx, srcs, buildFlags) |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 559 | pathDeps = append(pathDeps, genDeps...) |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 560 | |
Pirama Arumuga Nainar | 70ba5a3 | 2017-12-19 15:11:01 -0800 | [diff] [blame] | 561 | compiler.pathDeps = pathDeps |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 562 | compiler.cFlagsDeps = flags.CFlagsDeps |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 563 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 564 | // Save src, buildFlags and context |
| 565 | compiler.srcs = srcs |
| 566 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 567 | // Compile files listed in c.Properties.Srcs into objects |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 568 | objs := compileObjs(ctx, buildFlags, "", srcs, pathDeps, compiler.cFlagsDeps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 569 | |
| 570 | if ctx.Failed() { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 571 | return Objects{} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 574 | return objs |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | // Compile a list of source files into objects a specified subdirectory |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 578 | func compileObjs(ctx android.ModuleContext, flags builderFlags, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 579 | subdir string, srcFiles, pathDeps android.Paths, cFlagsDeps android.Paths) Objects { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 580 | |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 581 | return TransformSourceToObj(ctx, subdir, srcFiles, flags, pathDeps, cFlagsDeps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 582 | } |