@bazel/buildozer
Advanced tools
Comparing version 6.3.3 to 6.4.0
29
index.js
@@ -1,11 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @fileoverview NodeJS binding to run the buildozer command through a convenient API | ||
*/ | ||
const child_process_1 = require("child_process"); | ||
// Use require() here since the file doesn't exist at design-time; | ||
const {spawnSync} = require('node:child_process'); | ||
// bazel will copy the /launcher.js in this repo while building the package | ||
const { getNativeBinary } = require('./buildozer'); | ||
; | ||
const {getNativeBinary} = require('./buildozer'); | ||
/** | ||
@@ -19,3 +16,3 @@ * run buildozer with a list of commands | ||
} | ||
exports.run = run; | ||
/** | ||
@@ -34,11 +31,19 @@ * run buildozer with a list of commands | ||
const input = commands.map(c => [...c.commands, c.targets.join(',')].join('|')).join('\n'); | ||
const { stdout, stderr, status, error } = child_process_1.spawnSync(getNativeBinary(), flags.concat([ | ||
const {stdout, stderr, status, error} = spawnSync(getNativeBinary(), flags.concat([ | ||
'-f', '-' /* read commands from stdin */ | ||
]), Object.assign(Object.assign({}, options), { input, encoding: 'utf-8' })); | ||
]), { | ||
...options, | ||
input, | ||
encoding: 'utf-8', | ||
}); | ||
// https://github.com/bazelbuild/buildtools/tree/master/buildozer#error-code | ||
if (status == 0 || status == 3) | ||
return stdout.trim().split('\n').filter(l => !!l); | ||
if (status == 0 || status == 3) return stdout.trim().split('\n').filter(l => !!l); | ||
console.error(`buildozer exited with status ${status}\n${stderr}`); | ||
throw error; | ||
} | ||
exports.runWithOptions = runWithOptions; | ||
module.exports = { | ||
runWithOptions, | ||
run, | ||
}; |
{ | ||
"name": "@bazel/buildozer", | ||
"description": "A command line tool to rewrite multiple BUILD files using standard commands", | ||
"version": "6.3.3", | ||
"license": "Apache-2.0", | ||
"bin": { | ||
"buildozer": "buildozer.js" | ||
}, | ||
"keywords": [ | ||
"bazel" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bazelbuild/buildtools.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/buildtools/issues" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^13.9.0", | ||
"typescript": "^3.8.3" | ||
} | ||
"name": "@bazel/buildozer", | ||
"description": "A command line tool to rewrite multiple BUILD files using standard commands", | ||
"version": "6.4.0", | ||
"license": "Apache-2.0", | ||
"bin": { | ||
"buildozer": "buildozer.js" | ||
}, | ||
"keywords": [ | ||
"bazel" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bazelbuild/buildtools.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/buildtools/issues" | ||
} | ||
} |
@@ -18,20 +18,36 @@ # Buildozer | ||
```shell | ||
buildozer [OPTIONS] ['command args'... | -f FILE ] label-list | ||
buildozer [OPTIONS] ['command arg...'...|-f FILE] [label]... | ||
``` | ||
Here, `label-list` is a space-separated list of Bazel labels, for example | ||
`//path/to/pkg1:rule1 relative/path/to/pkg2:rule2`. In addition to the Bazel | ||
label syntax for specifying a package, Buildozer also allows the package part to | ||
refer to a BUILD-like file, for example `//WORKSPACE:all` or | ||
Here, `label...` is a (space-separated, possibly empty) list of Bazel labels, | ||
for example `//path/to/pkg1:rule1 relative/path/to/pkg2:rule2`. In addition to | ||
the Bazel label syntax for specifying a package, Buildozer also allows the | ||
package part to refer to a BUILD-like file, for example `//WORKSPACE:all` or | ||
`toolchains/BUILD.tpl:host_toolchain`. | ||
When `-f FILE` is used, buildozer reads commands from `FILE` (`-` for stdin). | ||
Format: lines of `|`-separated sets of commands and labels (`command args|label|label...`). | ||
When the label is a single '*', then the command will be applied to all | ||
elements of label-list from the command line. | ||
Buildozer commands are passed as single positional arguments, and thus have to | ||
be quoted (or otherwise escaped). Multiple commands and multiple labels can be | ||
passed. Buildozer will execute all commands on all targets. (So if you do not | ||
specify at least one command and one target, nothing will happen.) Commands are | ||
executed in order, files are processed in parallel. | ||
You should specify at least one command and one target. Buildozer will execute | ||
all commands on all targets. Commands are executed in order, files are processed | ||
in parallel. | ||
When `-f FILE` is used instead of literal commands, buildozer reads commands | ||
from `FILE`. `FILE` can be `-`, in which case commands are read from the | ||
standard input. | ||
The format of the command file is as follows: Empty lines and lines beginning | ||
with `#` are ignored (including leading whitespace). Non-ignored lines consist | ||
of `|`-separated sets of commands and labels: | ||
```shell | ||
command arg arg...|command arg arg...|...|label|label|... | ||
``` | ||
(In fact, commands and labels can appear interleaved in arbitrary order.) `|` | ||
characters in commands can be escaped like `\|`, but double null bytes | ||
(`\x00\x00`) are not valid in command files. See below for special handling of | ||
labels to allow reading from the standard input. When a line in a command file | ||
uses the single label '*', then the command(s) will be applied to all elements | ||
of the list `label...` from the command line. | ||
### Targets | ||
@@ -50,4 +66,6 @@ | ||
`//pkg:%123`. | ||
* Use `-` for the package name if you want to process standard input stream | ||
instead of a file: `-:all_tests`. | ||
* Use the special package name `-` to read the BUILD file from the standard | ||
input instead of from a local file in the package directory: `-:all_tests`. | ||
(It is presumably not useful to both use a `-` package name and use the `-f | ||
-` flag to read commands from the standard input.) | ||
@@ -151,2 +169,3 @@ ### Options | ||
`//MODULE.bazel:all`): | ||
* `use_repo_add <use_extension variable name> <repo(s)>`: | ||
@@ -293,6 +312,4 @@ Ensures that the given repositories are imported via `use_repo` for the | ||
Use `buildozer -f <file>` to load a list of commands from a file. The usage is | ||
just like arguments on the command-line, except that arguments are separated by | ||
`|`. Lines that start with `#` are ignored. `|`s in commands can be escaped like | ||
`\|`, but double null bytes (`\x00\x00`) are not valid in command files. | ||
Use `buildozer -f <file>` to load a list of commands and labels from a file (see | ||
[Usage](#usage) above). | ||
@@ -314,2 +331,25 @@ ```shell | ||
Alternatively, BUILD files can be read from the standard input and written to | ||
the standard output, by using the `-` package name: | ||
```shell | ||
$ cat /tmp/cmds | ||
add deps //base //strings|-:foo|-:bar | ||
$ cat some/path/BUILD | buildozer -f /tmp/cmds | ||
``` | ||
This writes the result of updating the `:foo` and `:bar` targets in the input | ||
BUILD file to the standard output. | ||
Buildozer commands can be made executable by means of a shebang line, too: | ||
```shell | ||
#!/usr/bin/env -S buildozer -f | ||
# | ||
# Adds //base and //string dependencies to :foo and :bar. | ||
add deps //base //strings|-:foo|-:bar | ||
``` | ||
## Error code | ||
@@ -316,0 +356,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
36359915
0
369
6
10
106