Add support for binary and static library and prebuilts

Add cc_prebuilt_library_static and cc_prebuilt_binary module types.

Bug: 35576244
Test: Add cc_prebuilt_library_static and cc_prebuilt_binary modules
      and verify they are used
Change-Id: I708ec7b1ed1a0eddae083159575ae04d5ea25a37
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 7deb0ed..08ba145 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -22,6 +22,8 @@
 
 func init() {
 	android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory)
+	android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory)
+	android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
 }
 
 type prebuiltLinkerInterface interface {
@@ -29,17 +31,21 @@
 	prebuilt() *android.Prebuilt
 }
 
-type prebuiltLibraryLinker struct {
-	*libraryDecorator
+type prebuiltLinker struct {
 	android.Prebuilt
 }
 
-var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
-
-func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt {
+func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
 	return &p.Prebuilt
 }
 
+type prebuiltLibraryLinker struct {
+	*libraryDecorator
+	prebuiltLinker
+}
+
+var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
+
 func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
 	props := p.libraryDecorator.linkerProps()
 	return append(props, &p.Prebuilt.Properties)
@@ -61,13 +67,61 @@
 
 func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
 	module, library := NewLibrary(android.HostAndDeviceSupported)
+	library.BuildOnlyShared()
 	module.compiler = nil
 
 	prebuilt := &prebuiltLibraryLinker{
 		libraryDecorator: library,
 	}
 	module.linker = prebuilt
-	module.installer = prebuilt
+
+	return module.Init()
+}
+
+func prebuiltStaticLibraryFactory() (blueprint.Module, []interface{}) {
+	module, library := NewLibrary(android.HostAndDeviceSupported)
+	library.BuildOnlyStatic()
+	module.compiler = nil
+
+	prebuilt := &prebuiltLibraryLinker{
+		libraryDecorator: library,
+	}
+	module.linker = prebuilt
+
+	return module.Init()
+}
+
+type prebuiltBinaryLinker struct {
+	*binaryDecorator
+	prebuiltLinker
+}
+
+var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
+
+func (p *prebuiltBinaryLinker) linkerProps() []interface{} {
+	props := p.binaryDecorator.linkerProps()
+	return append(props, &p.Prebuilt.Properties)
+}
+
+func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
+	flags Flags, deps PathDeps, objs Objects) android.Path {
+	// TODO(ccross): verify shared library dependencies
+	if len(p.Prebuilt.Properties.Srcs) > 0 {
+		// TODO(ccross): .toc optimization, stripping, packing
+		return p.Prebuilt.Path(ctx)
+	}
+
+	return nil
+}
+
+func prebuiltBinaryFactory() (blueprint.Module, []interface{}) {
+	module, binary := NewBinary(android.HostAndDeviceSupported)
+	module.compiler = nil
+
+	prebuilt := &prebuiltBinaryLinker{
+		binaryDecorator: binary,
+	}
+	module.linker = prebuilt
 
 	return module.Init()
 }