Ticket #13505: 0001-Rewrite-python-shebangs-during-make-install-step.patch
File 0001-Rewrite-python-shebangs-during-make-install-step.patch, 5.5 KB (added by , 4 years ago) |
---|
-
new file mythtv/programs/scripts/cp_rewrite_shebang
From 224ab5623bbdfe8952f598c0c200cb3dc34fc9d5 Mon Sep 17 00:00:00 2001 From: Roland Ernst <rcrernst@gmail.com> Date: Mon, 11 Nov 2019 20:27:54 +0100 Subject: [PATCH] Rewrite python shebangs during 'make install' step This patch is a follow up to ticket #13504: Feature patch - clean up (dead) QMAKE_COPY_DIR code As outlined in #13504, we need to set the python shebangs according to the configured python version for each installation. Python's PEP 394 already defines the usage of shebangs in respect of the configured python version: On recent linux distributions, the shebang `#!/usr/bin/env python` may not exist anymore and package install scripts already warn about 'ambiguous python shebang' during packaging. This patch rewrites the shebang of python scripts durig the 'make install' step of mythtv's 'metadata' scripts located in 'mythtv/programs/scripts' according the given python version. It ignores scripts that are set intentionally to python2. It can be easily expanded to other folders like 'hardwareprofile' or 'internetcontent'. Please note: This script looks like somehow 'quick and dirty', but i tried other solutions like creating an 'intermediate target' for the python scripts, and they are much more complicated than this one, albeit, I don't speak QMAKE well. --- mythtv/programs/scripts/cp_rewrite_shebang | 72 +++++++++++++++++++ .../scripts/metadata/readme_python_shebang | 3 + mythtv/programs/scripts/scripts.pro | 24 ++++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 mythtv/programs/scripts/cp_rewrite_shebang create mode 100644 mythtv/programs/scripts/metadata/readme_python_shebang diff --git a/mythtv/programs/scripts/cp_rewrite_shebang b/mythtv/programs/scripts/cp_rewrite_shebang new file mode 100644 index 0000000000..9f084f5bdb
- + 1 #!/bin/sh 2 # 3 # cp_rewrite_shebang: recursive directory copy and rewriting shebangs, 4 # based on cpsvndir: recursive directory copy excluding .svn sub dirs. 5 # This script sets all python shebangs to the 'MYTHPYTHON' variable except 6 # those already marked for 'python2'. 7 # Additionally, it ignores a file 'readme_python_shebang', which can be used 8 # to trigger an install step. 9 10 if [ -z "$1" -o -z "$2" ]; then 11 echo "Usage: $0 source-dir destination-dir" 12 exit -1 13 fi 14 15 # Some shells don't set EUID 16 if [ -z "$EUID" ]; then 17 if [ -x /usr/bin/id ]; then EUID=`id -u` ;fi 18 if [ -z "$EUID" ]; then EUID=$USER ;fi 19 if [ -z "$EUID" ]; then EUID=0 ;fi # Will fail if not root 20 fi 21 22 # Do similarly for EGID 23 if [ -z "$EGID" ]; then 24 if [ -x /usr/bin/id ]; then EGID=`id -g` ;fi 25 if [ -z "$EGID" ]; then EGID=0 ;fi # Will fail if not root 26 fi 27 28 BASE=$(basename "$1") 29 case "$BASE" in 30 .|..|/) BASE="" ;; 31 *) BASE="/$BASE" ;; 32 esac 33 34 SRC="$1" 35 36 case "$2" in 37 /*) DEST="$2$BASE" ;; 38 *) DEST="$(pwd)/$2$BASE" ;; 39 esac 40 41 #echo "BASE=$BASE SRC=$SRC DEST=$DEST" 42 43 IFS=' 44 ' 45 if [ ! -z ${MYTHPYTHON} ]; then 46 if [ ! -f ${MYTHPYTHON} ]; then 47 MYTHPYTHON="/usr/bin/env ${MYTHPYTHON}" 48 fi 49 fi 50 51 # Copy all files and directories except the file 'readme_python_shebang' 52 cd "$SRC" 53 for file in $(find . -name readme_python_shebang -prune -or -print); do 54 #echo "processing $file" 55 if [ -d "$file" -a ! -L "$file" ]; then 56 mkdir -p "$DEST/$file" 57 else 58 cp -pR "$file" "$DEST/$file" 59 ext=${file##*.} 60 if [ "x$ext" = "xpy" ]; then 61 # set all python shebangs except those for 'python2' 62 sed "1s%^#!.*[python][^2]$%#!${MYTHPYTHON}%" "$file" > "$DEST/$file" 63 # elif [ "x$ext" = "xpl" ]; then 64 # do some perly stuff 65 fi 66 chown -h $EUID:$EGID "$DEST/$file" 67 chmod +r "$DEST/$file" &> /dev/null 68 fi 69 done 70 71 exit 0 72 -
new file mythtv/programs/scripts/metadata/readme_python_shebang
diff --git a/mythtv/programs/scripts/metadata/readme_python_shebang b/mythtv/programs/scripts/metadata/readme_python_shebang new file mode 100644 index 0000000000..f9e5e15665
- + 1 Please review the shebangs of the python files! 2 Note: This file is needed by QMAKE install! 3 -
mythtv/programs/scripts/scripts.pro
diff --git a/mythtv/programs/scripts/scripts.pro b/mythtv/programs/scripts/scripts.pro index 94e74fe817..604b2e1387 100644
a b QMAKE_STRIP = echo 5 5 TEMPLATE = app 6 6 CONFIG -= moc qt 7 7 8 USED_PYTHON=$${PYTHON} 9 warning(USED_PYTHON = $$USED_PYTHON) 10 8 11 installscripts.path = $${PREFIX}/share/mythtv 9 12 installscripts.files = database/* 13 INSTALLS += installscripts 10 14 11 15 installinternetscripts.path = $${PREFIX}/share/mythtv 12 installinternetscripts.files = internetcontent metadata hardwareprofile 16 installinternetscripts.files = internetcontent 17 INSTALLS += installinternetscripts 18 19 installhardwareprofilescripts.path = $${PREFIX}/share/mythtv 20 installhardwareprofilescripts.files = hardwareprofile 21 INSTALLS += installhardwareprofile 22 23 !win32 { 24 installmetadatascripts.path = $${PREFIX}/share/mythtv/metadata 25 installmetadatascripts.files = metadata/readme_python_shebang 26 # this is called prior to the 'install' step: 27 installmetadatascripts.extra = MYTHPYTHON=$${PYTHON} sh ./cp_rewrite_shebang $${PWD}/metadata $${PREFIX}/share/mythtv 28 } 29 else { 30 installmetadatascripts.path = $${PREFIX}/share/mythtv 31 installmetadatascripts.files = metadata 32 } 33 INSTALLS += installmetadatascripts 13 34 14 INSTALLS += installscripts installinternetscripts15 35 16 36 SOURCES += dummy.c