Refactor bionic includes into a single place

Bionic includes are the same on all architectures, modulo
architecture-specific includes.  Use a single function to populate the
list, passing in bionic's and the kernel's names for the architecture.

Also get rid of the ${LibcRoot} variable, it is not providing any value
and makes grepping harder.

Change-Id: I39e7907d312f52dd1378a3937ab1bcba12c4e97f
diff --git a/cc/arm64_device.go b/cc/arm64_device.go
index b951c1a..583da44 100644
--- a/cc/arm64_device.go
+++ b/cc/arm64_device.go
@@ -99,14 +99,7 @@
 	pctx.StaticVariable("arm64Cflags", strings.Join(arm64Cflags, " "))
 	pctx.StaticVariable("arm64Ldflags", strings.Join(arm64Ldflags, " "))
 	pctx.StaticVariable("arm64Cppflags", strings.Join(arm64Cppflags, " "))
-	pctx.StaticVariable("arm64IncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-arm64/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-arm64",
-	}, " "))
+	pctx.StaticVariable("arm64IncludeFlags", bionicHeaders("arm64", "arm64"))
 
 	pctx.StaticVariable("arm64ClangCflags", strings.Join(clangFilterUnknownCflags(arm64Cflags), " "))
 	pctx.StaticVariable("arm64ClangLdflags", strings.Join(clangFilterUnknownCflags(arm64Ldflags), " "))
diff --git a/cc/arm_device.go b/cc/arm_device.go
index e985a38..dc8ba81 100644
--- a/cc/arm_device.go
+++ b/cc/arm_device.go
@@ -168,14 +168,7 @@
 	pctx.StaticVariable("armCflags", strings.Join(armCflags, " "))
 	pctx.StaticVariable("armLdflags", strings.Join(armLdflags, " "))
 	pctx.StaticVariable("armCppflags", strings.Join(armCppflags, " "))
-	pctx.StaticVariable("armIncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-arm/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-arm",
-	}, " "))
+	pctx.StaticVariable("armIncludeFlags", bionicHeaders("arm", "arm"))
 
 	// Extended cflags
 
diff --git a/cc/cc.go b/cc/cc.go
index b5545fc..acc807f 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -70,8 +70,6 @@
 
 var (
 	HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
-
-	LibcRoot = pctx.SourcePathVariable("LibcRoot", "bionic/libc")
 )
 
 // Flags used by lots of devices.  Putting them in package static variables will save bytes in
diff --git a/cc/mips64_device.go b/cc/mips64_device.go
index 19f9caf..a1ec3a2 100644
--- a/cc/mips64_device.go
+++ b/cc/mips64_device.go
@@ -100,14 +100,7 @@
 	pctx.StaticVariable("mips64Cflags", strings.Join(mips64Cflags, " "))
 	pctx.StaticVariable("mips64Ldflags", strings.Join(mips64Ldflags, " "))
 	pctx.StaticVariable("mips64Cppflags", strings.Join(mips64Cppflags, " "))
-	pctx.StaticVariable("mips64IncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-mips64/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-mips",
-	}, " "))
+	pctx.StaticVariable("mips64IncludeFlags", bionicHeaders("mips64", "mips"))
 
 	// Clang cflags
 	pctx.StaticVariable("mips64ClangTriple", "mips64el-linux-android")
diff --git a/cc/mips_device.go b/cc/mips_device.go
index ac6f2b1..0b23d37 100644
--- a/cc/mips_device.go
+++ b/cc/mips_device.go
@@ -137,14 +137,7 @@
 	pctx.StaticVariable("mipsCflags", strings.Join(mipsCflags, " "))
 	pctx.StaticVariable("mipsLdflags", strings.Join(mipsLdflags, " "))
 	pctx.StaticVariable("mipsCppflags", strings.Join(mipsCppflags, " "))
-	pctx.StaticVariable("mipsIncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-mips/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-mips",
-	}, " "))
+	pctx.StaticVariable("mipsIncludeFlags", bionicHeaders("mips", "mips"))
 
 	// Clang cflags
 	pctx.StaticVariable("mipsClangTriple", "mipsel-linux-android")
diff --git a/cc/toolchain.go b/cc/toolchain.go
index 2e2ee5a..89485f8 100644
--- a/cc/toolchain.go
+++ b/cc/toolchain.go
@@ -16,6 +16,7 @@
 
 import (
 	"fmt"
+	"strings"
 
 	"android/soong/android"
 )
@@ -139,3 +140,14 @@
 func (toolchain32Bit) Is64Bit() bool {
 	return false
 }
+
+func bionicHeaders(bionicArch, kernelArch string) string {
+	return strings.Join([]string{
+		"-isystem bionic/libc/arch-" + bionicArch + "/include",
+		"-isystem bionic/libc/include",
+		"-isystem bionic/libc/kernel/uapi",
+		"-isystem bionic/libc/kernel/android/uapi",
+		"-isystem bionic/libc/kernel/common",
+		"-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
+	}, " ")
+}
diff --git a/cc/x86_64_device.go b/cc/x86_64_device.go
index a795ba7..6923f5f 100644
--- a/cc/x86_64_device.go
+++ b/cc/x86_64_device.go
@@ -148,14 +148,7 @@
 	pctx.StaticVariable("x86_64Cflags", strings.Join(x86_64Cflags, " "))
 	pctx.StaticVariable("x86_64Ldflags", strings.Join(x86_64Ldflags, " "))
 	pctx.StaticVariable("x86_64Cppflags", strings.Join(x86_64Cppflags, " "))
-	pctx.StaticVariable("x86_64IncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-x86_64/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-x86",
-	}, " "))
+	pctx.StaticVariable("x86_64IncludeFlags", bionicHeaders("x86_64", "x86"))
 
 	// Clang cflags
 	pctx.StaticVariable("x86_64ClangCflags", strings.Join(clangFilterUnknownCflags(x86_64Cflags), " "))
diff --git a/cc/x86_device.go b/cc/x86_device.go
index 72689fb..ba2f23a 100644
--- a/cc/x86_device.go
+++ b/cc/x86_device.go
@@ -167,14 +167,7 @@
 	pctx.StaticVariable("x86Cflags", strings.Join(x86Cflags, " "))
 	pctx.StaticVariable("x86Ldflags", strings.Join(x86Ldflags, " "))
 	pctx.StaticVariable("x86Cppflags", strings.Join(x86Cppflags, " "))
-	pctx.StaticVariable("x86IncludeFlags", strings.Join([]string{
-		"-isystem ${LibcRoot}/arch-x86/include",
-		"-isystem ${LibcRoot}/include",
-		"-isystem ${LibcRoot}/kernel/uapi",
-		"-isystem ${LibcRoot}/kernel/android/uapi",
-		"-isystem ${LibcRoot}/kernel/common",
-		"-isystem ${LibcRoot}/kernel/uapi/asm-x86",
-	}, " "))
+	pctx.StaticVariable("x86IncludeFlags", bionicHeaders("x86", "x86"))
 
 	// Clang cflags
 	pctx.StaticVariable("x86ClangCflags", strings.Join(clangFilterUnknownCflags(x86ClangCflags), " "))