diff options
author | Andrew J. Hesford <ajh@sideband.org> | 2020-06-09 02:36:59 +0000 |
---|---|---|
committer | Piotr <chocimier@tlen.pl> | 2020-06-10 17:11:58 +0000 |
commit | b56a3b06509155ab3be6f23f0d96d9a1bc758d1f (patch) | |
tree | d64b7cf3a58dc2686112059377f7106e4f73efa0 | |
parent | cd0bcc861a43ae3a4ecd6d2c596bde87a1545aad (diff) | |
download | void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar.gz void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar.bz2 void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar.lz void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar.xz void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.tar.zst void-packages-b56a3b06509155ab3be6f23f0d96d9a1bc758d1f.zip |
xbps-src: improve python shebang rewrites
-rw-r--r-- | common/hooks/pre-pkg/03-rewrite-python-shebang.sh | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh index 3450c3a3a8f..99e1205f142 100644 --- a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh +++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh @@ -13,15 +13,28 @@ hook() { fi if [ -n "$pyver" ]; then - shebang="#!/usr/bin/python${pyver%.*}" + default_shebang="#!/usr/bin/python${pyver%.*}" fi find "${PKGDESTDIR}" -type f -print0 | \ while IFS= read -r -d '' file; do [ ! -s "$file" ] && continue - [ -z "$(sed -n -E -e 2q -e '/^#!.*([[:space:]]|\/)python([0-9]\.[0-9])?([[:space:]]+|$)/p' "$file")" ] && continue - [ -n "$shebang" ] || msg_error "cannot convert shebang, set python_version\n" - echo " Shebang converted to '$shebang': ${file#$PKGDESTDIR}" + + pyinterp=$(sed -n -E -e 2q -e 's@^#!.*([[:space:]]|/)(python([0-9](\.[0-9]+)?)?)([[:space:]]+|$)@\2@p' "$file") + [ -z "$pyinterp" ] && continue + + pyver=${pyinterp#python} + if [ -n "$pyver" ]; then + shebang="#!/usr/bin/python${pyver%.*}" + else + shebang="$default_shebang" + fi + + basefile=${file#$PKGDESTDIR} + + [ -n "$shebang" ] || msg_error "python_version missing in template: unable to convert shebang in $basefile\n" + + echo " Shebang converted to '$shebang': $basefile" sed -i "1s@.*python.*@${shebang}@" -- "$file" done } |