Remove the Users map now that it is taken care of by MFE
[armadillo.git] / build.py
1 #!/usr/bin/env python2.5
2 #
3 # Armadillo File Manager
4 # Copyright (c) 2010-2011, 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
11 import optparse
12 import os
13 import re
14 import shutil
15 import string
16 import subprocess
17 import sys
18 import time
19
20 ROOT = os.path.dirname(os.path.realpath(__file__))
21 SRC_PATH = os.path.join(ROOT, 'src')
22 PROD_PATH = os.path.join(ROOT, 'out')
23 FE_PATH = os.path.join(ROOT, 'web_frontend')
24
25 CLOSURE_SVN = 'http://closure-library.googlecode.com/svn/trunk/'
26 CLOSURE_REV = '886'
27 CLOSURE_DEST = os.path.join(ROOT, 'closure')
28 CLOSURE_COMPILER = os.path.join(ROOT, 'closure-compiler.jar')
29 CLOSURE_CALCDEPS = os.path.join(CLOSURE_DEST, 'closure', 'bin', 'calcdeps.py')
30
31 VERSION_FILE = os.path.join(FE_PATH, 'version.js.proto')
32
33 SOURCES = [
34 'config.go',
35 'paths.go',
36 'tv_rename.go',
37 'server.go',
38 'main.go'
39 ]
40 SOURCES_FE = [
41 'version.js',
42 'tv_renamer.js',
43 'path_control.js',
44 'actor.js',
45 'file.js',
46 'main.js',
47 ]
48 RESOURCES_FE = [
49 'index.html',
50 'screen.css',
51 'reset.css'
52 ]
53 RESOURCES_CLOSURE = [
54 'common.css',
55 'dialog.css',
56 'menu.css',
57 'menuitem.css',
58 'menubutton.css',
59 ]
60 PRODUCT_NAME = 'armadillo'
61
62 # The Golang version (hg id).
63 BACK_END_COMPILER_VERSION = '95d2ce135523 (release-branch.r57) release/release.r57.1'
64
65 COMPILER = '6g'
66 LINKER = '6l'
67 O_EXTENSION = '6'
68
69 def _PullDeps():
70 print '=== Pulling Dependencies ==='
71 if os.path.exists(CLOSURE_DEST):
72 handle = subprocess.Popen([ 'svn', 'info', CLOSURE_DEST ], stdout = subprocess.PIPE)
73 handle.wait()
74 for line in handle.stdout:
75 if line.startswith('Revision'):
76 if not line.strip().endswith(CLOSURE_REV):
77 subprocess.Popen([ 'svn', 'update', '-r', CLOSURE_REV, CLOSURE_DEST ]).wait()
78 else:
79 print ' Closure @ ' + CLOSURE_REV
80 else:
81 subprocess.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV, CLOSURE_SVN, CLOSURE_DEST ]).wait()
82
83 def _CompileBackEnd():
84 for gofile in SOURCES:
85 gofile = os.path.join(SRC_PATH, gofile)
86 args = [ COMPILER, gofile ]
87 print ' ' + ' '.join(args)
88 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
89 handle.wait()
90
91 # Link
92 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.' + O_EXTENSION ]
93 print ' ' + ' ' .join(args)
94 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
95 handle.wait()
96
97 def _StampVersion(options):
98 print '=== Version Stamp ==='
99 if os.path.exists(VERSION_FILE):
100 gitcrement = subprocess.Popen([ 'gitcrement', 'next' ], stdout = subprocess.PIPE, cwd = ROOT)
101 gitcrement.wait()
102 build_stamp = gitcrement.stdout.read().strip()
103 time_stamp = str(int(time.time()))
104
105 fd = open(VERSION_FILE, 'a+')
106 fd.seek(0)
107 lines = fd.readlines()
108 fd.seek(0)
109 fd.truncate()
110 for line in lines:
111 line = re.sub(r'(BUILD =) ([0-9\.]+)', r'\1 ' + build_stamp, line)
112 line = re.sub(r'(STAMP =) ([0-9]+)', r'\1 ' + time_stamp, line)
113 fd.write(line)
114 fd.close()
115 print ' BUILD ' + build_stamp + ' @ ' + time_stamp
116 if options.compile_fe:
117 mfiles = subprocess.Popen([ 'git', 'ls-files', '-m' ], stdout = subprocess.PIPE, cwd = ROOT)
118 mfiles.wait()
119 versioned_stamp_file = string.replace(VERSION_FILE, '.proto', '')
120 shutil.copy(VERSION_FILE, versioned_stamp_file)
121 print ' COPY version.js.proto -> version.js'
122 if not len(mfiles.stdout.readlines()):
123 subprocess.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
124 '-m', 'Stamp version.js @ ' + build_stamp + '.', versioned_stamp_file ], stdout = sys.stdout,
125 stderr = sys.stderr).wait()
126
127 def _CompileFrontEnd(options):
128 _PullDeps()
129
130 # Copy
131 print '=== Copying Resources ==='
132 fe_resources = os.path.join(PROD_PATH, 'fe')
133 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
134 os.mkdir(fe_resources)
135 for resource in RESOURCES_FE:
136 print ' COPY ' + resource
137 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
138 fd = open(os.path.join(fe_resources, 'closure.css'), 'w+')
139 fd.write('/*=== Generated Resources for Closure Library ===*/')
140 for resource in RESOURCES_CLOSURE:
141 print ' COPY closure/' + resource
142 respath = os.path.join(CLOSURE_DEST, 'closure', 'goog', 'css', resource)
143 ofd = open(respath, 'r')
144 fd.write('\n\n/*=== File: ' + respath.replace(ROOT, '/') + ' ===*/\n')
145 fd.writelines(ofd.readlines())
146 ofd.close()
147 fd.close()
148
149 # Version
150 _StampVersion(options)
151
152 # Compile JS.
153 print '=== Compiling Front End ==='
154 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
155 fe_sources = map(lambda f: '-i' + os.path.join(FE_PATH, f), SOURCES_FE)
156 closure_sources = os.path.join(CLOSURE_DEST, 'closure', 'goog')
157 args = [ CLOSURE_CALCDEPS ]
158 args.extend(fe_sources)
159 output = "script"
160 if options.compile_fe:
161 output = "compiled"
162 args.extend([ '-p', closure_sources, '-o', output, '-c', CLOSURE_COMPILER,
163 '--output_file', outfile ])
164 print ' ' + ' '.join(args)
165 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
166 handle.wait()
167
168
169 def Main():
170 parser = optparse.OptionParser()
171 parser.add_option('-c', '--closure_fe', action="store_true", dest="compile_fe",
172 help="Run the Front End inputs through the Closure Compiler")
173 parser.add_option('-b', '--back-end', action="store_true", dest="backend_only",
174 help="Compiles only the back-end")
175 parser.add_option('-f', '--front-end', action="store_true", dest="frontend_only",
176 help="Compiles only the front-end")
177 (options, args) = parser.parse_args()
178
179 print '=== Starting Build ==='
180 os.chdir(PROD_PATH)
181
182 if not options.frontend_only:
183 _CompileBackEnd()
184
185 if not options.backend_only:
186 _CompileFrontEnd(options)
187
188 if __name__ == '__main__':
189 Main()