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
This commit is contained in:
Colin Cross
2016-12-13 12:50:57 -08:00
parent ab3b7323c4
commit 5950f3827c
3 changed files with 49 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ func init() {
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 @@ func libraryHostSharedFactory() (blueprint.Module, []interface{}) {
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) compilerFlags(ctx ModuleContext, flags Flags) F
}
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 @@ func (library *libraryDecorator) BuildOnlyShared() {
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)