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')
45 PRODUCT_NAME
= 'armadillo'
47 # The Golang version (hg id).
48 BACK_END_COMPILER_VERSION
= '920e9d1ffd1f (release-branch.go1) go1/release'
50 def _CompileBackEnd():
51 args
= [ 'go', 'build', '-v', '.' ]
52 print ' ' + ' ' .join(args
)
53 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
56 def _StampVersion(options
):
57 print '=== Version Stamp ==='
58 if os
.path
.exists(VERSION_FILE
):
59 gitcrement
= subprocess
.Popen([ 'gitcrement', 'next' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
61 build_stamp
= gitcrement
.stdout
.read().strip()
62 time_stamp
= str(int(time
.time()))
64 fd
= open(VERSION_FILE
, 'a+')
66 lines
= fd
.readlines()
70 line
= re
.sub(r
'(BUILD =) ([0-9\.]+)', r
'\1 ' + build_stamp
, line
)
71 line
= re
.sub(r
'(STAMP =) ([0-9]+)', r
'\1 ' + time_stamp
, line
)
74 print ' BUILD ' + build_stamp
+ ' @ ' + time_stamp
75 if options
.compile_fe
:
76 mfiles
= subprocess
.Popen([ 'git', 'ls-files', '-m' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
78 versioned_stamp_file
= string
.replace(VERSION_FILE
, '.proto', '')
79 shutil
.copy(VERSION_FILE
, versioned_stamp_file
)
80 print ' COPY version.js.proto -> version.js'
81 if not len(mfiles
.stdout
.readlines()):
82 subprocess
.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
83 '-m', 'Stamp version.js @ ' + build_stamp
+ '.', versioned_stamp_file
], stdout
= sys
.stdout
,
84 stderr
= sys
.stderr
).wait()
86 def _CompileFrontEnd(options
):
88 _StampVersion(options
)
91 print '=== Compiling Front End ==='
92 outfile
= os
.path
.join(PROD_PATH
, PRODUCT_NAME
+ '.js')
93 if options
.compile_fe
:
94 fe_sources
= map(lambda f
: '--js=' + os
.path
.join(FE_PATH
, f
), SOURCES_FE
)
95 args
= [ 'java', '-jar', CLOSURE_COMPILER
]
96 args
.extend(fe_sources
)
97 args
.extend(['--js_output_file', outfile
, '--compilation_level', 'SIMPLE_OPTIMIZATIONS'])
98 print ' ' + ' '.join(args
)
99 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
102 fd
= open(outfile
, 'w+')
103 for fe_source
in SOURCES_FE
:
104 fd2
= open(os
.path
.join(FE_PATH
, fe_source
), 'r')
105 fd
.write('// === ' + fe_source
+ '\n')
113 parser
= optparse
.OptionParser()
114 parser
.add_option('-c', '--closure_fe', action
="store_true", dest
="compile_fe",
115 help="Run the Front End inputs through the Closure Compiler")
116 parser
.add_option('-b', '--back-end', action
="store_true", dest
="backend_only",
117 help="Compiles only the back-end")
118 parser
.add_option('-f', '--front-end', action
="store_true", dest
="frontend_only",
119 help="Compiles only the front-end")
120 (options
, args
) = parser
.parse_args()
122 print '=== Starting Build ==='
124 if not options
.frontend_only
:
127 if not options
.backend_only
:
128 _CompileFrontEnd(options
)
130 if __name__
== '__main__':