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