Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attrs as a special attribute of the print command #1323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildozer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ the attribute, a warning is printed on stderr.
There are some special attributes in the `print` command:

* `kind`: displays the name of the function
* `attrs`: displays the attribute names of the rule
* `label`: the fully qualified label
* `rule`: the entire rule definition
* `startline`: the line number on which the rule begins in the BUILD file
Expand Down
12 changes: 12 additions & 0 deletions buildozer/buildozer_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,18 @@ function test_print_version() {
assert_output '12345'
}

function test_print_attrs() {
in='package()
cc_library(
name = "a",
srcs = ["a.cc"],
deps = ["//foo"],
)'
run "$in" 'print attrs' '//pkg:*'
assert_output '[]
[name srcs deps]'
}

function test_new_cc_library() {
in='cc_test(name = "a")

Expand Down
4 changes: 4 additions & 0 deletions edit/buildozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ func cmdPrint(opts *Options, env CmdEnvironment) (*build.File, error) {
fields[i] = &apipb.Output_Record_Field{
Value: &apipb.Output_Record_Field_Text{Text: env.File.Path},
}
} else if str == "attrs" {
fields[i] = &apipb.Output_Record_Field{
Value: &apipb.Output_Record_Field_List{List: &apipb.RepeatedString{Strings: env.Rule.AttrKeys()}},
}
} else if value == nil {
fmt.Fprintf(opts.ErrWriter, "rule \"//%s:%s\" has no attribute \"%s\"\n",
env.Pkg, env.Rule.Name(), str)
Expand Down