summaryrefslogtreecommitdiff
path: root/autoconf/py-compile
diff options
context:
space:
mode:
Diffstat (limited to 'autoconf/py-compile')
-rwxr-xr-xautoconf/py-compile92
1 files changed, 59 insertions, 33 deletions
diff --git a/autoconf/py-compile b/autoconf/py-compile
index 865cda8..bc20391 100755
--- a/autoconf/py-compile
+++ b/autoconf/py-compile
@@ -1,13 +1,13 @@
#!/bin/sh
# py-compile - Compile a Python program
-scriptversion=2005-05-14.22
+scriptversion=2011-06-08.12; # UTC
-# Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2000-2014 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
+# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
@@ -31,28 +31,36 @@ if [ -z "$PYTHON" ]; then
PYTHON=python
fi
+me=py-compile
+
+usage_error ()
+{
+ echo "$me: $*" >&2
+ echo "Try '$me --help' for more information." >&2
+ exit 1
+}
+
basedir=
destdir=
-files=
while test $# -ne 0; do
case "$1" in
--basedir)
- basedir=$2
- if test -z "$basedir"; then
- echo "$0: Missing argument to --basedir." 1>&2
- exit 1
+ if test $# -lt 2; then
+ usage_error "option '--basedir' requires an argument"
+ else
+ basedir=$2
fi
shift
;;
--destdir)
- destdir=$2
- if test -z "$destdir"; then
- echo "$0: Missing argument to --destdir." 1>&2
- exit 1
+ if test $# -lt 2; then
+ usage_error "option '--destdir' requires an argument"
+ else
+ destdir=$2
fi
shift
;;
- -h|--h*)
+ -h|--help)
cat <<\EOF
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
@@ -68,20 +76,27 @@ Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
- -v|--v*)
- echo "py-compile $scriptversion"
+ -v|--version)
+ echo "$me $scriptversion"
exit $?
;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage_error "unrecognized option '$1'"
+ ;;
*)
- files="$files $1"
+ break
;;
esac
shift
done
+files=$*
if test -z "$files"; then
- echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
- exit 1
+ usage_error "no files given"
fi
# if basedir was given, then it should be prepended to filenames before
@@ -101,38 +116,48 @@ else
fi
$PYTHON -c "
-import sys, os, string, py_compile
+import sys, os, py_compile, imp
files = '''$files'''
-print 'Byte-compiling python modules...'
-for file in string.split(files):
+sys.stdout.write('Byte-compiling python modules...\n')
+for file in files.split():
$pathtrans
$filetrans
if not os.path.exists(filepath) or not (len(filepath) >= 3
and filepath[-3:] == '.py'):
- continue
- print file,
+ continue
+ sys.stdout.write(file)
sys.stdout.flush()
- py_compile.compile(filepath, filepath + 'c', path)
-print" || exit $?
+ if hasattr(imp, 'get_tag'):
+ py_compile.compile(filepath, imp.cache_from_source(filepath), path)
+ else:
+ py_compile.compile(filepath, filepath + 'c', path)
+sys.stdout.write('\n')" || exit $?
# this will fail for python < 1.5, but that doesn't matter ...
$PYTHON -O -c "
-import sys, os, string, py_compile
+import sys, os, py_compile, imp
+
+# pypy does not use .pyo optimization
+if hasattr(sys, 'pypy_translation_info'):
+ sys.exit(0)
files = '''$files'''
-print 'Byte-compiling python modules (optimized versions) ...'
-for file in string.split(files):
+sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
+for file in files.split():
$pathtrans
$filetrans
if not os.path.exists(filepath) or not (len(filepath) >= 3
and filepath[-3:] == '.py'):
- continue
- print file,
+ continue
+ sys.stdout.write(file)
sys.stdout.flush()
- py_compile.compile(filepath, filepath + 'o', path)
-print" 2>/dev/null || :
+ if hasattr(imp, 'get_tag'):
+ py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
+ else:
+ py_compile.compile(filepath, filepath + 'o', path)
+sys.stdout.write('\n')" 2>/dev/null || :
# Local Variables:
# mode: shell-script
@@ -140,5 +165,6 @@ print" 2>/dev/null || :
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
# End: