mixed builds for cc_static_library without deps

Test: Manual mixed builds testing of `libc` target with manually
migrated "libc_nopthread" and "libc_init_dynamic".

Change-Id: If7d67e95eca9899271b1eeb662c7c2e571f64afa
diff --git a/cc/library.go b/cc/library.go
index 0e6e107..6a3b876 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -230,6 +230,7 @@
 	module, library := NewLibrary(android.HostAndDeviceSupported)
 	library.BuildOnlyStatic()
 	module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
+	module.bazelHandler = &staticLibraryBazelHandler{module: module}
 	return module.Init()
 }
 
@@ -406,6 +407,49 @@
 	collectedSnapshotHeaders android.Paths
 }
 
+type staticLibraryBazelHandler struct {
+	bazelHandler
+
+	module *Module
+}
+
+func (handler *staticLibraryBazelHandler) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
+	bazelCtx := ctx.Config().BazelContext
+	outputPaths, objPaths, ok := bazelCtx.GetAllFilesAndCcObjectFiles(label, ctx.Arch().ArchType)
+	if ok {
+		if len(outputPaths) != 1 {
+			// TODO(cparsons): This is actually expected behavior for static libraries with no srcs.
+			// We should support this.
+			ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, objPaths)
+			return false
+		}
+		outputFilePath := android.PathForBazelOut(ctx, outputPaths[0])
+		handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
+
+		objFiles := make(android.Paths, len(objPaths))
+		for i, objPath := range objPaths {
+			objFiles[i] = android.PathForBazelOut(ctx, objPath)
+		}
+		objects := Objects{
+			objFiles: objFiles,
+		}
+
+		ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
+			StaticLibrary: outputFilePath,
+			ReuseObjects:  objects,
+			Objects:       objects,
+
+			// TODO(cparsons): Include transitive static libraries in this provider to support
+			// static libraries with deps.
+			TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
+				Direct(outputFilePath).
+				Build(),
+		})
+		handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
+	}
+	return ok
+}
+
 // collectHeadersForSnapshot collects all exported headers from library.
 // It globs header files in the source tree for exported include directories,
 // and tracks generated header files separately.