| 1 | #!/bin/sh |
| 2 | # Drives the Mac OS X 10.6 test machine over ssh (scp doesn't pass its proxy). |
| 3 | # |
| 4 | # remote.sh run [-C DIR] BINARY [ARGS...] |
| 5 | # ship to /tmp/snow-leopard, run in DIR (default there), |
| 6 | # print any new crash log |
| 7 | # remote.sh start BINARY [ARGS...] ship and leave running there, output in NAME.log; |
| 8 | # BINARY may be an .app bundle |
| 9 | # remote.sh stop NAME end what start started (a bundle by its executable) |
| 10 | # remote.sh screen LOCAL.png [APP] wake the display and capture it, or APP's window with |
| 11 | # its shadow (screencapture writes nothing from ssh) |
| 12 | # remote.sh input ARGS... click|double X Y | drag X Y X2 Y2 | scroll X Y LINES |
| 13 | # | type TEXT | key KEYCODE [command|shift|option|control]... |
| 14 | # remote.sh selectors BINARY selector-like names BINARY holds that nothing on |
| 15 | # 10.6 implements |
| 16 | # remote.sh art fetch 10.6's window buttons and scroller pieces |
| 17 | # into crates/snowbound/assets/snow-leopard |
| 18 | # remote.sh mirror PATH... copy repo paths to the same absolute paths there, so |
| 19 | # test binaries find fixtures by CARGO_MANIFEST_DIR |
| 20 | # remote.sh pull REMOTE [LOCAL] copy a file back (e.g. a screenshot) |
| 21 | # remote.sh sdk fetch the machine's MacOSX10.6.sdk for link.sh |
| 22 | # remote.sh sh COMMAND... run a shell command there |
| 23 | set -eu |
| 24 | host=${SNOW_LEOPARD_HOST:-osx10.6@10.0.0.1} |
| 25 | here=$(cd "$(dirname "$0")" && pwd) |
| 26 | dir=/tmp/snow-leopard |
| 27 | |
| 28 | ship() { |
| 29 | base=$(basename "$1") |
| 30 | if [ -d "$1" ]; then |
| 31 | (cd "$(dirname "$1")" && COPYFILE_DISABLE=1 tar czf - --no-mac-metadata --no-xattrs "$base") | |
| 32 | ssh "$host" "mkdir -p $dir && rm -rf '$dir/${base:?}' && tar xzf - -C $dir" |
| 33 | else |
| 34 | ssh "$host" "mkdir -p $dir && cat > $dir/$base && chmod +x $dir/$base" < "$1" |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | # Builds a console/ tool against the 10.6 SDK and ships it. |
| 39 | tool() { |
| 40 | sdk=$here/../../target/snow-leopard/MacOSX10.6.sdk |
| 41 | out=$here/../../target/snow-leopard/$1 |
| 42 | source=$(ls "$here/console/$1".[cm]) |
| 43 | if [ ! "$out" -nt "$source" ]; then |
| 44 | clang -arch x86_64 -isysroot "$sdk" -mmacosx-version-min=10.6 -O2 -Wall \ |
| 45 | -framework AppKit -framework ApplicationServices -framework CoreServices -lobjc \ |
| 46 | "$source" -o "$out" 2>&1 | grep -v -e "MH_DYLIB_STUB" -e "no platform load" >&2 || true |
| 47 | fi |
| 48 | ship "$out" |
| 49 | } |
| 50 | |
| 51 | quote() { |
| 52 | quoted= |
| 53 | for arg; do quoted="$quoted '$(printf %s "$arg" | sed "s/'/'\\\\''/g")'"; done |
| 54 | } |
| 55 | |
| 56 | case "${1:-}" in |
| 57 | run) |
| 58 | shift |
| 59 | cwd=$dir |
| 60 | if [ "$1" = -C ]; then cwd=$2; shift 2; fi |
| 61 | binary=$1 |
| 62 | shift |
| 63 | name=$(basename "$binary") |
| 64 | ship "$binary" |
| 65 | quote "$@" |
| 66 | # A crash report lands a few seconds after the process dies. |
| 67 | ssh "$host" "touch $dir/.start && cd '$cwd' && status=0 && $dir/$name$quoted || status=\$? |
| 68 | if [ \$status -ge 128 ]; then |
| 69 | sleep 5 |
| 70 | for log in \$(find ~/Library/Logs/CrashReporter -name '${name}_*' -newer $dir/.start); do |
| 71 | echo \"--- \$log\" >&2; sed -n '1,/^Binary Images/p' \"\$log\" >&2 |
| 72 | done |
| 73 | fi |
| 74 | exit \$status" < /dev/null |
| 75 | ;; |
| 76 | start) |
| 77 | shift |
| 78 | name=$(basename "$1") |
| 79 | program=./$name |
| 80 | if [ -d "$1" ]; then |
| 81 | name=$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$1/Contents/Info.plist") |
| 82 | program=./$(basename "$1")/Contents/MacOS/$name |
| 83 | fi |
| 84 | ship "$1" |
| 85 | shift |
| 86 | quote "$@" |
| 87 | ssh "$host" "cd $dir && (nohup $program$quoted < /dev/null > $name.log 2>&1 &)" |
| 88 | ;; |
| 89 | stop) |
| 90 | ssh "$host" "kill \$(ps axo pid,command | awk '{ sub(\".*/\", \"\", \$2) } \$2 == \"$2\" { print \$1 }')" |
| 91 | ;; |
| 92 | screen) |
| 93 | tool screen |
| 94 | quote "${3:-}" |
| 95 | ssh "$host" "$dir/screen $dir/screen.png${3:+$quoted} && cat $dir/screen.png" > "$2" |
| 96 | ;; |
| 97 | input) |
| 98 | shift |
| 99 | tool input |
| 100 | quote "$@" |
| 101 | ssh "$host" "$dir/input$quoted" |
| 102 | ;; |
| 103 | selectors) |
| 104 | tool selectors |
| 105 | strings -a "$2" | grep -E '^[a-z][a-z]+([A-Z][a-z0-9]+)*[A-Z]?[A-Za-z0-9]*(:([A-Za-z][A-Za-z0-9]*:)*)?$' | |
| 106 | grep -E '[a-z]{2}[A-Z][a-z]|:$' | sort -u | ssh "$host" "$dir/selectors 2>/dev/null" |
| 107 | ;; |
| 108 | art) |
| 109 | tool art |
| 110 | art=$here/../../crates/snowbound/assets/snow-leopard |
| 111 | mkdir -p "$art" |
| 112 | ssh "$host" "rm -rf $dir/pieces && $dir/art $dir/pieces 2>/dev/null && cd $dir/pieces && tar czf - *.png" | |
| 113 | tar xzf - -C "$art" |
| 114 | ;; |
| 115 | mirror) |
| 116 | shift |
| 117 | root=$(cd "$here/../.." && pwd) |
| 118 | (cd "$root" && COPYFILE_DISABLE=1 tar czf - --no-mac-metadata --no-xattrs --no-acls --exclude 'corpus/private' --exclude target "$@") | |
| 119 | ssh "$host" "mkdir -p '$root' && tar xzf - -C '$root'" |
| 120 | ;; |
| 121 | pull) |
| 122 | ssh "$host" "cat '$2'" > "${3:-$(basename "$2")}" |
| 123 | ;; |
| 124 | sdk) |
| 125 | mkdir -p "$here/../../target/snow-leopard" |
| 126 | ssh "$host" 'cd /Developer/SDKs && tar czf - MacOSX10.6.sdk' | |
| 127 | tar xzf - -C "$here/../../target/snow-leopard" |
| 128 | ;; |
| 129 | sh) |
| 130 | shift |
| 131 | ssh "$host" "$@" |
| 132 | ;; |
| 133 | *) |
| 134 | sed -n '2,23s/^# \{0,1\}//p' "$0" >&2 |
| 135 | exit 2 |
| 136 | ;; |
| 137 | esac |