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:
15
cc/cc.go
15
cc/cc.go
@@ -54,8 +54,9 @@ func init() {
|
|||||||
type Deps struct {
|
type Deps struct {
|
||||||
SharedLibs, LateSharedLibs []string
|
SharedLibs, LateSharedLibs []string
|
||||||
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
||||||
|
HeaderLibs []string
|
||||||
|
|
||||||
ReexportSharedLibHeaders, ReexportStaticLibHeaders []string
|
ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
|
||||||
|
|
||||||
ObjFiles []string
|
ObjFiles []string
|
||||||
|
|
||||||
@@ -221,6 +222,7 @@ var (
|
|||||||
staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
|
staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
|
||||||
lateStaticDepTag = dependencyTag{name: "late static", library: true}
|
lateStaticDepTag = dependencyTag{name: "late static", library: true}
|
||||||
wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
|
wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
|
||||||
|
headerDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
|
||||||
genSourceDepTag = dependencyTag{name: "gen source"}
|
genSourceDepTag = dependencyTag{name: "gen source"}
|
||||||
genHeaderDepTag = dependencyTag{name: "gen header"}
|
genHeaderDepTag = dependencyTag{name: "gen header"}
|
||||||
genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
|
genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
|
||||||
@@ -556,6 +558,7 @@ func (c *Module) deps(ctx BaseModuleContext) Deps {
|
|||||||
deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
|
deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
|
||||||
deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
|
deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
|
||||||
deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
|
deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
|
||||||
|
deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
|
||||||
|
|
||||||
for _, lib := range deps.ReexportSharedLibHeaders {
|
for _, lib := range deps.ReexportSharedLibHeaders {
|
||||||
if !inList(lib, deps.SharedLibs) {
|
if !inList(lib, deps.SharedLibs) {
|
||||||
@@ -569,6 +572,12 @@ func (c *Module) deps(ctx BaseModuleContext) Deps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, lib := range deps.ReexportHeaderLibHeaders {
|
||||||
|
if !inList(lib, deps.HeaderLibs) {
|
||||||
|
ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, gen := range deps.ReexportGeneratedHeaders {
|
for _, gen := range deps.ReexportGeneratedHeaders {
|
||||||
if !inList(gen, deps.GeneratedHeaders) {
|
if !inList(gen, deps.GeneratedHeaders) {
|
||||||
ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
|
ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
|
||||||
@@ -644,6 +653,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||||||
deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
|
deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actx.AddVariationDependencies(nil, headerDepTag, deps.HeaderLibs...)
|
||||||
|
|
||||||
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
||||||
deps.WholeStaticLibs...)
|
deps.WholeStaticLibs...)
|
||||||
|
|
||||||
@@ -910,6 +921,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
ctx.AddMissingDependencies(missingDeps)
|
ctx.AddMissingDependencies(missingDeps)
|
||||||
}
|
}
|
||||||
depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
|
depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
|
||||||
|
case headerDepTag:
|
||||||
|
// Nothing
|
||||||
case objDepTag:
|
case objDepTag:
|
||||||
depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
|
depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
|
||||||
case crtBeginDepTag:
|
case crtBeginDepTag:
|
||||||
|
@@ -90,6 +90,7 @@ func init() {
|
|||||||
android.RegisterModuleType("cc_library", libraryFactory)
|
android.RegisterModuleType("cc_library", libraryFactory)
|
||||||
android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
|
android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
|
||||||
android.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
|
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
|
// 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()
|
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 {
|
type flagExporter struct {
|
||||||
Properties FlagExporterProperties
|
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 {
|
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)
|
objs := library.baseCompiler.compile(ctx, flags, deps)
|
||||||
library.reuseObjects = objs
|
library.reuseObjects = objs
|
||||||
buildFlags := flagsToBuilderFlags(flags)
|
buildFlags := flagsToBuilderFlags(flags)
|
||||||
@@ -574,6 +595,11 @@ func (library *libraryDecorator) BuildOnlyShared() {
|
|||||||
library.Properties.BuildStatic = false
|
library.Properties.BuildStatic = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (library *libraryDecorator) HeaderOnly() {
|
||||||
|
library.Properties.BuildShared = false
|
||||||
|
library.Properties.BuildStatic = false
|
||||||
|
}
|
||||||
|
|
||||||
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
||||||
module := newModule(hod, android.MultilibBoth)
|
module := newModule(hod, android.MultilibBoth)
|
||||||
|
|
||||||
|
@@ -37,6 +37,9 @@ type BaseLinkerProperties struct {
|
|||||||
// list of modules that should be dynamically linked into this module.
|
// list of modules that should be dynamically linked into this module.
|
||||||
Shared_libs []string `android:"arch_variant"`
|
Shared_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// list of modules that should only provide headers for this module.
|
||||||
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
// list of module-specific flags that will be used for all link steps
|
// list of module-specific flags that will be used for all link steps
|
||||||
Ldflags []string `android:"arch_variant"`
|
Ldflags []string `android:"arch_variant"`
|
||||||
|
|
||||||
@@ -69,6 +72,10 @@ type BaseLinkerProperties struct {
|
|||||||
// present in static_libs.
|
// present in static_libs.
|
||||||
Export_static_lib_headers []string `android:"arch_variant"`
|
Export_static_lib_headers []string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// list of header libraries to re-export include directories from. Entries must be
|
||||||
|
// present in header_libs.
|
||||||
|
Export_header_lib_headers []string `android:"arch_variant"`
|
||||||
|
|
||||||
// list of generated headers to re-export include directories from. Entries must be
|
// list of generated headers to re-export include directories from. Entries must be
|
||||||
// present in generated_headers.
|
// present in generated_headers.
|
||||||
Export_generated_headers []string `android:"arch_variant"`
|
Export_generated_headers []string `android:"arch_variant"`
|
||||||
@@ -112,9 +119,11 @@ func (linker *baseLinker) linkerProps() []interface{} {
|
|||||||
|
|
||||||
func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
||||||
|
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
||||||
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
||||||
|
|
||||||
|
deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, linker.Properties.Export_header_lib_headers...)
|
||||||
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
|
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
|
||||||
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
|
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
|
||||||
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
|
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
|
||||||
|
Reference in New Issue
Block a user