]> src.bluestatic.org Git - armadillo.git/blob - build.py
Create a README file
[armadillo.git] / build.py
1 #!/usr/bin/env python2.5
2 #
3 # Armadillo File Manager
4 # Copyright (c) 2010-2012, 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, 'frontend')
23 FE_PATH = os.path.join(ROOT, '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_FE = [
30 'jquery-1.7.1.js',
31 'utils.js',
32 'version.js',
33 'tv_renamer.js',
34 'path_control.js',
35 'actor.js',
36 'file.js',
37 'main.js',
38 ]
39 PRODUCT_NAME = 'armadillo'
40
41 # The Golang version (hg id).
42 BACK_END_COMPILER_VERSION = '920e9d1ffd1f (release-branch.go1) go1/release'
43
44 def _CompileBackEnd():
45 args = [ 'go', 'build', '-v', '.' ]
46 print ' ' + ' ' .join(args)
47 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
48 handle.wait()
49
50 def _StampVersion(options):
51 print '=== Version Stamp ==='
52 if os.path.exists(VERSION_FILE):
53 gitcrement = subprocess.Popen([ 'gitcrement', 'next' ], stdout = subprocess.PIPE, cwd = ROOT)
54 gitcrement.wait()
55 build_stamp = gitcrement.stdout.read().strip()
56 time_stamp = str(int(time.time()))
57
58 fd = open(VERSION_FILE, 'a+')
59 fd.seek(0)
60 lines = fd.readlines()
61 fd.seek(0)
62 fd.truncate()
63 for line in lines:
64 line = re.sub(r'(BUILD =) ([0-9\.]+)', r'\1 ' + build_stamp, line)
65 line = re.sub(r'(STAMP =) ([0-9]+)', r'\1 ' + time_stamp, line)
66 fd.write(line)
67 fd.close()
68 print ' BUILD ' + build_stamp + ' @ ' + time_stamp
69 if options.compile_fe:
70 mfiles = subprocess.Popen([ 'git', 'ls-files', '-m' ], stdout = subprocess.PIPE, cwd = ROOT)
71 mfiles.wait()
72 versioned_stamp_file = string.replace(VERSION_FILE, '.proto', '')
73 shutil.copy(VERSION_FILE, versioned_stamp_file)
74 print ' COPY version.js.proto -> version.js'
75 if not len(mfiles.stdout.readlines()):
76 subprocess.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
77 '-m', 'Stamp version.js @ ' + build_stamp + '.', versioned_stamp_file ], stdout = sys.stdout,
78 stderr = sys.stderr).wait()
79
80 def _CompileFrontEnd(options):
81 # Version
82 _StampVersion(options)
83
84 # Compile JS.
85 print '=== Compiling Front End ==='
86 outfile = os.path.join(PROD_PATH, PRODUCT_NAME + '.js')
87 if options.compile_fe:
88 fe_sources = map(lambda f: '--js=' + os.path.join(FE_PATH, f), SOURCES_FE)
89 args = [ 'java', '-jar', CLOSURE_COMPILER ]
90 args.extend(fe_sources)
91 args.extend(['--js_output_file', outfile, '--compilation_level', 'SIMPLE_OPTIMIZATIONS'])
92 print ' ' + ' '.join(args)
93 handle = subprocess.Popen(args, stdout = sys.stdout, stderr = sys.stderr)
94 handle.wait()
95 else:
96 fd = open(outfile, 'w+')
97 for fe_source in SOURCES_FE:
98 fd2 = open(os.path.join(FE_PATH, fe_source), 'r')
99 fd.write('// === ' + fe_source + '\n')
100 fd.write(fd2.read())
101 fd2.close()
102 fd.close()
103 print ' DONE'
104
105
106 def Main():
107 parser = optparse.OptionParser()
108 parser.add_option('-c', '--closure_fe', action="store_true", dest="compile_fe",
109 help="Run the Front End inputs through the Closure Compiler")
110 parser.add_option('-b', '--back-end', action="store_true", dest="backend_only",
111 help="Compiles only the back-end")
112 parser.add_option('-f', '--front-end', action="store_true", dest="frontend_only",
113 help="Compiles only the front-end")
114 (options, args) = parser.parse_args()
115
116 print '=== Starting Build ==='
117 os.chdir(ROOT)
118 if not options.frontend_only:
119 _CompileBackEnd()
120
121 if not options.backend_only:
122 _CompileFrontEnd(options)
123
124 if __name__ == '__main__':
125 Main()