Merge "Use a unique depfile for each gensrcs command" am: b0ce5757b9
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1509811 Change-Id: I3ebce42606360e3d78bc4a8e49021cf89d440faf
This commit is contained in:
commit
2282a24858
1 changed files with 41 additions and 22 deletions
|
@ -148,14 +148,16 @@ type Module struct {
|
||||||
type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
|
type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
|
||||||
|
|
||||||
type generateTask struct {
|
type generateTask struct {
|
||||||
in android.Paths
|
in android.Paths
|
||||||
out android.WritablePaths
|
out android.WritablePaths
|
||||||
depFile android.WritablePath
|
depFile android.WritablePath
|
||||||
copyTo android.WritablePaths
|
copyTo android.WritablePaths
|
||||||
genDir android.WritablePath
|
genDir android.WritablePath
|
||||||
cmd string
|
extraTools android.Paths // dependencies on tools used by the generator
|
||||||
shard int
|
|
||||||
shards int
|
cmd string
|
||||||
|
shard int
|
||||||
|
shards int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Module) GeneratedSourceFiles() android.Paths {
|
func (g *Module) GeneratedSourceFiles() android.Paths {
|
||||||
|
@ -434,6 +436,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
cmd.ImplicitOutputs(task.out)
|
cmd.ImplicitOutputs(task.out)
|
||||||
cmd.Implicits(task.in)
|
cmd.Implicits(task.in)
|
||||||
cmd.Implicits(g.deps)
|
cmd.Implicits(g.deps)
|
||||||
|
cmd.Implicits(task.extraTools)
|
||||||
if Bool(g.properties.Depfile) {
|
if Bool(g.properties.Depfile) {
|
||||||
cmd.ImplicitDepFile(task.depFile)
|
cmd.ImplicitDepFile(task.depFile)
|
||||||
}
|
}
|
||||||
|
@ -584,8 +587,8 @@ func NewGenSrcs() *Module {
|
||||||
for i, shard := range shards {
|
for i, shard := range shards {
|
||||||
var commands []string
|
var commands []string
|
||||||
var outFiles android.WritablePaths
|
var outFiles android.WritablePaths
|
||||||
|
var commandDepFiles []string
|
||||||
var copyTo android.WritablePaths
|
var copyTo android.WritablePaths
|
||||||
var depFile android.WritablePath
|
|
||||||
|
|
||||||
// When sharding is enabled (i.e. len(shards) > 1), the sbox rules for each
|
// When sharding is enabled (i.e. len(shards) > 1), the sbox rules for each
|
||||||
// shard will be write to their own directories and then be merged together
|
// shard will be write to their own directories and then be merged together
|
||||||
|
@ -598,7 +601,7 @@ func NewGenSrcs() *Module {
|
||||||
|
|
||||||
genDir := android.PathForModuleGen(ctx, genSubDir)
|
genDir := android.PathForModuleGen(ctx, genSubDir)
|
||||||
|
|
||||||
for j, in := range shard {
|
for _, in := range shard {
|
||||||
outFile := android.GenPathWithExt(ctx, finalSubDir, in, String(properties.Output_extension))
|
outFile := android.GenPathWithExt(ctx, finalSubDir, in, String(properties.Output_extension))
|
||||||
|
|
||||||
// If sharding is enabled, then outFile is the path to the output file in
|
// If sharding is enabled, then outFile is the path to the output file in
|
||||||
|
@ -610,10 +613,6 @@ func NewGenSrcs() *Module {
|
||||||
outFile = shardFile
|
outFile = shardFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if j == 0 {
|
|
||||||
depFile = outFile.ReplaceExtension(ctx, "d")
|
|
||||||
}
|
|
||||||
|
|
||||||
outFiles = append(outFiles, outFile)
|
outFiles = append(outFiles, outFile)
|
||||||
|
|
||||||
// pre-expand the command line to replace $in and $out with references to
|
// pre-expand the command line to replace $in and $out with references to
|
||||||
|
@ -624,6 +623,12 @@ func NewGenSrcs() *Module {
|
||||||
return in.String(), nil
|
return in.String(), nil
|
||||||
case "out":
|
case "out":
|
||||||
return android.SboxPathForOutput(outFile, genDir), nil
|
return android.SboxPathForOutput(outFile, genDir), nil
|
||||||
|
case "depfile":
|
||||||
|
// Generate a depfile for each output file. Store the list for
|
||||||
|
// later in order to combine them all into a single depfile.
|
||||||
|
depFile := android.SboxPathForOutput(outFile.ReplaceExtension(ctx, "d"), genDir)
|
||||||
|
commandDepFiles = append(commandDepFiles, depFile)
|
||||||
|
return depFile, nil
|
||||||
default:
|
default:
|
||||||
return "$(" + name + ")", nil
|
return "$(" + name + ")", nil
|
||||||
}
|
}
|
||||||
|
@ -638,15 +643,29 @@ func NewGenSrcs() *Module {
|
||||||
}
|
}
|
||||||
fullCommand := strings.Join(commands, " && ")
|
fullCommand := strings.Join(commands, " && ")
|
||||||
|
|
||||||
|
var outputDepfile android.WritablePath
|
||||||
|
var extraTools android.Paths
|
||||||
|
if len(commandDepFiles) > 0 {
|
||||||
|
// Each command wrote to a depfile, but ninja can only handle one
|
||||||
|
// depfile per rule. Use the dep_fixer tool at the end of the
|
||||||
|
// command to combine all the depfiles into a single output depfile.
|
||||||
|
outputDepfile = android.PathForModuleGen(ctx, genSubDir, "gensrcs.d")
|
||||||
|
depFixerTool := ctx.Config().HostToolPath(ctx, "dep_fixer")
|
||||||
|
fullCommand += fmt.Sprintf(" && %s -o $(depfile) %s",
|
||||||
|
depFixerTool.String(), strings.Join(commandDepFiles, " "))
|
||||||
|
extraTools = append(extraTools, depFixerTool)
|
||||||
|
}
|
||||||
|
|
||||||
generateTasks = append(generateTasks, generateTask{
|
generateTasks = append(generateTasks, generateTask{
|
||||||
in: shard,
|
in: shard,
|
||||||
out: outFiles,
|
out: outFiles,
|
||||||
depFile: depFile,
|
depFile: outputDepfile,
|
||||||
copyTo: copyTo,
|
copyTo: copyTo,
|
||||||
genDir: genDir,
|
genDir: genDir,
|
||||||
cmd: fullCommand,
|
cmd: fullCommand,
|
||||||
shard: i,
|
shard: i,
|
||||||
shards: len(shards),
|
shards: len(shards),
|
||||||
|
extraTools: extraTools,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue