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
This commit is contained in:
Colin Cross
2019-11-04 09:37:55 -08:00
parent 1f056cd69d
commit 4af21ed26f
26 changed files with 286 additions and 259 deletions

View File

@@ -140,26 +140,34 @@ type PathDeps struct {
DynamicLinker android.OptionalPath
}
type Flags struct {
GlobalFlags []string // Flags that apply to C, C++, and assembly source files
ArFlags []string // Flags that apply to ar
// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
// command line so they can be overridden by the local module flags).
type LocalOrGlobalFlags struct {
CommonFlags []string // Flags that apply to C, C++, and assembly source files
AsFlags []string // Flags that apply to assembly source files
YasmFlags []string // Flags that apply to yasm assembly source files
CFlags []string // Flags that apply to C and C++ source files
ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
ConlyFlags []string // Flags that apply to C source files
CppFlags []string // Flags that apply to C++ source files
ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
aidlFlags []string // Flags that apply to aidl source files
rsFlags []string // Flags that apply to renderscript source files
LdFlags []string // Flags that apply to linker command lines
libFlags []string // Flags to add libraries early to the link order
extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
TidyFlags []string // Flags that apply to clang-tidy
SAbiFlags []string // Flags that apply to header-abi-dumper
YasmFlags []string // Flags that apply to yasm assembly source files
}
type Flags struct {
Local LocalOrGlobalFlags
Global LocalOrGlobalFlags
aidlFlags []string // Flags that apply to aidl source files
rsFlags []string // Flags that apply to renderscript source files
libFlags []string // Flags to add libraries early to the link order
extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
TidyFlags []string // Flags that apply to clang-tidy
SAbiFlags []string // Flags that apply to header-abi-dumper
// Global include flags that apply to C, C++, and assembly source files
// These must be after any module include flags, which will be in GlobalFlags.
// These must be after any module include flags, which will be in CommonFlags.
SystemIncludeFlags []string
Toolchain config.Toolchain
@@ -1277,17 +1285,17 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
return
}
flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
for _, dir := range deps.IncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir.String())
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
}
for _, dir := range deps.SystemIncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir.String())
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
}
c.flags = flags
@@ -1296,16 +1304,16 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags = c.sabi.flags(ctx, flags)
}
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
// Optimization to reduce size of build.ninja
// Replace the long list of flags for each file with a module-local variable
ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
flags.CFlags = []string{"$cflags"}
flags.CppFlags = []string{"$cppflags"}
flags.AsFlags = []string{"$asflags"}
ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
flags.Local.CFlags = []string{"$cflags"}
flags.Local.CppFlags = []string{"$cppflags"}
flags.Local.AsFlags = []string{"$asflags"}
var objs Objects
if c.compiler != nil {