diff options
author | jbj <devnull@localhost> | 2003-06-20 19:04:15 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-06-20 19:04:15 +0000 |
commit | 86704da569d91112768240b28a05e77fc1ac2d13 (patch) | |
tree | 943e494986b31418a37592e9907cbae92aa59121 /scripts | |
parent | 1f7f5254641744ee4e9edbfa3fce4a08acb591db (diff) | |
download | librpm-tizen-86704da569d91112768240b28a05e77fc1ac2d13.tar.gz librpm-tizen-86704da569d91112768240b28a05e77fc1ac2d13.tar.bz2 librpm-tizen-86704da569d91112768240b28a05e77fc1ac2d13.zip |
Automagically byte compile python code.
CVS patchset: 6913
CVS date: 2003/06/20 19:04:15
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.am | 6 | ||||
-rw-r--r-- | scripts/brp-python-bytecompile | 26 |
2 files changed, 30 insertions, 2 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index c62121293..3307a9518 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = 1.4 foreign EXTRA_DIST = \ - brp-compress brp-redhat brp-strip brp-strip-comment-note \ + brp-compress brp-python-bytecompile brp-redhat \ + brp-strip brp-strip-comment-note \ brp-strip-shared brp-strip-static-archive brp-sparc64-linux \ check-files check-prereqs convertrpmrc.sh cross-build \ find-debuginfo.sh find-lang.sh find-prov.pl find-req.pl \ @@ -23,7 +24,8 @@ all: configdir = ${prefix}/lib/rpm config_SCRIPTS = \ - brp-compress brp-redhat brp-strip brp-strip-comment-note \ + brp-compress brp-python-bytecompile brp-redhat \ + brp-strip brp-strip-comment-note \ brp-strip-shared brp-strip-static-archive brp-sparc64-linux \ check-files check-prereqs convertrpmrc.sh cross-build \ find-debuginfo.sh find-lang.sh find-prov.pl find-req.pl \ diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile new file mode 100644 index 000000000..77be2d50b --- /dev/null +++ b/scripts/brp-python-bytecompile @@ -0,0 +1,26 @@ +#!/bin/sh + +# If using normal root, avoid changing anything. +if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then + exit 0 +fi + +# If we don't have a python interpreter, avoid changing anything. +python=${1:-/usr/bin/python} +if [ ! -x "$python" ]; then + exit 0 +fi + +# Figure out how deep we need to descend. We could pick an insanely high +# number and hope it's enough, but somewhere, somebody's sure to run into it. +depth=`(find $RPM_BUILD_ROOT -type f -name "*.py" -print0 ; echo /) | \ + xargs -0 -n 1 dirname | sed 's,[^/],,g' | sort -u | tail -n 1 | wc -c` +if [ -z "$depth" -o "$depth" -le "1" ]; then + exit 0 +fi + +# Generate normal (.pyc) byte-compiled files. +$python -c 'import compileall; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1)' > /dev/null + +# Generate optimized (.pyo) byte-compiled files. +$python -O -c 'import compileall; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1)' > /dev/null |