blob: e962949b271967d61b7314d019655ac089f3f589 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
15package cc
16
17import (
18 "fmt"
19 "path/filepath"
20 "strings"
21
Colin Cross4b963f82016-09-29 14:06:02 -070022 "github.com/google/blueprint/proptools"
23
Colin Cross4d9c2d12016-07-29 12:48:20 -070024 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070025 "android/soong/cc/config"
Colin Cross4d9c2d12016-07-29 12:48:20 -070026)
27
28// This file contains the basic C/C++/assembly to .o compliation steps
29
30type BaseCompilerProperties struct {
31 // list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
Colin Cross068e0fe2016-12-13 15:23:47 -080032 // srcs may reference the outputs of other modules that produce source files like genrule
33 // or filegroup using the syntax ":module".
Colin Cross4d9c2d12016-07-29 12:48:20 -070034 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.
65 Instruction_set string `android:"arch_variant"`
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.
72 Include_dirs []string `android:"arch_variant"`
73
74 // list of directories relative to the Blueprints file that will
75 // be added to the include path using -I
76 Local_include_dirs []string `android:"arch_variant"`
77
78 // list of generated sources to compile. These are the names of gensrcs or
79 // genrule modules.
80 Generated_sources []string `android:"arch_variant"`
81
82 // list of generated headers to add to the include path. These are the names
83 // of genrule modules.
84 Generated_headers []string `android:"arch_variant"`
85
86 // pass -frtti instead of -fno-rtti
87 Rtti *bool
88
Dan Albert043833c2017-02-03 16:13:38 -080089 // C standard version to use. Can be a specific version (such as "gnu11"),
90 // "experimental" (which will use draft versions like C1x when available),
91 // or the empty string (which will use the default).
92 C_std string
93
94 // C++ standard version to use. Can be a specific version (such as
95 // "gnu++11"), "experimental" (which will use draft versions like C++1z when
96 // available), or the empty string (which will use the default).
97 Cpp_std string
98
Colin Cross948f0cb2016-10-17 14:24:56 -070099 // if set to false, use -std=c++* instead of -std=gnu++*
100 Gnu_extensions *bool
101
Dan Willemsene1240db2016-11-03 14:28:51 -0700102 Aidl struct {
103 // list of directories that will be added to the aidl include paths.
104 Include_dirs []string
105
106 // list of directories relative to the Blueprints file that will
107 // be added to the aidl include paths.
108 Local_include_dirs []string
109 }
110
Colin Cross4d9c2d12016-07-29 12:48:20 -0700111 Debug, Release struct {
112 // list of module-specific flags that will be used for C and C++ compiles in debug or
113 // release builds
114 Cflags []string `android:"arch_variant"`
115 } `android:"arch_variant"`
116}
117
Colin Crossb916a382016-07-29 17:28:03 -0700118func NewBaseCompiler() *baseCompiler {
119 return &baseCompiler{}
120}
121
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122type baseCompiler struct {
123 Properties BaseCompilerProperties
Colin Cross0c461f12016-10-20 16:11:43 -0700124 Proto ProtoProperties
Colin Cross2f336352016-10-26 10:03:47 -0700125 deps android.Paths
Colin Cross4d9c2d12016-07-29 12:48:20 -0700126}
127
128var _ compiler = (*baseCompiler)(nil)
129
130func (compiler *baseCompiler) appendCflags(flags []string) {
131 compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...)
132}
133
134func (compiler *baseCompiler) appendAsflags(flags []string) {
135 compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...)
136}
137
Colin Cross42742b82016-08-01 13:20:05 -0700138func (compiler *baseCompiler) compilerProps() []interface{} {
Colin Cross0feb1692016-11-03 14:38:52 -0700139 return []interface{}{&compiler.Properties, &compiler.Proto}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700140}
141
Colin Cross42742b82016-08-01 13:20:05 -0700142func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700143
Colin Cross37047f12016-12-13 17:06:13 -0800144func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700145 deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
146 deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
147
Colin Cross068e0fe2016-12-13 15:23:47 -0800148 android.ExtractSourcesDeps(ctx, compiler.Properties.Srcs)
149
Dan Willemsene1a3ce32016-11-02 20:44:08 -0700150 if compiler.hasSrcExt(".proto") {
Colin Cross0c461f12016-10-20 16:11:43 -0700151 deps = protoDeps(ctx, deps, &compiler.Proto)
152 }
153
Colin Cross4d9c2d12016-07-29 12:48:20 -0700154 return deps
155}
156
157// Create a Flags struct that collects the compile flags from global values,
158// per-target values, module type values, and per-module Blueprints properties
Colin Cross42742b82016-08-01 13:20:05 -0700159func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700160 tc := ctx.toolchain()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700161
162 CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
163 CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
164 CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
165 CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags)
166
Colin Cross4b963f82016-09-29 14:06:02 -0700167 esc := proptools.NinjaAndShellEscape
168
169 flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Cflags)...)
170 flags.CppFlags = append(flags.CppFlags, esc(compiler.Properties.Cppflags)...)
171 flags.ConlyFlags = append(flags.ConlyFlags, esc(compiler.Properties.Conlyflags)...)
172 flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Asflags)...)
Colin Cross91e90042016-12-02 17:13:24 -0800173 flags.YasmFlags = append(flags.YasmFlags, esc(compiler.Properties.Asflags)...)
Colin Cross4b963f82016-09-29 14:06:02 -0700174 flags.YaccFlags = append(flags.YaccFlags, esc(compiler.Properties.Yaccflags)...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700175
176 // Include dir cflags
Colin Cross4d9c2d12016-07-29 12:48:20 -0700177 localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
Dan Willemsen273af7f2016-11-03 15:53:42 -0700178 if len(localIncludeDirs) > 0 {
179 flags.GlobalFlags = append(flags.GlobalFlags, includeDirsToFlags(localIncludeDirs))
180 }
181 rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs)
182 if len(rootIncludeDirs) > 0 {
183 flags.GlobalFlags = append(flags.GlobalFlags, includeDirsToFlags(rootIncludeDirs))
184 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700185
186 if !ctx.noDefaultCompilerFlags() {
Dan Willemsend2ede872016-11-18 14:54:24 -0800187 if !(ctx.sdk() || ctx.vndk()) || ctx.Host() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700188 flags.GlobalFlags = append(flags.GlobalFlags,
Colin Crossb98c8b02016-07-29 13:44:28 -0700189 "${config.CommonGlobalIncludes}",
Colin Cross1cfd89a2016-09-15 09:30:46 -0700190 "${config.CommonGlobalSystemIncludes}",
Colin Crossb98c8b02016-07-29 13:44:28 -0700191 tc.IncludeFlags(),
192 "${config.CommonNativehelperInclude}")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700193 }
194
Colin Cross0c461f12016-10-20 16:11:43 -0700195 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700196 }
197
Dan Willemsend2ede872016-11-18 14:54:24 -0800198 if ctx.sdk() || ctx.vndk() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700199 // The NDK headers are installed to a common sysroot. While a more
200 // typical Soong approach would be to only make the headers for the
201 // library you're using available, we're trying to emulate the NDK
202 // behavior here, and the NDK always has all the NDK headers available.
203 flags.GlobalFlags = append(flags.GlobalFlags,
204 "-isystem "+getCurrentIncludePath(ctx).String(),
Colin Crossb98c8b02016-07-29 13:44:28 -0700205 "-isystem "+getCurrentIncludePath(ctx).Join(ctx, tc.ClangTriple()).String())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700206
207 // Traditionally this has come from android/api-level.h, but with the
208 // libc headers unified it must be set by the build system since we
209 // don't have per-API level copies of that header now.
Dan Albertebedf672016-11-08 15:06:22 -0800210 version := ctx.sdkVersion()
211 if version == "current" {
212 version = "__ANDROID_API_FUTURE__"
213 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700214 flags.GlobalFlags = append(flags.GlobalFlags,
Dan Albertebedf672016-11-08 15:06:22 -0800215 "-D__ANDROID_API__="+version)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700216
217 // Until the full NDK has been migrated to using ndk_headers, we still
218 // need to add the legacy sysroot includes to get the full set of
219 // headers.
220 legacyIncludes := fmt.Sprintf(
221 "prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/include",
222 ctx.sdkVersion(), ctx.Arch().ArchType.String())
223 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+legacyIncludes)
224 }
225
226 instructionSet := compiler.Properties.Instruction_set
227 if flags.RequiredInstructionSet != "" {
228 instructionSet = flags.RequiredInstructionSet
229 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700230 instructionSetFlags, err := tc.InstructionSetFlags(instructionSet)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700231 if flags.Clang {
Colin Crossb98c8b02016-07-29 13:44:28 -0700232 instructionSetFlags, err = tc.ClangInstructionSetFlags(instructionSet)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700233 }
234 if err != nil {
235 ctx.ModuleErrorf("%s", err)
236 }
237
238 CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
239
240 // TODO: debug
Colin Cross4b963f82016-09-29 14:06:02 -0700241 flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Release.Cflags)...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700242
243 if flags.Clang {
244 CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags)
245 CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags)
246
Colin Crossb98c8b02016-07-29 13:44:28 -0700247 flags.CFlags = config.ClangFilterUnknownCflags(flags.CFlags)
Colin Cross4b963f82016-09-29 14:06:02 -0700248 flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Clang_cflags)...)
249 flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Clang_asflags)...)
Colin Crossb98c8b02016-07-29 13:44:28 -0700250 flags.CppFlags = config.ClangFilterUnknownCflags(flags.CppFlags)
251 flags.ConlyFlags = config.ClangFilterUnknownCflags(flags.ConlyFlags)
252 flags.LdFlags = config.ClangFilterUnknownCflags(flags.LdFlags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700253
Colin Crossb98c8b02016-07-29 13:44:28 -0700254 target := "-target " + tc.ClangTriple()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700255 var gccPrefix string
256 if !ctx.Darwin() {
Colin Crossb98c8b02016-07-29 13:44:28 -0700257 gccPrefix = "-B" + filepath.Join(tc.GccRoot(), tc.GccTriple(), "bin")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700258 }
259
260 flags.CFlags = append(flags.CFlags, target, gccPrefix)
261 flags.AsFlags = append(flags.AsFlags, target, gccPrefix)
262 flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
263 }
264
Colin Crossb98c8b02016-07-29 13:44:28 -0700265 hod := "Host"
Colin Cross4d9c2d12016-07-29 12:48:20 -0700266 if ctx.Os().Class == android.Device {
Colin Crossb98c8b02016-07-29 13:44:28 -0700267 hod = "Device"
Colin Cross4d9c2d12016-07-29 12:48:20 -0700268 }
269
270 if !ctx.noDefaultCompilerFlags() {
271 flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
Colin Crossb6688262016-11-22 12:32:47 -0800272 flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700273
274 if flags.Clang {
Colin Crossb98c8b02016-07-29 13:44:28 -0700275 flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags())
Colin Crossb6688262016-11-22 12:32:47 -0800276 flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700277 flags.GlobalFlags = append(flags.GlobalFlags,
Colin Crossb98c8b02016-07-29 13:44:28 -0700278 tc.ClangCflags(),
279 "${config.CommonClangGlobalCflags}",
280 fmt.Sprintf("${config.%sClangGlobalCflags}", hod))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700281 } else {
Colin Crossb6688262016-11-22 12:32:47 -0800282 flags.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.CppFlags...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700283 flags.GlobalFlags = append(flags.GlobalFlags,
Colin Crossb98c8b02016-07-29 13:44:28 -0700284 tc.Cflags(),
285 "${config.CommonGlobalCflags}",
286 fmt.Sprintf("${config.%sGlobalCflags}", hod))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700287 }
288
289 if Bool(ctx.AConfig().ProductVariables.Brillo) {
290 flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
291 }
292
293 if ctx.Device() {
294 if Bool(compiler.Properties.Rtti) {
295 flags.CppFlags = append(flags.CppFlags, "-frtti")
296 } else {
297 flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
298 }
299 }
300
301 flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
302
303 if flags.Clang {
Colin Crossb98c8b02016-07-29 13:44:28 -0700304 flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700305 } else {
Colin Crossb98c8b02016-07-29 13:44:28 -0700306 flags.CppFlags = append(flags.CppFlags, tc.Cppflags())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700307 }
Colin Cross91e90042016-12-02 17:13:24 -0800308
309 flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700310 }
311
312 if flags.Clang {
Colin Crossb98c8b02016-07-29 13:44:28 -0700313 flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700314 } else {
Colin Crossb98c8b02016-07-29 13:44:28 -0700315 flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainCflags())
Colin Cross4d9c2d12016-07-29 12:48:20 -0700316 }
317
318 if !ctx.sdk() {
Colin Cross6f6a4282016-10-17 14:19:06 -0700319 cStd := config.CStdVersion
Dan Albert043833c2017-02-03 16:13:38 -0800320 if compiler.Properties.C_std == "experimental" {
321 cStd = config.ExperimentalCStdVersion
322 } else if compiler.Properties.C_std != "" {
323 cStd = compiler.Properties.C_std
324 }
325
Colin Cross6f6a4282016-10-17 14:19:06 -0700326 cppStd := config.CppStdVersion
Dan Albert043833c2017-02-03 16:13:38 -0800327 if compiler.Properties.Cpp_std == "experimental" {
328 cppStd = config.ExperimentalCppStdVersion
329 } else if compiler.Properties.Cpp_std != "" {
330 cppStd = compiler.Properties.Cpp_std
331 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700332
333 if !flags.Clang {
334 // GCC uses an invalid C++14 ABI (emits calls to
335 // __cxa_throw_bad_array_length, which is not a valid C++ RT ABI).
336 // http://b/25022512
337 cppStd = config.GccCppStdVersion
338 } else if ctx.Host() && !flags.Clang {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700339 // The host GCC doesn't support C++14 (and is deprecated, so likely
340 // never will). Build these modules with C++11.
Colin Cross6f6a4282016-10-17 14:19:06 -0700341 cppStd = config.GccCppStdVersion
Colin Cross4d9c2d12016-07-29 12:48:20 -0700342 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700343
Colin Cross948f0cb2016-10-17 14:24:56 -0700344 if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false {
345 cStd = gnuToCReplacer.Replace(cStd)
346 cppStd = gnuToCReplacer.Replace(cppStd)
347 }
348
Colin Cross6f6a4282016-10-17 14:19:06 -0700349 flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...)
350 flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700351 }
352
353 // We can enforce some rules more strictly in the code we own. strict
354 // indicates if this is code that we can be stricter with. If we have
355 // rules that we want to apply to *our* code (but maybe can't for
356 // vendor/device specific things), we could extend this to be a ternary
357 // value.
358 strict := true
359 if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") {
360 strict = false
361 }
362
363 // Can be used to make some annotations stricter for code we can fix
364 // (such as when we mark functions as deprecated).
365 if strict {
366 flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT")
367 }
368
Dan Willemsene1a3ce32016-11-02 20:44:08 -0700369 if compiler.hasSrcExt(".proto") {
Colin Cross0c461f12016-10-20 16:11:43 -0700370 flags = protoFlags(ctx, flags, &compiler.Proto)
371 }
372
Dan Willemsene1a3ce32016-11-02 20:44:08 -0700373 if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") {
374 flags.GlobalFlags = append(flags.GlobalFlags,
375 "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
376 }
377
Dan Willemsene1240db2016-11-03 14:28:51 -0700378 if compiler.hasSrcExt(".aidl") {
379 if len(compiler.Properties.Aidl.Local_include_dirs) > 0 {
380 localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs)
381 flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(localAidlIncludeDirs))
382 }
383 if len(compiler.Properties.Aidl.Include_dirs) > 0 {
384 rootAidlIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Aidl.Include_dirs)
385 flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs))
386 }
387
388 flags.GlobalFlags = append(flags.GlobalFlags,
389 "-I"+android.PathForModuleGen(ctx, "aidl").String())
390 }
391
Colin Cross4d9c2d12016-07-29 12:48:20 -0700392 return flags
393}
394
Dan Willemsene1a3ce32016-11-02 20:44:08 -0700395func (compiler *baseCompiler) hasSrcExt(ext string) bool {
Colin Cross0c461f12016-10-20 16:11:43 -0700396 for _, src := range compiler.Properties.Srcs {
Dan Willemsene1a3ce32016-11-02 20:44:08 -0700397 if filepath.Ext(src) == ext {
Colin Cross0c461f12016-10-20 16:11:43 -0700398 return true
399 }
400 }
401
402 return false
403}
404
Colin Cross948f0cb2016-10-17 14:24:56 -0700405var gnuToCReplacer = strings.NewReplacer("gnu", "c")
406
Colin Cross4d9c2d12016-07-29 12:48:20 -0700407func ndkPathDeps(ctx ModuleContext) android.Paths {
Dan Willemsend2ede872016-11-18 14:54:24 -0800408 if ctx.sdk() || ctx.vndk() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700409 // The NDK sysroot timestamp file depends on all the NDK sysroot files
410 // (headers and libraries).
411 return android.Paths{getNdkSysrootTimestampFile(ctx)}
412 }
413 return nil
414}
415
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700416func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700417 pathDeps := deps.GeneratedHeaders
418 pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
Colin Cross2f336352016-10-26 10:03:47 -0700419
420 srcs := ctx.ExpandSources(compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
421 srcs = append(srcs, deps.GeneratedSources...)
422
423 buildFlags := flagsToBuilderFlags(flags)
424
425 srcs, genDeps := genSources(ctx, srcs, buildFlags)
426
427 pathDeps = append(pathDeps, genDeps...)
428 pathDeps = append(pathDeps, flags.CFlagsDeps...)
429
430 compiler.deps = pathDeps
431
Colin Cross4d9c2d12016-07-29 12:48:20 -0700432 // Compile files listed in c.Properties.Srcs into objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700433 objs := compileObjs(ctx, buildFlags, "", srcs, compiler.deps)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700434
435 if ctx.Failed() {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700436 return Objects{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700437 }
438
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700439 return objs
Colin Cross4d9c2d12016-07-29 12:48:20 -0700440}
441
442// Compile a list of source files into objects a specified subdirectory
Colin Cross2f336352016-10-26 10:03:47 -0700443func compileObjs(ctx android.ModuleContext, flags builderFlags,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700444 subdir string, srcFiles, deps android.Paths) Objects {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700445
Colin Cross2f336352016-10-26 10:03:47 -0700446 return TransformSourceToObj(ctx, subdir, srcFiles, flags, deps)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700447}