Skip to content

Commit

Permalink
rule: set update flag on Rule.AddArg (bazelbuild#1702)
Browse files Browse the repository at this point in the history
Otherwise the shortcut logic in Sync() will prevent the change to be
reflected in the syntax tree if no other action sets the updated flag.
  • Loading branch information
t-8ch authored and jeromep-stripe committed Mar 22, 2024
1 parent 22d72b9 commit 844add8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ func (r *Rule) Args() []bzl.Expr {
// AddArg adds a positional argument to the rule.
func (r *Rule) AddArg(value bzl.Expr) {
r.args = append(r.args, value)
r.updated = true
}

// Insert marks this statement for insertion at the end of the file. Multiple
Expand Down
28 changes: 28 additions & 0 deletions rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,31 @@ a_rule(
t.Errorf("got:%s\nwant:%s", got, want)
}
}

func TestSimpleArgument(t *testing.T) {
f := EmptyFile("foo", "bar")

r := NewRule("export_files", "")
r.AddArg(&bzl.CallExpr{
X: &bzl.Ident{Name: "glob"},
List: []bzl.Expr{
&bzl.ListExpr{
List: []bzl.Expr{
&bzl.StringExpr{Value: "**"},
},
},
},
})

r.Insert(f)
f.Sync()

got := strings.TrimSpace(string(bzl.FormatWithoutRewriting(f.File)))
want := strings.TrimSpace(`
export_files(glob(["**"]))
`)

if got != want {
t.Errorf("got:%s\nwant:%s", got, want)
}
}

0 comments on commit 844add8

Please sign in to comment.