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
diff --git a/cc/cflag_artifacts.go b/cc/cflag_artifacts.go
index 855ff25..be46fc0 100644
--- a/cc/cflag_artifacts.go
+++ b/cc/cflag_artifacts.go
@@ -68,7 +68,7 @@
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 @@
length := len(modules)
if length == 0 {
- rule.Build(pctx, ctx, filename, "gen "+filename)
+ rule.Build(filename, "gen "+filename)
part++
}
@@ -98,11 +98,11 @@
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 @@
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)
}
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index dddfe94..6b17c48 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -246,25 +246,25 @@
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 @@
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 @@
// 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 @@
}
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 @@
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 @@
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 @@
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)
}
}
diff --git a/cc/gen.go b/cc/gen.go
index 5895b31..75b9e49 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -75,10 +75,9 @@
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 @@
}
cmd := rule.Command()
- cmd.BuiltTool(ctx, "aidl-cpp").
+ cmd.BuiltTool("aidl-cpp").
FlagWithDepFile("-d", depFile).
Flag("--ninja").
Flag(aidlFlags).
@@ -232,7 +231,7 @@
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 @@
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 @@
}
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 {
diff --git a/cc/library.go b/cc/library.go
index 7ae75f2..d2a3116 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1754,13 +1754,13 @@
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
diff --git a/cc/proto.go b/cc/proto.go
index 9c102a2..4466144 100644
--- a/cc/proto.go
+++ b/cc/proto.go
@@ -50,11 +50,11 @@
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
}
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 6563f6e..4524f24 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -1124,7 +1124,7 @@
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 @@
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)
}
diff --git a/cc/vndk.go b/cc/vndk.go
index 4a005f3..4f2646c 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -762,7 +762,7 @@
})
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 @@
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)
}