File: shellwrap.sh

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (58 lines) | stat: -rwxr-xr-x 1,559 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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