From 2981a8197746bdd98ab20119229a65a68f659b5e Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 3 Feb 2010 10:44:56 +0000 Subject: [PATCH] - python byte-compilation fixes + improvements (#558997) --- rpm-4.8.0-python-bytecompile.patch | 74 ++++++++++++++++++++++++++++++ rpm.spec | 7 ++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 rpm-4.8.0-python-bytecompile.patch diff --git a/rpm-4.8.0-python-bytecompile.patch b/rpm-4.8.0-python-bytecompile.patch new file mode 100644 index 0000000..0bd6c0c --- /dev/null +++ b/rpm-4.8.0-python-bytecompile.patch @@ -0,0 +1,74 @@ +commit 7617dfec85012a75bf15dec963f2f9a65e8550d9 +Author: Panu Matilainen +Date: Wed Feb 3 12:26:23 2010 +0200 + + brp-python-bytecompile fixes + improvements (RhBug:558997) + - fix incorrect paths (eg /site-packages/filename.py instead of + /usr/lib/pythonX.Y/site-packages/filename.py) ending up in bytecode + - add a "strict" mode where byte-compilation errors will abort the build + - when in non-strict mode, byte-compile everything we can instead of + bailing out at first error + - patch originally from Toshio Kuratomi, slightly changed to preserve + the original order of arguments to avoid unnecessary incompatibilities + +diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile +index 9fac5a7..79996ea 100644 +--- a/scripts/brp-python-bytecompile ++++ b/scripts/brp-python-bytecompile +@@ -1,4 +1,5 @@ + #!/bin/bash ++errors_terminate=$2 + + # If using normal root, avoid changing anything. + if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then +@@ -33,16 +34,25 @@ fi + # and below /usr/lib/python3.1/, we're targetting /usr/bin/python3.1 + + shopt -s nullglob +-for python_libdir in $RPM_BUILD_ROOT/usr/lib*/python*/ ; ++for python_libdir in $RPM_BUILD_ROOT/usr/lib{,64}/python[0-9].[0-9]/ ; + do + python_binary=/usr/bin/$(basename $python_libdir) ++ real_libdir=${python_libdir/$RPM_BUILD_ROOT/} + echo "Bytecompiling .py files below $python_libdir using $python_binary" + + # Generate normal (.pyc) byte-compiled files. +- $python_binary -c 'import compileall; compileall.compile_dir("'"$python_libdir"'", '"$depth"', "/", force=1, quiet=1)' ++ $python_binary -c 'import compileall, sys; sys.exit(not compileall.compile_dir("'"$python_libdir"'", '"$depth"', "'"$real_libdir"'", force=1, quiet=1))' ++ if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then ++ # One or more of the files had a syntax error ++ exit 1 ++ fi + + # Generate optimized (.pyo) byte-compiled files. +- $python_binary -O -c 'import compileall; compileall.compile_dir("'"$python_libdir"'", '"$depth"', "/", force=1, quiet=1)' ++ $python_binary -O -c 'import compileall, sys; sys.exit(not compileall.compile_dir("'"$python_libdir"'", '"$depth"', "'"$real_libdir"'", force=1, quiet=1))' ++ if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then ++ # One or more of the files had a syntax error ++ exit 1 ++ fi + done + + +@@ -50,12 +60,16 @@ done + # implementation: + + # Generate normal (.pyc) byte-compiled files. +-$default_python -c 'import compileall, re, sys; sys.exit (not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/|/usr/lib.*/python.+/"'"), quiet=1))' +-if [ $? != 0 ]; then ++$default_python -c 'import compileall, re, sys; sys.exit (not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/|/usr/lib(64)?/python[0-9]\.[0-9]"'"), quiet=1))' ++if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then + # One or more of the files had a syntax error +- # XXX TODO: parametrize the exit code, only warn for now +- exit 0 ++ exit 1 + fi + + # Generate optimized (.pyo) byte-compiled files. +-$default_python -O -c 'import compileall, re; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/|/usr/lib.*/python.+/"'"))' > /dev/null ++$default_python -O -c 'import compileall, re, sys; sys.exit(not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/|/usr/lib(64)?/python[0-9]\.[0-9]"'"), quiet=1))' > /dev/null ++if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then ++ # One or more of the files had a syntax error ++ exit 1 ++fi ++exit 0 diff --git a/rpm.spec b/rpm.spec index 9680970..5bb19cd 100644 --- a/rpm.spec +++ b/rpm.spec @@ -21,7 +21,7 @@ Summary: The RPM package management system Name: rpm Version: %{rpmver} -Release: 4%{?dist} +Release: 5%{?dist} Group: System Environment/Base Url: http://www.rpm.org/ Source0: http://rpm.org/releases/testing/%{name}-%{srcver}.tar.bz2 @@ -40,6 +40,7 @@ Patch3: rpm-4.7.90-fedora-specspo.patch Patch200: rpm-4.8.0-url-segfault.patch Patch201: rpm-4.8.0-verify-exitcode.patch Patch202: rpm-4.8.0-pythondeps-parallel.patch +Patch203: rpm-4.8.0-python-bytecompile.patch # These are not yet upstream Patch301: rpm-4.6.0-niagara.patch @@ -187,6 +188,7 @@ packages on a system. %patch200 -p1 -b .url-segfault %patch201 -p1 -b .verify-exitcode %patch202 -p1 -b .pythondeps-parallel +%patch203 -p1 -b .python-bytecompile %patch301 -p1 -b .niagara %patch302 -p1 -b .geode @@ -402,6 +404,9 @@ exit 0 %doc doc/librpm/html/* %changelog +* Wed Feb 03 2010 Panu Matilainen - 4.8.0-5 +- python byte-compilation fixes + improvements (#558997) + * Sat Jan 30 2010 Panu Matilainen - 4.8.0-4 - support parallel python versions in python dependency extractor (#532118)