Properly unlisten to tile events.
[armadillo.git] / build.py
1 #!/usr/bin/env python2.5
2 #
3 # Armadillo File Manager
4 # Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 #
6 # This program is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation, either version 3 of the License, or any later version.
9 #
10 import os
11 import shutil
12 import subprocess
13 import sys
14
15 ROOT = os.path.dirname(os.path.realpath(__file__))
16 SRC_PATH = os.path.join(ROOT, 'src')
17 PROD_PATH = os.path.join(ROOT, 'out')
18 FE_PATH = os.path.join(ROOT, 'web_frontend')
19
20 CLOSURE_SVN = 'http://closure-library.googlecode.com/svn/trunk/'
21 CLOSURE_REV = '235'
22 CLOSURE_DEST = os.path.join(ROOT, 'closure')
23 CLOSURE_COMPILER = os.path.join(ROOT, 'closure-compiler.jar')
24 CLOSURE_CALCDEPS = os.path.join(CLOSURE_DEST, 'closure', 'bin', 'calcdeps.py')
25
26 SOURCES = [
27 'paths.go',
28 'server.go',
29 'main.go'
30 ]
31 SOURCES_FE = [
32 'actor.js',
33 'file.js',
34 'main.js',
35 ]
36 RESOURCES_FE = [
37 'index.html',
38 'screen.css',
39 'reset.css'
40 ]
41 PRODUCT_NAME = 'armadillo'
42
43 COMPILER = '8g'
44 LINKER = '8l'
45 O_EXTENSION = '8'
46
47 def _ObjFileName(gofile):
48 gofile = os.path.basename(gofile)
49 return os.path.join(PROD_PATH, os.path.splitext(gofile)[0] + '.' + O_EXTENSION)
50
51 def _PullDeps():
52 print '=== Pulling Dependencies ==='
53 if os.path.exists(CLOSURE_DEST):
54 handle = subprocess.Popen([ 'svn', 'info', CLOSURE_DEST ], stdout = subprocess.PIPE)
55 handle.wait()
56 for line in handle.stdout:
57 if line.startswith('Revision'):
58 if not line.startswith('Revision: ' + CLOSURE_REV):
59 subprocess.Popen([ 'svn', 'update', '-r', CLOSURE_REV, CLOSURE_DEST ]).wait()
60 else:
61 print ' Closure @ ' + CLOSURE_REV
62 else:
63 subprocess.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV, CLOSURE_SVN, CLOSURE_DEST ]).wait()
64
65 def Main():
66 print '=== Starting Build ==='
67 os.chdir(PROD_PATH)
68
69 # Compile.
70 for gofile in SOURCES:
71 gofile = os.path.join(SRC_PATH, gofile)
72 args = [ COMPILER, gofile ]
73 print ' ' + ' '.join(args)
74 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
75 handle.wait()
76
77 # Link
78 objects = map(_ObjFileName, SOURCES)
79 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.8' ]
80 print ' ' + ' ' .join(args)
81 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
82 handle.wait()
83
84 _PullDeps()
85
86 # Copy
87 print '=== Copying Resources ==='
88 fe_resources = os.path.join(PROD_PATH, 'fe')
89 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
90 os.mkdir(fe_resources)
91 for resource in RESOURCES_FE:
92 print ' COPY ' + resource
93 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
94
95 # Compile JS.
96 print '=== Compiling Front End ==='
97 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
98 fe_sources = map(lambda f: '-i' + os.path.join(FE_PATH, f), SOURCES_FE)
99 closure_sources = os.path.join(CLOSURE_DEST, 'closure', 'goog')
100 args = [ CLOSURE_CALCDEPS ]
101 args.extend(fe_sources)
102 args.extend([ '-p', closure_sources, '-o', 'compiled', '-c', CLOSURE_COMPILER,
103 '--output_file', outfile ])
104 print ' ' + ' '.join(args)
105 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
106 handle.wait()
107
108 if __name__ == '__main__':
109 Main()