Support explicit header-only libraries

To date we have been using static libraries with no source files as
header-only libraries.  Switch to using header_libs to make the user's
expectations clear, in case we need to differentiate the semantics of
static libraries and header-only libraries when we enable transitive
static library dependencies.

Test: mma -j external/llvm
Change-Id: I3ce16df11076b637bd192880e86ec9027738b9e7
diff --git a/cc/library.go b/cc/library.go
index 5ba1a97..666c47a 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -90,6 +90,7 @@
 	android.RegisterModuleType("cc_library", libraryFactory)
 	android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
 	android.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
+	android.RegisterModuleType("cc_library_headers", libraryHeaderFactory)
 }
 
 // Module factory for combined static + shared libraries, device by default but with possible host
@@ -127,6 +128,13 @@
 	return module.Init()
 }
 
+// Module factory for header-only libraries
+func libraryHeaderFactory() (blueprint.Module, []interface{}) {
+	module, library := NewLibrary(android.HostAndDeviceSupported)
+	library.HeaderOnly()
+	return module.Init()
+}
+
 type flagExporter struct {
 	Properties FlagExporterProperties
 
@@ -271,6 +279,19 @@
 }
 
 func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
+	if !library.buildShared() && !library.buildStatic() {
+		if len(library.baseCompiler.Properties.Srcs) > 0 {
+			ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs")
+		}
+		if len(library.Properties.Static.Srcs) > 0 {
+			ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs")
+		}
+		if len(library.Properties.Shared.Srcs) > 0 {
+			ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs")
+		}
+		return Objects{}
+	}
+
 	objs := library.baseCompiler.compile(ctx, flags, deps)
 	library.reuseObjects = objs
 	buildFlags := flagsToBuilderFlags(flags)
@@ -574,6 +595,11 @@
 	library.Properties.BuildStatic = false
 }
 
+func (library *libraryDecorator) HeaderOnly() {
+	library.Properties.BuildShared = false
+	library.Properties.BuildStatic = false
+}
+
 func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
 	module := newModule(hod, android.MultilibBoth)