diff options
author | Đoàn Trần Công Danh <congdanhqx@gmail.com> | 2019-12-28 04:50:24 +0000 |
---|---|---|
committer | Juan RP <xtraeme@gmail.com> | 2019-12-28 17:02:39 +0000 |
commit | f130fb058add60b5df03840810c2438759a80572 (patch) | |
tree | 26ade80df42cab9d1e60fd674524f8ecda0fdfcc | |
parent | cc48cd207d9995e56b4b54c065965f85eaa9569c (diff) | |
download | void-packages-f130fb058add60b5df03840810c2438759a80572.tar void-packages-f130fb058add60b5df03840810c2438759a80572.tar.gz void-packages-f130fb058add60b5df03840810c2438759a80572.tar.bz2 void-packages-f130fb058add60b5df03840810c2438759a80572.tar.lz void-packages-f130fb058add60b5df03840810c2438759a80572.tar.xz void-packages-f130fb058add60b5df03840810c2438759a80572.tar.zst void-packages-f130fb058add60b5df03840810c2438759a80572.zip |
hook: python-shebang: check for shebang in the first line only
- Grepping whole files is inefficient
- git-instaweb (in git package) has the code to generate python file in
a here doc in the middle of its code, old hook generates false
positive with this package
-rw-r--r-- | common/hooks/pre-pkg/03-rewrite-python-shebang.sh | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh index 81e45b9821f..4de75da2a76 100644 --- a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh +++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh @@ -20,9 +20,10 @@ hook() { shebang="#!/usr/bin/python${pyver%.*}" find "${PKGDESTDIR}" -type f -print0 | \ - xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([0-9]\.[0-9]\)\?\([[:space:]]\+\|$\)" -- | while IFS=: read -r f off _; do - [ -z "$off" ] && continue - echo " Shebang converted to '$shebang': ${f#$PKGDESTDIR}" - sed -i "1s@.*python.*@${shebang}@" -- "$f" - done + 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 + echo " Shebang converted to '$shebang': ${file#$PKGDESTDIR}" + sed -i "1s@.*python.*@${shebang}@" -- "$file" + done } |