Create the unhooked Move action interface.
[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 optparse
11 import os
12 import shutil
13 import subprocess
14 import sys
15
16 ROOT = os.path.dirname(os.path.realpath(__file__))
17 SRC_PATH = os.path.join(ROOT, 'src')
18 PROD_PATH = os.path.join(ROOT, 'out')
19 FE_PATH = os.path.join(ROOT, 'web_frontend')
20
21 CLOSURE_SVN = 'http://closure-library.googlecode.com/svn/trunk/'
22 CLOSURE_REV = '235'
23 CLOSURE_DEST = os.path.join(ROOT, 'closure')
24 CLOSURE_COMPILER = os.path.join(ROOT, 'closure-compiler.jar')
25 CLOSURE_CALCDEPS = os.path.join(CLOSURE_DEST, 'closure', 'bin', 'calcdeps.py')
26
27 SOURCES = [
28 'paths.go',
29 'server.go',
30 'main.go'
31 ]
32 SOURCES_FE = [
33 'actor.js',
34 'file.js',
35 'main.js',
36 ]
37 RESOURCES_FE = [
38 'index.html',
39 'screen.css',
40 'reset.css'
41 ]
42 PRODUCT_NAME = 'armadillo'
43
44 COMPILER = '8g'
45 LINKER = '8l'
46 O_EXTENSION = '8'
47
48 def _ObjFileName(gofile):
49 gofile = os.path.basename(gofile)
50 return os.path.join(PROD_PATH, os.path.splitext(gofile)[0] + '.' + O_EXTENSION)
51
52 def _PullDeps():
53 print '=== Pulling Dependencies ==='
54 if os.path.exists(CLOSURE_DEST):
55 handle = subprocess.Popen([ 'svn', 'info', CLOSURE_DEST ], stdout = subprocess.PIPE)
56 handle.wait()
57 for line in handle.stdout:
58 if line.startswith('Revision'):
59 if not line.startswith('Revision: ' + CLOSURE_REV):
60 subprocess.Popen([ 'svn', 'update', '-r', CLOSURE_REV, CLOSURE_DEST ]).wait()
61 else:
62 print ' Closure @ ' + CLOSURE_REV
63 else:
64 subprocess.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV, CLOSURE_SVN, CLOSURE_DEST ]).wait()
65
66 def Main():
67 parser = optparse.OptionParser()
68 parser.add_option('-c', '--closure_fe', action="store_true", dest="compile_fe",
69 help="Run the Front End inputs through the Closure Compiler")
70 (options, args) = parser.parse_args()
71
72 print '=== Starting Build ==='
73 os.chdir(PROD_PATH)
74
75 # Compile.
76 for gofile in SOURCES:
77 gofile = os.path.join(SRC_PATH, gofile)
78 args = [ COMPILER, gofile ]
79 print ' ' + ' '.join(args)
80 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
81 handle.wait()
82
83 # Link
84 objects = map(_ObjFileName, SOURCES)
85 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.8' ]
86 print ' ' + ' ' .join(args)
87 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
88 handle.wait()
89
90 _PullDeps()
91
92 # Copy
93 print '=== Copying Resources ==='
94 fe_resources = os.path.join(PROD_PATH, 'fe')
95 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
96 os.mkdir(fe_resources)
97 for resource in RESOURCES_FE:
98 print ' COPY ' + resource
99 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
100
101 # Compile JS.
102 print '=== Compiling Front End ==='
103 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
104 fe_sources = map(lambda f: '-i' + os.path.join(FE_PATH, f), SOURCES_FE)
105 closure_sources = os.path.join(CLOSURE_DEST, 'closure', 'goog')
106 args = [ CLOSURE_CALCDEPS ]
107 args.extend(fe_sources)
108 output = "script"
109 if options.compile_fe:
110 output = "compiled"
111 args.extend([ '-p', closure_sources, '-o', output, '-c', CLOSURE_COMPILER,
112 '--output_file', outfile ])
113 print ' ' + ' '.join(args)
114 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
115 handle.wait()
116
117 if __name__ == '__main__':
118 Main()