1 #!/usr/bin/env python2.5
3 # Armadillo File Manager
4 # Copyright (c) 2010-2011, 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
, 'out')
23 FE_PATH
= os
.path
.join(ROOT
, 'web_frontend')
25 CLOSURE_COMPILER
= os
.path
.join(ROOT
, 'closure-compiler.jar')
27 VERSION_FILE
= os
.path
.join(FE_PATH
, 'version.js.proto')
51 PRODUCT_NAME
= 'armadillo'
53 # The Golang version (hg id).
54 BACK_END_COMPILER_VERSION
= '95d2ce135523 (release-branch.r57) release/release.r57.1'
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
)
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
)
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
)
79 build_stamp
= gitcrement
.stdout
.read().strip()
80 time_stamp
= str(int(time
.time()))
82 fd
= open(VERSION_FILE
, 'a+')
84 lines
= fd
.readlines()
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
)
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
)
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()
104 def _CompileFrontEnd(options
):
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
)
115 _StampVersion(options
)
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
)
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')
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()
149 print '=== Starting Build ==='
152 if not options
.frontend_only
:
155 if not options
.backend_only
:
156 _CompileFrontEnd(options
)
158 if __name__
== '__main__':