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