Revert "Use soong_cc_prebuilt.mk instead of prebuilt.mk for Soong cc modules"

This reverts commit e2874cd99d574de49d34f8987a0af64331c7ad6e.

Reason for revert: broke mac builds
Bug: 113936524

Change-Id: Id0311d6b202b18e80953da632133548d56ed851a
diff --git a/cc/androidmk.go b/cc/androidmk.go
index bb82529..9258bd4 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -60,17 +60,24 @@
 	ret := android.AndroidMkData{
 		OutputFile: c.outputFile,
 		Required:   c.Properties.AndroidMkRuntimeLibs,
-		Include:    "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
 
 		Extra: []android.AndroidMkExtraFunc{
 			func(w io.Writer, outputFile android.Path) {
 				if len(c.Properties.Logtags) > 0 {
 					fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(c.Properties.Logtags, " "))
 				}
+				fmt.Fprintln(w, "LOCAL_SANITIZE := never")
 				if len(c.Properties.AndroidMkSharedLibs) > 0 {
 					fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
 				}
-				fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.getMakeLinkType())
+				if c.Target().Os == android.Android &&
+					String(c.Properties.Sdk_version) != "" && !c.useVndk() && !c.inRecovery() {
+					fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+String(c.Properties.Sdk_version))
+					fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
+				} else {
+					// These are already included in LOCAL_SHARED_LIBRARIES
+					fmt.Fprintln(w, "LOCAL_CXX_STL := none")
+				}
 				if c.useVndk() {
 					fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
 				}
@@ -133,13 +140,44 @@
 	if library.static() {
 		ret.Class = "STATIC_LIBRARIES"
 	} else if library.shared() {
+		ctx.subAndroidMk(ret, &library.stripper)
+
 		ret.Class = "SHARED_LIBRARIES"
-		ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
-			fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", library.toc().String())
-			fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
-		})
 	} else if library.header() {
-		ret.Class = "HEADER_LIBRARIES"
+		ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
+			fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
+			fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
+			fmt.Fprintln(w, "LOCAL_MODULE :=", name+data.SubName)
+
+			archStr := ctx.Target().Arch.ArchType.String()
+			var host bool
+			switch ctx.Target().Os.Class {
+			case android.Host:
+				fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH := ", archStr)
+				host = true
+			case android.HostCross:
+				fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH := ", archStr)
+				host = true
+			case android.Device:
+				fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH := ", archStr)
+			}
+
+			if host {
+				makeOs := ctx.Target().Os.String()
+				if ctx.Target().Os == android.Linux || ctx.Target().Os == android.LinuxBionic {
+					makeOs = "linux"
+				}
+				fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
+				fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
+			} else if ctx.useVndk() {
+				fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
+			}
+
+			library.androidMkWriteExportedFlags(w)
+			fmt.Fprintln(w, "include $(BUILD_HEADER_LIBRARY)")
+		}
+
+		return
 	}
 
 	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
@@ -157,6 +195,8 @@
 
 		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
 
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
+
 		if library.coverageOutputFile.Valid() {
 			fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
 		}
@@ -164,10 +204,6 @@
 
 	if library.shared() {
 		ctx.subAndroidMk(ret, library.baseInstaller)
-	} else {
-		ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
-			fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
-		})
 	}
 }
 
@@ -182,10 +218,15 @@
 
 func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	ctx.subAndroidMk(ret, binary.baseInstaller)
+	ctx.subAndroidMk(ret, &binary.stripper)
 
 	ret.Class = "EXECUTABLES"
 	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
-		fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
+		if Bool(binary.Properties.Static_executable) {
+			fmt.Fprintln(w, "LOCAL_FORCE_STATIC_EXECUTABLE := true")
+		}
+
 		if len(binary.symlinks) > 0 {
 			fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
 		}
@@ -246,6 +287,25 @@
 	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
 		_, suffix, _ := splitFileExt(outputFile.Base())
 		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
+	})
+}
+
+func (stripper *stripper) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+	// Make only supports stripping target modules
+	if ctx.Target().Os != android.Android {
+		return
+	}
+
+	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+		if Bool(stripper.StripProperties.Strip.None) {
+
+			fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
+		} else if Bool(stripper.StripProperties.Strip.Keep_symbols) {
+			fmt.Fprintln(w, "LOCAL_STRIP_MODULE := keep_symbols")
+		} else {
+			fmt.Fprintln(w, "LOCAL_STRIP_MODULE := mini-debug-info")
+		}
 	})
 }
 
@@ -273,6 +333,7 @@
 	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
 		path, file := filepath.Split(c.installPath.String())
 		stem, suffix, _ := splitFileExt(file)
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
 		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
 		fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
 		fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
@@ -294,9 +355,11 @@
 		_, _, ext := splitFileExt(outputFile.Base())
 
 		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
+		fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
 		fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
 		fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
-		fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", c.toc().String())
+		fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
 	})
 }
 
@@ -311,6 +374,9 @@
 		path := c.path.RelPathString()
 		dir, file := filepath.Split(path)
 		stem, suffix, ext := splitFileExt(file)
+		fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
+		fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
 		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
 		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
 		fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
@@ -338,6 +404,8 @@
 		_, _, ext := splitFileExt(outputFile.Base())
 
 		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
+		fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
+		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
 		fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
 		fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
 	})
diff --git a/cc/binary.go b/cc/binary.go
index 6352ba1..be79032 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -78,9 +78,6 @@
 
 	toolPath android.OptionalPath
 
-	// Location of the linked, unstripped binary
-	unstrippedOutputFile android.Path
-
 	// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
 	symlinks []string
 
@@ -309,8 +306,6 @@
 		binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
 	}
 
-	binary.unstrippedOutputFile = outputFile
-
 	if String(binary.Properties.Prefix_symbols) != "" {
 		afterPrefixSymbols := outputFile
 		outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName)
diff --git a/cc/cc.go b/cc/cc.go
index 188a1cc..358bff6 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1177,7 +1177,7 @@
 		// We can be permissive with the system "STL" since it is only the C++
 		// ABI layer, but in the future we should make sure that everyone is
 		// using either libc++ or nothing.
-	} else if getNdkStlFamily(from) != getNdkStlFamily(to) {
+	} else if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
 		ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
 			from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
 			to.stl.Properties.SelectedStl)
@@ -1487,29 +1487,6 @@
 	return false
 }
 
-func (c *Module) getMakeLinkType() string {
-	if c.useVndk() {
-		if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
-			if inList(c.Name(), vndkPrivateLibraries) {
-				return "native:vndk_private"
-			} else {
-				return "native:vndk"
-			}
-		} else {
-			return "native:vendor"
-		}
-	} else if c.inRecovery() {
-		return "native:recovery"
-	} else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
-		return "native:ndk:none:none"
-		// TODO(b/114741097): use the correct ndk stl once build errors have been fixed
-		//family, link := getNdkStlFamilyAndLinkType(c)
-		//return fmt.Sprintf("native:ndk:%s:%s", family, link)
-	} else {
-		return "native:platform"
-	}
-}
-
 //
 // Defaults
 //
diff --git a/cc/library.go b/cc/library.go
index 7330e3f..7886c35 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -237,9 +237,6 @@
 	// not included in the NDK.
 	ndkSysrootPath android.Path
 
-	// Location of the linked, unstripped library for shared libraries
-	unstrippedOutputFile android.Path
-
 	// Decorated interafaces
 	*baseCompiler
 	*baseLinker
@@ -567,8 +564,6 @@
 		library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
 	}
 
-	library.unstrippedOutputFile = outputFile
-
 	if Bool(library.baseLinker.Properties.Use_version_lib) && ctx.Host() {
 		versionedOutputFile := outputFile
 		outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index c23dfd4..6e64acf 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -172,7 +172,6 @@
 		libraryDecorator: library,
 	}
 	stub.Properties.Vendor_available = BoolPtr(true)
-	module.Properties.UseVndk = true
 	module.compiler = stub
 	module.linker = stub
 	module.installer = nil
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 42d680a..d6018eb 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -82,7 +82,6 @@
 		in := p.Prebuilt.SingleSourcePath(ctx)
 
 		if p.shared() {
-			p.unstrippedOutputFile = in
 			libName := ctx.baseModuleName() + flags.Toolchain.ShlibSuffix()
 			if p.needsStrip(ctx) {
 				stripped := android.PathForModuleOut(ctx, "stripped", libName)
@@ -163,8 +162,6 @@
 		fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
 		in := p.Prebuilt.SingleSourcePath(ctx)
 
-		p.unstrippedOutputFile = in
-
 		if p.needsStrip(ctx) {
 			stripped := android.PathForModuleOut(ctx, "stripped", fileName)
 			p.strip(ctx, in, stripped, builderFlags)
diff --git a/cc/stl.go b/cc/stl.go
index 5c69948..6f63835 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -19,24 +19,18 @@
 	"fmt"
 )
 
-func getNdkStlFamily(m *Module) string {
-	family, _ := getNdkStlFamilyAndLinkType(m)
-	return family
-}
-
-func getNdkStlFamilyAndLinkType(m *Module) (string, string) {
+func getNdkStlFamily(ctx android.ModuleContext, m *Module) string {
 	stl := m.stl.Properties.SelectedStl
 	switch stl {
-	case "ndk_libc++_shared":
-		return "libc++", "shared"
-	case "ndk_libc++_static":
-		return "libc++", "static"
+	case "ndk_libc++_shared", "ndk_libc++_static":
+		return "libc++"
 	case "ndk_system":
-		return "system", "shared"
+		return "system"
 	case "":
-		return "none", "none"
+		return "none"
 	default:
-		panic(fmt.Errorf("stl: %q is not a valid STL", stl))
+		ctx.ModuleErrorf("stl: %q is not a valid STL", stl)
+		return ""
 	}
 }
 
diff --git a/cc/strip.go b/cc/strip.go
index 02397f4..ec2450a 100644
--- a/cc/strip.go
+++ b/cc/strip.go
@@ -31,8 +31,7 @@
 }
 
 func (stripper *stripper) needsStrip(ctx ModuleContext) bool {
-	// TODO(ccross): enable host stripping when embedded in make?  Make never had support for stripping host binaries.
-	return (!ctx.Config().EmbeddedInMake() || ctx.Device()) && !Bool(stripper.StripProperties.Strip.None)
+	return !ctx.Config().EmbeddedInMake() && !Bool(stripper.StripProperties.Strip.None)
 }
 
 func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android.ModuleOutPath,
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index 2d7274d..849bb3f 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -149,7 +149,6 @@
 	module.stl = nil
 	module.sanitize = nil
 	library.StripProperties.Strip.None = BoolPtr(true)
-	module.Properties.UseVndk = true
 
 	prebuilt := &vndkPrebuiltLibraryDecorator{
 		libraryDecorator: library,