Add target.linux_glibc and target.bionic

target.linux_glibc will apply to host builds with glibc, which is
identical to the current target.linux. In a future change, target.linux
will change to affect all targets using the Linux kernel (android,
linux_bionic, and linux_glibc).

target.bionic will apply to all OS variants using Bionic.

Bug: 31559095
Test: Add target.linux_glibc, target.bionic sections to an Android.bp, build
Test: m host
Change-Id: I677a67c22fba148fec264132311e355283f9d88d
diff --git a/android/androidmk.go b/android/androidmk.go
index 319f711..5ce486d 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -243,7 +243,11 @@
 	}
 
 	if host {
-		fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
+		makeOs := amod.Os().String()
+		if amod.Os() == Linux || amod.Os() == LinuxBionic {
+			makeOs = "linux"
+		}
+		fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", makeOs)
 		fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true")
 	}
 
diff --git a/android/arch.go b/android/arch.go
index 05887a1..3fe0345 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -192,7 +192,7 @@
 	commonTargetMap = make(map[string]Target)
 
 	NoOsType    OsType
-	Linux       = NewOsType("linux", Host, false)
+	Linux       = NewOsType("linux_glibc", Host, false)
 	Darwin      = NewOsType("darwin", Host, false)
 	LinuxBionic = NewOsType("linux_bionic", Host, true)
 	Windows     = NewOsType("windows", HostCross, true)
@@ -242,6 +242,14 @@
 	return os.Name
 }
 
+func (os OsType) Bionic() bool {
+	return os == Android || os == LinuxBionic
+}
+
+func (os OsType) Linux() bool {
+	return os == Android || os == Linux || os == LinuxBionic
+}
+
 func NewOsType(name string, class OsClass, defDisabled bool) OsType {
 	os := OsType{
 		Name:  name,
@@ -459,6 +467,8 @@
 		"Host",
 		"Android64",
 		"Android32",
+		"Bionic",
+		"Linux",
 		"Not_windows",
 		"Arm_on_x86",
 		"Arm_on_x86_64",
@@ -468,6 +478,19 @@
 
 		for _, archType := range osArchTypeMap[os] {
 			targets = append(targets, os.Field+"_"+archType.Name)
+
+			if os == Linux { // TODO(dwillemsen): os.Linux()
+				target := "Linux_" + archType.Name
+				if !inList(target, targets) {
+					targets = append(targets, target)
+				}
+			}
+			if os.Bionic() {
+				target := "Bionic_" + archType.Name
+				if !inList(target, targets) {
+					targets = append(targets, target)
+				}
+			}
 		}
 	}
 
@@ -663,18 +686,47 @@
 			a.appendProperties(ctx, genProps, targetProp, field, prefix)
 		}
 
+		// Handle target OS generalities of the form:
+		// target: {
+		//     bionic: {
+		//         key: value,
+		//     },
+		//     bionic_x86: {
+		//         key: value,
+		//     },
+		// }
+		if os == Linux { // TODO(dwillemsen): os.Linux()
+			field = "Linux"
+			prefix = "target.linux"
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+
+			field = "Linux_" + t.Name
+			prefix = "target.linux_" + t.Name
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+		}
+
+		if os.Bionic() {
+			field = "Bionic"
+			prefix = "target.bionic"
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+
+			field = "Bionic_" + t.Name
+			prefix = "target.bionic_" + t.Name
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+		}
+
 		// Handle target OS properties in the form:
 		// target: {
-		//     linux: {
+		//     linux_glibc: {
 		//         key: value,
 		//     },
 		//     not_windows: {
 		//         key: value,
 		//     },
-		//     linux_x86: {
+		//     linux_glibc_x86: {
 		//         key: value,
 		//     },
-		//     linux_arm: {
+		//     linux_glibc_arm: {
 		//         key: value,
 		//     },
 		//     android {
@@ -687,7 +739,6 @@
 		//         key: value,
 		//     },
 		// },
-		// },
 		field = os.Field
 		prefix = "target." + os.Name
 		a.appendProperties(ctx, genProps, targetProp, field, prefix)
diff --git a/android/paths.go b/android/paths.go
index 9c8e93a..4a49d55 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -714,7 +714,15 @@
 		}
 		outPaths = []string{"target", "product", ctx.AConfig().DeviceName(), partition}
 	} else {
-		outPaths = []string{"host", ctx.Os().String() + "-x86"}
+		switch ctx.Os() {
+		case Linux:
+			outPaths = []string{"host", "linux-x86"}
+		case LinuxBionic:
+			// TODO: should this be a separate top level, or shared with linux-x86?
+			outPaths = []string{"host", "linux_bionic-x86"}
+		default:
+			outPaths = []string{"host", ctx.Os().String() + "-x86"}
+		}
 	}
 	if ctx.Debug() {
 		outPaths = append([]string{"debug"}, outPaths...)