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
|
||||
// installing the source module.
|
||||
// PrebuiltSelectModuleMutator marks prebuilts that are used, either overriding source modules or
|
||||
// because the source module doesn't exist. It also disables installing overridden source modules.
|
||||
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) {
|
||||
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
|
||||
p := m.(PrebuiltInterface).Prebuilt()
|
||||
@@ -121,5 +126,5 @@ func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
|
||||
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")
|
||||
}
|
||||
|
||||
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 !foo.(*sourceModule).dependsOnPrebuiltModule {
|
||||
if !dependsOnPrebuiltModule {
|
||||
t.Errorf("doesn't depend on prebuilt module")
|
||||
}
|
||||
|
||||
if foo.(*sourceModule).dependsOnSourceModule {
|
||||
if dependsOnSourceModule {
|
||||
t.Errorf("depends on source module")
|
||||
}
|
||||
} else {
|
||||
if foo.(*sourceModule).dependsOnPrebuiltModule {
|
||||
if dependsOnPrebuiltModule {
|
||||
t.Errorf("depends on prebuilt module")
|
||||
}
|
||||
|
||||
if !foo.(*sourceModule).dependsOnSourceModule {
|
||||
if !dependsOnSourceModule {
|
||||
t.Errorf("doens't depend on source module")
|
||||
}
|
||||
}
|
||||
@@ -209,14 +222,6 @@ func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@@ -21,7 +21,9 @@ import (
|
||||
)
|
||||
|
||||
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 {
|
||||
@@ -29,17 +31,21 @@ type prebuiltLinkerInterface interface {
|
||||
prebuilt() *android.Prebuilt
|
||||
}
|
||||
|
||||
type prebuiltLibraryLinker struct {
|
||||
*libraryDecorator
|
||||
type prebuiltLinker struct {
|
||||
android.Prebuilt
|
||||
}
|
||||
|
||||
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
||||
|
||||
func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt {
|
||||
func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
|
||||
return &p.Prebuilt
|
||||
}
|
||||
|
||||
type prebuiltLibraryLinker struct {
|
||||
*libraryDecorator
|
||||
prebuiltLinker
|
||||
}
|
||||
|
||||
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
|
||||
|
||||
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
||||
props := p.libraryDecorator.linkerProps()
|
||||
return append(props, &p.Prebuilt.Properties)
|
||||
@@ -61,13 +67,61 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
||||
|
||||
func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyShared()
|
||||
module.compiler = nil
|
||||
|
||||
prebuilt := &prebuiltLibraryLinker{
|
||||
libraryDecorator: library,
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user