diff options
author | Colin Cross <ccross@android.com> | 2019-11-04 09:37:55 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-11-07 15:27:58 -0800 |
commit | 4af21ed26f41f9779c4e48dfb3b8d86366a24346 (patch) | |
tree | 045e68db56a42c2556f4726a6140f1a2f416ebf3 /cc/compiler.go | |
parent | 1f056cd69d5d6e5e720a028fea345e09e3508ffe (diff) | |
download | build_soong-4af21ed26f41f9779c4e48dfb3b8d86366a24346.tar.gz build_soong-4af21ed26f41f9779c4e48dfb3b8d86366a24346.tar.bz2 build_soong-4af21ed26f41f9779c4e48dfb3b8d86366a24346.zip |
Split local and global cflags
Native compiler flags are currently applied in approximately:
global cflags
local cflags
local include dirs
global include dirs
global conlyflags
local conlyflags
global cppflags
local cppflags
This means that a flag that is enabled in the global cppflags
cannot be disabled in the local cflags, and an Android.bp author
must know to disable it in the local cppflags. A better order
would be:
global cflags
global conlyflags
global cppflags
local cflags
local conlyflags
local cppflags
local include dirs
global include dirs
We are mixing both the global and local cflags into a single
variable, and similar for conlyflags and cppflags, which
prevents reordering them. This CL prepares to reorder them
by splitting the global and local cflags into separate variables.
Bug: 143713277
Test: m native
Change-Id: Ic55a8c3516c331dc5f2af9d00e59ceca9d3e6c15
Diffstat (limited to 'cc/compiler.go')
-rw-r--r-- | cc/compiler.go | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/cc/compiler.go b/cc/compiler.go index ff681017..bb40a5bd 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -265,11 +265,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps esc := proptools.NinjaAndShellEscapeList - flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Cflags)...) - flags.CppFlags = append(flags.CppFlags, esc(compiler.Properties.Cppflags)...) - flags.ConlyFlags = append(flags.ConlyFlags, esc(compiler.Properties.Conlyflags)...) - flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Asflags)...) - flags.YasmFlags = append(flags.YasmFlags, esc(compiler.Properties.Asflags)...) + flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Cflags)...) + flags.Local.CppFlags = append(flags.Local.CppFlags, esc(compiler.Properties.Cppflags)...) + flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, esc(compiler.Properties.Conlyflags)...) + flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Asflags)...) + flags.Local.YasmFlags = append(flags.Local.YasmFlags, esc(compiler.Properties.Asflags)...) flags.Yacc = compiler.Properties.Yacc @@ -277,20 +277,20 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) if len(localIncludeDirs) > 0 { f := includeDirsToFlags(localIncludeDirs) - flags.GlobalFlags = append(flags.GlobalFlags, f) - flags.YasmFlags = append(flags.YasmFlags, f) + flags.Local.CommonFlags = append(flags.Local.CommonFlags, f) + flags.Local.YasmFlags = append(flags.Local.YasmFlags, f) } rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) if len(rootIncludeDirs) > 0 { f := includeDirsToFlags(rootIncludeDirs) - flags.GlobalFlags = append(flags.GlobalFlags, f) - flags.YasmFlags = append(flags.YasmFlags, f) + flags.Local.CommonFlags = append(flags.Local.CommonFlags, f) + flags.Local.YasmFlags = append(flags.Local.YasmFlags, f) } if compiler.Properties.Include_build_directory == nil || *compiler.Properties.Include_build_directory { - flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) - flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleSrc(ctx).String()) + flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) } if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { @@ -312,16 +312,17 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if ctx.useVndk() { - flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_VNDK__") + flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__") } if ctx.inRecovery() { - flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_RECOVERY__") + flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_RECOVERY__") } if ctx.apexName() != "" { - flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__") - flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__") + flags.Global.CommonFlags = append(flags.Global.CommonFlags, + "-D__ANDROID_APEX__", + "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__") } instructionSet := String(compiler.Properties.Instruction_set) @@ -336,17 +337,17 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) // TODO: debug - flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Release.Cflags)...) + flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...) CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) - flags.CFlags = config.ClangFilterUnknownCflags(flags.CFlags) - flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Clang_cflags)...) - flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Clang_asflags)...) - flags.CppFlags = config.ClangFilterUnknownCflags(flags.CppFlags) - flags.ConlyFlags = config.ClangFilterUnknownCflags(flags.ConlyFlags) - flags.LdFlags = config.ClangFilterUnknownCflags(flags.LdFlags) + flags.Local.CFlags = config.ClangFilterUnknownCflags(flags.Local.CFlags) + flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Clang_cflags)...) + flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Clang_asflags)...) + flags.Local.CppFlags = config.ClangFilterUnknownCflags(flags.Local.CppFlags) + flags.Local.ConlyFlags = config.ClangFilterUnknownCflags(flags.Local.ConlyFlags) + flags.Local.LdFlags = config.ClangFilterUnknownCflags(flags.Local.LdFlags) target := "-target " + tc.ClangTriple() if ctx.Os().Class == android.Device { @@ -360,45 +361,45 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps gccPrefix := "-B" + config.ToolPath(tc) - flags.CFlags = append(flags.CFlags, target, gccPrefix) - flags.AsFlags = append(flags.AsFlags, target, gccPrefix) - flags.LdFlags = append(flags.LdFlags, target, gccPrefix) + flags.Global.CFlags = append(flags.Global.CFlags, target, gccPrefix) + flags.Global.AsFlags = append(flags.Global.AsFlags, target, gccPrefix) + flags.Global.LdFlags = append(flags.Global.LdFlags, target, gccPrefix) hod := "Host" if ctx.Os().Class == android.Device { hod = "Device" } - flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) - flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...) - flags.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.CppFlags...) + flags.Global.CommonFlags = append(flags.Global.CommonFlags, instructionSetFlags) + flags.Global.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.Global.ConlyFlags...) + flags.Global.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.Global.CppFlags...) - flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags()) - flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...) - flags.GlobalFlags = append(flags.GlobalFlags, + flags.Global.AsFlags = append(flags.Global.AsFlags, tc.ClangAsflags()) + flags.Global.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.Global.CppFlags...) + flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ClangCflags(), "${config.CommonClangGlobalCflags}", fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { - flags.GlobalFlags = append([]string{"${config.ClangExternalCflags}"}, flags.GlobalFlags...) + flags.Global.CommonFlags = append([]string{"${config.ClangExternalCflags}"}, flags.Global.CommonFlags...) } if tc.Bionic() { if Bool(compiler.Properties.Rtti) { - flags.CppFlags = append(flags.CppFlags, "-frtti") + flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti") } else { - flags.CppFlags = append(flags.CppFlags, "-fno-rtti") + flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti") } } - flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") + flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__") - flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags()) + flags.Global.CppFlags = append(flags.Global.CppFlags, tc.ClangCppflags()) - flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) + flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags()) - flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags()) + flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainClangCflags()) cStd := config.CStdVersion if String(compiler.Properties.C_std) == "experimental" { @@ -420,15 +421,15 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps cppStd = gnuToCReplacer.Replace(cppStd) } - flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...) - flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) + flags.Local.ConlyFlags = append([]string{"-std=" + cStd}, flags.Local.ConlyFlags...) + flags.Local.CppFlags = append([]string{"-std=" + cppStd}, flags.Local.CppFlags...) if ctx.useVndk() { - flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) + flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) } if ctx.inRecovery() { - flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...) + flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...) } // We can enforce some rules more strictly in the code we own. strict @@ -444,7 +445,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps // Can be used to make some annotations stricter for code we can fix // (such as when we mark functions as deprecated). if strict { - flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT") + flags.Global.CFlags = append(flags.Global.CFlags, "-DANDROID_STRICT") } if compiler.hasSrcExt(".proto") { @@ -452,12 +453,12 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") { - flags.GlobalFlags = append(flags.GlobalFlags, + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) } if compiler.hasSrcExt(".mc") { - flags.GlobalFlags = append(flags.GlobalFlags, + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String()) } @@ -475,7 +476,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps flags.aidlFlags = append(flags.aidlFlags, "-t") } - flags.GlobalFlags = append(flags.GlobalFlags, + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleGen(ctx, "aidl").String()) } @@ -484,26 +485,26 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if compiler.hasSrcExt(".sysprop") { - flags.GlobalFlags = append(flags.GlobalFlags, + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleGen(ctx, "sysprop", "include").String()) } if len(compiler.Properties.Srcs) > 0 { module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName() - if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) { + if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) { addToModuleList(ctx, modulesUsingWnoErrorKey, module) - } else if !inList("-Werror", flags.CFlags) && !inList("-Werror", flags.CppFlags) { + } else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) { if warningsAreAllowed(ctx.ModuleDir()) { addToModuleList(ctx, modulesAddedWallKey, module) - flags.CFlags = append([]string{"-Wall"}, flags.CFlags...) + flags.Local.CFlags = append([]string{"-Wall"}, flags.Local.CFlags...) } else { - flags.CFlags = append([]string{"-Wall", "-Werror"}, flags.CFlags...) + flags.Local.CFlags = append([]string{"-Wall", "-Werror"}, flags.Local.CFlags...) } } } if Bool(compiler.Properties.Openmp) { - flags.CFlags = append(flags.CFlags, "-fopenmp") + flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp") } return flags |