| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Demonstrate some OSH debug/development features.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # ./osh-debug.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 |
|
| 11 | set -o errexit
|
| 12 |
|
| 13 | myfunc() {
|
| 14 | metrics/source-code.sh osh-cloc
|
| 15 | }
|
| 16 |
|
| 17 | # Make sure it works recursively
|
| 18 | #
|
| 19 | # Problem: xargs, find -exec, make, etc. won't respect this! They will use the
|
| 20 | # real shebang.
|
| 21 |
|
| 22 | recursive() {
|
| 23 | echo ===
|
| 24 | $0 myfunc
|
| 25 | echo ===
|
| 26 | }
|
| 27 |
|
| 28 | hijack-recursive() {
|
| 29 | # $(which osh)
|
| 30 |
|
| 31 | local dir=_tmp/osh-debug
|
| 32 | mkdir -p $dir
|
| 33 |
|
| 34 | OILS_DEBUG_DIR=$dir \
|
| 35 | OILS_HIJACK_SHEBANG=bin/osh \
|
| 36 | bin/osh $0 recursive
|
| 37 | }
|
| 38 |
|
| 39 | #
|
| 40 | # For the release
|
| 41 | #
|
| 42 |
|
| 43 | # Must be an absolute path! Otherwise it will fail.
|
| 44 | readonly RELEASE_LOGS_DIR=$PWD/_tmp/osh-debug-release
|
| 45 |
|
| 46 | osh-for-release() {
|
| 47 | mkdir -p $RELEASE_LOGS_DIR
|
| 48 | rm -f $RELEASE_LOGS_DIR/*
|
| 49 |
|
| 50 | # NOTE: This runs the SYSTEM osh, because running bin/osh while doing the
|
| 51 | # release doesn't work!
|
| 52 | OILS_DEBUG_DIR=$RELEASE_LOGS_DIR OILS_HIJACK_SHEBANG=$(which osh) osh
|
| 53 | }
|
| 54 |
|
| 55 | analyze() {
|
| 56 | grep '^Hijacked' $RELEASE_LOGS_DIR/*
|
| 57 | }
|
| 58 |
|
| 59 | "$@"
|