Start using "struct Objects" to store object Paths

So that we can represent other files that get generated along with the
objects, like the gcno coverage information, and per-file clang-tidy
runs.

Test: Soong's build.ninja identical before/after
Change-Id: I5c553a153c436d5403549f62c73fe79c5f101779
This commit is contained in:
Dan Willemsen
2016-09-26 17:33:01 -07:00
parent 5d5db02bf6
commit 5cb580f407
11 changed files with 81 additions and 67 deletions

View File

@@ -250,7 +250,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
} }
func (binary *binaryDecorator) link(ctx ModuleContext, func (binary *binaryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName) outputFile := android.PathForModuleOut(ctx, fileName)
@@ -283,7 +283,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs, TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs,
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
builderFlags, outputFile) builderFlags, outputFile)

View File

@@ -182,11 +182,27 @@ type builderFlags struct {
stripAddGnuDebuglink bool stripAddGnuDebuglink bool
} }
type Objects struct {
objFiles android.Paths
}
func (a Objects) Copy() Objects {
return Objects{
objFiles: append(android.Paths{}, a.objFiles...),
}
}
func (a Objects) Append(b Objects) Objects {
return Objects{
objFiles: append(a.objFiles, b.objFiles...),
}
}
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files // Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths, func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths,
flags builderFlags, deps android.Paths) (objFiles android.Paths) { flags builderFlags, deps android.Paths) Objects {
objFiles = make(android.Paths, len(srcFiles)) objFiles := make(android.Paths, len(srcFiles))
cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
@@ -250,7 +266,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
}) })
} }
return objFiles return Objects{
objFiles: objFiles,
}
} }
// Generate a rule for compiling multiple .o files to a static library (.a) // Generate a rule for compiling multiple .o files to a static library (.a)

View File

@@ -76,8 +76,8 @@ type PathDeps struct {
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
// Paths to .o files // Paths to .o files
ObjFiles android.Paths Objs Objects
WholeStaticLibObjFiles android.Paths WholeStaticLibObjs Objects
// Paths to generated source files // Paths to generated source files
GeneratedSources android.Paths GeneratedSources android.Paths
@@ -174,7 +174,7 @@ type compiler interface {
appendCflags([]string) appendCflags([]string)
appendAsflags([]string) appendAsflags([]string)
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
} }
type linker interface { type linker interface {
@@ -183,7 +183,7 @@ type linker interface {
linkerFlags(ctx ModuleContext, flags Flags) Flags linkerFlags(ctx ModuleContext, flags Flags) Flags
linkerProps() []interface{} linkerProps() []interface{}
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
appendLdflags([]string) appendLdflags([]string)
} }
@@ -440,16 +440,16 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
var objFiles android.Paths var objs Objects
if c.compiler != nil { if c.compiler != nil {
objFiles = c.compiler.compile(ctx, flags, deps) objs = c.compiler.compile(ctx, flags, deps)
if ctx.Failed() { if ctx.Failed() {
return return
} }
} }
if c.linker != nil { if c.linker != nil {
outputFile := c.linker.link(ctx, flags, deps, objFiles) outputFile := c.linker.link(ctx, flags, deps, objs)
if ctx.Failed() { if ctx.Failed() {
return return
} }
@@ -813,8 +813,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
if tag == reuseObjTag { if tag == reuseObjTag {
depPaths.ObjFiles = append(depPaths.ObjFiles, depPaths.Objs = depPaths.Objs.Append(cc.compiler.(libraryInterface).reuseObjs())
cc.compiler.(libraryInterface).reuseObjs()...)
return return
} }
@@ -868,10 +867,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
ctx.AddMissingDependencies(missingDeps) ctx.AddMissingDependencies(missingDeps)
} }
depPaths.WholeStaticLibObjFiles = depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
case objDepTag: case objDepTag:
ptr = &depPaths.ObjFiles depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
case crtBeginDepTag: case crtBeginDepTag:
depPaths.CrtBegin = linkFile depPaths.CrtBegin = linkFile
case crtEndDepTag: case crtEndDepTag:

View File

@@ -350,7 +350,7 @@ func ndkPathDeps(ctx ModuleContext) android.Paths {
return nil return nil
} }
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
pathDeps := deps.GeneratedHeaders pathDeps := deps.GeneratedHeaders
pathDeps = append(pathDeps, ndkPathDeps(ctx)...) pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
@@ -367,18 +367,18 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
compiler.deps = pathDeps compiler.deps = pathDeps
// Compile files listed in c.Properties.Srcs into objects // Compile files listed in c.Properties.Srcs into objects
objFiles := compileObjs(ctx, buildFlags, "", srcs, compiler.deps) objs := compileObjs(ctx, buildFlags, "", srcs, compiler.deps)
if ctx.Failed() { if ctx.Failed() {
return nil return Objects{}
} }
return objFiles return objs
} }
// Compile a list of source files into objects a specified subdirectory // Compile a list of source files into objects a specified subdirectory
func compileObjs(ctx android.ModuleContext, flags builderFlags, func compileObjs(ctx android.ModuleContext, flags builderFlags,
subdir string, srcFiles, deps android.Paths) android.Paths { subdir string, srcFiles, deps android.Paths) Objects {
return TransformSourceToObj(ctx, subdir, srcFiles, flags, deps) return TransformSourceToObj(ctx, subdir, srcFiles, flags, deps)
} }

View File

@@ -160,7 +160,7 @@ type libraryDecorator struct {
Properties LibraryProperties Properties LibraryProperties
// For reusing static library objects for shared library // For reusing static library objects for shared library
reuseObjFiles android.Paths reuseObjects Objects
// table-of-contents file to optimize out relinking when possible // table-of-contents file to optimize out relinking when possible
tocFile android.OptionalPath tocFile android.OptionalPath
@@ -173,7 +173,7 @@ type libraryDecorator struct {
wholeStaticMissingDeps []string wholeStaticMissingDeps []string
// For whole_static_libs // For whole_static_libs
objFiles android.Paths objects Objects
// Uses the module's name if empty, but can be overridden. Does not include // Uses the module's name if empty, but can be overridden. Does not include
// shlib suffix. // shlib suffix.
@@ -251,31 +251,29 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
return flags return flags
} }
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
var objFiles android.Paths objs := library.baseCompiler.compile(ctx, flags, deps)
library.reuseObjects = objs
objFiles = library.baseCompiler.compile(ctx, flags, deps)
library.reuseObjFiles = objFiles
buildFlags := flagsToBuilderFlags(flags) buildFlags := flagsToBuilderFlags(flags)
if library.static() { if library.static() {
srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs) srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
objFiles = append(objFiles, compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
srcs, library.baseCompiler.deps)...) srcs, library.baseCompiler.deps))
} else { } else {
srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs) srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
objFiles = append(objFiles, compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
srcs, library.baseCompiler.deps)...) srcs, library.baseCompiler.deps))
} }
return objFiles return objs
} }
type libraryInterface interface { type libraryInterface interface {
getWholeStaticMissingDeps() []string getWholeStaticMissingDeps() []string
static() bool static() bool
objs() android.Paths objs() Objects
reuseObjs() android.Paths reuseObjs() Objects
toc() android.OptionalPath toc() android.OptionalPath
// Returns true if the build options for the module have selected a static or shared build // Returns true if the build options for the module have selected a static or shared build
@@ -340,18 +338,18 @@ func (library *libraryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) De
} }
func (library *libraryDecorator) linkStatic(ctx ModuleContext, func (library *libraryDecorator) linkStatic(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
library.objFiles = append(android.Paths{}, deps.WholeStaticLibObjFiles...) library.objects = deps.WholeStaticLibObjs.Copy()
library.objFiles = append(library.objFiles, objFiles...) library.objects = library.objects.Append(objs)
outputFile := android.PathForModuleOut(ctx, outputFile := android.PathForModuleOut(ctx,
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension) ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
if ctx.Darwin() { if ctx.Darwin() {
TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) TransformDarwinObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile)
} else { } else {
TransformObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) TransformObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile)
} }
library.wholeStaticMissingDeps = ctx.GetMissingDependencies() library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
@@ -362,7 +360,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
} }
func (library *libraryDecorator) linkShared(ctx ModuleContext, func (library *libraryDecorator) linkShared(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
var linkerDeps android.Paths var linkerDeps android.Paths
@@ -455,7 +453,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
@@ -463,15 +461,15 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
} }
func (library *libraryDecorator) link(ctx ModuleContext, func (library *libraryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
objFiles = append(objFiles, deps.ObjFiles...) objs = objs.Append(deps.Objs)
var out android.Path var out android.Path
if library.static() { if library.static() {
out = library.linkStatic(ctx, flags, deps, objFiles) out = library.linkStatic(ctx, flags, deps, objs)
} else { } else {
out = library.linkShared(ctx, flags, deps, objFiles) out = library.linkShared(ctx, flags, deps, objs)
} }
library.exportIncludes(ctx, "-I") library.exportIncludes(ctx, "-I")
@@ -505,12 +503,12 @@ func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
return library.wholeStaticMissingDeps return library.wholeStaticMissingDeps
} }
func (library *libraryDecorator) objs() android.Paths { func (library *libraryDecorator) objs() Objects {
return library.objFiles return library.objects
} }
func (library *libraryDecorator) reuseObjs() android.Paths { func (library *libraryDecorator) reuseObjs() Objects {
return library.reuseObjFiles return library.reuseObjects
} }
func (library *libraryDecorator) toc() android.OptionalPath { func (library *libraryDecorator) toc() android.OptionalPath {

View File

@@ -197,6 +197,6 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
} }
func (linker *baseLinker) link(ctx ModuleContext, func (linker *baseLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
panic(fmt.Errorf("baseLinker doesn't know how to link")) panic(fmt.Errorf("baseLinker doesn't know how to link"))
} }

View File

@@ -189,7 +189,7 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
ndkMigratedLibs = append(ndkMigratedLibs, name) ndkMigratedLibs = append(ndkMigratedLibs, name)
} }
func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
arch := ctx.Arch().ArchType.String() arch := ctx.Arch().ArchType.String()
if !strings.HasSuffix(ctx.ModuleName(), ndkLibrarySuffix) { if !strings.HasSuffix(ctx.ModuleName(), ndkLibrarySuffix) {
@@ -242,11 +242,11 @@ func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
} }
func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
objFiles android.Paths) android.Path { objs Objects) android.Path {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlag) flags.LdFlags = append(flags.LdFlags, linkerScriptFlag)
return stub.libraryDecorator.link(ctx, flags, deps, objFiles) return stub.libraryDecorator.link(ctx, flags, deps, objs)
} }
func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) { func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {

View File

@@ -79,7 +79,7 @@ func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
} }
func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags, func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
deps PathDeps, objFiles android.Paths) android.Path { deps PathDeps, objs Objects) android.Path {
// A null build step, but it sets up the output path. // A null build step, but it sets up the output path.
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") { if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name") ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name")
@@ -115,7 +115,7 @@ func ndkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) {
} }
func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags, func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
deps PathDeps, objFiles android.Paths) android.Path { deps PathDeps, objs Objects) android.Path {
// A null build step, but it sets up the output path. // A null build step, but it sets up the output path.
ndk.exportIncludes(ctx, "-isystem") ndk.exportIncludes(ctx, "-isystem")
@@ -181,7 +181,7 @@ func getNdkStlLibDir(ctx android.ModuleContext, toolchain config.Toolchain, stl
} }
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
deps PathDeps, objFiles android.Paths) android.Path { deps PathDeps, objs Objects) android.Path {
// A null build step, but it sets up the output path. // A null build step, but it sets up the output path.
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")

View File

@@ -70,16 +70,16 @@ func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
} }
func (object *objectLinker) link(ctx ModuleContext, func (object *objectLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
objFiles = append(objFiles, deps.ObjFiles...) objs = objs.Append(deps.Objs)
var outputFile android.Path var outputFile android.Path
if len(objFiles) == 1 { if len(objs.objFiles) == 1 {
outputFile = objFiles[0] outputFile = objs.objFiles[0]
} else { } else {
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output) TransformObjsToObj(ctx, objs.objFiles, flagsToBuilderFlags(flags), output)
outputFile = output outputFile = output
} }

View File

@@ -46,7 +46,7 @@ func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
} }
func (p *prebuiltLibraryLinker) link(ctx ModuleContext, func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
// TODO(ccross): verify shared library dependencies // TODO(ccross): verify shared library dependencies
if len(p.Prebuilt.Properties.Srcs) > 0 { if len(p.Prebuilt.Properties.Srcs) > 0 {
p.libraryDecorator.exportIncludes(ctx, "-I") p.libraryDecorator.exportIncludes(ctx, "-I")

View File

@@ -53,12 +53,12 @@ func toolchainLibraryFactory() (blueprint.Module, []interface{}) {
} }
func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags, func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags,
deps PathDeps) android.Paths { deps PathDeps) Objects {
return nil return Objects{}
} }
func (library *toolchainLibraryDecorator) link(ctx ModuleContext, func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles android.Paths) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
libName := ctx.ModuleName() + staticLibraryExtension libName := ctx.ModuleName() + staticLibraryExtension
outputFile := android.PathForModuleOut(ctx, libName) outputFile := android.PathForModuleOut(ctx, libName)