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:
@@ -250,7 +250,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
|
||||
}
|
||||
|
||||
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()
|
||||
outputFile := android.PathForModuleOut(ctx, fileName)
|
||||
@@ -283,7 +283,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
||||
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
||||
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,
|
||||
builderFlags, outputFile)
|
||||
|
||||
|
@@ -182,11 +182,27 @@ type builderFlags struct {
|
||||
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
|
||||
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
|
||||
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)
|
||||
|
22
cc/cc.go
22
cc/cc.go
@@ -76,8 +76,8 @@ type PathDeps struct {
|
||||
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
|
||||
|
||||
// Paths to .o files
|
||||
ObjFiles android.Paths
|
||||
WholeStaticLibObjFiles android.Paths
|
||||
Objs Objects
|
||||
WholeStaticLibObjs Objects
|
||||
|
||||
// Paths to generated source files
|
||||
GeneratedSources android.Paths
|
||||
@@ -174,7 +174,7 @@ type compiler interface {
|
||||
|
||||
appendCflags([]string)
|
||||
appendAsflags([]string)
|
||||
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
|
||||
compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
|
||||
}
|
||||
|
||||
type linker interface {
|
||||
@@ -183,7 +183,7 @@ type linker interface {
|
||||
linkerFlags(ctx ModuleContext, flags Flags) Flags
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -440,16 +440,16 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
|
||||
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
|
||||
|
||||
var objFiles android.Paths
|
||||
var objs Objects
|
||||
if c.compiler != nil {
|
||||
objFiles = c.compiler.compile(ctx, flags, deps)
|
||||
objs = c.compiler.compile(ctx, flags, deps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if c.linker != nil {
|
||||
outputFile := c.linker.link(ctx, flags, deps, objFiles)
|
||||
outputFile := c.linker.link(ctx, flags, deps, objs)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -813,8 +813,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
}
|
||||
|
||||
if tag == reuseObjTag {
|
||||
depPaths.ObjFiles = append(depPaths.ObjFiles,
|
||||
cc.compiler.(libraryInterface).reuseObjs()...)
|
||||
depPaths.Objs = depPaths.Objs.Append(cc.compiler.(libraryInterface).reuseObjs())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -868,10 +867,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
}
|
||||
ctx.AddMissingDependencies(missingDeps)
|
||||
}
|
||||
depPaths.WholeStaticLibObjFiles =
|
||||
append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
|
||||
depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
|
||||
case objDepTag:
|
||||
ptr = &depPaths.ObjFiles
|
||||
depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
|
||||
case crtBeginDepTag:
|
||||
depPaths.CrtBegin = linkFile
|
||||
case crtEndDepTag:
|
||||
|
@@ -350,7 +350,7 @@ func ndkPathDeps(ctx ModuleContext) android.Paths {
|
||||
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 = append(pathDeps, ndkPathDeps(ctx)...)
|
||||
|
||||
@@ -367,18 +367,18 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
|
||||
compiler.deps = pathDeps
|
||||
|
||||
// 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() {
|
||||
return nil
|
||||
return Objects{}
|
||||
}
|
||||
|
||||
return objFiles
|
||||
return objs
|
||||
}
|
||||
|
||||
// Compile a list of source files into objects a specified subdirectory
|
||||
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)
|
||||
}
|
||||
|
@@ -160,7 +160,7 @@ type libraryDecorator struct {
|
||||
Properties LibraryProperties
|
||||
|
||||
// For reusing static library objects for shared library
|
||||
reuseObjFiles android.Paths
|
||||
reuseObjects Objects
|
||||
// table-of-contents file to optimize out relinking when possible
|
||||
tocFile android.OptionalPath
|
||||
|
||||
@@ -173,7 +173,7 @@ type libraryDecorator struct {
|
||||
wholeStaticMissingDeps []string
|
||||
|
||||
// For whole_static_libs
|
||||
objFiles android.Paths
|
||||
objects Objects
|
||||
|
||||
// Uses the module's name if empty, but can be overridden. Does not include
|
||||
// shlib suffix.
|
||||
@@ -251,31 +251,29 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
|
||||
return flags
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths {
|
||||
var objFiles android.Paths
|
||||
|
||||
objFiles = library.baseCompiler.compile(ctx, flags, deps)
|
||||
library.reuseObjFiles = objFiles
|
||||
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
||||
objs := library.baseCompiler.compile(ctx, flags, deps)
|
||||
library.reuseObjects = objs
|
||||
buildFlags := flagsToBuilderFlags(flags)
|
||||
|
||||
if library.static() {
|
||||
srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
|
||||
objFiles = append(objFiles, compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
||||
srcs, library.baseCompiler.deps)...)
|
||||
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
||||
srcs, library.baseCompiler.deps))
|
||||
} else {
|
||||
srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
|
||||
objFiles = append(objFiles, compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
||||
srcs, library.baseCompiler.deps)...)
|
||||
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
||||
srcs, library.baseCompiler.deps))
|
||||
}
|
||||
|
||||
return objFiles
|
||||
return objs
|
||||
}
|
||||
|
||||
type libraryInterface interface {
|
||||
getWholeStaticMissingDeps() []string
|
||||
static() bool
|
||||
objs() android.Paths
|
||||
reuseObjs() android.Paths
|
||||
objs() Objects
|
||||
reuseObjs() Objects
|
||||
toc() android.OptionalPath
|
||||
|
||||
// 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,
|
||||
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.objFiles = append(library.objFiles, objFiles...)
|
||||
library.objects = deps.WholeStaticLibObjs.Copy()
|
||||
library.objects = library.objects.Append(objs)
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx,
|
||||
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
||||
|
||||
if ctx.Darwin() {
|
||||
TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile)
|
||||
TransformDarwinObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile)
|
||||
} else {
|
||||
TransformObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile)
|
||||
TransformObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile)
|
||||
}
|
||||
|
||||
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
||||
@@ -362,7 +360,7 @@ func (library *libraryDecorator) linkStatic(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
|
||||
|
||||
@@ -455,7 +453,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
||||
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
||||
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
||||
|
||||
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs,
|
||||
TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
||||
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
||||
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
||||
|
||||
@@ -463,15 +461,15 @@ func (library *libraryDecorator) linkShared(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
|
||||
if library.static() {
|
||||
out = library.linkStatic(ctx, flags, deps, objFiles)
|
||||
out = library.linkStatic(ctx, flags, deps, objs)
|
||||
} else {
|
||||
out = library.linkShared(ctx, flags, deps, objFiles)
|
||||
out = library.linkShared(ctx, flags, deps, objs)
|
||||
}
|
||||
|
||||
library.exportIncludes(ctx, "-I")
|
||||
@@ -505,12 +503,12 @@ func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
|
||||
return library.wholeStaticMissingDeps
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) objs() android.Paths {
|
||||
return library.objFiles
|
||||
func (library *libraryDecorator) objs() Objects {
|
||||
return library.objects
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) reuseObjs() android.Paths {
|
||||
return library.reuseObjFiles
|
||||
func (library *libraryDecorator) reuseObjs() Objects {
|
||||
return library.reuseObjects
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) toc() android.OptionalPath {
|
||||
|
@@ -197,6 +197,6 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
|
||||
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()
|
||||
|
||||
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,
|
||||
objFiles android.Paths) android.Path {
|
||||
objs Objects) android.Path {
|
||||
|
||||
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
|
||||
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) {
|
||||
|
@@ -79,7 +79,7 @@ func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
|
||||
}
|
||||
|
||||
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.
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
|
||||
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,
|
||||
deps PathDeps, objFiles android.Paths) android.Path {
|
||||
deps PathDeps, objs Objects) android.Path {
|
||||
// A null build step, but it sets up the output path.
|
||||
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,
|
||||
deps PathDeps, objFiles android.Paths) android.Path {
|
||||
deps PathDeps, objs Objects) android.Path {
|
||||
// A null build step, but it sets up the output path.
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
||||
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
||||
|
10
cc/object.go
10
cc/object.go
@@ -70,16 +70,16 @@ func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
}
|
||||
|
||||
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
|
||||
if len(objFiles) == 1 {
|
||||
outputFile = objFiles[0]
|
||||
if len(objs.objFiles) == 1 {
|
||||
outputFile = objs.objFiles[0]
|
||||
} else {
|
||||
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
||||
TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output)
|
||||
TransformObjsToObj(ctx, objs.objFiles, flagsToBuilderFlags(flags), output)
|
||||
outputFile = output
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
|
||||
}
|
||||
|
||||
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
|
||||
if len(p.Prebuilt.Properties.Srcs) > 0 {
|
||||
p.libraryDecorator.exportIncludes(ctx, "-I")
|
||||
|
@@ -53,12 +53,12 @@ func toolchainLibraryFactory() (blueprint.Module, []interface{}) {
|
||||
}
|
||||
|
||||
func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags,
|
||||
deps PathDeps) android.Paths {
|
||||
return nil
|
||||
deps PathDeps) Objects {
|
||||
return Objects{}
|
||||
}
|
||||
|
||||
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
|
||||
outputFile := android.PathForModuleOut(ctx, libName)
|
||||
|
Reference in New Issue
Block a user