Revert "Simplify arch target handling"

This reverts commit 6713fb26cbcadf525cd75e47d7d0cbc23d282b3e.

Change-Id: Ic473cea2563b0b37dc08b0bc5d3a0ac8c4b6afe6
diff --git a/cc/cc.go b/cc/cc.go
index 3cc0d0d..bac3e88 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -118,7 +118,7 @@
 )
 
 func init() {
-	if android.BuildOs == android.Linux {
+	if android.CurrentHostType() == android.Linux {
 		commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
 	}
 
@@ -729,10 +729,11 @@
 func (c *Module) toolchain(ctx BaseModuleContext) Toolchain {
 	if c.cachedToolchain == nil {
 		arch := ctx.Arch()
-		os := ctx.Os()
-		factory := toolchainFactories[os][arch.ArchType]
+		hod := ctx.HostOrDevice()
+		ht := ctx.HostType()
+		factory := toolchainFactories[hod][ht][arch.ArchType]
 		if factory == nil {
-			ctx.ModuleErrorf("Toolchain not found for %s arch %q", os.String(), arch.String())
+			ctx.ModuleErrorf("Toolchain not found for %s %s arch %q", hod.String(), ht.String(), arch.String())
 			return nil
 		}
 		c.cachedToolchain = factory(arch)
@@ -904,13 +905,8 @@
 			return
 		}
 
-		if a.Target().Os != ctx.Os() {
-			ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
-			return
-		}
-
-		if a.Target().Arch.ArchType != ctx.Arch().ArchType {
-			ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
+		if a.HostOrDevice() != ctx.HostOrDevice() {
+			ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), name)
 			return
 		}
 
@@ -1085,11 +1081,6 @@
 		flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
 	}
 
-	hod := "host"
-	if ctx.Os().Class == android.Device {
-		hod = "device"
-	}
-
 	if !ctx.noDefaultCompilerFlags() {
 		flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
 
@@ -1099,7 +1090,7 @@
 			flags.GlobalFlags = append(flags.GlobalFlags,
 				toolchain.ClangCflags(),
 				"${commonClangGlobalCflags}",
-				fmt.Sprintf("${%sClangGlobalCflags}", hod))
+				fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
 
 			flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
 		} else {
@@ -1107,7 +1098,7 @@
 			flags.GlobalFlags = append(flags.GlobalFlags,
 				toolchain.Cflags(),
 				"${commonGlobalCflags}",
-				fmt.Sprintf("${%sGlobalCflags}", hod))
+				fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
 		}
 
 		if Bool(ctx.AConfig().ProductVariables.Brillo) {
@@ -1419,7 +1410,7 @@
 	// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
 	// all code is position independent, and then those warnings get promoted to
 	// errors.
-	if ctx.Os() != android.Windows {
+	if ctx.HostType() != android.Windows {
 		flags.CFlags = append(flags.CFlags, "-fPIC")
 	}
 
@@ -1872,7 +1863,7 @@
 
 	static := Bool(binary.Properties.Static_executable)
 	if ctx.Host() {
-		if ctx.Os() == android.Linux {
+		if ctx.HostType() == android.Linux {
 			if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) {
 				static = true
 			}
@@ -1892,7 +1883,7 @@
 
 	if ctx.Host() && !binary.staticBinary() {
 		flags.LdFlags = append(flags.LdFlags, "-pie")
-		if ctx.Os() == android.Windows {
+		if ctx.HostType() == android.Windows {
 			flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup")
 		}
 	}
@@ -1900,7 +1891,7 @@
 	// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
 	// all code is position independent, and then those warnings get promoted to
 	// errors.
-	if ctx.Os() != android.Windows {
+	if ctx.HostType() != android.Windows {
 		flags.CFlags = append(flags.CFlags, "-fpie")
 	}
 
@@ -1954,7 +1945,7 @@
 	fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
 	outputFile := android.PathForModuleOut(ctx, fileName)
 	ret := outputFile
-	if ctx.Os().Class == android.Host {
+	if ctx.HostOrDevice().Host() {
 		binary.hostToolPath = android.OptionalPathForPath(outputFile)
 	}
 
@@ -2061,7 +2052,7 @@
 	if ctx.Host() {
 		flags.CFlags = append(flags.CFlags, "-O0", "-g")
 
-		switch ctx.Os() {
+		switch ctx.HostType() {
 		case android.Windows:
 			flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
 		case android.Linux: