source: trunk/scripts/pybin.sh @ 1184

Revision 993, 1.7 KB checked in by strat.cristian@…, 3 years ago (diff)

Experimental Python Support

This is highly experimental, potentially unsafe. I only enabled it for admins until it's stable.

  • Bash script to compile and link static binaries from Python scripts.
  • Additional unit tests for jrun. (Added several Python test cases.)
  • UI changes for admins only.
  • Property svn:executable set to *
Line 
1#!/usr/bin/env bash
2
3# This tries to compile a Python script into a self-contained binary.
4# It uses the freeze.py tool in the standard Python distribution.
5# Dependencies are statically linked, with the exception of glibc.
6# Compilation will exclude most of the "batteries included" in the
7# Python distribution, as they are not appropriate for infoarena.
8#
9# Usage:
10#   pybin.sh <python-dist-dir> <temp-dir> <python-script> <output-binary>
11#   (Note: It will fill your temp dir with tons of files!)
12#
13# Example:
14#   ./pybin.sh ~/Desktop/Python-2.6.1 /tmp/pybin myscript.py mybinary
15
16if [ $# -ne 4 ]
17then
18    echo -n "Usage: "
19    echo "pybin.sh <python-dist-dir> <temp-dir> <python-script> <output-binary>"
20    exit 1
21fi
22
23DIR_PY_DIST=$1
24DIR_TMP=$2
25PY_SRC=$3
26PY_BINARY=$4
27PY_TMP_BINARY=$DIR_TMP/`basename $PY_SRC | cut -f1 -d"."`
28
29echo Freezing python module...
30FREEZE="$DIR_PY_DIST/python $DIR_PY_DIST/Tools/freeze/freeze.py"
31$FREEZE -q -o $DIR_TMP \
32        -X BaseHTTPServer -X distutils -X difflib -X EasyDialogs -X email \
33        -X email.utils -X FixTk -X ftplib -X getopt -X gettext \
34        -X httplib -X MacOS -X mimetools -X msvcrt -X ntpath \
35        -X pdb -X pkgutil -X pydoc -X readline -X riscos -X shlex -X socket \
36        -X SocketServer -X sre -X sre_compile -X sre_constants -X sre_parse \
37        -X ssl -X subprocess -X textwrap -X threading -X Tkinter \
38        -X unittest -X urllib -X uu -X _warnings -X webbrowser $PY_SRC
39
40echo Compiling python binary...
41# Change Makefile, add static link flag.
42mv $DIR_TMP/Makefile $DIR_TMP/Makefile.dynamic
43sed $DIR_TMP/Makefile.dynamic -e 's/^LDFLAGS=\(.*\)/LDFLAGS=\1 --static/' > $DIR_TMP/Makefile
44make -C $DIR_TMP 1>/dev/null
45cp -p $PY_TMP_BINARY $PY_BINARY 2>/dev/null
46echo Done
47
Note: See TracBrowser for help on using the repository browser.