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_SVN
= 'http://closure-library.googlecode.com/svn/trunk/'
27 CLOSURE_DEST
= os
.path
.join(ROOT
, 'closure')
28 CLOSURE_COMPILER
= os
.path
.join(ROOT
, 'closure-compiler.jar')
29 CLOSURE_CALCDEPS
= os
.path
.join(CLOSURE_DEST
, 'closure', 'bin', 'calcdeps.py')
31 VERSION_FILE
= os
.path
.join(FE_PATH
, 'version.js.proto')
55 PRODUCT_NAME
= 'armadillo'
57 # The Golang version (hg id).
58 BACK_END_COMPILER_VERSION
= '95d2ce135523 (release-branch.r57) release/release.r57.1'
65 print '=== Pulling Dependencies ==='
66 if os
.path
.exists(CLOSURE_DEST
):
67 handle
= subprocess
.Popen([ 'svn', 'info', CLOSURE_DEST
], stdout
= subprocess
.PIPE
)
69 for line
in handle
.stdout
:
70 if line
.startswith('Revision'):
71 if not line
.strip().endswith(CLOSURE_REV
):
72 subprocess
.Popen([ 'svn', 'update', '-r', CLOSURE_REV
, CLOSURE_DEST
]).wait()
74 print ' Closure @ ' + CLOSURE_REV
76 subprocess
.Popen([ 'svn', 'checkout', '-r', CLOSURE_REV
, CLOSURE_SVN
, CLOSURE_DEST
]).wait()
78 def _CompileBackEnd():
79 for gofile
in SOURCES
:
80 gofile
= os
.path
.join(SRC_PATH
, gofile
)
81 args
= [ COMPILER
, gofile
]
82 print ' ' + ' '.join(args
)
83 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
87 args
= [ LINKER
, '-o', os
.path
.join(PROD_PATH
, PRODUCT_NAME
), 'main.' + O_EXTENSION
]
88 print ' ' + ' ' .join(args
)
89 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
92 def _StampVersion(options
):
93 print '=== Version Stamp ==='
94 if os
.path
.exists(VERSION_FILE
):
95 gitcrement
= subprocess
.Popen([ 'gitcrement', 'next' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
97 build_stamp
= gitcrement
.stdout
.read().strip()
98 time_stamp
= str(int(time
.time()))
100 fd
= open(VERSION_FILE
, 'a+')
102 lines
= fd
.readlines()
106 line
= re
.sub(r
'(BUILD =) ([0-9\.]+)', r
'\1 ' + build_stamp
, line
)
107 line
= re
.sub(r
'(STAMP =) ([0-9]+)', r
'\1 ' + time_stamp
, line
)
110 print ' BUILD ' + build_stamp
+ ' @ ' + time_stamp
111 if options
.compile_fe
:
112 mfiles
= subprocess
.Popen([ 'git', 'ls-files', '-m' ], stdout
= subprocess
.PIPE
, cwd
= ROOT
)
114 versioned_stamp_file
= string
.replace(VERSION_FILE
, '.proto', '')
115 shutil
.copy(VERSION_FILE
, versioned_stamp_file
)
116 print ' COPY version.js.proto -> version.js'
117 if not len(mfiles
.stdout
.readlines()):
118 subprocess
.Popen([ 'git', 'commit', '--author=Armadillo Build Script <armadillo@bluestatic.org>',
119 '-m', 'Stamp version.js @ ' + build_stamp
+ '.', versioned_stamp_file
], stdout
= sys
.stdout
,
120 stderr
= sys
.stderr
).wait()
122 def _CompileFrontEnd(options
):
126 print '=== Copying Resources ==='
127 fe_resources
= os
.path
.join(PROD_PATH
, 'fe')
128 subprocess
.Popen([ 'rm', '-rf', fe_resources
]).wait()
129 os
.mkdir(fe_resources
)
130 for resource
in RESOURCES_FE
:
131 print ' COPY ' + resource
132 shutil
.copy(os
.path
.join(FE_PATH
, resource
), fe_resources
)
135 _StampVersion(options
)
138 print '=== Compiling Front End ==='
139 outfile
= os
.path
.join(PROD_PATH
, 'fe', PRODUCT_NAME
+ '.js')
140 fe_sources
= map(lambda f
: '-i' + os
.path
.join(FE_PATH
, f
), SOURCES_FE
)
141 args
= [ CLOSURE_CALCDEPS
]
142 args
.extend(fe_sources
)
144 if options
.compile_fe
:
146 args
.extend([ '-o', output
, '-c', CLOSURE_COMPILER
, '--output_file', outfile
])
147 print ' ' + ' '.join(args
)
148 handle
= subprocess
.Popen(args
, stdout
= sys
.stdout
, stderr
= sys
.stderr
)
153 parser
= optparse
.OptionParser()
154 parser
.add_option('-c', '--closure_fe', action
="store_true", dest
="compile_fe",
155 help="Run the Front End inputs through the Closure Compiler")
156 parser
.add_option('-b', '--back-end', action
="store_true", dest
="backend_only",
157 help="Compiles only the back-end")
158 parser
.add_option('-f', '--front-end', action
="store_true", dest
="frontend_only",
159 help="Compiles only the front-end")
160 (options
, args
) = parser
.parse_args()
162 print '=== Starting Build ==='
165 if not options
.frontend_only
:
168 if not options
.backend_only
:
169 _CompileFrontEnd(options
)
171 if __name__
== '__main__':