Add explicit rspfile argument to RuleBuilderCommand.FlagWithRspFileInputList am: 70c4741215
am: 37225a7b05
am: 27a4326c78
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1634804 Change-Id: I6a33941387ce9d6054c49f61b41d4f9a4b911e36
This commit is contained in:
commit
ecd91c9ffa
|
@ -385,6 +385,21 @@ func (r *RuleBuilder) RspFileInputs() Paths {
|
||||||
return rspFileInputs
|
return rspFileInputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RspFile returns the path to the rspfile that was passed to the RuleBuilderCommand.FlagWithRspFileInputList method.
|
||||||
|
func (r *RuleBuilder) RspFile() WritablePath {
|
||||||
|
var rspFile WritablePath
|
||||||
|
for _, c := range r.commands {
|
||||||
|
if c.rspFile != nil {
|
||||||
|
if rspFile != nil {
|
||||||
|
panic("Multiple commands in a rule may not have rsp file inputs")
|
||||||
|
}
|
||||||
|
rspFile = c.rspFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rspFile
|
||||||
|
}
|
||||||
|
|
||||||
// Commands returns a slice containing the built command line for each call to RuleBuilder.Command.
|
// Commands returns a slice containing the built command line for each call to RuleBuilder.Command.
|
||||||
func (r *RuleBuilder) Commands() []string {
|
func (r *RuleBuilder) Commands() []string {
|
||||||
var commands []string
|
var commands []string
|
||||||
|
@ -461,6 +476,8 @@ func (r *RuleBuilder) Build(name string, desc string) {
|
||||||
commands := r.NinjaEscapedCommands()
|
commands := r.NinjaEscapedCommands()
|
||||||
outputs := r.Outputs()
|
outputs := r.Outputs()
|
||||||
inputs := r.Inputs()
|
inputs := r.Inputs()
|
||||||
|
rspFileInputs := r.RspFileInputs()
|
||||||
|
rspFilePath := r.RspFile()
|
||||||
|
|
||||||
if len(commands) == 0 {
|
if len(commands) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -559,15 +576,14 @@ func (r *RuleBuilder) Build(name string, desc string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ninja doesn't like multiple outputs when depfiles are enabled, move all but the first output to
|
// Ninja doesn't like multiple outputs when depfiles are enabled, move all but the first output to
|
||||||
// ImplicitOutputs. RuleBuilder only uses "$out" for the rsp file location, so the distinction between Outputs and
|
// ImplicitOutputs. RuleBuilder doesn't use "$out", so the distinction between Outputs and
|
||||||
// ImplicitOutputs doesn't matter.
|
// ImplicitOutputs doesn't matter.
|
||||||
output := outputs[0]
|
output := outputs[0]
|
||||||
implicitOutputs := outputs[1:]
|
implicitOutputs := outputs[1:]
|
||||||
|
|
||||||
var rspFile, rspFileContent string
|
var rspFile, rspFileContent string
|
||||||
rspFileInputs := r.RspFileInputs()
|
if rspFilePath != nil {
|
||||||
if rspFileInputs != nil {
|
rspFile = rspFilePath.String()
|
||||||
rspFile = "$out.rsp"
|
|
||||||
rspFileContent = "$in"
|
rspFileContent = "$in"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,6 +636,7 @@ type RuleBuilderCommand struct {
|
||||||
tools Paths
|
tools Paths
|
||||||
packagedTools []PackagingSpec
|
packagedTools []PackagingSpec
|
||||||
rspFileInputs Paths
|
rspFileInputs Paths
|
||||||
|
rspFile WritablePath
|
||||||
|
|
||||||
// spans [start,end) of the command that should not be ninja escaped
|
// spans [start,end) of the command that should not be ninja escaped
|
||||||
unescapedSpans [][2]int
|
unescapedSpans [][2]int
|
||||||
|
@ -1020,8 +1037,9 @@ func (c *RuleBuilderCommand) FlagWithDepFile(flag string, path WritablePath) *Ru
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlagWithRspFileInputList adds the specified flag and path to an rspfile to the command line, with no separator
|
// FlagWithRspFileInputList adds the specified flag and path to an rspfile to the command line, with no separator
|
||||||
// between them. The paths will be written to the rspfile.
|
// between them. The paths will be written to the rspfile. If sbox is enabled, the rspfile must
|
||||||
func (c *RuleBuilderCommand) FlagWithRspFileInputList(flag string, paths Paths) *RuleBuilderCommand {
|
// be outside the sbox directory.
|
||||||
|
func (c *RuleBuilderCommand) FlagWithRspFileInputList(flag string, rspFile WritablePath, paths Paths) *RuleBuilderCommand {
|
||||||
if c.rspFileInputs != nil {
|
if c.rspFileInputs != nil {
|
||||||
panic("FlagWithRspFileInputList cannot be called if rsp file inputs have already been provided")
|
panic("FlagWithRspFileInputList cannot be called if rsp file inputs have already been provided")
|
||||||
}
|
}
|
||||||
|
@ -1033,10 +1051,16 @@ func (c *RuleBuilderCommand) FlagWithRspFileInputList(flag string, paths Paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.rspFileInputs = paths
|
c.rspFileInputs = paths
|
||||||
|
c.rspFile = rspFile
|
||||||
|
|
||||||
rspFile := "$out.rsp"
|
if c.rule.sbox {
|
||||||
c.FlagWithArg(flag, rspFile)
|
if _, isRel, _ := maybeRelErr(c.rule.outDir.String(), rspFile.String()); isRel {
|
||||||
c.unescapedSpans = append(c.unescapedSpans, [2]int{c.buf.Len() - len(rspFile), c.buf.Len()})
|
panic(fmt.Errorf("FlagWithRspFileInputList rspfile %q must not be inside out dir %q",
|
||||||
|
rspFile.String(), c.rule.outDir.String()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.FlagWithArg(flag, rspFile.String())
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,10 +267,10 @@ func ExampleRuleBuilderCommand_FlagWithRspFileInputList() {
|
||||||
ctx := builderContext()
|
ctx := builderContext()
|
||||||
fmt.Println(NewRuleBuilder(pctx, ctx).Command().
|
fmt.Println(NewRuleBuilder(pctx, ctx).Command().
|
||||||
Tool(PathForSource(ctx, "javac")).
|
Tool(PathForSource(ctx, "javac")).
|
||||||
FlagWithRspFileInputList("@", PathsForTesting("a.java", "b.java")).
|
FlagWithRspFileInputList("@", PathForOutput(ctx, "foo.rsp"), PathsForTesting("a.java", "b.java")).
|
||||||
NinjaEscapedString())
|
String())
|
||||||
// Output:
|
// Output:
|
||||||
// javac @$out.rsp
|
// javac @out/foo.rsp
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleRuleBuilderCommand_String() {
|
func ExampleRuleBuilderCommand_String() {
|
||||||
|
|
|
@ -68,7 +68,7 @@ func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) W
|
||||||
FlagWithOutput("-o ", outputFile).
|
FlagWithOutput("-o ", outputFile).
|
||||||
FlagWithArg("-P ", "host/testcases").
|
FlagWithArg("-P ", "host/testcases").
|
||||||
FlagWithArg("-C ", testCasesDir.String()).
|
FlagWithArg("-C ", testCasesDir.String()).
|
||||||
FlagWithRspFileInputList("-r ", installedPaths.Paths())
|
FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths())
|
||||||
rule.Build("robolectric_tests_zip", "robolectric-tests.zip")
|
rule.Build("robolectric_tests_zip", "robolectric-tests.zip")
|
||||||
|
|
||||||
return outputFile
|
return outputFile
|
||||||
|
|
|
@ -440,7 +440,8 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||||
command := builder.Command().BuiltTool("soong_zip").
|
command := builder.Command().BuiltTool("soong_zip").
|
||||||
Flag("-j").
|
Flag("-j").
|
||||||
FlagWithOutput("-o ", corpusZip)
|
FlagWithOutput("-o ", corpusZip)
|
||||||
command.FlagWithRspFileInputList("-r ", fuzzModule.corpus)
|
rspFile := corpusZip.ReplaceExtension(ctx, "rsp")
|
||||||
|
command.FlagWithRspFileInputList("-r ", rspFile, fuzzModule.corpus)
|
||||||
files = append(files, fileToZip{corpusZip, ""})
|
files = append(files, fileToZip{corpusZip, ""})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -528,10 +528,11 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||||
ctx,
|
ctx,
|
||||||
snapshotDir,
|
snapshotDir,
|
||||||
c.name+"-"+ctx.Config().DeviceName()+"_list")
|
c.name+"-"+ctx.Config().DeviceName()+"_list")
|
||||||
|
rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
|
||||||
zipRule.Command().
|
zipRule.Command().
|
||||||
Text("tr").
|
Text("tr").
|
||||||
FlagWithArg("-d ", "\\'").
|
FlagWithArg("-d ", "\\'").
|
||||||
FlagWithRspFileInputList("< ", snapshotOutputs).
|
FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
|
||||||
FlagWithOutput("> ", snapshotOutputList)
|
FlagWithOutput("> ", snapshotOutputList)
|
||||||
|
|
||||||
zipRule.Temporary(snapshotOutputList)
|
zipRule.Temporary(snapshotOutputList)
|
||||||
|
|
|
@ -827,10 +827,11 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
|
||||||
|
|
||||||
// filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
|
// filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
|
||||||
snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
|
snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
|
||||||
|
rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
|
||||||
zipRule.Command().
|
zipRule.Command().
|
||||||
Text("tr").
|
Text("tr").
|
||||||
FlagWithArg("-d ", "\\'").
|
FlagWithArg("-d ", "\\'").
|
||||||
FlagWithRspFileInputList("< ", snapshotOutputs).
|
FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
|
||||||
FlagWithOutput("> ", snapshotOutputList)
|
FlagWithOutput("> ", snapshotOutputList)
|
||||||
|
|
||||||
zipRule.Temporary(snapshotOutputList)
|
zipRule.Temporary(snapshotOutputList)
|
||||||
|
|
|
@ -298,6 +298,14 @@ func TestGenruleCmd(t *testing.T) {
|
||||||
`,
|
`,
|
||||||
expect: "echo foo > __SBOX_SANDBOX_DIR__/out/foo && cp __SBOX_SANDBOX_DIR__/out/foo __SBOX_SANDBOX_DIR__/out/out",
|
expect: "echo foo > __SBOX_SANDBOX_DIR__/out/foo && cp __SBOX_SANDBOX_DIR__/out/foo __SBOX_SANDBOX_DIR__/out/out",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "$",
|
||||||
|
prop: `
|
||||||
|
out: ["out"],
|
||||||
|
cmd: "echo $$ > $(out)",
|
||||||
|
`,
|
||||||
|
expect: "echo $ > __SBOX_SANDBOX_DIR__/out/out",
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "error empty location",
|
name: "error empty location",
|
||||||
|
|
|
@ -812,7 +812,7 @@ func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs andro
|
||||||
BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
|
BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
|
||||||
Flag(config.JavacVmFlags).
|
Flag(config.JavacVmFlags).
|
||||||
FlagWithArg("-encoding ", "UTF-8").
|
FlagWithArg("-encoding ", "UTF-8").
|
||||||
FlagWithRspFileInputList("@", srcs).
|
FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs).
|
||||||
FlagWithInput("@", srcJarList)
|
FlagWithInput("@", srcJarList)
|
||||||
|
|
||||||
// TODO(ccross): Remove this if- statement once we finish migration for all Doclava
|
// TODO(ccross): Remove this if- statement once we finish migration for all Doclava
|
||||||
|
@ -1243,7 +1243,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
|
||||||
Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
|
Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
|
||||||
FlagWithArg("-encoding ", "UTF-8").
|
FlagWithArg("-encoding ", "UTF-8").
|
||||||
FlagWithArg("-source ", javaVersion.String()).
|
FlagWithArg("-source ", javaVersion.String()).
|
||||||
FlagWithRspFileInputList("@", srcs).
|
FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "metalava.rsp"), srcs).
|
||||||
FlagWithInput("@", srcJarList)
|
FlagWithInput("@", srcJarList)
|
||||||
|
|
||||||
if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" {
|
if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" {
|
||||||
|
@ -1446,7 +1446,9 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
// add a large number of inputs to a file without exceeding bash command length limits (which
|
// add a large number of inputs to a file without exceeding bash command length limits (which
|
||||||
// would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
|
// would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
|
||||||
// rsp file to be ${output}.rsp.
|
// rsp file to be ${output}.rsp.
|
||||||
impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp)
|
impCmd.Text("cp").
|
||||||
|
FlagWithRspFileInputList("", android.PathForModuleOut(ctx, "metalava-implicits.rsp"), cmd.GetImplicits()).
|
||||||
|
Output(implicitsRsp)
|
||||||
impRule.Build("implicitsGen", "implicits generation")
|
impRule.Build("implicitsGen", "implicits generation")
|
||||||
cmd.Implicit(implicitsRsp)
|
cmd.Implicit(implicitsRsp)
|
||||||
|
|
||||||
|
@ -1750,7 +1752,7 @@ func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleCon
|
||||||
Flag("-jar").
|
Flag("-jar").
|
||||||
FlagWithOutput("-o ", p.stubsSrcJar).
|
FlagWithOutput("-o ", p.stubsSrcJar).
|
||||||
FlagWithArg("-C ", srcDir.String()).
|
FlagWithArg("-C ", srcDir.String()).
|
||||||
FlagWithRspFileInputList("-r ", srcPaths)
|
FlagWithRspFileInputList("-r ", p.stubsSrcJar.ReplaceExtension(ctx, "rsp"), srcPaths)
|
||||||
|
|
||||||
rule.Restat()
|
rule.Restat()
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Path
|
||||||
// Insert a second rule to write out the list of resources to a file.
|
// Insert a second rule to write out the list of resources to a file.
|
||||||
commonSrcsList := android.PathForModuleOut(ctx, "kotlinc_common_srcs.list")
|
commonSrcsList := android.PathForModuleOut(ctx, "kotlinc_common_srcs.list")
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
rule.Command().Text("cp").FlagWithRspFileInputList("", commonSrcFiles).Output(commonSrcsList)
|
rule.Command().Text("cp").
|
||||||
|
FlagWithRspFileInputList("", commonSrcsList.ReplaceExtension(ctx, "rsp"), commonSrcFiles).
|
||||||
|
Output(commonSrcsList)
|
||||||
rule.Build("kotlin_common_srcs_list", "kotlin common_srcs list")
|
rule.Build("kotlin_common_srcs_list", "kotlin common_srcs list")
|
||||||
return android.OptionalPathForPath(commonSrcsList)
|
return android.OptionalPathForPath(commonSrcsList)
|
||||||
}
|
}
|
||||||
|
|
11
java/lint.go
11
java/lint.go
|
@ -220,7 +220,9 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
|
||||||
// Insert a second rule to write out the list of resources to a file.
|
// Insert a second rule to write out the list of resources to a file.
|
||||||
resourcesList = android.PathForModuleOut(ctx, "lint", "resources.list")
|
resourcesList = android.PathForModuleOut(ctx, "lint", "resources.list")
|
||||||
resListRule := android.NewRuleBuilder(pctx, ctx)
|
resListRule := android.NewRuleBuilder(pctx, ctx)
|
||||||
resListRule.Command().Text("cp").FlagWithRspFileInputList("", l.resources).Output(resourcesList)
|
resListRule.Command().Text("cp").
|
||||||
|
FlagWithRspFileInputList("", resourcesList.ReplaceExtension(ctx, "rsp"), l.resources).
|
||||||
|
Output(resourcesList)
|
||||||
resListRule.Build("lint_resources_list", "lint resources list")
|
resListRule.Build("lint_resources_list", "lint resources list")
|
||||||
trackRSPDependency(l.resources, resourcesList)
|
trackRSPDependency(l.resources, resourcesList)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +243,10 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
|
||||||
// TODO(ccross): some of the files in l.srcs are generated sources and should be passed to
|
// TODO(ccross): some of the files in l.srcs are generated sources and should be passed to
|
||||||
// lint separately.
|
// lint separately.
|
||||||
srcsList := android.PathForModuleOut(ctx, "lint", "srcs.list")
|
srcsList := android.PathForModuleOut(ctx, "lint", "srcs.list")
|
||||||
rule.Command().Text("cp").FlagWithRspFileInputList("", l.srcs).Output(srcsList)
|
srcsListRsp := android.PathForModuleOut(ctx, "lint-srcs.list.rsp")
|
||||||
|
rule.Command().Text("cp").
|
||||||
|
FlagWithRspFileInputList("", srcsListRsp, l.srcs).
|
||||||
|
Output(srcsList)
|
||||||
trackRSPDependency(l.srcs, srcsList)
|
trackRSPDependency(l.srcs, srcsList)
|
||||||
|
|
||||||
cmd := rule.Command().
|
cmd := rule.Command().
|
||||||
|
@ -635,7 +640,7 @@ func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android
|
||||||
rule.Command().BuiltTool("soong_zip").
|
rule.Command().BuiltTool("soong_zip").
|
||||||
FlagWithOutput("-o ", outputPath).
|
FlagWithOutput("-o ", outputPath).
|
||||||
FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
|
FlagWithArg("-C ", android.PathForIntermediates(ctx).String()).
|
||||||
FlagWithRspFileInputList("-r ", paths)
|
FlagWithRspFileInputList("-r ", outputPath.ReplaceExtension(ctx, "rsp"), paths)
|
||||||
|
|
||||||
rule.Build(outputPath.Base(), outputPath.Base())
|
rule.Build(outputPath.Base(), outputPath.Base())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue