|
Panu Matilainen |
2981a8 |
commit 7617dfec85012a75bf15dec963f2f9a65e8550d9
|
|
Panu Matilainen |
2981a8 |
Author: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
2981a8 |
Date: Wed Feb 3 12:26:23 2010 +0200
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
brp-python-bytecompile fixes + improvements (RhBug:558997)
|
|
Panu Matilainen |
2981a8 |
- fix incorrect paths (eg /site-packages/filename.py instead of
|
|
Panu Matilainen |
2981a8 |
/usr/lib/pythonX.Y/site-packages/filename.py) ending up in bytecode
|
|
Panu Matilainen |
2981a8 |
- add a "strict" mode where byte-compilation errors will abort the build
|
|
Panu Matilainen |
2981a8 |
- when in non-strict mode, byte-compile everything we can instead of
|
|
Panu Matilainen |
2981a8 |
bailing out at first error
|
|
Panu Matilainen |
2981a8 |
- patch originally from Toshio Kuratomi, slightly changed to preserve
|
|
Panu Matilainen |
2981a8 |
the original order of arguments to avoid unnecessary incompatibilities
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile
|
|
Panu Matilainen |
2981a8 |
index 9fac5a7..79996ea 100644
|
|
Panu Matilainen |
2981a8 |
--- a/scripts/brp-python-bytecompile
|
|
Panu Matilainen |
2981a8 |
+++ b/scripts/brp-python-bytecompile
|
|
Panu Matilainen |
2981a8 |
@@ -1,4 +1,5 @@
|
|
Panu Matilainen |
2981a8 |
#!/bin/bash
|
|
Panu Matilainen |
2981a8 |
+errors_terminate=$2
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
# If using normal root, avoid changing anything.
|
|
Panu Matilainen |
2981a8 |
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
|
|
Panu Matilainen |
2981a8 |
@@ -33,16 +34,25 @@ fi
|
|
Panu Matilainen |
2981a8 |
# and below /usr/lib/python3.1/, we're targetting /usr/bin/python3.1
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
shopt -s nullglob
|
|
Panu Matilainen |
2981a8 |
-for python_libdir in $RPM_BUILD_ROOT/usr/lib*/python*/ ;
|
|
Panu Matilainen |
2981a8 |
+for python_libdir in $RPM_BUILD_ROOT/usr/lib{,64}/python[0-9].[0-9]/ ;
|
|
Panu Matilainen |
2981a8 |
do
|
|
Panu Matilainen |
2981a8 |
python_binary=/usr/bin/$(basename $python_libdir)
|
|
Panu Matilainen |
2981a8 |
+ real_libdir=${python_libdir/$RPM_BUILD_ROOT/}
|
|
Panu Matilainen |
2981a8 |
echo "Bytecompiling .py files below $python_libdir using $python_binary"
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
# Generate normal (.pyc) byte-compiled files.
|
|
Panu Matilainen |
2981a8 |
- $python_binary -c 'import compileall; compileall.compile_dir("'"$python_libdir"'", '"$depth"', "/", force=1, quiet=1)'
|
|
Panu Matilainen |
2981a8 |
+ $python_binary -c 'import compileall, sys; sys.exit(not compileall.compile_dir("'"$python_libdir"'", '"$depth"', "'"$real_libdir"'", force=1, quiet=1))'
|
|
Panu Matilainen |
2981a8 |
+ if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
Panu Matilainen |
2981a8 |
+ # One or more of the files had a syntax error
|
|
Panu Matilainen |
2981a8 |
+ exit 1
|
|
Panu Matilainen |
2981a8 |
+ fi
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
# Generate optimized (.pyo) byte-compiled files.
|
|
Panu Matilainen |
2981a8 |
- $python_binary -O -c 'import compileall; compileall.compile_dir("'"$python_libdir"'", '"$depth"', "/", force=1, quiet=1)'
|
|
Panu Matilainen |
2981a8 |
+ $python_binary -O -c 'import compileall, sys; sys.exit(not compileall.compile_dir("'"$python_libdir"'", '"$depth"', "'"$real_libdir"'", force=1, quiet=1))'
|
|
Panu Matilainen |
2981a8 |
+ if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
Panu Matilainen |
2981a8 |
+ # One or more of the files had a syntax error
|
|
Panu Matilainen |
2981a8 |
+ exit 1
|
|
Panu Matilainen |
2981a8 |
+ fi
|
|
Panu Matilainen |
2981a8 |
done
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
@@ -50,12 +60,16 @@ done
|
|
Panu Matilainen |
2981a8 |
# implementation:
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
# Generate normal (.pyc) byte-compiled files.
|
|
Panu Matilainen |
2981a8 |
-$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))'
|
|
Panu Matilainen |
2981a8 |
-if [ $? != 0 ]; then
|
|
Panu Matilainen |
2981a8 |
+$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))'
|
|
Panu Matilainen |
2981a8 |
+if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
Panu Matilainen |
2981a8 |
# One or more of the files had a syntax error
|
|
Panu Matilainen |
2981a8 |
- # XXX TODO: parametrize the exit code, only warn for now
|
|
Panu Matilainen |
2981a8 |
- exit 0
|
|
Panu Matilainen |
2981a8 |
+ exit 1
|
|
Panu Matilainen |
2981a8 |
fi
|
|
Panu Matilainen |
2981a8 |
|
|
Panu Matilainen |
2981a8 |
# Generate optimized (.pyo) byte-compiled files.
|
|
Panu Matilainen |
2981a8 |
-$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
|
|
Panu Matilainen |
2981a8 |
+$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
|
|
Panu Matilainen |
2981a8 |
+if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
Panu Matilainen |
2981a8 |
+ # One or more of the files had a syntax error
|
|
Panu Matilainen |
2981a8 |
+ exit 1
|
|
Panu Matilainen |
2981a8 |
+fi
|
|
Panu Matilainen |
2981a8 |
+exit 0
|