19
19
# Author: Matt Giuca, Refactored by David Coles
23
# Compiles all files and sets up a jail template in the source directory.
25
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
27
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
28
# Copies console/ to a location within the jail.
29
# Copies OS programs and files to corresponding locations within the jail
30
# (eg. python and Python libs, ld.so, etc).
31
# Generates .pyc files for all the IVLE .py files.
27
from setup import util
36
from setuputil import *
30
39
usage = """usage: %prog build [options]
32
Compiles platform-specific code, and optionally Python too.
41
Compiles all files and sets up a jail template in the source directory.
42
-O is recommended to cause compilation to be optimised.
34
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
35
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
36
Optionally generates .pyc files for all the IVLE .py files."""
44
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
45
Compiles (GCC) timount/timount.c to timount/timount.
46
Creates jail with system and student packages installed from MIRROR.
47
Copies console/ to a location within the jail.
48
Copies OS programs and files to corresponding locations within the jail
49
(eg. python and Python libs, ld.so, etc).
50
Generates .pyc or .pyo files for all the IVLE .py files."""
39
53
parser = optparse.OptionParser(usage)
40
54
parser.add_option("-n", "--dry",
41
55
action="store_true", dest="dry",
42
56
help="Print out the actions but don't do anything.")
43
parser.add_option("--no-compile",
44
action="store_true", dest="nocompile",
45
help="Don't byte-compile .py files.")
57
parser.add_option("-J", "--norebuildjail",
58
action="store_true", dest="norebuildjail",
59
help="Don't recreate jail/ - just update its IVLE code.")
60
parser.add_option("-m", "--mirror",
61
action="store", dest="apt_mirror",
62
help="Sets the APT mirror used to build the jail.")
46
63
(options, args) = parser.parse_args(args)
48
65
# Call the real function
49
return __build(options.dry, options.nocompile)
51
def __build(dry=False, no_compile=None):
52
# We need to import the one in the working copy, not in the system path.
53
confmodule = __import__("ivle/conf/conf")
54
install_list = util.InstallList()
66
__build(options.dry, options.norebuildjail, options.apt_mirror)
68
def __build(dry=False,norebuildjail=False,apt_mirror=None):
69
# Importing configuration is a little tricky
70
sys.path.append(os.pardir)
73
# Must be run as root or a dry run
57
75
print "Dry run (no actions will be executed)\n"
77
if not dry and os.geteuid() != 0:
78
print >>sys.stderr, "Must be root to run build"
79
print >>sys.stderr, "(I need to chroot)."
82
# Find out the revison number
83
revnum = get_svn_revision()
84
print "Building Revision %s"%str(revnum)
86
vfile = open('BUILD-VERSION','w')
87
vfile.write(str(revnum) + '\n')
59
90
# Compile the trampoline
60
91
curdir = os.getcwd()
61
os.chdir('bin/trampoline')
62
util.action_runprog('make', [], dry)
92
os.chdir('trampoline')
93
action_runprog('make', [], dry)
66
97
curdir = os.getcwd()
67
os.chdir('bin/timount')
68
util.action_runprog('make', [], dry)
99
action_runprog('make', [], dry)
102
if not norebuildjail:
103
# Create the jail and its subdirectories
104
# Note: Other subdirs will be made by copying files
105
if apt_mirror != None:
106
os.environ['MIRROR'] = apt_mirror
107
action_runprog('./buildjail.sh', [], dry)
109
# Copy all console and operating system files into the jail
110
action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
112
# Chmod the python console
113
action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
114
action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
115
action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
117
# Also copy the IVLE lib directory into the jail
118
# This is necessary for running certain scripts
119
action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
120
# IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
121
# which could compromise security if left in the jail (such as the DB
123
# The "safe" version is in jailconf.py. Delete conf.py and replace it with
125
action_copyfile('lib/conf/jailconf.py',
126
'jail/opt/ivle/lib/conf/conf.py', dry)
71
128
# Compile .py files into .pyc or .pyo files
73
compileall.compile_dir('www', quiet=True)
74
compileall.compile_dir('ivle', quiet=True)
75
compileall.compile_dir('services', quiet=True)
129
compileall.compile_dir('www', quiet=True)
130
compileall.compile_dir('lib', quiet=True)
131
compileall.compile_dir('scripts', quiet=True)
132
compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
134
# Set up ivle.pth inside the jail
135
# Need to set /opt/ivle/lib to be on the import path
137
"jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
138
f = open(ivle_pth, 'w')
139
f.write('/opt/ivle/lib\n')