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