1 #!/usr/bin/env python2.5
3 # Armadillo File Manager
4 # Copyright (c) 2010-2012, Robert Sesek <http://www.bluestatic.org>
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.
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')
25 CLOSURE_COMPILER
= os
.path
.join(ROOT
, 'closure-compiler.jar')
27 VERSION_FILE
= os
.path
.join(FE_PATH
, 'version.js.proto')
39 PRODUCT_NAME
= 'armadillo'
41 # The Golang version (hg id).
42 BACK_END_COMPILER_VERSION
= '920e9d1ffd1f (release-branch.go1) go1/release'
44 def _CompileBackEnd():
45 args
= [ 'go', 'build', '-v', '.' ]
46 print ' ' + ' ' .join(args
)
47 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
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
)
55 build_stamp
= gitcrement
.stdout
.read().strip()
56 time_stamp
= str(int(time
.time()))
58 fd
= open(VERSION_FILE
, 'a+')
60 lines
= fd
.readlines()
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
)
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
)
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()
80 def _CompileFrontEnd(options
):
82 _StampVersion(options
)
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
)
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')
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()
116 print '=== Starting Build ==='
118 if not options
.frontend_only
:
121 if not options
.backend_only
:
122 _CompileFrontEnd(options
)
124 if __name__
== '__main__':