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')
52 PRODUCT_NAME
= 'armadillo'
54 # The Golang version (hg id).
55 BACK_END_COMPILER_VERSION
= 'c1702f36df03 (release-branch.r60) release/release.r60.3'
61 def _CompileBackEnd():
62 for gofile
in SOURCES
:
63 gofile
= os
.path
.join(SRC_PATH
, gofile
)
64 args
= [ COMPILER
, gofile
]
65 print ' ' + ' '.join(args
)
66 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
70 args
= [ LINKER
, '-o', os
.path
.join(PROD_PATH
, PRODUCT_NAME
), 'main.' + O_EXTENSION
]
71 print ' ' + ' ' .join(args
)
72 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
75 def _StampVersion(options
):
76 print '=== Version Stamp ==='
77 if os
.path
.exists(VERSION_FILE
):
78 gitcrement
= subprocess
.Popen([ 'gitcrement', 'next' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
80 build_stamp
= gitcrement
.stdout
.read().strip()
81 time_stamp
= str(int(time
.time()))
83 fd
= open(VERSION_FILE
, 'a+')
85 lines
= fd
.readlines()
89 line
= re
.sub(r
'(BUILD =) ([0-9\.]+)', r
'\1 ' + build_stamp
, line
)
90 line
= re
.sub(r
'(STAMP =) ([0-9]+)', r
'\1 ' + time_stamp
, line
)
93 print ' BUILD ' + build_stamp
+ ' @ ' + time_stamp
94 if options
.compile_fe
:
95 mfiles
= subprocess
.Popen([ 'git', 'ls-files', '-m' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
97 versioned_stamp_file
= string
.replace(VERSION_FILE
, '.proto', '')
98 shutil
.copy(VERSION_FILE
, versioned_stamp_file
)
99 print ' COPY version.js.proto -> version.js'
100 if not len(mfiles
.stdout
.readlines()):
101 subprocess
.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
102 '-m', 'Stamp version.js @ ' + build_stamp
+ '.', versioned_stamp_file
], stdout
= sys
.stdout
,
103 stderr
= sys
.stderr
).wait()
105 def _CompileFrontEnd(options
):
107 print '=== Copying Resources ==='
108 fe_resources
= os
.path
.join(PROD_PATH
, 'fe')
109 subprocess
.Popen([ 'rm', '-rf', fe_resources
]).wait()
110 os
.mkdir(fe_resources
)
111 for resource
in RESOURCES_FE
:
112 print ' COPY ' + resource
113 shutil
.copy(os
.path
.join(FE_PATH
, resource
), fe_resources
)
116 _StampVersion(options
)
119 print '=== Compiling Front End ==='
120 outfile
= os
.path
.join(PROD_PATH
, 'fe', PRODUCT_NAME
+ '.js')
121 if options
.compile_fe
:
122 fe_sources
= map(lambda f
: '--js=' + os
.path
.join(FE_PATH
, f
), SOURCES_FE
)
123 args
= [ 'java', '-jar', CLOSURE_COMPILER
]
124 args
.extend(fe_sources
)
125 args
.extend(['--js_output_file', outfile
, '--compilation_level', 'SIMPLE_OPTIMIZATIONS'])
126 print ' ' + ' '.join(args
)
127 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
130 fd
= open(outfile
, 'w+')
131 for fe_source
in SOURCES_FE
:
132 fd2
= open(os
.path
.join(FE_PATH
, fe_source
), 'r')
133 fd
.write('// === ' + fe_source
+ '\n')
141 parser
= optparse
.OptionParser()
142 parser
.add_option('-c', '--closure_fe', action
="store_true", dest
="compile_fe",
143 help="Run the Front End inputs through the Closure Compiler")
144 parser
.add_option('-b', '--back-end', action
="store_true", dest
="backend_only",
145 help="Compiles only the back-end")
146 parser
.add_option('-f', '--front-end', action
="store_true", dest
="frontend_only",
147 help="Compiles only the front-end")
148 (options
, args
) = parser
.parse_args()
150 print '=== Starting Build ==='
153 if not options
.frontend_only
:
156 if not options
.backend_only
:
157 _CompileFrontEnd(options
)
159 if __name__
== '__main__':