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