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