]> src.bluestatic.org Git - armadillo.git/blob - build.py
Move inline CSS to the screen.css file
[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_COMPILER = os.path.join(ROOT, 'closure-compiler.jar')
26
27 VERSION_FILE = os.path.join(FE_PATH, 'version.js.proto')
28
29 SOURCES = [
30 'config.go',
31 'paths.go',
32 'tv_rename.go',
33 'server.go',
34 'main.go'
35 ]
36 SOURCES_FE = [
37 'jquery-1.7.1.js',
38 'utils.js',
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 PRODUCT_NAME = 'armadillo'
52
53 # The Golang version (hg id).
54 BACK_END_COMPILER_VERSION = '95d2ce135523 (release-branch.r57) release/release.r57.1'
55
56 COMPILER = '6g'
57 LINKER = '6l'
58 O_EXTENSION = '6'
59
60 def _CompileBackEnd():
61 for gofile in SOURCES:
62 gofile = os.path.join(SRC_PATH, gofile)
63 args = [ COMPILER, gofile ]
64 print ' ' + ' '.join(args)
65 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
66 handle.wait()
67
68 # Link
69 args = [ LINKER, '-o', os.path.join(PROD_PATH, PRODUCT_NAME), 'main.' + O_EXTENSION ]
70 print ' ' + ' ' .join(args)
71 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
72 handle.wait()
73
74 def _StampVersion(options):
75 print '=== Version Stamp ==='
76 if os.path.exists(VERSION_FILE):
77 gitcrement = subprocess.Popen([ 'gitcrement', 'next' ], stdout = subprocess.PIPE, cwd = ROOT)
78 gitcrement.wait()
79 build_stamp = gitcrement.stdout.read().strip()
80 time_stamp = str(int(time.time()))
81
82 fd = open(VERSION_FILE, 'a+')
83 fd.seek(0)
84 lines = fd.readlines()
85 fd.seek(0)
86 fd.truncate()
87 for line in lines:
88 line = re.sub(r'(BUILD =) ([0-9\.]+)', r'\1 ' + build_stamp, line)
89 line = re.sub(r'(STAMP =) ([0-9]+)', r'\1 ' + time_stamp, line)
90 fd.write(line)
91 fd.close()
92 print ' BUILD ' + build_stamp + ' @ ' + time_stamp
93 if options.compile_fe:
94 mfiles = subprocess.Popen([ 'git', 'ls-files', '-m' ], stdout = subprocess.PIPE, cwd = ROOT)
95 mfiles.wait()
96 versioned_stamp_file = string.replace(VERSION_FILE, '.proto', '')
97 shutil.copy(VERSION_FILE, versioned_stamp_file)
98 print ' COPY version.js.proto -> version.js'
99 if not len(mfiles.stdout.readlines()):
100 subprocess.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
101 '-m', 'Stamp version.js @ ' + build_stamp + '.', versioned_stamp_file ], stdout = sys.stdout,
102 stderr = sys.stderr).wait()
103
104 def _CompileFrontEnd(options):
105 # Copy
106 print '=== Copying Resources ==='
107 fe_resources = os.path.join(PROD_PATH, 'fe')
108 subprocess.Popen([ 'rm', '-rf', fe_resources ]).wait()
109 os.mkdir(fe_resources)
110 for resource in RESOURCES_FE:
111 print ' COPY ' + resource
112 shutil.copy(os.path.join(FE_PATH, resource), fe_resources)
113
114 # Version
115 _StampVersion(options)
116
117 # Compile JS.
118 print '=== Compiling Front End ==='
119 outfile = os.path.join(PROD_PATH, 'fe', PRODUCT_NAME + '.js')
120 if options.compile_fe:
121 fe_sources = map(lambda f: '--js=' + os.path.join(FE_PATH, f), SOURCES_FE)
122 args = [ 'java', '-jar', CLOSURE_COMPILER ]
123 args.extend(fe_sources)
124 args.extend(['--js_output_file', outfile, '--compilation_level', 'SIMPLE_OPTIMIZATIONS'])
125 print ' ' + ' '.join(args)
126 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
127 handle.wait()
128 else:
129 fd = open(outfile, 'w+')
130 for fe_source in SOURCES_FE:
131 fd2 = open(os.path.join(FE_PATH, fe_source), 'r')
132 fd.write('// === ' + fe_source + '\n')
133 fd.write(fd2.read())
134 fd2.close()
135 fd.close()
136 print ' DONE'
137
138
139 def Main():
140 parser = optparse.OptionParser()
141 parser.add_option('-c', '--closure_fe', action="store_true", dest="compile_fe",
142 help="Run the Front End inputs through the Closure Compiler")
143 parser.add_option('-b', '--back-end', action="store_true", dest="backend_only",
144 help="Compiles only the back-end")
145 parser.add_option('-f', '--front-end', action="store_true", dest="frontend_only",
146 help="Compiles only the front-end")
147 (options, args) = parser.parse_args()
148
149 print '=== Starting Build ==='
150 os.chdir(PROD_PATH)
151
152 if not options.frontend_only:
153 _CompileBackEnd()
154
155 if not options.backend_only:
156 _CompileFrontEnd(options)
157
158 if __name__ == '__main__':
159 Main()