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