From 10c78c6b97a5a02cd72b6bed0a16a9c7656f0fa3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 20 Jul 2016 12:14:19 -0700 Subject: [PATCH] Rename exported make variables for system headers Add SYSTEM_ to variables that contain headers that are used with -isystem, and split -I and -isystem variables into separate make variables. Also export SRC_HEADERS and SRC_SYSTEM_HEADERS to compare against make. Change-Id: I02097c35d1d5342ebce8311d8878fff33b118adb --- cc/makevars.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/cc/makevars.go b/cc/makevars.go index a4fe0770e..0e75329ef 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -42,6 +42,14 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) + includeFlags, err := ctx.Eval("${commonGlobalIncludes}") + if err != nil { + panic(err) + } + includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) + ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " ")) + ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " ")) + hostTargets := ctx.Config().Targets[android.Host] makeVarsToolchain(ctx, "", hostTargets[0]) if len(hostTargets) > 1 { @@ -115,7 +123,9 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, if err != nil { panic(err) } - ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Replace(includeFlags, "-isystem ", "", -1)) + includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) + ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " ")) + ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " ")) if target.Arch.ArchType == android.Arm { flags, err := toolchain.InstructionSetFlags("arm") @@ -195,3 +205,39 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix()) ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix()) } + +func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) { + flags, err := ctx.Eval(val) + if err != nil { + panic(err) + } + + extract := func(flags string, dirs []string, prefix string) (string, []string, bool) { + if strings.HasPrefix(flags, prefix) { + flags = strings.TrimPrefix(flags, prefix) + flags = strings.TrimLeft(flags, " ") + s := strings.SplitN(flags, " ", 2) + dirs = append(dirs, s[0]) + if len(s) > 1 { + return strings.TrimLeft(s[1], " "), dirs, true + } + return "", dirs, true + } else { + return flags, dirs, false + } + } + + flags = strings.TrimLeft(flags, " ") + for flags != "" { + found := false + flags, includes, found = extract(flags, includes, "-I") + if !found { + flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ") + } + if !found { + panic(fmt.Errorf("Unexpected flag in %q", flags)) + } + } + + return includes, systemIncludes +}