Merge "Use WriteFileRule instead of custom echo commands" am: da5e739628
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2362261 Change-Id: Icd6bbba8d409936f558b623d9899f8e9a0fdc796 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -36,11 +36,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
writeBazelFile = pctx.AndroidStaticRule("bazelWriteFileRule", blueprint.RuleParams{
|
|
||||||
Command: `sed "s/\\\\n/\n/g" ${out}.rsp >${out}`,
|
|
||||||
Rspfile: "${out}.rsp",
|
|
||||||
RspfileContent: "${content}",
|
|
||||||
}, "content")
|
|
||||||
_ = pctx.HostBinToolVariable("bazelBuildRunfilesTool", "build-runfiles")
|
_ = pctx.HostBinToolVariable("bazelBuildRunfilesTool", "build-runfiles")
|
||||||
buildRunfilesRule = pctx.AndroidStaticRule("bazelBuildRunfiles", blueprint.RuleParams{
|
buildRunfilesRule = pctx.AndroidStaticRule("bazelBuildRunfiles", blueprint.RuleParams{
|
||||||
Command: "${bazelBuildRunfilesTool} ${in} ${outDir}",
|
Command: "${bazelBuildRunfilesTool} ${in} ${outDir}",
|
||||||
@@ -1089,19 +1084,8 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|||||||
// because this would cause circular dependency. So, until we move aquery processing
|
// because this would cause circular dependency. So, until we move aquery processing
|
||||||
// to the 'android' package, we need to handle special cases here.
|
// to the 'android' package, we need to handle special cases here.
|
||||||
if buildStatement.Mnemonic == "FileWrite" || buildStatement.Mnemonic == "SourceSymlinkManifest" {
|
if buildStatement.Mnemonic == "FileWrite" || buildStatement.Mnemonic == "SourceSymlinkManifest" {
|
||||||
// Pass file contents as the value of the rule's "content" argument.
|
out := PathForBazelOut(ctx, buildStatement.OutputPaths[0])
|
||||||
// Escape newlines and $ in the contents (the action "writeBazelFile" restores "\\n"
|
WriteFileRuleVerbatim(ctx, out, buildStatement.FileContents)
|
||||||
// back to the newline, and Ninja reads $$ as $.
|
|
||||||
escaped := strings.ReplaceAll(strings.ReplaceAll(buildStatement.FileContents, "\n", "\\n"),
|
|
||||||
"$", "$$")
|
|
||||||
ctx.Build(pctx, BuildParams{
|
|
||||||
Rule: writeBazelFile,
|
|
||||||
Output: PathForBazelOut(ctx, buildStatement.OutputPaths[0]),
|
|
||||||
Description: fmt.Sprintf("%s %s", buildStatement.Mnemonic, buildStatement.OutputPaths[0]),
|
|
||||||
Args: map[string]string{
|
|
||||||
"content": escaped,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else if buildStatement.Mnemonic == "SymlinkTree" {
|
} else if buildStatement.Mnemonic == "SymlinkTree" {
|
||||||
// build-runfiles arguments are the manifest file and the target directory
|
// build-runfiles arguments are the manifest file and the target directory
|
||||||
// where it creates the symlink tree according to this manifest (and then
|
// where it creates the symlink tree according to this manifest (and then
|
||||||
|
@@ -61,11 +61,10 @@ func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rule := NewRuleBuilder(pctx, ctx)
|
lines := make([]string, 0)
|
||||||
cmd := rule.Command().Text("(")
|
|
||||||
|
|
||||||
writeString := func(str string) {
|
writeString := func(str string) {
|
||||||
cmd.Text(`echo "` + str + `" && `)
|
lines = append(lines, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
writeString("# begin build properties")
|
writeString("# begin build properties")
|
||||||
@@ -142,8 +141,7 @@ func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|||||||
|
|
||||||
writeString("# end build properties")
|
writeString("# end build properties")
|
||||||
|
|
||||||
cmd.Text("true) > ").Output(p.outputFilePath)
|
WriteFileRule(ctx, p.outputFilePath, strings.Join(lines, "\n"))
|
||||||
rule.Build("build.prop", "generating build.prop")
|
|
||||||
|
|
||||||
if !p.installable() {
|
if !p.installable() {
|
||||||
p.SkipInstall()
|
p.SkipInstall()
|
||||||
|
@@ -174,10 +174,15 @@ func buildWriteFileRule(ctx BuilderContext, outputFile WritablePath, content str
|
|||||||
// WriteFileRule creates a ninja rule to write contents to a file. The contents will be escaped
|
// WriteFileRule creates a ninja rule to write contents to a file. The contents will be escaped
|
||||||
// so that the file contains exactly the contents passed to the function, plus a trailing newline.
|
// so that the file contains exactly the contents passed to the function, plus a trailing newline.
|
||||||
func WriteFileRule(ctx BuilderContext, outputFile WritablePath, content string) {
|
func WriteFileRule(ctx BuilderContext, outputFile WritablePath, content string) {
|
||||||
|
WriteFileRuleVerbatim(ctx, outputFile, content+"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteFileRuleVerbatim creates a ninja rule to write contents to a file. The contents will be
|
||||||
|
// escaped so that the file contains exactly the contents passed to the function.
|
||||||
|
func WriteFileRuleVerbatim(ctx BuilderContext, outputFile WritablePath, content string) {
|
||||||
// This is MAX_ARG_STRLEN subtracted with some safety to account for shell escapes
|
// This is MAX_ARG_STRLEN subtracted with some safety to account for shell escapes
|
||||||
const SHARD_SIZE = 131072 - 10000
|
const SHARD_SIZE = 131072 - 10000
|
||||||
|
|
||||||
content += "\n"
|
|
||||||
if len(content) > SHARD_SIZE {
|
if len(content) > SHARD_SIZE {
|
||||||
var chunks WritablePaths
|
var chunks WritablePaths
|
||||||
for i, c := range ShardString(content, SHARD_SIZE) {
|
for i, c := range ShardString(content, SHARD_SIZE) {
|
||||||
|
@@ -179,13 +179,6 @@ var (
|
|||||||
Description: "app bundle",
|
Description: "app bundle",
|
||||||
}, "abi", "config")
|
}, "abi", "config")
|
||||||
|
|
||||||
emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
|
|
||||||
Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
|
|
||||||
Rspfile: "${out}.emit_commands",
|
|
||||||
RspfileContent: "${emit_commands}",
|
|
||||||
Description: "Emit APEX image content",
|
|
||||||
}, "emit_commands")
|
|
||||||
|
|
||||||
diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
|
diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
|
||||||
Command: `diff --unchanged-group-format='' \` +
|
Command: `diff --unchanged-group-format='' \` +
|
||||||
`--changed-group-format='%<' \` +
|
`--changed-group-format='%<' \` +
|
||||||
@@ -546,29 +539,20 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
|
|||||||
// to be using this at this moment. Furthermore, this looks very similar to what
|
// to be using this at this moment. Furthermore, this looks very similar to what
|
||||||
// buildInstalledFilesFile does. At least, move this to somewhere else so that this doesn't
|
// buildInstalledFilesFile does. At least, move this to somewhere else so that this doesn't
|
||||||
// hurt readability.
|
// hurt readability.
|
||||||
// TODO(jiyong): use RuleBuilder
|
|
||||||
if a.overridableProperties.Allowed_files != nil {
|
if a.overridableProperties.Allowed_files != nil {
|
||||||
// Build content.txt
|
// Build content.txt
|
||||||
var emitCommands []string
|
var contentLines []string
|
||||||
imageContentFile := android.PathForModuleOut(ctx, "content.txt")
|
imageContentFile := android.PathForModuleOut(ctx, "content.txt")
|
||||||
emitCommands = append(emitCommands, "echo ./apex_manifest.pb >> "+imageContentFile.String())
|
contentLines = append(contentLines, "./apex_manifest.pb")
|
||||||
minSdkVersion := a.minSdkVersion(ctx)
|
minSdkVersion := a.minSdkVersion(ctx)
|
||||||
if minSdkVersion.EqualTo(android.SdkVersion_Android10) {
|
if minSdkVersion.EqualTo(android.SdkVersion_Android10) {
|
||||||
emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
|
contentLines = append(contentLines, "./apex_manifest.json")
|
||||||
}
|
}
|
||||||
for _, fi := range a.filesInfo {
|
for _, fi := range a.filesInfo {
|
||||||
emitCommands = append(emitCommands, "echo './"+fi.path()+"' >> "+imageContentFile.String())
|
contentLines = append(contentLines, "./"+fi.path())
|
||||||
}
|
}
|
||||||
emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
|
sort.Strings(contentLines)
|
||||||
ctx.Build(pctx, android.BuildParams{
|
android.WriteFileRule(ctx, imageContentFile, strings.Join(contentLines, "\n"))
|
||||||
Rule: emitApexContentRule,
|
|
||||||
Implicits: implicitInputs,
|
|
||||||
Output: imageContentFile,
|
|
||||||
Description: "emit apex image content",
|
|
||||||
Args: map[string]string{
|
|
||||||
"emit_commands": strings.Join(emitCommands, " && "),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
implicitInputs = append(implicitInputs, imageContentFile)
|
implicitInputs = append(implicitInputs, imageContentFile)
|
||||||
|
|
||||||
// Compare content.txt against allowed_files.
|
// Compare content.txt against allowed_files.
|
||||||
|
Reference in New Issue
Block a user