Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 775af07

Browse files
committed
Intercept the PYTHON exec in node-gyp
1 parent e8b28ce commit 775af07

File tree

5 files changed

+2282
-0
lines changed

5 files changed

+2282
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.DS_Store
55
npm-debug.log
66
*~
7+
*.pyc

bin/apm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ then
3131
export npm_config_node_gyp="$maybe_node_gyp_path"
3232
fi
3333

34+
export PYTHON="${binDir}/python-interceptor.sh"
35+
3436
builtin cd "$initialCwd"
3537
"$binDir/$nodeBin" "$binDir/../lib/cli.js" "$@"

bin/npm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33
export PATH="$SCRIPT_DIR:$PATH"
44

5+
export PYTHON="${SCRIPT_DIR}/python-interceptor.sh"
6+
57
maybe_node_gyp_path="$SCRIPT_DIR"/../node_modules/.bin/node-gyp
68
if [ -e "$maybe_node_gyp_path" ]
79
then

bin/python-interceptor.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
printf "Invoked with: " >>${HOME}/interceptor.log
6+
printf '[%s] | ' "${@}" >>${HOME}/interceptor.log
7+
printf '\n' >>${HOME}/interceptor.log
8+
9+
case $1 in
10+
*/gyp_main.py)
11+
GENERATOR_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'generator')
12+
trap "rm -r ${GENERATOR_DIR}" EXIT
13+
FORMAT_PY="${GENERATOR_DIR}/safemake.py"
14+
cp "${SCRIPT_DIR}/../src/generator/safemake.py" "${FORMAT_PY}"
15+
16+
ARGS=()
17+
FORMAT_ARG_ADDED="no"
18+
while [ $# -gt 0 ]; do
19+
case "${1}" in
20+
-f=*|--format=*)
21+
if [ "${FORMAT_ARG_ADDED}" = "no" ]; then
22+
ARGS+=("--format" "${FORMAT_PY}")
23+
FORMAT_ARG_ADDED="yes"
24+
fi
25+
;;
26+
-f|--format)
27+
shift
28+
if [ "${FORMAT_ARG_ADDED}" = "no" ]; then
29+
ARGS+=("--format" "${FORMAT_PY}")
30+
FORMAT_ARG_ADDED="yes"
31+
fi
32+
;;
33+
*)
34+
ARGS+=("$1")
35+
;;
36+
esac
37+
shift
38+
done
39+
40+
if [ "${FORMAT_ARG_ADDED}" = "no" ]; then
41+
ARGS+=("--format=${FORMAT_PY}")
42+
fi
43+
44+
printf "exec python with: " >>${HOME}/interceptor.log
45+
printf '[%s] | ' "${ARGS[@]}" >>${HOME}/interceptor.log
46+
printf '\n' >>${HOME}/interceptor.log
47+
48+
python "${ARGS[@]}"
49+
;;
50+
*)
51+
printf "passthrough unmodified\n" >>${HOME}/interceptor.log
52+
exec python "$@"
53+
;;
54+
esac

0 commit comments

Comments
 (0)