forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bazel] Add --config=shell for easier debugging (pytorch#79350)
Bazel quality of life improvement. This change adds a new option `--config=shell` which allows you to drop-in the shell right before the `bazel run` command is executed. For example you will have ability to examine bazel sandbox this way, run things under gdb instead of a normal run and so on. Example usage: ``` bazel run --config=shell //:init_test ``` Pull Request resolved: pytorch#79350 Approved by: https://github.com/dagitses
- Loading branch information
1 parent
02093da
commit 972a209
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sh_binary( | ||
name = "shellwrap", | ||
srcs = ["shellwrap.sh"], | ||
visibility = ["//visibility:public"], | ||
) |
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,58 @@ | ||
#!/bin/bash | ||
|
||
# This script is helpful in entering an interactive shell from a bazel build | ||
# before running a given bazel executable. | ||
# This can provide a quick way to explore the sandbox directory and filesystem. | ||
# Typical use is with | ||
# | ||
# bazel run --run_under=//tools/bazel:shell_wrapper //:target | ||
# OR | ||
# bazel run --config=shell //:target | ||
|
||
shell='/bin/bash' | ||
rcfile='/tmp/pytorch_bazel_tools_shellwrap' | ||
while [[ $# -gt 0 ]] ; do | ||
case "$1" in | ||
--shell_bin_path) | ||
# path for the shell executable | ||
shell="$2" | ||
shift 2 | ||
;; | ||
--rcfile) | ||
# path for the file used to write the environment | ||
rcfile="$2" | ||
shift 2 | ||
;; | ||
*) | ||
# remaining arguments are part of the command for execution | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
if ! tty -s; then | ||
echo 'A tty is not available.' | ||
echo "Use \`bazel run\`, not \`bazel test\`." | ||
exit 1 | ||
fi | ||
|
||
NOCOLOR='\033[0m' | ||
YELLOW='\033[1;33m' | ||
|
||
# store the environment in a file | ||
export PYTORCH_SHELL_COMMAND=$* | ||
echo "alias run=\"$*\"" > "$rcfile" | ||
echo "PS1='\s-\v\$ '" >> "$rcfile" | ||
|
||
echo ===== | ||
# print the execution command (command is yellow) | ||
echo -e "alias run=${YELLOW}$PYTORCH_SHELL_COMMAND${NOCOLOR}" | ||
echo ===== | ||
|
||
echo "Entering interactive shell at the execution root:" | ||
|
||
# quote escape all the arguments to use as a single input string | ||
cmd="'$shell' --noprofile --rcfile '$rcfile'" | ||
|
||
# run the command in a script psuedo terminal and dump to null | ||
/usr/bin/script -c "$cmd" -q /dev/null |