diff options
| -rw-r--r-- | android/rule_builder.go | 43 | ||||
| -rw-r--r-- | android/rule_builder_test.go | 84 |
2 files changed, 3 insertions, 124 deletions
diff --git a/android/rule_builder.go b/android/rule_builder.go index cc0bfa6af..17f211bf3 100644 --- a/android/rule_builder.go +++ b/android/rule_builder.go @@ -409,16 +409,6 @@ func (r *RuleBuilder) Commands() []string { return commands } -// NinjaEscapedCommands returns a slice containing the built command line after ninja escaping for each call to -// RuleBuilder.Command. -func (r *RuleBuilder) NinjaEscapedCommands() []string { - var commands []string - for _, c := range r.commands { - commands = append(commands, c.NinjaEscapedString()) - } - return commands -} - // BuilderContext is a subset of ModuleContext and SingletonContext. type BuilderContext interface { PathContext @@ -473,7 +463,7 @@ func (r *RuleBuilder) Build(name string, desc string) { } tools := r.Tools() - commands := r.NinjaEscapedCommands() + commands := r.Commands() outputs := r.Outputs() inputs := r.Inputs() rspFileInputs := r.RspFileInputs() @@ -547,7 +537,7 @@ func (r *RuleBuilder) Build(name string, desc string) { } // Create a rule to write the manifest as a the textproto. - WriteFileRule(r.ctx, r.sboxManifestPath, proto.MarshalTextString(&manifest)) + WriteFileRule(r.ctx, r.sboxManifestPath, proptools.NinjaEscape(proto.MarshalTextString(&manifest))) // Generate a new string to use as the command line of the sbox rule. This uses // a RuleBuilderCommand as a convenience method of building the command line, then @@ -601,7 +591,7 @@ func (r *RuleBuilder) Build(name string, desc string) { r.ctx.Build(r.pctx, BuildParams{ Rule: r.ctx.Rule(pctx, name, blueprint.RuleParams{ - Command: commandString, + Command: proptools.NinjaEscape(commandString), CommandDeps: proptools.NinjaEscapeList(tools.Strings()), Restat: r.restat, Rspfile: proptools.NinjaEscape(rspFile), @@ -637,9 +627,6 @@ type RuleBuilderCommand struct { packagedTools []PackagingSpec rspFileInputs Paths rspFile WritablePath - - // spans [start,end) of the command that should not be ninja escaped - unescapedSpans [][2]int } func (c *RuleBuilderCommand) addInput(path Path) string { @@ -1069,11 +1056,6 @@ func (c *RuleBuilderCommand) String() string { return c.buf.String() } -// String returns the command line. -func (c *RuleBuilderCommand) NinjaEscapedString() string { - return ninjaEscapeExceptForSpans(c.String(), c.unescapedSpans) -} - // RuleBuilderSboxProtoForTests takes the BuildParams for the manifest passed to RuleBuilder.Sbox() // and returns sbox testproto generated by the RuleBuilder. func RuleBuilderSboxProtoForTests(t *testing.T, params TestingBuildParams) *sbox_proto.Manifest { @@ -1087,25 +1069,6 @@ func RuleBuilderSboxProtoForTests(t *testing.T, params TestingBuildParams) *sbox return &manifest } -func ninjaEscapeExceptForSpans(s string, spans [][2]int) string { - if len(spans) == 0 { - return proptools.NinjaEscape(s) - } - - sb := strings.Builder{} - sb.Grow(len(s) * 11 / 10) - - i := 0 - for _, span := range spans { - sb.WriteString(proptools.NinjaEscape(s[i:span[0]])) - sb.WriteString(s[span[0]:span[1]]) - i = span[1] - } - sb.WriteString(proptools.NinjaEscape(s[i:])) - - return sb.String() -} - func ninjaNameEscape(s string) string { b := []byte(s) escaped := false diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go index fbf624ee3..080e236b4 100644 --- a/android/rule_builder_test.go +++ b/android/rule_builder_test.go @@ -283,16 +283,6 @@ func ExampleRuleBuilderCommand_String() { // FOO=foo echo $FOO } -func ExampleRuleBuilderCommand_NinjaEscapedString() { - ctx := builderContext() - fmt.Println(NewRuleBuilder(pctx, ctx).Command(). - Text("FOO=foo"). - Text("echo $FOO"). - NinjaEscapedString()) - // Output: - // FOO=foo echo $$FOO -} - func TestRuleBuilder(t *testing.T) { fs := map[string][]byte{ "dep_fixer": nil, @@ -631,80 +621,6 @@ func TestRuleBuilder_Build(t *testing.T) { }) } -func Test_ninjaEscapeExceptForSpans(t *testing.T) { - type args struct { - s string - spans [][2]int - } - tests := []struct { - name string - args args - want string - }{ - { - name: "empty", - args: args{ - s: "", - }, - want: "", - }, - { - name: "unescape none", - args: args{ - s: "$abc", - }, - want: "$$abc", - }, - { - name: "unescape all", - args: args{ - s: "$abc", - spans: [][2]int{{0, 4}}, - }, - want: "$abc", - }, - { - name: "unescape first", - args: args{ - s: "$abc$", - spans: [][2]int{{0, 1}}, - }, - want: "$abc$$", - }, - { - name: "unescape last", - args: args{ - s: "$abc$", - spans: [][2]int{{4, 5}}, - }, - want: "$$abc$", - }, - { - name: "unescape middle", - args: args{ - s: "$a$b$c$", - spans: [][2]int{{2, 5}}, - }, - want: "$$a$b$c$$", - }, - { - name: "unescape multiple", - args: args{ - s: "$a$b$c$", - spans: [][2]int{{2, 3}, {4, 5}}, - }, - want: "$$a$b$c$$", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := ninjaEscapeExceptForSpans(tt.args.s, tt.args.spans); got != tt.want { - t.Errorf("ninjaEscapeExceptForSpans() = %v, want %v", got, tt.want) - } - }) - } -} - func TestRuleBuilderHashInputs(t *testing.T) { // The basic idea here is to verify that the command (in the case of a // non-sbox rule) or the sbox textproto manifest contain a hash of the |