Replace android.WriteFile rule with android.WriteFileRule

The android.WriteFile rule takes careful escaping to produce the
right contents.  Wrap it in an android.WriteFileRule that handles
the escaping.

Test: compare all android.WriteFile outputs
Change-Id: If71a5843af47a37ca61714e1a1ebb32d08536c31
This commit is contained in:
Colin Cross
2020-11-13 11:48:42 -08:00
parent 1d26d3033a
commit cf371cc1f7
13 changed files with 90 additions and 114 deletions

View File

@@ -5574,7 +5574,7 @@ func TestAppBundle(t *testing.T) {
}
`, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json")
content := bundleConfigRule.Args["content"]
ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
@@ -5600,7 +5600,7 @@ func TestAppSetBundle(t *testing.T) {
set: "AppSet.apks",
}`)
mod := ctx.ModuleForTests("myapex", "android_common_myapex_image")
bundleConfigRule := mod.Description("Bundle Config")
bundleConfigRule := mod.Output("bundle_config.json")
content := bundleConfigRule.Args["content"]
ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
s := mod.Rule("apexRule").Args["copy_commands"]

View File

@@ -373,14 +373,7 @@ func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.Output
panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
}
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,
Output: output,
Description: "Bundle Config " + output.String(),
Args: map[string]string{
"content": string(j),
},
})
android.WriteFileRule(ctx, output, string(j))
return output.OutputPath
}

View File

@@ -116,7 +116,7 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
partition string
}
toString := func(e apexKeyEntry) string {
format := "name=%q public_key=%q private_key=%q container_certificate=%q container_private_key=%q partition=%q\\n"
format := "name=%q public_key=%q private_key=%q container_certificate=%q container_private_key=%q partition=%q\n"
if e.presigned {
return fmt.Sprintf(format, e.name, "PRESIGNED", "PRESIGNED", "PRESIGNED", "PRESIGNED", e.partition)
} else {
@@ -173,17 +173,9 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
var filecontent strings.Builder
for _, name := range moduleNames {
fmt.Fprintf(&filecontent, "%s", toString(apexKeyMap[name]))
filecontent.WriteString(toString(apexKeyMap[name]))
}
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,
Description: "apexkeys.txt",
Output: s.output,
Args: map[string]string{
"content": filecontent.String(),
},
})
android.WriteFileRule(ctx, s.output, filecontent.String())
}
func apexKeysTextFactory() android.Singleton {