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
diff --git a/cc/binary.go b/cc/binary.go
index e7d22c1..1e923a4 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -250,7 +250,7 @@
}
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 @@
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)
diff --git a/cc/builder.go b/cc/builder.go
index 60aad0b..0006ed3 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -182,11 +182,27 @@
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 @@
})
}
- return objFiles
+ return Objects{
+ objFiles: objFiles,
+ }
}
// Generate a rule for compiling multiple .o files to a static library (.a)
diff --git a/cc/cc.go b/cc/cc.go
index 33c9611..c2884ac 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -76,8 +76,8 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
}
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:
diff --git a/cc/compiler.go b/cc/compiler.go
index 0184ee9..454be5e 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -350,7 +350,7 @@
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 @@
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)
}
diff --git a/cc/library.go b/cc/library.go
index 99a9b48..db19d66 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -160,7 +160,7 @@
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 @@
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 @@
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) 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) 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 @@
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) 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 @@
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 {
diff --git a/cc/linker.go b/cc/linker.go
index 0923338..28572c6 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -197,6 +197,6 @@
}
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"))
}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 6b0c325..48fbf4d 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -189,7 +189,7 @@
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) 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) {
diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go
index 106c9b5..46b383b 100644
--- a/cc/ndk_prebuilt.go
+++ b/cc/ndk_prebuilt.go
@@ -79,7 +79,7 @@
}
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 (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 (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")
diff --git a/cc/object.go b/cc/object.go
index 72fd55b..57cc8b0 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -70,16 +70,16 @@
}
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
}
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 55775b6..4328df8 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -46,7 +46,7 @@
}
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")
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 0097ca3..2f3c9a1 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -53,12 +53,12 @@
}
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)