Add an ability to navigate upwards.
[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 'paths.go',
20 'server.go',
21 'main.go'
22 ]
23 SOURCES_FE = [
24 'main.js'
25 ]
26 RESOURCES_FE = [
27 'index.html'
28 ]
29 PRODUCT_NAME = 'armadillo'
30
31 COMPILER = '8g'
32 LINKER = '8l'
33 O_EXTENSION = '8'
34
35 def _ObjFileName(gofile):
36 gofile = os.path.basename(gofile)
37 return os.path.join(PROD_PATH, os.path.splitext(gofile)[0] + '.' + O_EXTENSION)
38
39 def _PullDeps():
40 print '=== Pulling Dependencies ==='
41 if os.path.exists(CLOSURE_DEST):
42 handle = subprocess.Popen([ 'svn', 'info', CLOSURE_DEST ], stdout = subprocess.PIPE)
43 handle.wait()
44 for line in handle.stdout:
45 if line.startswith('Revision'):
46 if not line.startswith('Revision: ' + CLOSURE_REV):
47 subprocess.Popen([ 'svn', 'update', '-r', CLOSURE_REV, CLOSURE_DEST ]).wait()
48 else:
49 print ' Closure @ ' + CLOSURE_REV
50 else:
51 subprocess.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV, CLOSURE_SVN, CLOSURE_DEST ]).wait()
52
53 def Main():
54 print '=== Starting Build ==='
55 os.chdir(PROD_PATH)
56
57 # Compile.
58 for gofile in SOURCES:
59 gofile = os.path.join(SRC_PATH, gofile)
60 args = [ COMPILER, gofile ]
61 print ' ' + ' '.join(args)
62 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
63 handle.wait()
64
65 # Link
66 objects = map(_ObjFileName, SOURCES)
67 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.8' ]
68 print ' ' + ' ' .join(args)
69 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
70 handle.wait()
71
72 _PullDeps()
73
74 # Copy
75 fe_resources = os.path.join(PROD_PATH, 'fe')
76 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
77 os.mkdir(fe_resources)
78 for resource in RESOURCES_FE:
79 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
80
81 # Compile JS.
82 print '=== Compiling Front End ==='
83 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
84 fe_sources = map(lambda f: os.path.join(FE_PATH, f), SOURCES_FE)
85 closure_sources = os.path.join(CLOSURE_DEST, 'closure', 'goog')
86 args = [ CLOSURE_CALCDEPS, '-i', ' '.join(fe_sources), '-p', closure_sources,
87 '-o', 'compiled', '-c', CLOSURE_COMPILER, '--output_file', outfile ]
88 print ' ' + ' '.join(args)
89 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
90 handle.wait()
91
92 if __name__ == '__main__':
93 Main()