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