Merge changes from topic 'prebuilts'
* changes: Add support for binary and static library and prebuilts Rename to cc_prebuilts_library_shared Fix installing prebuilts with no source module
This commit is contained in:
@@ -76,10 +76,15 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrebuiltSelectModuleMutator marks prebuilts that are overriding source modules, and disables
|
// PrebuiltSelectModuleMutator marks prebuilts that are used, either overriding source modules or
|
||||||
// installing the source module.
|
// because the source module doesn't exist. It also disables installing overridden source modules.
|
||||||
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
|
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
|
||||||
if s, ok := ctx.Module().(Module); ok {
|
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
||||||
|
p := m.Prebuilt()
|
||||||
|
if !p.Properties.SourceExists {
|
||||||
|
p.Properties.UsePrebuilt = p.usePrebuilt(ctx, nil)
|
||||||
|
}
|
||||||
|
} else if s, ok := ctx.Module().(Module); ok {
|
||||||
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||||
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
|
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
|
||||||
p := m.(PrebuiltInterface).Prebuilt()
|
p := m.(PrebuiltInterface).Prebuilt()
|
||||||
@@ -121,5 +126,5 @@ func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return !source.Enabled()
|
return source == nil || !source.Enabled()
|
||||||
}
|
}
|
||||||
|
@@ -144,20 +144,33 @@ func TestPrebuilts(t *testing.T) {
|
|||||||
t.Fatalf("failed to find module foo")
|
t.Fatalf("failed to find module foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dependsOnSourceModule, dependsOnPrebuiltModule bool
|
||||||
|
ctx.VisitDirectDeps(foo, func(m blueprint.Module) {
|
||||||
|
if _, ok := m.(*sourceModule); ok {
|
||||||
|
dependsOnSourceModule = true
|
||||||
|
}
|
||||||
|
if p, ok := m.(*prebuiltModule); ok {
|
||||||
|
dependsOnPrebuiltModule = true
|
||||||
|
if !p.Prebuilt().Properties.UsePrebuilt {
|
||||||
|
t.Errorf("dependency on prebuilt module not marked used")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if test.prebuilt {
|
if test.prebuilt {
|
||||||
if !foo.(*sourceModule).dependsOnPrebuiltModule {
|
if !dependsOnPrebuiltModule {
|
||||||
t.Errorf("doesn't depend on prebuilt module")
|
t.Errorf("doesn't depend on prebuilt module")
|
||||||
}
|
}
|
||||||
|
|
||||||
if foo.(*sourceModule).dependsOnSourceModule {
|
if dependsOnSourceModule {
|
||||||
t.Errorf("depends on source module")
|
t.Errorf("depends on source module")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if foo.(*sourceModule).dependsOnPrebuiltModule {
|
if dependsOnPrebuiltModule {
|
||||||
t.Errorf("depends on prebuilt module")
|
t.Errorf("depends on prebuilt module")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !foo.(*sourceModule).dependsOnSourceModule {
|
if !dependsOnSourceModule {
|
||||||
t.Errorf("doens't depend on source module")
|
t.Errorf("doens't depend on source module")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,14 +222,6 @@ func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||||
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
||||||
if _, ok := m.(*sourceModule); ok {
|
|
||||||
s.dependsOnSourceModule = true
|
|
||||||
}
|
|
||||||
if _, ok := m.(*prebuiltModule); ok {
|
|
||||||
s.dependsOnPrebuiltModule = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findModule(ctx *blueprint.Context, name string) blueprint.Module {
|
func findModule(ctx *blueprint.Context, name string) blueprint.Module {
|
||||||
|
@@ -21,7 +21,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterModuleType("cc_prebuilt_shared_library", prebuiltSharedLibraryFactory)
|
android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory)
|
||||||
|
android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory)
|
||||||
|
android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type prebuiltLinkerInterface interface {
|
type prebuiltLinkerInterface interface {
|
||||||
@@ -29,17 +31,21 @@ type prebuiltLinkerInterface interface {
|
|||||||
prebuilt() *android.Prebuilt
|
prebuilt() *android.Prebuilt
|
||||||
}
|
}
|
||||||
|
|
||||||
type prebuiltLibraryLinker struct {
|
type prebuiltLinker struct {
|
||||||
*libraryDecorator
|
|
||||||
android.Prebuilt
|
android.Prebuilt
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
|
||||||
|
|
||||||
func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt {
|
|
||||||
return &p.Prebuilt
|
return &p.Prebuilt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type prebuiltLibraryLinker struct {
|
||||||
|
*libraryDecorator
|
||||||
|
prebuiltLinker
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
||||||
|
|
||||||
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
||||||
props := p.libraryDecorator.linkerProps()
|
props := p.libraryDecorator.linkerProps()
|
||||||
return append(props, &p.Prebuilt.Properties)
|
return append(props, &p.Prebuilt.Properties)
|
||||||
@@ -61,13 +67,61 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||||||
|
|
||||||
func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
|
func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
|
||||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||||
|
library.BuildOnlyShared()
|
||||||
module.compiler = nil
|
module.compiler = nil
|
||||||
|
|
||||||
prebuilt := &prebuiltLibraryLinker{
|
prebuilt := &prebuiltLibraryLinker{
|
||||||
libraryDecorator: library,
|
libraryDecorator: library,
|
||||||
}
|
}
|
||||||
module.linker = prebuilt
|
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()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user