Initial prebuilt support

Support prebuilt shared libraries as an initial proof-of-concept of
prebuilts.  Future changes will support binaries and static libraries,
and the ability to select which to use based on something besides
blueprint properties.

Test: TestPrebuilts run during m -j
Change-Id: I6e84da667e9005ae11844bad01d25cbe4ced1ce3
diff --git a/cc/cc.go b/cc/cc.go
index b51e13c..529a329 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -19,7 +19,6 @@
 // is handled in builder.go
 
 import (
-	"fmt"
 	"strconv"
 	"strings"
 
@@ -146,6 +145,7 @@
 	sdk() bool
 	sdkVersion() string
 	selectedStl() string
+	baseModuleName() string
 }
 
 type ModuleContext interface {
@@ -354,6 +354,10 @@
 	return ""
 }
 
+func (ctx *moduleContextImpl) baseModuleName() string {
+	return ctx.mod.ModuleBase.BaseModuleName()
+}
+
 func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
 	return &Module{
 		hod:      hod,
@@ -368,6 +372,21 @@
 	return module
 }
 
+func (c *Module) Prebuilt() *android.Prebuilt {
+	if p, ok := c.linker.(prebuiltLinkerInterface); ok {
+		return p.prebuilt()
+	}
+	return nil
+}
+
+func (c *Module) Name() string {
+	name := c.ModuleBase.Name()
+	if p, ok := c.linker.(prebuiltLinkerInterface); ok {
+		name = p.Name(name)
+	}
+	return name
+}
+
 func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
 	ctx := &moduleContext{
 		ModuleContext: actx,
@@ -434,12 +453,12 @@
 			return
 		}
 		c.outputFile = android.OptionalPathForPath(outputFile)
+	}
 
-		if c.installer != nil && !c.Properties.PreventInstall {
-			c.installer.install(ctx, outputFile)
-			if ctx.Failed() {
-				return
-			}
+	if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
+		c.installer.install(ctx, c.outputFile.Path())
+		if ctx.Failed() {
+			return
 		}
 	}
 }
@@ -792,11 +811,6 @@
 			return
 		}
 
-		if !cc.outputFile.Valid() {
-			ctx.ModuleErrorf("module %q missing output file", name)
-			return
-		}
-
 		if tag == reuseObjTag {
 			depPaths.ObjFiles = append(depPaths.ObjFiles,
 				cc.compiler.(libraryInterface).reuseObjs()...)
@@ -861,11 +875,13 @@
 			depPaths.CrtBegin = linkFile
 		case crtEndDepTag:
 			depPaths.CrtEnd = linkFile
-		default:
-			panic(fmt.Errorf("unknown dependency tag: %s", tag))
 		}
 
 		if ptr != nil {
+			if !linkFile.Valid() {
+				ctx.ModuleErrorf("module %q missing output file", name)
+				return
+			}
 			*ptr = append(*ptr, linkFile.Path())
 		}