Pass pctx and ctx to NewRuleBuilder
Enable the RuleBuilder and RuleBuilderCommand methods to access the BuilderContext by passing it to NewRuleBuilder instead of RuleBuilder.Build. Test: genrule_test.go Test: rule_builder_test.go Test: m checkbuild Change-Id: I63e6597e19167393876dc2259d6f521363b7dabc
This commit is contained in:
@@ -68,7 +68,7 @@ func (s *cflagArtifactsText) GenCFlagArtifactParts(ctx android.SingletonContext,
|
||||
|
||||
cleanedName := strings.Replace(flag, "=", "_", -1)
|
||||
filename, filepath := s.incrementFile(ctx, cleanedName, part)
|
||||
rule := android.NewRuleBuilder()
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().Textf("rm -f %s", filepath.String())
|
||||
|
||||
if using {
|
||||
@@ -84,7 +84,7 @@ func (s *cflagArtifactsText) GenCFlagArtifactParts(ctx android.SingletonContext,
|
||||
length := len(modules)
|
||||
|
||||
if length == 0 {
|
||||
rule.Build(pctx, ctx, filename, "gen "+filename)
|
||||
rule.Build(filename, "gen "+filename)
|
||||
part++
|
||||
}
|
||||
|
||||
@@ -98,11 +98,11 @@ func (s *cflagArtifactsText) GenCFlagArtifactParts(ctx android.SingletonContext,
|
||||
strings.Join(proptools.ShellEscapeList(shard), " ")).
|
||||
FlagWithOutput(">> ", filepath).
|
||||
Text("; done")
|
||||
rule.Build(pctx, ctx, filename, "gen "+filename)
|
||||
rule.Build(filename, "gen "+filename)
|
||||
|
||||
if index+1 != len(moduleShards) {
|
||||
filename, filepath = s.incrementFile(ctx, cleanedName, part+index+1)
|
||||
rule = android.NewRuleBuilder()
|
||||
rule = android.NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().Textf("rm -f %s", filepath.String())
|
||||
}
|
||||
}
|
||||
@@ -121,14 +121,14 @@ func (s *cflagArtifactsText) GenCFlagArtifacts(ctx android.SingletonContext) {
|
||||
for _, flag := range TrackedCFlags {
|
||||
// Generate build rule to combine related intermediary files into a
|
||||
// C Flag artifact
|
||||
rule := android.NewRuleBuilder()
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
filename := s.genFlagFilename(flag)
|
||||
outputpath := android.PathForOutput(ctx, "cflags", filename)
|
||||
rule.Command().
|
||||
Text("cat").
|
||||
Inputs(s.interOutputs[flag].Paths()).
|
||||
FlagWithOutput("> ", outputpath)
|
||||
rule.Build(pctx, ctx, filename, "gen "+filename)
|
||||
rule.Build(filename, "gen "+filename)
|
||||
s.outputs = append(s.outputs, outputpath)
|
||||
}
|
||||
}
|
||||
|
24
cc/fuzz.go
24
cc/fuzz.go
@@ -246,25 +246,25 @@ func (fuzz *fuzzBinary) install(ctx ModuleContext, file android.Path) {
|
||||
fuzz.binaryDecorator.baseInstaller.install(ctx, file)
|
||||
|
||||
fuzz.corpus = android.PathsForModuleSrc(ctx, fuzz.Properties.Corpus)
|
||||
builder := android.NewRuleBuilder()
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
intermediateDir := android.PathForModuleOut(ctx, "corpus")
|
||||
for _, entry := range fuzz.corpus {
|
||||
builder.Command().Text("cp").
|
||||
Input(entry).
|
||||
Output(intermediateDir.Join(ctx, entry.Base()))
|
||||
}
|
||||
builder.Build(pctx, ctx, "copy_corpus", "copy corpus")
|
||||
builder.Build("copy_corpus", "copy corpus")
|
||||
fuzz.corpusIntermediateDir = intermediateDir
|
||||
|
||||
fuzz.data = android.PathsForModuleSrc(ctx, fuzz.Properties.Data)
|
||||
builder = android.NewRuleBuilder()
|
||||
builder = android.NewRuleBuilder(pctx, ctx)
|
||||
intermediateDir = android.PathForModuleOut(ctx, "data")
|
||||
for _, entry := range fuzz.data {
|
||||
builder.Command().Text("cp").
|
||||
Input(entry).
|
||||
Output(intermediateDir.Join(ctx, entry.Rel()))
|
||||
}
|
||||
builder.Build(pctx, ctx, "copy_data", "copy data")
|
||||
builder.Build("copy_data", "copy data")
|
||||
fuzz.dataIntermediateDir = intermediateDir
|
||||
|
||||
if fuzz.Properties.Dictionary != nil {
|
||||
@@ -419,12 +419,12 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
sharedLibraries := collectAllSharedDependencies(ctx, module)
|
||||
|
||||
var files []fileToZip
|
||||
builder := android.NewRuleBuilder()
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
// Package the corpora into a zipfile.
|
||||
if fuzzModule.corpus != nil {
|
||||
corpusZip := archDir.Join(ctx, module.Name()+"_seed_corpus.zip")
|
||||
command := builder.Command().BuiltTool(ctx, "soong_zip").
|
||||
command := builder.Command().BuiltTool("soong_zip").
|
||||
Flag("-j").
|
||||
FlagWithOutput("-o ", corpusZip)
|
||||
command.FlagWithRspFileInputList("-r ", fuzzModule.corpus)
|
||||
@@ -434,7 +434,7 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
// Package the data into a zipfile.
|
||||
if fuzzModule.data != nil {
|
||||
dataZip := archDir.Join(ctx, module.Name()+"_data.zip")
|
||||
command := builder.Command().BuiltTool(ctx, "soong_zip").
|
||||
command := builder.Command().BuiltTool("soong_zip").
|
||||
FlagWithOutput("-o ", dataZip)
|
||||
for _, f := range fuzzModule.data {
|
||||
intermediateDir := strings.TrimSuffix(f.String(), f.Rel())
|
||||
@@ -492,7 +492,7 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
}
|
||||
|
||||
fuzzZip := archDir.Join(ctx, module.Name()+".zip")
|
||||
command := builder.Command().BuiltTool(ctx, "soong_zip").
|
||||
command := builder.Command().BuiltTool("soong_zip").
|
||||
Flag("-j").
|
||||
FlagWithOutput("-o ", fuzzZip)
|
||||
for _, file := range files {
|
||||
@@ -504,7 +504,7 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
command.FlagWithInput("-f ", file.SourceFilePath)
|
||||
}
|
||||
|
||||
builder.Build(pctx, ctx, "create-"+fuzzZip.String(),
|
||||
builder.Build("create-"+fuzzZip.String(),
|
||||
"Package "+module.Name()+" for "+archString+"-"+hostOrTargetString)
|
||||
|
||||
// Don't add modules to 'make haiku' that are set to not be exported to the
|
||||
@@ -531,11 +531,11 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
filesToZip := archDirs[archOs]
|
||||
arch := archOs.arch
|
||||
hostOrTarget := archOs.hostOrTarget
|
||||
builder := android.NewRuleBuilder()
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
outputFile := android.PathForOutput(ctx, "fuzz-"+hostOrTarget+"-"+arch+".zip")
|
||||
s.packages = append(s.packages, outputFile)
|
||||
|
||||
command := builder.Command().BuiltTool(ctx, "soong_zip").
|
||||
command := builder.Command().BuiltTool("soong_zip").
|
||||
Flag("-j").
|
||||
FlagWithOutput("-o ", outputFile).
|
||||
Flag("-L 0") // No need to try and re-compress the zipfiles.
|
||||
@@ -549,7 +549,7 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
command.FlagWithInput("-f ", fileToZip.SourceFilePath)
|
||||
}
|
||||
|
||||
builder.Build(pctx, ctx, "create-fuzz-package-"+arch+"-"+hostOrTarget,
|
||||
builder.Build("create-fuzz-package-"+arch+"-"+hostOrTarget,
|
||||
"Create fuzz target packages for "+arch+"-"+hostOrTarget)
|
||||
}
|
||||
}
|
||||
|
15
cc/gen.go
15
cc/gen.go
@@ -75,10 +75,9 @@ func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile andr
|
||||
cmd := rule.Command()
|
||||
|
||||
// Fix up #line markers to not use the sbox temporary directory
|
||||
// android.SboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out
|
||||
// android.sboxPathForOutput(outDir, outDir) returns the sbox placeholder for the out
|
||||
// directory itself, without any filename appended.
|
||||
// TODO(ccross): make this cmd.PathForOutput(outDir) instead.
|
||||
sboxOutDir := android.SboxPathForOutput(outDir, outDir)
|
||||
sboxOutDir := cmd.PathForOutput(outDir)
|
||||
sedCmd := "sed -i.bak 's#" + sboxOutDir + "#" + outDir.String() + "#'"
|
||||
rule.Command().Text(sedCmd).Input(outFile)
|
||||
rule.Command().Text(sedCmd).Input(headerFile)
|
||||
@@ -137,7 +136,7 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr
|
||||
}
|
||||
|
||||
cmd := rule.Command()
|
||||
cmd.BuiltTool(ctx, "aidl-cpp").
|
||||
cmd.BuiltTool("aidl-cpp").
|
||||
FlagWithDepFile("-d", depFile).
|
||||
Flag("--ninja").
|
||||
Flag(aidlFlags).
|
||||
@@ -232,7 +231,7 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
||||
var yaccRule_ *android.RuleBuilder
|
||||
yaccRule := func() *android.RuleBuilder {
|
||||
if yaccRule_ == nil {
|
||||
yaccRule_ = android.NewRuleBuilder().Sbox(android.PathForModuleGen(ctx, "yacc"),
|
||||
yaccRule_ = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "yacc"),
|
||||
android.PathForModuleGen(ctx, "yacc.sbox.textproto"))
|
||||
}
|
||||
return yaccRule_
|
||||
@@ -262,7 +261,7 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
||||
deps = append(deps, headerFile)
|
||||
case ".aidl":
|
||||
if aidlRule == nil {
|
||||
aidlRule = android.NewRuleBuilder().Sbox(android.PathForModuleGen(ctx, "aidl"),
|
||||
aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"),
|
||||
android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
|
||||
}
|
||||
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
|
||||
@@ -285,11 +284,11 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
||||
}
|
||||
|
||||
if aidlRule != nil {
|
||||
aidlRule.Build(pctx, ctx, "aidl", "gen aidl")
|
||||
aidlRule.Build("aidl", "gen aidl")
|
||||
}
|
||||
|
||||
if yaccRule_ != nil {
|
||||
yaccRule_.Build(pctx, ctx, "yacc", "gen yacc")
|
||||
yaccRule_.Build("yacc", "gen yacc")
|
||||
}
|
||||
|
||||
if len(rsFiles) > 0 {
|
||||
|
@@ -1754,13 +1754,13 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu
|
||||
hashedOutputfile := outputFile
|
||||
outputFile = android.PathForModuleOut(ctx, "unhashed", fileName)
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().
|
||||
BuiltTool(ctx, "bssl_inject_hash").
|
||||
BuiltTool("bssl_inject_hash").
|
||||
Flag("-sha256").
|
||||
FlagWithInput("-in-object ", outputFile).
|
||||
FlagWithOutput("-o ", hashedOutputfile)
|
||||
rule.Build(pctx, ctx, "injectCryptoHash", "inject crypto hash")
|
||||
rule.Build("injectCryptoHash", "inject crypto hash")
|
||||
}
|
||||
|
||||
return outputFile
|
||||
|
@@ -50,11 +50,11 @@ func genProto(ctx android.ModuleContext, protoFile android.Path, flags builderFl
|
||||
depFile := ccFile.ReplaceExtension(ctx, "d")
|
||||
outputs := android.WritablePaths{ccFile, headerFile}
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
android.ProtoRule(ctx, rule, protoFile, flags.proto, protoDeps, outDir, depFile, outputs)
|
||||
android.ProtoRule(rule, protoFile, flags.proto, protoDeps, outDir, depFile, outputs)
|
||||
|
||||
rule.Build(pctx, ctx, "protoc_"+protoFile.Rel(), "protoc "+protoFile.Rel())
|
||||
rule.Build("protoc_"+protoFile.Rel(), "protoc "+protoFile.Rel())
|
||||
|
||||
return ccFile, headerFile
|
||||
}
|
||||
|
@@ -1124,7 +1124,7 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
ctx,
|
||||
snapshotDir,
|
||||
c.name+"-"+ctx.Config().DeviceName()+".zip")
|
||||
zipRule := android.NewRuleBuilder()
|
||||
zipRule := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
// filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
|
||||
snapshotOutputList := android.PathForOutput(
|
||||
@@ -1140,12 +1140,12 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
zipRule.Temporary(snapshotOutputList)
|
||||
|
||||
zipRule.Command().
|
||||
BuiltTool(ctx, "soong_zip").
|
||||
BuiltTool("soong_zip").
|
||||
FlagWithOutput("-o ", zipPath).
|
||||
FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
|
||||
FlagWithInput("-l ", snapshotOutputList)
|
||||
|
||||
zipRule.Build(pctx, ctx, zipPath.String(), c.name+" snapshot "+zipPath.String())
|
||||
zipRule.Build(zipPath.String(), c.name+" snapshot "+zipPath.String())
|
||||
zipRule.DeleteTemporaryFiles()
|
||||
c.snapshotZipFile = android.OptionalPathForPath(zipPath)
|
||||
}
|
||||
|
@@ -762,7 +762,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
|
||||
})
|
||||
|
||||
zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
|
||||
zipRule := android.NewRuleBuilder()
|
||||
zipRule := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
// filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with xargs
|
||||
snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
|
||||
@@ -775,12 +775,12 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
|
||||
zipRule.Temporary(snapshotOutputList)
|
||||
|
||||
zipRule.Command().
|
||||
BuiltTool(ctx, "soong_zip").
|
||||
BuiltTool("soong_zip").
|
||||
FlagWithOutput("-o ", zipPath).
|
||||
FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
|
||||
FlagWithInput("-l ", snapshotOutputList)
|
||||
|
||||
zipRule.Build(pctx, ctx, zipPath.String(), "vndk snapshot "+zipPath.String())
|
||||
zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
|
||||
zipRule.DeleteTemporaryFiles()
|
||||
c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
|
||||
}
|
||||
|
Reference in New Issue
Block a user