From c31994825a4846382147931022b2fcd2654e16f6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 30 Mar 2017 15:03:04 -0700 Subject: [PATCH] Fix include order Include order should be module includes, dependency exported includes, and then global includes. Module includes and global includes are computed during compileFlags, but dependency exported includes are not handled until later. Move the global includes into a new flags variable so that the dependency includes can be appended to the module includes. Test: m -j native Change-Id: Ifc3894f0a898a070d6da8eed4f4b9e8cc0cd2523 --- cc/builder.go | 24 +++++++++++++++++++++--- cc/cc.go | 4 ++++ cc/cmakelists.go | 8 ++++++-- cc/compiler.go | 10 +++++----- cc/util.go | 2 ++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/cc/builder.go b/cc/builder.go index cdfea92df..0694cb7dd 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -201,6 +201,8 @@ type builderFlags struct { tidy bool coverage bool + systemIncludeFlags string + groupStaticLibs bool stripKeepSymbols bool @@ -244,9 +246,25 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and coverageFiles = make(android.Paths, 0, len(srcFiles)) } - cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags - cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags - asflags := flags.globalFlags + " " + flags.asFlags + cflags := strings.Join([]string{ + flags.globalFlags, + flags.systemIncludeFlags, + flags.cFlags, + flags.conlyFlags, + }, " ") + + cppflags := strings.Join([]string{ + flags.globalFlags, + flags.systemIncludeFlags, + flags.cFlags, + flags.cppFlags, + }, " ") + + asflags := strings.Join([]string{ + flags.globalFlags, + flags.systemIncludeFlags, + flags.asFlags, + }, " ") if flags.clang { cflags += " ${config.NoOverrideClangGlobalCflags}" diff --git a/cc/cc.go b/cc/cc.go index 84afa733d..b107d015e 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -109,6 +109,10 @@ type Flags struct { TidyFlags []string // Flags that apply to clang-tidy 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. + SystemIncludeFlags []string + Toolchain config.Toolchain Clang bool Tidy bool diff --git a/cc/cmakelists.go b/cc/cmakelists.go index e0192e767..4df9ece9b 100644 --- a/cc/cmakelists.go +++ b/cc/cmakelists.go @@ -5,11 +5,12 @@ import ( "android/soong/android" "android/soong/cc/config" - "github.com/google/blueprint" "os" "path" "path/filepath" "strings" + + "github.com/google/blueprint" ) // This singleton generates CMakeLists.txt files. It does so for each blueprint Android.bp resulting in a cc.Module @@ -162,6 +163,10 @@ func generateCLionProject(compiledModule CompiledInterface, ctx blueprint.Single cppParameters := parseCompilerParameters(ccModule.flags.CppFlags, ctx, f) translateToCMake(cppParameters, f, false, true) + f.WriteString("\n# SYSTEM INCLUDE FLAGS:\n") + includeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) + translateToCMake(includeParameters, f, true, true) + // Add project executable. f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n", cleanExecutableName(ccModule.ModuleBase.Name()))) @@ -171,7 +176,6 @@ func cleanExecutableName(s string) string { return strings.Replace(s, "@", "-", -1) } - func translateToCMake(c compilerParameters, f *os.File, cflags bool, cppflags bool) { writeAllIncludeDirectories(c.systemHeaderSearchPath, f, true) writeAllIncludeDirectories(c.headerSearchPath, f, false) diff --git a/cc/compiler.go b/cc/compiler.go index 84ee65209..91eda3884 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -194,15 +194,15 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag } if !ctx.noDefaultCompilerFlags() { + flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) + if !(ctx.sdk() || ctx.vndk()) || ctx.Host() { - flags.GlobalFlags = append(flags.GlobalFlags, + flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "${config.CommonGlobalIncludes}", "${config.CommonGlobalSystemIncludes}", tc.IncludeFlags(), "${config.CommonNativehelperInclude}") } - - flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) } if ctx.sdk() || ctx.vndk() { @@ -210,7 +210,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag // typical Soong approach would be to only make the headers for the // library you're using available, we're trying to emulate the NDK // behavior here, and the NDK always has all the NDK headers available. - flags.GlobalFlags = append(flags.GlobalFlags, + flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+getCurrentIncludePath(ctx).String(), "-isystem "+getCurrentIncludePath(ctx).Join(ctx, tc.ClangTriple()).String()) @@ -230,7 +230,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag legacyIncludes := fmt.Sprintf( "prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/include", ctx.sdkVersion(), ctx.Arch().ArchType.String()) - flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+legacyIncludes) + flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+legacyIncludes) } instructionSet := compiler.Properties.Instruction_set diff --git a/cc/util.go b/cc/util.go index 919e14c7e..36d8dd269 100644 --- a/cc/util.go +++ b/cc/util.go @@ -105,6 +105,8 @@ func flagsToBuilderFlags(in Flags) builderFlags { coverage: in.Coverage, tidy: in.Tidy, + systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "), + groupStaticLibs: in.GroupStaticLibs, } }