github.com/bazelbuild/buildtools v0.0.0-20180226164855-80c7f0d45d7e

Used only by github.com/bazelbuild/bazel-gazelle, expecting 80c7f0d45d7e
This commit is contained in:
Jordan Liggitt
2019-04-05 10:33:56 -04:00
parent 2cbf496c8e
commit 4bd9dcb855
21 changed files with 1566 additions and 766 deletions

View File

@@ -92,6 +92,7 @@ Buildozer supports the following commands(`'command args'`):
* `new <rule_kind> <rule_name> [(before|after) <relative_rule_name>]`: Add a
new rule at the end of the BUILD file (before/after `<relative_rule>`).
* `print <attr(s)>`
* `remove <attr>`: Removes attribute `attr`.
* `remove <attr> <value(s)>`: Removes `value(s)` from the list `attr`. The
wildcard `*` matches all attributes. Lists containing none of the `value(s)` are
not modified.
@@ -100,6 +101,13 @@ Buildozer supports the following commands(`'command args'`):
* `replace <attr> <old_value> <new_value>`: Replaces `old_value` with `new_value`
in the list `attr`. Wildcard `*` matches all attributes. Lists not containing
`old_value` are not modified.
* `substitute <attr> <old_regexp> <new_template>`: Replaces strings which
match `old_regexp` in the list `attr` according to `new_template`. Wildcard
`*` matches all attributes. The regular expression must follow
[RE2 syntax](https://github.com/google/re2/wiki/Syntax). `new_template` may
be a simple replacement string, but it may also expand numbered or named
groups using `$0` or `$x`. Lists without strings that match `old_regexp`
are not modified.
* `set <attr> <value(s)>`: Sets the value of an attribute. If the attribute
was already present, its old value is replaced.
* `set_if_absent <attr> <value(s)>`: Sets the value of an attribute. If the
@@ -138,6 +146,9 @@ buildozer 'set kind java_library' //pkg:%gwt_module
# Replace the dependency on pkg_v1 with a dependency on pkg_v2
buildozer 'replace deps //pkg_v1 //pkg_v2' //pkg:rule
# Replace all dependencies using regular expressions.
buildozer 'substitute deps //old/(.*) //new/${1}' //pkg:rule
# Delete the dependency on foo in every cc_library in the package
buildozer 'remove deps foo' //pkg:%cc_library

View File

@@ -38,6 +38,7 @@ var (
editVariables = flag.Bool("edit-variables", false, "For attributes that simply assign a variable (e.g. hdrs = LIB_HDRS), edit the build variable instead of appending to the attribute.")
isPrintingProto = flag.Bool("output_proto", false, "output serialized devtools.buildozer.Output protos instead of human-readable strings.")
tablesPath = flag.String("tables", "", "path to JSON file with custom table definitions which will replace the built-in tables")
addTablesPath = flag.String("add_tables", "", "path to JSON file with custom table definitions which will be merged with the built-in tables")
shortenLabelsFlag = flag.Bool("shorten_labels", true, "convert added labels to short form, e.g. //foo:bar => :bar")
deleteWithComments = flag.Bool("delete_with_comments", true, "If a list attribute should be deleted even if there is a comment attached to it")
@@ -67,9 +68,16 @@ func main() {
}
}
if *addTablesPath != "" {
if err := tables.ParseAndUpdateJSONDefinitions(*addTablesPath, true); err != nil {
fmt.Fprintf(os.Stderr, "buildifier: failed to parse %s for -add_tables: %s\n", *addTablesPath, err)
os.Exit(2)
}
}
edit.ShortenLabelsFlag = *shortenLabelsFlag
edit.DeleteWithComments = *deleteWithComments
edit.Opts = edit.Options{
opts := &edit.Options{
Stdout: *stdout,
Buildifier: *buildifier,
Parallelism: *parallelism,
@@ -83,5 +91,5 @@ func main() {
EditVariables: *editVariables,
IsPrintingProto: *isPrintingProto,
}
os.Exit(edit.Buildozer(flag.Args()))
os.Exit(edit.Buildozer(opts, flag.Args()))
}