Merge "Make all soong modules optional when building in make"
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index c45b3f4..31eb6cc 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -80,6 +80,7 @@
 	"LOCAL_C_INCLUDES":            {localIncludeDirs},
 	"LOCAL_EXPORT_C_INCLUDE_DIRS": {exportIncludeDirs},
 	"LOCAL_MODULE_STEM":           {stem},
+	"LOCAL_MODULE_HOST_OS":        {hostOs},
 }
 
 func localAbsPath(value bpparser.Value) (*bpparser.Value, error) {
@@ -267,6 +268,46 @@
 	return setVariable(file, appendVariable, prefix, varName, val, true)
 }
 
+func hostOs(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
+	val, err := makeVariableToBlueprint(file, value, bpparser.List)
+	if err != nil {
+		return err
+	}
+
+	inList := func(s string) bool {
+		for _, v := range val.ListValue {
+			if v.StringValue == s {
+				return true
+			}
+		}
+		return false
+	}
+
+	falseValue := &bpparser.Value{
+		Type:      bpparser.Bool,
+		BoolValue: false,
+	}
+
+	trueValue := &bpparser.Value{
+		Type:      bpparser.Bool,
+		BoolValue: true,
+	}
+
+	if inList("windows") {
+		err = setVariable(file, appendVariable, "target.windows", "enabled", trueValue, true)
+	}
+
+	if !inList("linux") && err == nil {
+		err = setVariable(file, appendVariable, "target.linux", "enabled", falseValue, true)
+	}
+
+	if !inList("darwin") && err == nil {
+		err = setVariable(file, appendVariable, "target.darwin", "enabled", falseValue, true)
+	}
+
+	return err
+}
+
 var deleteProperties = map[string]struct{}{
 	"LOCAL_CPP_EXTENSION": struct{}{},
 }
diff --git a/common/androidmk.go b/common/androidmk.go
index 9470b6b..7006bb9 100644
--- a/common/androidmk.go
+++ b/common/androidmk.go
@@ -185,6 +185,10 @@
 		amod := m.(AndroidModule).base()
 		data := provider.AndroidMk()
 
+		if !amod.Enabled() {
+			return
+		}
+
 		arch := amod.commonProperties.CompileArch
 
 		prefix := ""
diff --git a/common/arch.go b/common/arch.go
index 37f7c38..1d7d0de 100644
--- a/common/arch.go
+++ b/common/arch.go
@@ -581,7 +581,7 @@
 	return m, allProperties
 }
 
-var dashToUnderscoreReplacer = strings.NewReplacer("-", "_")
+var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
 
 func (a *AndroidModuleBase) appendProperties(ctx AndroidBottomUpMutatorContext,
 	dst, src interface{}, field, srcPrefix string) interface{} {
@@ -660,7 +660,7 @@
 		//         key: value,
 		//     },
 		// },
-		v := dashToUnderscoreReplacer.Replace(arch.ArchVariant)
+		v := variantReplacer.Replace(arch.ArchVariant)
 		if v != "" {
 			field := proptools.FieldNameForProperty(v)
 			prefix := "arch." + t.Name + "." + v
@@ -673,7 +673,7 @@
 		//         key: value,
 		//     },
 		// },
-		c := dashToUnderscoreReplacer.Replace(arch.CpuVariant)
+		c := variantReplacer.Replace(arch.CpuVariant)
 		if c != "" {
 			field := proptools.FieldNameForProperty(c)
 			prefix := "arch." + t.Name + "." + c