-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenience target for running in the current working directory (#29
) It's common for users of multitool to want to run tools in the current working directory. In #26, @alexeagle documented a technique we've used for a while with creating a script and symlinking to it. Our internal copy of this script is a bit more complicated to help avoid expensive calls to Bazel that simple `bazel run` calls don't really need. More refinements have been proposed in #27. All of these things are fundamentally workarounds for bazelbuild/bazel#3325. To help simplify things, this PR adds a convenience wrapper that captures the execpath, switches to $BUILD_WORKING_DIRECTORY, and then runs the desired tool. The resulting shell script gets to use a very simple `bazel run`, should be compatible across any slew of Bazel options, and cache as well as any typical run target.
- Loading branch information
Showing
8 changed files
with
74 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"multitool cwd execution rule" | ||
|
||
load("@rules_multitool//multitool/private:cwd.bzl", _cwd = "cwd") | ||
|
||
cwd = _cwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"cwd: a rule for executing an executable in the BUILD_WORKING_DIRECTORY" | ||
|
||
def _cwd_impl(ctx): | ||
output = ctx.actions.declare_file(ctx.label.name) | ||
ctx.actions.expand_template( | ||
template = ctx.file._template, | ||
output = output, | ||
substitutions = { | ||
"{{tool}}": ctx.file.tool.short_path, | ||
}, | ||
) | ||
return [DefaultInfo(executable = output, runfiles = ctx.runfiles(files = [ctx.file.tool]))] | ||
|
||
cwd = rule( | ||
implementation = _cwd_impl, | ||
attrs = { | ||
"tool": attr.label(mandatory = True, allow_single_file = True, executable = True, cfg = "exec"), | ||
"_template": attr.label(default = "//multitool/private:cwd.template.sh", allow_single_file = True), | ||
}, | ||
executable = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
tool="{{tool}}" | ||
execdir="$PWD" | ||
|
||
pushd "$BUILD_WORKING_DIRECTORY" > /dev/null | ||
"$execdir/$tool" "$@" | ||
popd > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters