| 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" | 
 | 20 | 	"strings" | 
 | 21 |  | 
| Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 22 | 	"github.com/google/blueprint/proptools" | 
 | 23 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | 	"android/soong/android" | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 25 | 	"android/soong/cc/config" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 26 | ) | 
 | 27 |  | 
 | 28 | // This file contains the basic C/C++/assembly to .o compliation steps | 
 | 29 |  | 
 | 30 | type BaseCompilerProperties struct { | 
 | 31 | 	// 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] | 32 | 	// srcs may reference the outputs of other modules that produce source files like genrule | 
 | 33 | 	// or filegroup using the syntax ":module". | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 34 | 	Srcs []string `android:"arch_variant"` | 
 | 35 |  | 
 | 36 | 	// list of source files that should not be used to build the C/C++ module. | 
 | 37 | 	// This is most useful in the arch/multilib variants to remove non-common files | 
 | 38 | 	Exclude_srcs []string `android:"arch_variant"` | 
 | 39 |  | 
 | 40 | 	// list of module-specific flags that will be used for C and C++ compiles. | 
 | 41 | 	Cflags []string `android:"arch_variant"` | 
 | 42 |  | 
 | 43 | 	// list of module-specific flags that will be used for C++ compiles | 
 | 44 | 	Cppflags []string `android:"arch_variant"` | 
 | 45 |  | 
 | 46 | 	// list of module-specific flags that will be used for C compiles | 
 | 47 | 	Conlyflags []string `android:"arch_variant"` | 
 | 48 |  | 
 | 49 | 	// list of module-specific flags that will be used for .S compiles | 
 | 50 | 	Asflags []string `android:"arch_variant"` | 
 | 51 |  | 
 | 52 | 	// list of module-specific flags that will be used for C and C++ compiles when | 
 | 53 | 	// compiling with clang | 
 | 54 | 	Clang_cflags []string `android:"arch_variant"` | 
 | 55 |  | 
 | 56 | 	// list of module-specific flags that will be used for .S compiles when | 
 | 57 | 	// compiling with clang | 
 | 58 | 	Clang_asflags []string `android:"arch_variant"` | 
 | 59 |  | 
 | 60 | 	// list of module-specific flags that will be used for .y and .yy compiles | 
 | 61 | 	Yaccflags []string | 
 | 62 |  | 
 | 63 | 	// the instruction set architecture to use to compile the C/C++ | 
 | 64 | 	// module. | 
| Dan Willemsen | 5922f3c | 2017-10-25 15:20:50 -0700 | [diff] [blame] | 65 | 	Instruction_set *string `android:"arch_variant"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 66 |  | 
 | 67 | 	// list of directories relative to the root of the source tree that will | 
 | 68 | 	// be added to the include path using -I. | 
 | 69 | 	// If possible, don't use this.  If adding paths from the current directory use | 
 | 70 | 	// local_include_dirs, if adding paths from other modules use export_include_dirs in | 
 | 71 | 	// that module. | 
| Colin Cross | ccf01e7 | 2017-04-26 17:01:07 -0700 | [diff] [blame] | 72 | 	Include_dirs []string `android:"arch_variant,variant_prepend"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 73 |  | 
 | 74 | 	// list of directories relative to the Blueprints file that will | 
 | 75 | 	// be added to the include path using -I | 
| Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 76 | 	Local_include_dirs []string `android:"arch_variant,variant_prepend"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 77 |  | 
| Dan Albert | 899c23e | 2018-12-06 11:04:03 -0800 | [diff] [blame] | 78 | 	// Add the directory containing the Android.bp file to the list of include | 
 | 79 | 	// directories. Defaults to true. | 
 | 80 | 	Include_build_directory *bool | 
 | 81 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 82 | 	// list of generated sources to compile. These are the names of gensrcs or | 
 | 83 | 	// genrule modules. | 
 | 84 | 	Generated_sources []string `android:"arch_variant"` | 
 | 85 |  | 
 | 86 | 	// list of generated headers to add to the include path. These are the names | 
 | 87 | 	// of genrule modules. | 
 | 88 | 	Generated_headers []string `android:"arch_variant"` | 
 | 89 |  | 
 | 90 | 	// pass -frtti instead of -fno-rtti | 
 | 91 | 	Rtti *bool | 
 | 92 |  | 
| Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 93 | 	// C standard version to use. Can be a specific version (such as "gnu11"), | 
 | 94 | 	// "experimental" (which will use draft versions like C1x when available), | 
 | 95 | 	// or the empty string (which will use the default). | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 96 | 	C_std *string | 
| Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 97 |  | 
 | 98 | 	// C++ standard version to use. Can be a specific version (such as | 
 | 99 | 	// "gnu++11"), "experimental" (which will use draft versions like C++1z when | 
 | 100 | 	// available), or the empty string (which will use the default). | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 101 | 	Cpp_std *string | 
| Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 102 |  | 
| Colin Cross | 948f0cb | 2016-10-17 14:24:56 -0700 | [diff] [blame] | 103 | 	// if set to false, use -std=c++* instead of -std=gnu++* | 
 | 104 | 	Gnu_extensions *bool | 
 | 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. | 
 | 139 | 			Srcs []string | 
 | 140 |  | 
 | 141 | 			// list of source files that should not be used to | 
 | 142 | 			// build the vendor variant of the C/C++ module. | 
 | 143 | 			Exclude_srcs []string | 
| 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. | 
 | 152 | 			Srcs []string | 
 | 153 |  | 
 | 154 | 			// list of source files that should not be used to | 
 | 155 | 			// build the recovery variant of the C/C++ module. | 
 | 156 | 			Exclude_srcs []string | 
 | 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 | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 224 | 	android.ExtractSourcesDeps(ctx, compiler.Properties.Srcs) | 
| Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 225 | 	android.ExtractSourcesDeps(ctx, compiler.Properties.Exclude_srcs) | 
| Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 226 |  | 
| Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 227 | 	if compiler.hasSrcExt(".proto") { | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 228 | 		deps = protoDeps(ctx, deps, &compiler.Proto, Bool(compiler.Properties.Proto.Static)) | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 229 | 	} | 
 | 230 |  | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 231 | 	if compiler.hasSrcExt(".sysprop") { | 
 | 232 | 		deps.SharedLibs = append(deps.SharedLibs, "libbase") | 
 | 233 | 	} | 
 | 234 |  | 
| Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 235 | 	if Bool(compiler.Properties.Openmp) { | 
 | 236 | 		deps.StaticLibs = append(deps.StaticLibs, "libomp") | 
 | 237 | 	} | 
 | 238 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 239 | 	return deps | 
 | 240 | } | 
 | 241 |  | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 242 | // Return true if the module is in the WarningAllowedProjects. | 
 | 243 | func warningsAreAllowed(subdir string) bool { | 
 | 244 | 	subdir += "/" | 
 | 245 | 	for _, prefix := range config.WarningAllowedProjects { | 
 | 246 | 		if strings.HasPrefix(subdir, prefix) { | 
 | 247 | 			return true | 
 | 248 | 		} | 
 | 249 | 	} | 
 | 250 | 	return false | 
 | 251 | } | 
 | 252 |  | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 253 | func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) { | 
 | 254 | 	getNamedMapForConfig(ctx.Config(), key).Store(module, true) | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 255 | } | 
 | 256 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 257 | // Create a Flags struct that collects the compile flags from global values, | 
 | 258 | // per-target values, module type values, and per-module Blueprints properties | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 259 | func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 260 | 	tc := ctx.toolchain() | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 261 |  | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 262 | 	compiler.srcsBeforeGen = ctx.ExpandSources(compiler.Properties.Srcs, compiler.Properties.Exclude_srcs) | 
 | 263 | 	compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...) | 
 | 264 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 265 | 	CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags) | 
 | 266 | 	CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags) | 
 | 267 | 	CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags) | 
 | 268 | 	CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags) | 
| Jiyong Park | 4a2dcb5 | 2018-05-24 16:44:14 +0900 | [diff] [blame] | 269 | 	CheckBadCompilerFlags(ctx, "vendor.cflags", compiler.Properties.Target.Vendor.Cflags) | 
 | 270 | 	CheckBadCompilerFlags(ctx, "recovery.cflags", compiler.Properties.Target.Recovery.Cflags) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 271 |  | 
| Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 272 | 	esc := proptools.NinjaAndShellEscape | 
 | 273 |  | 
 | 274 | 	flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Cflags)...) | 
 | 275 | 	flags.CppFlags = append(flags.CppFlags, esc(compiler.Properties.Cppflags)...) | 
 | 276 | 	flags.ConlyFlags = append(flags.ConlyFlags, esc(compiler.Properties.Conlyflags)...) | 
 | 277 | 	flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Asflags)...) | 
| Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 278 | 	flags.YasmFlags = append(flags.YasmFlags, esc(compiler.Properties.Asflags)...) | 
| Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 279 | 	flags.YaccFlags = append(flags.YaccFlags, esc(compiler.Properties.Yaccflags)...) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 280 |  | 
 | 281 | 	// Include dir cflags | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 282 | 	localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) | 
| Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 283 | 	if len(localIncludeDirs) > 0 { | 
| Colin Cross | dad8c95 | 2017-04-26 14:55:27 -0700 | [diff] [blame] | 284 | 		f := includeDirsToFlags(localIncludeDirs) | 
 | 285 | 		flags.GlobalFlags = append(flags.GlobalFlags, f) | 
 | 286 | 		flags.YasmFlags = append(flags.YasmFlags, f) | 
| Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 287 | 	} | 
 | 288 | 	rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) | 
 | 289 | 	if len(rootIncludeDirs) > 0 { | 
| Colin Cross | dad8c95 | 2017-04-26 14:55:27 -0700 | [diff] [blame] | 290 | 		f := includeDirsToFlags(rootIncludeDirs) | 
 | 291 | 		flags.GlobalFlags = append(flags.GlobalFlags, f) | 
 | 292 | 		flags.YasmFlags = append(flags.YasmFlags, f) | 
| Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 293 | 	} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 294 |  | 
| Dan Albert | 899c23e | 2018-12-06 11:04:03 -0800 | [diff] [blame] | 295 | 	if compiler.Properties.Include_build_directory == nil || | 
 | 296 | 		*compiler.Properties.Include_build_directory { | 
 | 297 | 		flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) | 
 | 298 | 		flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) | 
 | 299 | 	} | 
| Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 300 |  | 
| Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 301 | 	if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { | 
 | 302 | 		flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, | 
 | 303 | 			"${config.CommonGlobalIncludes}", | 
 | 304 | 			tc.IncludeFlags(), | 
 | 305 | 			"${config.CommonNativehelperInclude}") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 306 | 	} | 
 | 307 |  | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 308 | 	if ctx.useSdk() { | 
| Dan Albert | fac114b | 2018-11-14 21:22:00 -0800 | [diff] [blame] | 309 | 		// TODO: Switch to --sysroot. | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 310 | 		// The NDK headers are installed to a common sysroot. While a more | 
 | 311 | 		// typical Soong approach would be to only make the headers for the | 
 | 312 | 		// library you're using available, we're trying to emulate the NDK | 
 | 313 | 		// behavior here, and the NDK always has all the NDK headers available. | 
| Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 314 | 		flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 315 | 			"-isystem "+getCurrentIncludePath(ctx).String(), | 
| Chih-Hung Hsieh | 1e7d1bf | 2018-03-15 18:44:57 -0700 | [diff] [blame] | 316 | 			"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String()) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 317 |  | 
| Dan Albert | fac114b | 2018-11-14 21:22:00 -0800 | [diff] [blame] | 318 | 		// TODO: Migrate to API suffixed triple? | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 319 | 		// Traditionally this has come from android/api-level.h, but with the | 
 | 320 | 		// libc headers unified it must be set by the build system since we | 
 | 321 | 		// don't have per-API level copies of that header now. | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 322 | 		version := ctx.sdkVersion() | 
 | 323 | 		if version == "current" { | 
 | 324 | 			version = "__ANDROID_API_FUTURE__" | 
 | 325 | 		} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 326 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 327 | 			"-D__ANDROID_API__="+version) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 328 | 	} | 
 | 329 |  | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 330 | 	if ctx.useVndk() { | 
| Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 331 | 		// sdkVersion() returns VNDK version for vendor modules. | 
 | 332 | 		version := ctx.sdkVersion() | 
 | 333 | 		if version == "current" { | 
 | 334 | 			version = "__ANDROID_API_FUTURE__" | 
 | 335 | 		} | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 336 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
| Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 337 | 			"-D__ANDROID_API__="+version, "-D__ANDROID_VNDK__") | 
| Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 338 | 	} | 
 | 339 |  | 
| Jiyong Park | d54aee5 | 2018-06-09 01:32:54 +0900 | [diff] [blame] | 340 | 	if ctx.inRecovery() { | 
 | 341 | 		flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_RECOVERY__") | 
 | 342 | 	} | 
 | 343 |  | 
| Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 344 | 	if ctx.apexName() != "" { | 
 | 345 | 		flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__="+ctx.apexName()) | 
 | 346 | 	} | 
 | 347 |  | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 348 | 	instructionSet := String(compiler.Properties.Instruction_set) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 349 | 	if flags.RequiredInstructionSet != "" { | 
 | 350 | 		instructionSet = flags.RequiredInstructionSet | 
 | 351 | 	} | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 352 | 	instructionSetFlags, err := tc.ClangInstructionSetFlags(instructionSet) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 353 | 	if err != nil { | 
 | 354 | 		ctx.ModuleErrorf("%s", err) | 
 | 355 | 	} | 
 | 356 |  | 
 | 357 | 	CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) | 
 | 358 |  | 
 | 359 | 	// TODO: debug | 
| Colin Cross | 4b963f8 | 2016-09-29 14:06:02 -0700 | [diff] [blame] | 360 | 	flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Release.Cflags)...) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 361 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 362 | 	CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) | 
 | 363 | 	CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 364 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 365 | 	flags.CFlags = config.ClangFilterUnknownCflags(flags.CFlags) | 
 | 366 | 	flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Clang_cflags)...) | 
 | 367 | 	flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Clang_asflags)...) | 
 | 368 | 	flags.CppFlags = config.ClangFilterUnknownCflags(flags.CppFlags) | 
 | 369 | 	flags.ConlyFlags = config.ClangFilterUnknownCflags(flags.ConlyFlags) | 
 | 370 | 	flags.LdFlags = config.ClangFilterUnknownCflags(flags.LdFlags) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 371 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 372 | 	target := "-target " + tc.ClangTriple() | 
 | 373 | 	gccPrefix := "-B" + config.ToolPath(tc) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 374 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 375 | 	flags.CFlags = append(flags.CFlags, target, gccPrefix) | 
 | 376 | 	flags.AsFlags = append(flags.AsFlags, target, gccPrefix) | 
 | 377 | 	flags.LdFlags = append(flags.LdFlags, target, gccPrefix) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 378 |  | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 379 | 	hod := "Host" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 380 | 	if ctx.Os().Class == android.Device { | 
| Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 381 | 		hod = "Device" | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 382 | 	} | 
 | 383 |  | 
| Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 384 | 	flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) | 
 | 385 | 	flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...) | 
| Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 386 | 	flags.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.CppFlags...) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 387 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 388 | 	flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags()) | 
 | 389 | 	flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...) | 
 | 390 | 	flags.GlobalFlags = append(flags.GlobalFlags, | 
 | 391 | 		tc.ClangCflags(), | 
 | 392 | 		"${config.CommonClangGlobalCflags}", | 
 | 393 | 		fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 394 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 395 | 	if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { | 
 | 396 | 		flags.GlobalFlags = append([]string{"${config.ClangExternalCflags}"}, flags.GlobalFlags...) | 
| Yi Kong | cc80f8d | 2018-06-06 14:42:44 -0700 | [diff] [blame] | 397 | 	} | 
 | 398 |  | 
| Dan Willemsen | 10db384 | 2018-10-21 18:42:46 -0700 | [diff] [blame] | 399 | 	if tc.Bionic() { | 
| Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 400 | 		if Bool(compiler.Properties.Rtti) { | 
 | 401 | 			flags.CppFlags = append(flags.CppFlags, "-frtti") | 
 | 402 | 		} else { | 
 | 403 | 			flags.CppFlags = append(flags.CppFlags, "-fno-rtti") | 
 | 404 | 		} | 
 | 405 | 	} | 
 | 406 |  | 
 | 407 | 	flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") | 
 | 408 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 409 | 	flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags()) | 
| Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 410 |  | 
 | 411 | 	flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) | 
 | 412 |  | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 413 | 	flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags()) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 414 |  | 
| Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 415 | 	cStd := config.CStdVersion | 
 | 416 | 	if String(compiler.Properties.C_std) == "experimental" { | 
 | 417 | 		cStd = config.ExperimentalCStdVersion | 
 | 418 | 	} else if String(compiler.Properties.C_std) != "" { | 
 | 419 | 		cStd = String(compiler.Properties.C_std) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 420 | 	} | 
 | 421 |  | 
| Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 422 | 	cppStd := String(compiler.Properties.Cpp_std) | 
 | 423 | 	switch String(compiler.Properties.Cpp_std) { | 
 | 424 | 	case "": | 
 | 425 | 		cppStd = config.CppStdVersion | 
 | 426 | 	case "experimental": | 
 | 427 | 		cppStd = config.ExperimentalCppStdVersion | 
| Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 428 | 	} | 
 | 429 |  | 
| Elliott Hughes | 5789ca9 | 2018-02-16 17:15:19 -0800 | [diff] [blame] | 430 | 	if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false { | 
 | 431 | 		cStd = gnuToCReplacer.Replace(cStd) | 
 | 432 | 		cppStd = gnuToCReplacer.Replace(cppStd) | 
 | 433 | 	} | 
 | 434 |  | 
 | 435 | 	flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...) | 
 | 436 | 	flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) | 
 | 437 |  | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 438 | 	if ctx.useVndk() { | 
| Jiyong Park | a622de8 | 2017-08-10 13:33:27 +0900 | [diff] [blame] | 439 | 		flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) | 
 | 440 | 	} | 
 | 441 |  | 
| Jiyong Park | 4a2dcb5 | 2018-05-24 16:44:14 +0900 | [diff] [blame] | 442 | 	if ctx.inRecovery() { | 
 | 443 | 		flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...) | 
 | 444 | 	} | 
 | 445 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 446 | 	// We can enforce some rules more strictly in the code we own. strict | 
 | 447 | 	// indicates if this is code that we can be stricter with. If we have | 
 | 448 | 	// rules that we want to apply to *our* code (but maybe can't for | 
 | 449 | 	// vendor/device specific things), we could extend this to be a ternary | 
 | 450 | 	// value. | 
 | 451 | 	strict := true | 
 | 452 | 	if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { | 
 | 453 | 		strict = false | 
 | 454 | 	} | 
 | 455 |  | 
 | 456 | 	// Can be used to make some annotations stricter for code we can fix | 
 | 457 | 	// (such as when we mark functions as deprecated). | 
 | 458 | 	if strict { | 
 | 459 | 		flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT") | 
 | 460 | 	} | 
 | 461 |  | 
| Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 462 | 	if compiler.hasSrcExt(".proto") { | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 463 | 		flags = protoFlags(ctx, flags, &compiler.Proto) | 
 | 464 | 	} | 
 | 465 |  | 
| Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 466 | 	if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") { | 
 | 467 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
 | 468 | 			"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) | 
 | 469 | 	} | 
 | 470 |  | 
| Dan Willemsen | 4f1c3d4 | 2017-09-09 01:15:26 -0700 | [diff] [blame] | 471 | 	if compiler.hasSrcExt(".mc") { | 
 | 472 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
 | 473 | 			"-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String()) | 
 | 474 | 	} | 
 | 475 |  | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 476 | 	if compiler.hasSrcExt(".aidl") { | 
 | 477 | 		if len(compiler.Properties.Aidl.Local_include_dirs) > 0 { | 
 | 478 | 			localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs) | 
 | 479 | 			flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(localAidlIncludeDirs)) | 
 | 480 | 		} | 
 | 481 | 		if len(compiler.Properties.Aidl.Include_dirs) > 0 { | 
 | 482 | 			rootAidlIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Aidl.Include_dirs) | 
 | 483 | 			flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs)) | 
 | 484 | 		} | 
 | 485 |  | 
| Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 486 | 		if Bool(compiler.Properties.Aidl.Generate_traces) { | 
 | 487 | 			flags.aidlFlags = append(flags.aidlFlags, "-t") | 
 | 488 | 		} | 
 | 489 |  | 
| Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 490 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
 | 491 | 			"-I"+android.PathForModuleGen(ctx, "aidl").String()) | 
 | 492 | 	} | 
 | 493 |  | 
| Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 494 | 	if compiler.hasSrcExt(".rs") || compiler.hasSrcExt(".fs") { | 
 | 495 | 		flags = rsFlags(ctx, flags, &compiler.Properties) | 
 | 496 | 	} | 
 | 497 |  | 
| Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 498 | 	if compiler.hasSrcExt(".sysprop") { | 
 | 499 | 		flags.GlobalFlags = append(flags.GlobalFlags, | 
 | 500 | 			"-I"+android.PathForModuleGen(ctx, "sysprop", "include").String()) | 
 | 501 | 	} | 
 | 502 |  | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 503 | 	if len(compiler.Properties.Srcs) > 0 { | 
 | 504 | 		module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName() | 
 | 505 | 		if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) { | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 506 | 			addToModuleList(ctx, modulesUsingWnoErrorKey, module) | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 507 | 		} else if !inList("-Werror", flags.CFlags) && !inList("-Werror", flags.CppFlags) { | 
 | 508 | 			if warningsAreAllowed(ctx.ModuleDir()) { | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 509 | 				addToModuleList(ctx, modulesAddedWallKey, module) | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 510 | 				flags.CFlags = append([]string{"-Wall"}, flags.CFlags...) | 
 | 511 | 			} else { | 
| Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 512 | 				flags.CFlags = append([]string{"-Wall", "-Werror"}, flags.CFlags...) | 
 | 513 | 			} | 
 | 514 | 		} | 
 | 515 | 	} | 
 | 516 |  | 
| Pirama Arumuga Nainar | fadb7b5 | 2017-12-19 23:08:09 -0800 | [diff] [blame] | 517 | 	if Bool(compiler.Properties.Openmp) { | 
 | 518 | 		flags.CFlags = append(flags.CFlags, "-fopenmp") | 
 | 519 | 	} | 
 | 520 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 521 | 	return flags | 
 | 522 | } | 
 | 523 |  | 
| Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 524 | func (compiler *baseCompiler) hasSrcExt(ext string) bool { | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 525 | 	for _, src := range compiler.srcsBeforeGen { | 
 | 526 | 		if src.Ext() == ext { | 
 | 527 | 			return true | 
 | 528 | 		} | 
 | 529 | 	} | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 530 | 	for _, src := range compiler.Properties.Srcs { | 
| Dan Willemsen | e1a3ce3 | 2016-11-02 20:44:08 -0700 | [diff] [blame] | 531 | 		if filepath.Ext(src) == ext { | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 532 | 			return true | 
 | 533 | 		} | 
 | 534 | 	} | 
| Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 535 | 	for _, src := range compiler.Properties.OriginalSrcs { | 
 | 536 | 		if filepath.Ext(src) == ext { | 
 | 537 | 			return true | 
 | 538 | 		} | 
 | 539 | 	} | 
| Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 540 |  | 
 | 541 | 	return false | 
 | 542 | } | 
 | 543 |  | 
| Colin Cross | 948f0cb | 2016-10-17 14:24:56 -0700 | [diff] [blame] | 544 | var gnuToCReplacer = strings.NewReplacer("gnu", "c") | 
 | 545 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 546 | func ndkPathDeps(ctx ModuleContext) android.Paths { | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 547 | 	if ctx.useSdk() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 548 | 		// The NDK sysroot timestamp file depends on all the NDK sysroot files | 
 | 549 | 		// (headers and libraries). | 
| Dan Albert | 6ab43d8 | 2017-12-13 15:05:04 -0800 | [diff] [blame] | 550 | 		return android.Paths{getNdkBaseTimestampFile(ctx)} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 551 | 	} | 
 | 552 | 	return nil | 
 | 553 | } | 
 | 554 |  | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 555 | func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 556 | 	pathDeps := deps.GeneratedHeaders | 
 | 557 | 	pathDeps = append(pathDeps, ndkPathDeps(ctx)...) | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 558 |  | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 559 | 	buildFlags := flagsToBuilderFlags(flags) | 
 | 560 |  | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 561 | 	srcs := append(android.Paths(nil), compiler.srcsBeforeGen...) | 
 | 562 |  | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 563 | 	srcs, genDeps := genSources(ctx, srcs, buildFlags) | 
| Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 564 | 	pathDeps = append(pathDeps, genDeps...) | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 565 |  | 
| Pirama Arumuga Nainar | 70ba5a3 | 2017-12-19 15:11:01 -0800 | [diff] [blame] | 566 | 	compiler.pathDeps = pathDeps | 
| Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 567 | 	compiler.cFlagsDeps = flags.CFlagsDeps | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 568 |  | 
| Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 569 | 	// Save src, buildFlags and context | 
 | 570 | 	compiler.srcs = srcs | 
 | 571 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 572 | 	// Compile files listed in c.Properties.Srcs into objects | 
| Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 573 | 	objs := compileObjs(ctx, buildFlags, "", srcs, pathDeps, compiler.cFlagsDeps) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 574 |  | 
 | 575 | 	if ctx.Failed() { | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 576 | 		return Objects{} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 577 | 	} | 
 | 578 |  | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 579 | 	return objs | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 580 | } | 
 | 581 |  | 
 | 582 | // Compile a list of source files into objects a specified subdirectory | 
| Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 583 | func compileObjs(ctx android.ModuleContext, flags builderFlags, | 
| Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 584 | 	subdir string, srcFiles, pathDeps android.Paths, cFlagsDeps android.Paths) Objects { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 585 |  | 
| Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 586 | 	return TransformSourceToObj(ctx, subdir, srcFiles, flags, pathDeps, cFlagsDeps) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 587 | } |