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.
36
from setuputil import *
27
from setup import util
39
30
usage = """usage: %prog build [options]
41
32
Compiles all files and sets up a jail template in the source directory.
42
33
-O is recommended to cause compilation to be optimised.
44
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
45
Compiles (GCC) timount/timount.c to timount/timount.
35
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
36
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
46
37
Creates jail with system and student packages installed from MIRROR.
47
38
Copies console/ to a location within the jail.
48
39
Copies OS programs and files to corresponding locations within the jail
63
54
(options, args) = parser.parse_args(args)
65
56
# Call the real function
66
__build(options.dry, options.rebuildjail, options.apt_mirror)
57
return __build(options.dry, options.rebuildjail, options.apt_mirror)
68
59
def __build(dry=False,rebuildjail=False,apt_mirror=None):
69
# Importing configuration is a little tricky
70
sys.path.append(os.pardir)
60
# We need to import the one in the working copy, not in the system path.
61
confmodule = __import__("ivle/conf/conf")
62
install_list = util.InstallList()
73
64
# Must be run as root or a dry run
83
74
print >> sys.stderr, "No jail exists -- please rerun with -j."
86
# Find out the revison number
87
revnum = get_svn_revision()
88
print "Building Revision %s"%str(revnum)
90
vfile = open('BUILD-VERSION','w')
91
vfile.write(str(revnum) + '\n')
94
77
# Compile the trampoline
95
78
curdir = os.getcwd()
96
os.chdir('trampoline')
97
action_runprog('make', [], dry)
79
os.chdir('bin/trampoline')
80
util.action_runprog('make', [], dry)
101
84
curdir = os.getcwd()
103
action_runprog('make', [], dry)
85
os.chdir('bin/timount')
86
util.action_runprog('make', [], dry)
108
91
# Note: Other subdirs will be made by copying files
109
92
if apt_mirror != None:
110
93
os.environ['MIRROR'] = apt_mirror
111
action_runprog('./bin/buildjail.sh', [], dry)
94
util.action_runprog('setup/buildjail.sh', [], dry)
113
96
# Copy all console and operating system files into the jail
114
action_copylist(install_list.list_services, 'jail/opt/ivle', dry)
97
jail_share = os.path.join('jail', confmodule.share_path[1:])
98
jail_services = os.path.join(jail_share, 'services')
99
util.action_copylist(install_list.list_services, jail_share, dry)
116
101
# Chmod the python console
117
action_chmod_x('jail/opt/ivle/services/python-console', dry)
118
action_chmod_x('jail/opt/ivle/services/fileservice', dry)
119
action_chmod_x('jail/opt/ivle/services/serveservice', dry)
102
util.action_chmod_x(os.path.join(jail_services, 'python-console'), dry)
103
util.action_chmod_x(os.path.join(jail_services, 'fileservice'), dry)
104
util.action_chmod_x(os.path.join(jail_services, 'serveservice'), dry)
121
106
# Also copy the IVLE lib directory into the jail
122
107
# This is necessary for running certain services
123
action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
124
# IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
108
jail_site_packages = os.path.join('jail',
109
confmodule.python_site_packages[1:])
110
util.action_copylist(install_list.list_ivle_lib, jail_site_packages, dry)
111
# IMPORTANT: ivle/conf/conf.py contains details
125
112
# which could compromise security if left in the jail (such as the DB
127
114
# The "safe" version is in jailconf.py. Delete conf.py and replace it with
129
action_copyfile('lib/conf/jailconf.py',
130
'jail/opt/ivle/lib/conf/conf.py', dry)
116
util.action_copyfile('ivle/conf/jailconf.py',
117
os.path.join(jail_site_packages, 'ivle/conf/conf.py'), dry)
132
119
# Compile .py files into .pyc or .pyo files
133
120
compileall.compile_dir('www', quiet=True)
134
compileall.compile_dir('lib', quiet=True)
121
compileall.compile_dir('ivle', quiet=True)
135
122
compileall.compile_dir('services', quiet=True)
136
compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
138
# Set up ivle.pth inside the jail
139
# Need to set /opt/ivle/lib to be on the import path
141
"jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
142
f = open(ivle_pth, 'w')
143
f.write('/opt/ivle/lib\n')
123
compileall.compile_dir(os.path.join(jail_site_packages, 'ivle'),quiet=True)