|
|
23b3e9 |
#!/bin/bash
|
|
|
23b3e9 |
# Altered from brp-python-bytecompile
|
|
|
23b3e9 |
errors_terminate=$2
|
|
|
23b3e9 |
|
|
|
23b3e9 |
# If using normal root, avoid changing anything.
|
|
|
23b3e9 |
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
|
|
|
23b3e9 |
exit 0
|
|
|
23b3e9 |
fi
|
|
|
23b3e9 |
|
|
|
23b3e9 |
# If we don't have a python interpreter, exit.
|
|
|
23b3e9 |
python=$1
|
|
|
23b3e9 |
if [ ! -x "$python" ]; then
|
|
|
23b3e9 |
exit 2
|
|
|
23b3e9 |
fi
|
|
|
23b3e9 |
|
|
|
23b3e9 |
# Figure out how deep we need to descend. We could pick an insanely high
|
|
|
23b3e9 |
# number and hope it's enough, but somewhere, somebody's sure to run into it.
|
|
|
23b3e9 |
depth=`(find $RPM_BUILD_ROOT -type f -name "*.py" -print0 ; echo /) | \
|
|
|
23b3e9 |
xargs -0 -n 1 dirname | sed 's,[^/],,g' | sort -u | tail -n 1 | wc -c`
|
|
|
23b3e9 |
if [ -z "$depth" -o "$depth" -le "1" ]; then
|
|
|
23b3e9 |
exit 0
|
|
|
23b3e9 |
fi
|
|
|
23b3e9 |
|
|
|
23b3e9 |
# Generate normal (.pyc) byte-compiled files.
|
|
|
23b3e9 |
$python -c 'import compileall, re, sys; sys.exit (not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/"'"), quiet=1))'
|
|
|
23b3e9 |
if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
|
23b3e9 |
# One or more of the files had a syntax error
|
|
|
23b3e9 |
exit 1
|
|
|
23b3e9 |
fi
|
|
|
23b3e9 |
|
|
|
23b3e9 |
# Generate optimized (.pyo) byte-compiled files.
|
|
|
23b3e9 |
$python -O -c 'import compileall, re, sys; sys.exit(not compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1, re.compile(r"'"/bin/|/sbin/"'"), quiet=1))' > /dev/null
|
|
|
23b3e9 |
if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
|
|
|
23b3e9 |
# One or more of the files had a syntax error
|
|
|
23b3e9 |
exit 1
|
|
|
23b3e9 |
fi
|
|
|
23b3e9 |
exit 0
|