Updates from make

Contains equivalent changes for:

  561b4c1 Set mcpu targets based on cpu variant.
  6a66a88 Stop encoding absolute paths in symbols
  63e3b02 Enable color output from gcc and clang
  eb3e3fa Use exported includes for libc++.
  3a0a891 Link libgtest_main before libgtest

Change-Id: I45a06c02e9af1d40f0c52f1e6a20d6cd382a27fb
diff --git a/cc/arm_device.go b/cc/arm_device.go
index 15f0913..ce8a1cb 100644
--- a/cc/arm_device.go
+++ b/cc/arm_device.go
@@ -199,12 +199,14 @@
 	}
 
 	armCpuVariantCflagsVar = map[string]string{
-		"":           "",
-		"cortex-a7":  "${armCortexA7Cflags}",
-		"cortex-a8":  "${armCortexA8Cflags}",
-		"cortex-a15": "${armCortexA15Cflags}",
-		"krait":      "${armCortexA15Cflags}",
-		"denver":     "${armCortexA15Cflags}",
+		"":               "",
+		"cortex-a7":      "${armCortexA7Cflags}",
+		"cortex-a8":      "${armCortexA8Cflags}",
+		"cortex-a15":     "${armCortexA15Cflags}",
+		"cortex-a53":     "${armCortexA7Cflags}",
+		"cortex-a53.a57": "${armCortexA7Cflags}",
+		"krait":          "${armCortexA15Cflags}",
+		"denver":         "${armCortexA15Cflags}",
 	}
 
 	armClangArchVariantCflagsVar = map[string]string{
@@ -214,12 +216,14 @@
 	}
 
 	armClangCpuVariantCflagsVar = map[string]string{
-		"":           "",
-		"cortex-a7":  "${armClangCortexA7Cflags}",
-		"cortex-a8":  "${armClangCortexA8Cflags}",
-		"cortex-a15": "${armClangCortexA15Cflags}",
-		"krait":      "${armClangKraitCflags}",
-		"denver":     "${armClangCortexA15Cflags}",
+		"":               "",
+		"cortex-a7":      "${armClangCortexA7Cflags}",
+		"cortex-a8":      "${armClangCortexA8Cflags}",
+		"cortex-a15":     "${armClangCortexA15Cflags}",
+		"cortex-a53":     "${armClangCortexA7Cflags}",
+		"cortex-a53.a57": "${armClangCortexA7Cflags}",
+		"krait":          "${armClangKraitCflags}",
+		"denver":         "${armClangCortexA15Cflags}",
 	}
 )
 
diff --git a/cc/builder.go b/cc/builder.go
index 9c9bddd..f217082 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -44,10 +44,10 @@
 		blueprint.RuleParams{
 			Depfile:     "${out}.d",
 			Deps:        blueprint.DepsGCC,
-			Command:     "$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
+			Command:     "$relPwd $ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
 			Description: "cc $out",
 		},
-		"ccCmd", "cFlags")
+		"relPwd", "ccCmd", "cFlags")
 
 	ld = pctx.StaticRule("ld",
 		blueprint.RuleParams{
@@ -128,6 +128,15 @@
 	srcRoot := ctx.AConfig().SrcDir()
 	intermediatesRoot := ctx.AConfig().IntermediatesDir()
 
+	// We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the
+	// debug output. That way two builds in two different directories will
+	// create the same output.
+	relPwd := "PWD=/proc/self/cwd"
+	if ctx.Darwin() {
+		// /proc doesn't exist on Darwin
+		relPwd = ""
+	}
+
 	objFiles = make([]string, len(srcFiles))
 	objDir := common.ModuleObjDir(ctx)
 	if subdir != "" {
@@ -200,6 +209,7 @@
 			Args: map[string]string{
 				"cFlags": moduleCflags,
 				"ccCmd":  ccCmd,
+				"relPwd": relPwd,
 			},
 		})
 	}
diff --git a/cc/cc.go b/cc/cc.go
index 147559e..2278ec0 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -79,6 +79,8 @@
 		"-Wno-unused",
 		"-Winit-self",
 		"-Wpointer-arith",
+		"-fdiagnostics-color",
+		"-fdebug-prefix-map=/proc/self/cwd=",
 
 		// COMMON_RELEASE_CFLAGS
 		"-DNDEBUG",
@@ -838,7 +840,6 @@
 	switch stl {
 	case "libc++", "libc++_static":
 		flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
-		flags.CFlags = append(flags.CFlags, "-I${SrcDir}/external/libcxx/include")
 		if ctx.Host() {
 			flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
 			flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
@@ -1551,7 +1552,7 @@
 }
 
 func (c *CCTest) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
-	depNames.StaticLibs = append(depNames.StaticLibs, "libgtest", "libgtest_main")
+	depNames.StaticLibs = append(depNames.StaticLibs, "libgtest_main", "libgtest")
 	depNames = c.CCBinary.depNames(ctx, depNames)
 	return depNames
 }
diff --git a/cc/clang.go b/cc/clang.go
index 92061f3..6762247 100644
--- a/cc/clang.go
+++ b/cc/clang.go
@@ -6,7 +6,7 @@
 )
 
 // Cflags that should be filtered out when compiling with clang
-var clangUnknownCflags = []string{
+var clangUnknownCflags = sorted([]string{
 	"-finline-functions",
 	"-finline-limit=64",
 	"-fno-canonical-system-headers",
@@ -30,6 +30,8 @@
 	"-Wno-unused-local-typedefs",
 	"-Wunused-but-set-parameter",
 	"-Wunused-but-set-variable",
+	"-fdiagnostics-color",
+	"-fdebug-prefix-map=/proc/self/cwd=",
 
 	// arm + arm64 + mips + mips64
 	"-fgcse-after-reload",
@@ -61,11 +63,9 @@
 	"-fno-inline-functions-called-once",
 	"-mfpmath=sse",
 	"-mbionic",
-}
+})
 
 func init() {
-	sort.Strings(clangUnknownCflags)
-
 	pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
 		"-D__compiler_offsetof=__builtin_offsetof",
 
@@ -88,6 +88,10 @@
 		// Disable -Winconsistent-missing-override until we can clean up the existing
 		// codebase for it.
 		"-Wno-inconsistent-missing-override",
+
+		// Force clang to always output color diagnostics. Ninja will strip the ANSI
+		// color codes if it is not running in a terminal.
+		"-fcolor-diagnostics",
 	}, " "))
 
 	pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
@@ -120,3 +124,8 @@
 	}
 	return false
 }
+
+func sorted(list []string) []string {
+	sort.Strings(list)
+	return list
+}