Set up Closure in the build script
[armadillo.git] / build.py
1 #!/usr/bin/env python2.5
2 import os
3 import shutil
4 import subprocess
5 import sys
6
7 ROOT = os.path.dirname(os.path.realpath(__file__))
8 SRC_PATH = os.path.join(ROOT, 'src')
9 PROD_PATH = os.path.join(ROOT, 'out')
10 FE_PATH = os.path.join(ROOT, 'web_frontend')
11
12 CLOSURE_SVN = 'http://closure-library.googlecode.com/svn/trunk/'
13 CLOSURE_REV = '235'
14 CLOSURE_DEST = os.path.join(ROOT, 'closure')
15 CLOSURE_COMPILER = os.path.join(ROOT, 'closure-compiler.jar')
16 CLOSURE_CALCDEPS = os.path.join(CLOSURE_DEST, 'closure', 'bin', 'calcdeps.py')
17
18 SOURCES = [
19 'server.go',
20 'main.go'
21 ]
22 SOURCES_FE = [
23 'main.js'
24 ]
25 RESOURCES_FE = [
26 'index.html'
27 ]
28 PRODUCT_NAME = 'armadillo'
29
30 COMPILER = '8g'
31 LINKER = '8l'
32 O_EXTENSION = '8'
33
34 def _ObjFileName(gofile):
35 gofile = os.path.basename(gofile)
36 return os.path.join(PROD_PATH, os.path.splitext(gofile)[0] + '.' + O_EXTENSION)
37
38 def _PullDeps():
39 print '=== Pulling Dependencies ==='
40 if os.path.exists(CLOSURE_DEST):
41 handle = subprocess.Popen([ 'svn', 'info', CLOSURE_DEST ], stdout = subprocess.PIPE)
42 handle.wait()
43 for line in handle.stdout:
44 if line.startswith('Revision'):
45 if not line.startswith('Revision: ' + CLOSURE_REV):
46 subprocess.Popen([ 'svn', 'update', '-r', CLOSURE_REV, CLOSURE_DEST ]).wait()
47 else:
48 print ' Closure @ ' + CLOSURE_REV
49 else:
50 subprocess.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV, CLOSURE_SVN, CLOSURE_DEST ]).wait()
51
52 def Main():
53 print '=== Starting Build ==='
54 os.chdir(PROD_PATH)
55
56 # Compile.
57 for gofile in SOURCES:
58 gofile = os.path.join(SRC_PATH, gofile)
59 args = [ COMPILER, gofile ]
60 print ' ' + ' '.join(args)
61 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
62 handle.wait()
63
64 # Link
65 objects = map(_ObjFileName, SOURCES)
66 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.8' ]
67 print ' ' + ' ' .join(args)
68 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
69 handle.wait()
70
71 _PullDeps()
72
73 # Copy
74 fe_resources = os.path.join(PROD_PATH, 'fe')
75 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
76 os.mkdir(fe_resources)
77 for resource in RESOURCES_FE:
78 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
79
80 # Compile JS.
81 print '=== Compiling Front End ==='
82 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
83 fe_sources = map(lambda f: os.path.join(FE_PATH, f), SOURCES_FE)
84 closure_sources = os.path.join(CLOSURE_DEST, 'closure', 'goog')
85 args = [ CLOSURE_CALCDEPS, '-i', ' '.join(fe_sources), '-p', closure_sources,
86 '-o', 'compiled', '-c', CLOSURE_COMPILER, '--output_file', outfile ]
87 print ' ' + ' '.join(args)
88 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
89 handle.wait()
90
91 if __name__ == '__main__':
92 Main()