Merge "Check reused source files in hasSrcExt"
This commit is contained in:
commit
7c34c4c8eb
4
cc/cc.go
4
cc/cc.go
|
@ -950,7 +950,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
|
||||
if tag == reuseObjTag {
|
||||
if l, ok := cc.compiler.(libraryInterface); ok {
|
||||
depPaths.Objs = depPaths.Objs.Append(l.reuseObjs())
|
||||
objs, flags := l.reuseObjs()
|
||||
depPaths.Objs = depPaths.Objs.Append(objs)
|
||||
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,9 @@ type BaseCompilerProperties struct {
|
|||
Exclude_srcs []string
|
||||
}
|
||||
}
|
||||
|
||||
// Stores the original list of source files before being cleared by library reuse
|
||||
OriginalSrcs []string `blueprint:"mutated"`
|
||||
}
|
||||
|
||||
func NewBaseCompiler() *baseCompiler {
|
||||
|
@ -427,6 +430,11 @@ func (compiler *baseCompiler) hasSrcExt(ext string) bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
for _, src := range compiler.Properties.OriginalSrcs {
|
||||
if filepath.Ext(src) == ext {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -200,7 +200,9 @@ type libraryDecorator struct {
|
|||
MutatedProperties LibraryMutatedProperties
|
||||
|
||||
// For reusing static library objects for shared library
|
||||
reuseObjects Objects
|
||||
reuseObjects Objects
|
||||
reuseExportedFlags []string
|
||||
|
||||
// table-of-contents file to optimize out relinking when possible
|
||||
tocFile android.OptionalPath
|
||||
|
||||
|
@ -362,7 +364,7 @@ type libraryInterface interface {
|
|||
getWholeStaticMissingDeps() []string
|
||||
static() bool
|
||||
objs() Objects
|
||||
reuseObjs() Objects
|
||||
reuseObjs() (Objects, []string)
|
||||
toc() android.OptionalPath
|
||||
|
||||
// Returns true if the build options for the module have selected a static or shared build
|
||||
|
@ -615,19 +617,23 @@ func (library *libraryDecorator) link(ctx ModuleContext,
|
|||
|
||||
if library.Properties.Aidl.Export_aidl_headers {
|
||||
if library.baseCompiler.hasSrcExt(".aidl") {
|
||||
library.reexportFlags([]string{
|
||||
flags := []string{
|
||||
"-I" + android.PathForModuleGen(ctx, "aidl").String(),
|
||||
})
|
||||
}
|
||||
library.reexportFlags(flags)
|
||||
library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
|
||||
library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to aidl deps
|
||||
}
|
||||
}
|
||||
|
||||
if library.Properties.Proto.Export_proto_headers {
|
||||
if library.baseCompiler.hasSrcExt(".proto") {
|
||||
library.reexportFlags([]string{
|
||||
flags := []string{
|
||||
"-I" + protoSubDir(ctx).String(),
|
||||
"-I" + protoDir(ctx).String(),
|
||||
})
|
||||
}
|
||||
library.reexportFlags(flags)
|
||||
library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
|
||||
library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to proto deps
|
||||
}
|
||||
}
|
||||
|
@ -653,8 +659,8 @@ func (library *libraryDecorator) objs() Objects {
|
|||
return library.objects
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) reuseObjs() Objects {
|
||||
return library.reuseObjects
|
||||
func (library *libraryDecorator) reuseObjs() (Objects, []string) {
|
||||
return library.reuseObjects, library.reuseExportedFlags
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) toc() android.OptionalPath {
|
||||
|
@ -724,6 +730,23 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
|
|||
return module, library
|
||||
}
|
||||
|
||||
// connects a shared library to a static library in order to reuse its .o files to avoid
|
||||
// compiling source files twice.
|
||||
func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
|
||||
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
||||
sharedCompiler := shared.compiler.(*libraryDecorator)
|
||||
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
||||
len(sharedCompiler.Properties.Shared.Cflags) == 0 {
|
||||
|
||||
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
||||
sharedCompiler.baseCompiler.Properties.OriginalSrcs =
|
||||
sharedCompiler.baseCompiler.Properties.Srcs
|
||||
sharedCompiler.baseCompiler.Properties.Srcs = nil
|
||||
sharedCompiler.baseCompiler.Properties.Generated_sources = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func linkageMutator(mctx android.BottomUpMutatorContext) {
|
||||
if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
|
||||
if library, ok := m.linker.(libraryInterface); ok {
|
||||
|
@ -736,16 +759,8 @@ func linkageMutator(mctx android.BottomUpMutatorContext) {
|
|||
static.linker.(libraryInterface).setStatic()
|
||||
shared.linker.(libraryInterface).setShared()
|
||||
|
||||
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
||||
sharedCompiler := shared.compiler.(*libraryDecorator)
|
||||
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
||||
len(sharedCompiler.Properties.Shared.Cflags) == 0 {
|
||||
// Optimize out compiling common .o files twice for static+shared libraries
|
||||
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
||||
sharedCompiler.baseCompiler.Properties.Srcs = nil
|
||||
sharedCompiler.baseCompiler.Properties.Generated_sources = nil
|
||||
}
|
||||
}
|
||||
reuseStaticLibrary(mctx, static, shared)
|
||||
|
||||
} else if library.buildStatic() {
|
||||
modules = mctx.CreateLocalVariations("static")
|
||||
modules[0].(*Module).linker.(libraryInterface).setStatic()
|
||||
|
|
Loading…
Reference in New Issue