diff options
author | 2020-05-11 22:59:25 +0100 | |
---|---|---|
committer | 2020-05-11 22:59:25 +0100 | |
commit | 1110827b3f30bffb6cb811e8cb79bb03ac7d1f86 (patch) | |
tree | 0e8e1ef5c2875e64b52a85a9d0326dd66675db34 | |
parent | 9f10bbf4cfa518a49552a0cc7d14f4fcc8673c93 (diff) |
Defer \n quoting generatedContents until creating the ninja rule
Previously, when writing to generatedContents \n characters were
quoted (replaced with \\n) so as to allow them to be preserved through
ninja/rsp/bash and were unquoted (replaced \\n with \n) just before
redirecting to the output file. That meant that any code which wanted
to access the contents for other purposes, e.g. testing had to unquote
\\n.
This change moves the quoting to be part of the code that generates the
ninja rule which simplifies any other code that has to access the
contents.
Without quoting the generated Android.bp files are not formatted
properly, are all on one line and completely unreadable.
Bug: 156286550
Test: m art-module-sdk and check generated Android.bp file to make sure
it is properly formatted.
Change-Id: I768c3b96ed08a3daf251730e2a10d9d72338c49a
-rw-r--r-- | sdk/bp_test.go | 4 | ||||
-rw-r--r-- | sdk/testing.go | 2 | ||||
-rw-r--r-- | sdk/update.go | 17 |
3 files changed, 14 insertions, 9 deletions
diff --git a/sdk/bp_test.go b/sdk/bp_test.go index f89f38c1c..c630c2524 100644 --- a/sdk/bp_test.go +++ b/sdk/bp_test.go @@ -57,7 +57,7 @@ func TestTransformRemoveProperty(t *testing.T) { contents := &generatedContents{} outputPropertySet(contents, set) - helper.AssertTrimmedStringEquals("removing property failed", "name: \"name\",\\n", contents.content.String()) + helper.AssertTrimmedStringEquals("removing property failed", "name: \"name\",\n", contents.content.String()) } func TestTransformRemovePropertySet(t *testing.T) { @@ -72,5 +72,5 @@ func TestTransformRemovePropertySet(t *testing.T) { contents := &generatedContents{} outputPropertySet(contents, set) - helper.AssertTrimmedStringEquals("removing property set failed", "name: \"name\",\\n", contents.content.String()) + helper.AssertTrimmedStringEquals("removing property set failed", "name: \"name\",\n", contents.content.String()) } diff --git a/sdk/testing.go b/sdk/testing.go index 14a397c68..436175419 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -207,7 +207,7 @@ type testSdkResult struct { // e.g. find the src/dest pairs from each cp command, the various zip files // generated, etc. func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo { - androidBpContents := strings.NewReplacer("\\n", "\n").Replace(sdk.GetAndroidBpContentsForTests()) + androidBpContents := sdk.GetAndroidBpContentsForTests() info := &snapshotBuildInfo{ r: r, diff --git a/sdk/update.go b/sdk/update.go index d43a42d6e..476a4a5ea 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -87,18 +87,23 @@ func (gc *generatedContents) Dedent() { } func (gc *generatedContents) Printfln(format string, args ...interface{}) { - // ninja consumes newline characters in rspfile_content. Prevent it by - // escaping the backslash in the newline character. The extra backslash - // is removed when the rspfile is written to the actual script file - fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format+"\\n", args...) + fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format+"\n", args...) } func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) { rb := android.NewRuleBuilder() - // convert \\n to \n + + content := gf.content.String() + + // ninja consumes newline characters in rspfile_content. Prevent it by + // escaping the backslash in the newline character. The extra backslash + // is removed when the rspfile is written to the actual script file + content = strings.ReplaceAll(content, "\n", "\\n") + rb.Command(). Implicits(implicits). - Text("echo").Text(proptools.ShellEscape(gf.content.String())). + Text("echo").Text(proptools.ShellEscape(content)). + // convert \\n to \n Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path) rb.Command(). Text("chmod a+x").Output(gf.path) |