Loading cc/binary.go +12 −12 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags if ctx.Host() && !ctx.Windows() && !binary.static() { if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") { flags.LdFlags = append(flags.LdFlags, "-pie") flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie") } } Loading @@ -235,7 +235,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags // all code is position independent, and then those warnings get promoted to // errors. if !ctx.Windows() { flags.CFlags = append(flags.CFlags, "-fPIE") flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE") } if ctx.toolchain().Bionic() { Loading @@ -244,11 +244,11 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags // However, bionic/linker uses -shared to overwrite. // Linker for x86 targets does not allow coexistance of -static and -shared, // so we add -static only if -shared is not used. if !inList("-shared", flags.LdFlags) { flags.LdFlags = append(flags.LdFlags, "-static") if !inList("-shared", flags.Local.LdFlags) { flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") } flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-nostdlib", "-Bstatic", "-Wl,--gc-sections", Loading Loading @@ -278,14 +278,14 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags if ctx.Os() == android.LinuxBionic { // Use the dlwrap entry point, but keep _start around so // that it can be used by host_bionic_inject flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--entry=__dlwrap__start", "-Wl,--undefined=_start", ) } } flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie", "-nostdlib", "-Bdynamic", Loading @@ -295,10 +295,10 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags } } else { if binary.static() { flags.LdFlags = append(flags.LdFlags, "-static") flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") } if ctx.Darwin() { flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names") } } Loading @@ -315,14 +315,14 @@ func (binary *binaryDecorator) link(ctx ModuleContext, var linkerDeps android.Paths if deps.LinkerFlagsFile.Valid() { flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") flags.Local.LdFlags = append(flags.Local.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path()) } if flags.DynamicLinker != "" { flags.LdFlags = append(flags.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) } else if ctx.toolchain().Bionic() && !binary.static() { flags.LdFlags = append(flags.LdFlags, "-Wl,--no-dynamic-linker") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker") } builderFlags := flagsToBuilderFlags(flags) Loading cc/builder.go +85 −71 Original line number Diff line number Diff line Loading @@ -261,20 +261,30 @@ func init() { } type builderFlags struct { globalFlags string arFlags string asFlags string cFlags string toolingCFlags string // A separate set of cFlags for clang LibTooling tools toolingCppFlags string // A separate set of cppFlags for clang LibTooling tools conlyFlags string cppFlags string ldFlags string globalCommonFlags string globalAsFlags string globalYasmFlags string globalCFlags string globalToolingCFlags string // A separate set of cFlags for clang LibTooling tools globalToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools globalConlyFlags string globalCppFlags string globalLdFlags string localCommonFlags string localAsFlags string localYasmFlags string localCFlags string localToolingCFlags string // A separate set of cFlags for clang LibTooling tools localToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools localConlyFlags string localCppFlags string localLdFlags string libFlags string extraLibFlags string tidyFlags string sAbiFlags string yasmFlags string aidlFlags string rsFlags string toolchain config.Toolchain Loading Loading @@ -349,39 +359,45 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and kytheFiles = make(android.Paths, 0, len(srcFiles)) } commonFlags := strings.Join([]string{ flags.globalFlags, flags.systemIncludeFlags, }, " ") toolingCflags := strings.Join([]string{ commonFlags, flags.toolingCFlags, flags.conlyFlags, }, " ") cflags := strings.Join([]string{ commonFlags, flags.cFlags, flags.conlyFlags, }, " ") toolingCppflags := strings.Join([]string{ commonFlags, flags.toolingCFlags, flags.toolingCppFlags, }, " ") cppflags := strings.Join([]string{ commonFlags, flags.cFlags, flags.cppFlags, }, " ") asflags := strings.Join([]string{ commonFlags, flags.asFlags, }, " ") // Produce fully expanded flags for use by C tools, C compiles, C++ tools, C++ compiles, and asm compiles // respectively. toolingCflags := flags.globalCommonFlags + " " + flags.globalToolingCFlags + " " + flags.globalConlyFlags + " " + flags.localCommonFlags + " " + flags.localToolingCFlags + " " + flags.localConlyFlags + " " + flags.systemIncludeFlags cflags := flags.globalCommonFlags + " " + flags.globalCFlags + " " + flags.globalConlyFlags + " " + flags.localCommonFlags + " " + flags.localCFlags + " " + flags.localConlyFlags + " " + flags.systemIncludeFlags toolingCppflags := flags.globalCommonFlags + " " + flags.globalToolingCFlags + " " + flags.globalToolingCppFlags + " " + flags.localCommonFlags + " " + flags.localToolingCFlags + " " + flags.localToolingCppFlags + " " + flags.systemIncludeFlags cppflags := flags.globalCommonFlags + " " + flags.globalCFlags + " " + flags.globalCppFlags + " " + flags.localCommonFlags + " " + flags.localCFlags + " " + flags.localCppFlags + " " + flags.systemIncludeFlags asflags := flags.globalCommonFlags + " " + flags.globalAsFlags + " " + flags.localCommonFlags + " " + flags.localAsFlags + " " + flags.systemIncludeFlags var sAbiDumpFiles android.Paths if flags.sAbiDump { Loading @@ -408,7 +424,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "asFlags": flags.yasmFlags, "asFlags": flags.globalYasmFlags + " " + flags.localYasmFlags, }, }) continue Loading @@ -431,8 +447,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and continue } var moduleCflags string var moduleToolingCflags string var moduleFlags string var moduleToolingFlags string var ccCmd string tidy := flags.tidy coverage := flags.coverage Loading @@ -448,19 +465,19 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and fallthrough case ".S": ccCmd = "clang" moduleCflags = asflags moduleFlags = asflags tidy = false coverage = false dump = false emitXref = false case ".c": ccCmd = "clang" moduleCflags = cflags moduleToolingCflags = toolingCflags moduleFlags = cflags moduleToolingFlags = toolingCflags case ".cpp", ".cc", ".cxx", ".mm": ccCmd = "clang++" moduleCflags = cppflags moduleToolingCflags = toolingCppflags moduleFlags = cppflags moduleToolingFlags = toolingCppflags default: ctx.ModuleErrorf("File %s has unknown extension", srcFile) continue Loading @@ -486,7 +503,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleCflags, "cFlags": moduleFlags, "ccCmd": ccCmd, }, }) Loading @@ -501,7 +518,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleCflags, "cFlags": moduleFlags, }, }) kytheFiles = append(kytheFiles, kytheFile) Loading @@ -522,7 +539,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleToolingCflags, "cFlags": moduleToolingFlags, "tidyFlags": flags.tidyFlags, }, }) Loading @@ -541,7 +558,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleToolingCflags, "cFlags": moduleToolingFlags, "exportDirs": flags.sAbiFlags, }, }) Loading @@ -567,9 +584,6 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, if !ctx.Darwin() { arFlags += " -format=gnu" } if flags.arFlags != "" { arFlags += " " + flags.arFlags } ctx.Build(pctx, android.BuildParams{ Rule: ar, Loading Loading @@ -651,7 +665,7 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext, "crtBegin": crtBegin.String(), "libFlags": strings.Join(libFlagsList, " "), "extraLibFlags": flags.extraLibFlags, "ldFlags": flags.ldFlags, "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, "crtEnd": crtEnd.String(), }, }) Loading Loading @@ -788,7 +802,7 @@ func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, Implicits: deps, Args: map[string]string{ "ldCmd": ldCmd, "ldFlags": flags.ldFlags, "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, }, }) } Loading cc/cc.go +32 −24 Original line number Diff line number Diff line Loading @@ -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 LdFlags []string // Flags that apply to linker command lines } 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 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 // 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 Loading Loading @@ -1284,17 +1292,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 Loading @@ -1303,16 +1311,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 { Loading cc/cflag_artifacts.go +2 −2 Original line number Diff line number Diff line Loading @@ -147,8 +147,8 @@ func (s *cflagArtifactsText) GenerateBuildActions(ctx android.SingletonContext) ctx.VisitAllModules(func(module android.Module) { if ccModule, ok := module.(*Module); ok { if allowedDir(ctx.ModuleDir(ccModule)) { cflags := ccModule.flags.CFlags cppflags := ccModule.flags.CppFlags cflags := ccModule.flags.Local.CFlags cppflags := ccModule.flags.Local.CppFlags module := fmt.Sprintf("%s:%s (%s)", ctx.BlueprintFile(ccModule), ctx.ModuleName(ccModule), Loading cc/cmakelists.go +31 −15 Original line number Diff line number Diff line Loading @@ -162,25 +162,41 @@ func generateCLionProject(compiledModule CompiledInterface, ctx android.Singleto f.WriteString(")\n") // Add all header search path and compiler parameters (-D, -W, -f, -XXXX) f.WriteString("\n# GLOBAL FLAGS:\n") globalParameters := parseCompilerParameters(ccModule.flags.GlobalFlags, ctx, f) translateToCMake(globalParameters, f, true, true) f.WriteString("\n# GLOBAL ALL FLAGS:\n") globalAllParameters := parseCompilerParameters(ccModule.flags.Global.CommonFlags, ctx, f) translateToCMake(globalAllParameters, f, true, true) f.WriteString("\n# CFLAGS:\n") cParameters := parseCompilerParameters(ccModule.flags.CFlags, ctx, f) translateToCMake(cParameters, f, true, true) f.WriteString("\n# LOCAL ALL FLAGS:\n") localAllParameters := parseCompilerParameters(ccModule.flags.Local.CommonFlags, ctx, f) translateToCMake(localAllParameters, f, true, true) f.WriteString("\n# C ONLY FLAGS:\n") cOnlyParameters := parseCompilerParameters(ccModule.flags.ConlyFlags, ctx, f) translateToCMake(cOnlyParameters, f, true, false) f.WriteString("\n# GLOBAL CFLAGS:\n") globalCParameters := parseCompilerParameters(ccModule.flags.Global.CFlags, ctx, f) translateToCMake(globalCParameters, f, true, true) f.WriteString("\n# CPP FLAGS:\n") cppParameters := parseCompilerParameters(ccModule.flags.CppFlags, ctx, f) translateToCMake(cppParameters, f, false, true) f.WriteString("\n# LOCAL CFLAGS:\n") localCParameters := parseCompilerParameters(ccModule.flags.Local.CFlags, ctx, f) translateToCMake(localCParameters, f, true, true) f.WriteString("\n# SYSTEM INCLUDE FLAGS:\n") includeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) translateToCMake(includeParameters, f, true, true) f.WriteString("\n# GLOBAL C ONLY FLAGS:\n") globalConlyParameters := parseCompilerParameters(ccModule.flags.Global.ConlyFlags, ctx, f) translateToCMake(globalConlyParameters, f, true, false) f.WriteString("\n# LOCAL C ONLY FLAGS:\n") localConlyParameters := parseCompilerParameters(ccModule.flags.Local.ConlyFlags, ctx, f) translateToCMake(localConlyParameters, f, true, false) f.WriteString("\n# GLOBAL CPP FLAGS:\n") globalCppParameters := parseCompilerParameters(ccModule.flags.Global.CppFlags, ctx, f) translateToCMake(globalCppParameters, f, false, true) f.WriteString("\n# LOCAL CPP FLAGS:\n") localCppParameters := parseCompilerParameters(ccModule.flags.Local.CppFlags, ctx, f) translateToCMake(localCppParameters, f, false, true) f.WriteString("\n# GLOBAL SYSTEM INCLUDE FLAGS:\n") globalIncludeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) translateToCMake(globalIncludeParameters, f, true, true) // Add project executable. f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n", Loading Loading
cc/binary.go +12 −12 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags if ctx.Host() && !ctx.Windows() && !binary.static() { if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") { flags.LdFlags = append(flags.LdFlags, "-pie") flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie") } } Loading @@ -235,7 +235,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags // all code is position independent, and then those warnings get promoted to // errors. if !ctx.Windows() { flags.CFlags = append(flags.CFlags, "-fPIE") flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE") } if ctx.toolchain().Bionic() { Loading @@ -244,11 +244,11 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags // However, bionic/linker uses -shared to overwrite. // Linker for x86 targets does not allow coexistance of -static and -shared, // so we add -static only if -shared is not used. if !inList("-shared", flags.LdFlags) { flags.LdFlags = append(flags.LdFlags, "-static") if !inList("-shared", flags.Local.LdFlags) { flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") } flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-nostdlib", "-Bstatic", "-Wl,--gc-sections", Loading Loading @@ -278,14 +278,14 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags if ctx.Os() == android.LinuxBionic { // Use the dlwrap entry point, but keep _start around so // that it can be used by host_bionic_inject flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--entry=__dlwrap__start", "-Wl,--undefined=_start", ) } } flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie", "-nostdlib", "-Bdynamic", Loading @@ -295,10 +295,10 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags } } else { if binary.static() { flags.LdFlags = append(flags.LdFlags, "-static") flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") } if ctx.Darwin() { flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names") } } Loading @@ -315,14 +315,14 @@ func (binary *binaryDecorator) link(ctx ModuleContext, var linkerDeps android.Paths if deps.LinkerFlagsFile.Valid() { flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") flags.Local.LdFlags = append(flags.Local.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path()) } if flags.DynamicLinker != "" { flags.LdFlags = append(flags.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) } else if ctx.toolchain().Bionic() && !binary.static() { flags.LdFlags = append(flags.LdFlags, "-Wl,--no-dynamic-linker") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker") } builderFlags := flagsToBuilderFlags(flags) Loading
cc/builder.go +85 −71 Original line number Diff line number Diff line Loading @@ -261,20 +261,30 @@ func init() { } type builderFlags struct { globalFlags string arFlags string asFlags string cFlags string toolingCFlags string // A separate set of cFlags for clang LibTooling tools toolingCppFlags string // A separate set of cppFlags for clang LibTooling tools conlyFlags string cppFlags string ldFlags string globalCommonFlags string globalAsFlags string globalYasmFlags string globalCFlags string globalToolingCFlags string // A separate set of cFlags for clang LibTooling tools globalToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools globalConlyFlags string globalCppFlags string globalLdFlags string localCommonFlags string localAsFlags string localYasmFlags string localCFlags string localToolingCFlags string // A separate set of cFlags for clang LibTooling tools localToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools localConlyFlags string localCppFlags string localLdFlags string libFlags string extraLibFlags string tidyFlags string sAbiFlags string yasmFlags string aidlFlags string rsFlags string toolchain config.Toolchain Loading Loading @@ -349,39 +359,45 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and kytheFiles = make(android.Paths, 0, len(srcFiles)) } commonFlags := strings.Join([]string{ flags.globalFlags, flags.systemIncludeFlags, }, " ") toolingCflags := strings.Join([]string{ commonFlags, flags.toolingCFlags, flags.conlyFlags, }, " ") cflags := strings.Join([]string{ commonFlags, flags.cFlags, flags.conlyFlags, }, " ") toolingCppflags := strings.Join([]string{ commonFlags, flags.toolingCFlags, flags.toolingCppFlags, }, " ") cppflags := strings.Join([]string{ commonFlags, flags.cFlags, flags.cppFlags, }, " ") asflags := strings.Join([]string{ commonFlags, flags.asFlags, }, " ") // Produce fully expanded flags for use by C tools, C compiles, C++ tools, C++ compiles, and asm compiles // respectively. toolingCflags := flags.globalCommonFlags + " " + flags.globalToolingCFlags + " " + flags.globalConlyFlags + " " + flags.localCommonFlags + " " + flags.localToolingCFlags + " " + flags.localConlyFlags + " " + flags.systemIncludeFlags cflags := flags.globalCommonFlags + " " + flags.globalCFlags + " " + flags.globalConlyFlags + " " + flags.localCommonFlags + " " + flags.localCFlags + " " + flags.localConlyFlags + " " + flags.systemIncludeFlags toolingCppflags := flags.globalCommonFlags + " " + flags.globalToolingCFlags + " " + flags.globalToolingCppFlags + " " + flags.localCommonFlags + " " + flags.localToolingCFlags + " " + flags.localToolingCppFlags + " " + flags.systemIncludeFlags cppflags := flags.globalCommonFlags + " " + flags.globalCFlags + " " + flags.globalCppFlags + " " + flags.localCommonFlags + " " + flags.localCFlags + " " + flags.localCppFlags + " " + flags.systemIncludeFlags asflags := flags.globalCommonFlags + " " + flags.globalAsFlags + " " + flags.localCommonFlags + " " + flags.localAsFlags + " " + flags.systemIncludeFlags var sAbiDumpFiles android.Paths if flags.sAbiDump { Loading @@ -408,7 +424,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "asFlags": flags.yasmFlags, "asFlags": flags.globalYasmFlags + " " + flags.localYasmFlags, }, }) continue Loading @@ -431,8 +447,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and continue } var moduleCflags string var moduleToolingCflags string var moduleFlags string var moduleToolingFlags string var ccCmd string tidy := flags.tidy coverage := flags.coverage Loading @@ -448,19 +465,19 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and fallthrough case ".S": ccCmd = "clang" moduleCflags = asflags moduleFlags = asflags tidy = false coverage = false dump = false emitXref = false case ".c": ccCmd = "clang" moduleCflags = cflags moduleToolingCflags = toolingCflags moduleFlags = cflags moduleToolingFlags = toolingCflags case ".cpp", ".cc", ".cxx", ".mm": ccCmd = "clang++" moduleCflags = cppflags moduleToolingCflags = toolingCppflags moduleFlags = cppflags moduleToolingFlags = toolingCppflags default: ctx.ModuleErrorf("File %s has unknown extension", srcFile) continue Loading @@ -486,7 +503,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleCflags, "cFlags": moduleFlags, "ccCmd": ccCmd, }, }) Loading @@ -501,7 +518,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleCflags, "cFlags": moduleFlags, }, }) kytheFiles = append(kytheFiles, kytheFile) Loading @@ -522,7 +539,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleToolingCflags, "cFlags": moduleToolingFlags, "tidyFlags": flags.tidyFlags, }, }) Loading @@ -541,7 +558,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and Implicits: cFlagsDeps, OrderOnly: pathDeps, Args: map[string]string{ "cFlags": moduleToolingCflags, "cFlags": moduleToolingFlags, "exportDirs": flags.sAbiFlags, }, }) Loading @@ -567,9 +584,6 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, if !ctx.Darwin() { arFlags += " -format=gnu" } if flags.arFlags != "" { arFlags += " " + flags.arFlags } ctx.Build(pctx, android.BuildParams{ Rule: ar, Loading Loading @@ -651,7 +665,7 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext, "crtBegin": crtBegin.String(), "libFlags": strings.Join(libFlagsList, " "), "extraLibFlags": flags.extraLibFlags, "ldFlags": flags.ldFlags, "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, "crtEnd": crtEnd.String(), }, }) Loading Loading @@ -788,7 +802,7 @@ func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, Implicits: deps, Args: map[string]string{ "ldCmd": ldCmd, "ldFlags": flags.ldFlags, "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, }, }) } Loading
cc/cc.go +32 −24 Original line number Diff line number Diff line Loading @@ -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 LdFlags []string // Flags that apply to linker command lines } 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 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 // 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 Loading Loading @@ -1284,17 +1292,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 Loading @@ -1303,16 +1311,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 { Loading
cc/cflag_artifacts.go +2 −2 Original line number Diff line number Diff line Loading @@ -147,8 +147,8 @@ func (s *cflagArtifactsText) GenerateBuildActions(ctx android.SingletonContext) ctx.VisitAllModules(func(module android.Module) { if ccModule, ok := module.(*Module); ok { if allowedDir(ctx.ModuleDir(ccModule)) { cflags := ccModule.flags.CFlags cppflags := ccModule.flags.CppFlags cflags := ccModule.flags.Local.CFlags cppflags := ccModule.flags.Local.CppFlags module := fmt.Sprintf("%s:%s (%s)", ctx.BlueprintFile(ccModule), ctx.ModuleName(ccModule), Loading
cc/cmakelists.go +31 −15 Original line number Diff line number Diff line Loading @@ -162,25 +162,41 @@ func generateCLionProject(compiledModule CompiledInterface, ctx android.Singleto f.WriteString(")\n") // Add all header search path and compiler parameters (-D, -W, -f, -XXXX) f.WriteString("\n# GLOBAL FLAGS:\n") globalParameters := parseCompilerParameters(ccModule.flags.GlobalFlags, ctx, f) translateToCMake(globalParameters, f, true, true) f.WriteString("\n# GLOBAL ALL FLAGS:\n") globalAllParameters := parseCompilerParameters(ccModule.flags.Global.CommonFlags, ctx, f) translateToCMake(globalAllParameters, f, true, true) f.WriteString("\n# CFLAGS:\n") cParameters := parseCompilerParameters(ccModule.flags.CFlags, ctx, f) translateToCMake(cParameters, f, true, true) f.WriteString("\n# LOCAL ALL FLAGS:\n") localAllParameters := parseCompilerParameters(ccModule.flags.Local.CommonFlags, ctx, f) translateToCMake(localAllParameters, f, true, true) f.WriteString("\n# C ONLY FLAGS:\n") cOnlyParameters := parseCompilerParameters(ccModule.flags.ConlyFlags, ctx, f) translateToCMake(cOnlyParameters, f, true, false) f.WriteString("\n# GLOBAL CFLAGS:\n") globalCParameters := parseCompilerParameters(ccModule.flags.Global.CFlags, ctx, f) translateToCMake(globalCParameters, f, true, true) f.WriteString("\n# CPP FLAGS:\n") cppParameters := parseCompilerParameters(ccModule.flags.CppFlags, ctx, f) translateToCMake(cppParameters, f, false, true) f.WriteString("\n# LOCAL CFLAGS:\n") localCParameters := parseCompilerParameters(ccModule.flags.Local.CFlags, ctx, f) translateToCMake(localCParameters, f, true, true) f.WriteString("\n# SYSTEM INCLUDE FLAGS:\n") includeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) translateToCMake(includeParameters, f, true, true) f.WriteString("\n# GLOBAL C ONLY FLAGS:\n") globalConlyParameters := parseCompilerParameters(ccModule.flags.Global.ConlyFlags, ctx, f) translateToCMake(globalConlyParameters, f, true, false) f.WriteString("\n# LOCAL C ONLY FLAGS:\n") localConlyParameters := parseCompilerParameters(ccModule.flags.Local.ConlyFlags, ctx, f) translateToCMake(localConlyParameters, f, true, false) f.WriteString("\n# GLOBAL CPP FLAGS:\n") globalCppParameters := parseCompilerParameters(ccModule.flags.Global.CppFlags, ctx, f) translateToCMake(globalCppParameters, f, false, true) f.WriteString("\n# LOCAL CPP FLAGS:\n") localCppParameters := parseCompilerParameters(ccModule.flags.Local.CppFlags, ctx, f) translateToCMake(localCppParameters, f, false, true) f.WriteString("\n# GLOBAL SYSTEM INCLUDE FLAGS:\n") globalIncludeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) translateToCMake(globalIncludeParameters, f, true, true) // Add project executable. f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n", Loading