[12] | 1 | # Copyright (c) MetaCommunications, Inc. 2003-2004 |
---|
| 2 | # |
---|
| 3 | # Distributed under the Boost Software License, Version 1.0. |
---|
| 4 | # (See accompanying file LICENSE_1_0.txt or copy at |
---|
| 5 | # http://www.boost.org/LICENSE_1_0.txt) |
---|
| 6 | |
---|
| 7 | import sys |
---|
| 8 | import os |
---|
| 9 | import shutil |
---|
| 10 | import optparse |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | import utils |
---|
| 14 | |
---|
| 15 | my_location = os.path.abspath( os.path.dirname( sys.argv[0] ) ) |
---|
| 16 | |
---|
| 17 | def accept_args( args ): |
---|
| 18 | #( release_version, cvs_tag, sf_user, temp_dir, start_step ) = accept_args( sys.argv[ 1: ] ) |
---|
| 19 | parser = optparse.OptionParser() |
---|
| 20 | parser.add_option( "-v", "--release-version", dest="release_version", metavar="release-version", help="release version (e.g. 1.32.0)") |
---|
| 21 | parser.add_option( "", "--tag", dest="tag", help="CVS tag" ) |
---|
| 22 | parser.add_option( "-r", "--cvs-branch", dest="cvs_branch", metavar="cvs-branch" |
---|
| 23 | , help = "cvs branch to get the sources from (e.g RC_1_32_0). Important: it is case sensitive" ) |
---|
| 24 | parser.add_option( "-u", "--sf-user", dest="sf_user", metavar="sf-user" |
---|
| 25 | , help = "SourceForge user name (for CVS)" ) |
---|
| 26 | parser.add_option( "-t", "--toolset", dest="toolset", help="toolset to use to build needed tools" ) |
---|
| 27 | parser.add_option( "-s", "--start-step", dest="start_step" ) |
---|
| 28 | parser.usage = "make_tarballs [options] target_directory \n\n" + \ |
---|
| 29 | "Requirements:\n" + \ |
---|
| 30 | " CVS:\n"+ \ |
---|
| 31 | " cvs - (windows) to export sources with windows newlines \n" + \ |
---|
| 32 | " /usr/bin/cvs - (cygwin) to export sources with posix newlines\n" + \ |
---|
| 33 | " Utilities:\n" + \ |
---|
| 34 | " mv - (cygwin) posix move\n" + \ |
---|
| 35 | " /usr/bin/find - (cygwin) to export sources with posix newlines\n" + \ |
---|
| 36 | " 7z - to create zipball\n" + \ |
---|
| 37 | " BoostBook generation:\n" + \ |
---|
| 38 | " bjam\n" + \ |
---|
| 39 | " user-config.jam - in user directory ($HOME/%HOME%) for BoostBook generation\n" + \ |
---|
| 40 | " java\n" + \ |
---|
| 41 | " doxygen\n" |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | ( options, args ) = parser.parse_args( args ) |
---|
| 46 | |
---|
| 47 | temp_dir = None |
---|
| 48 | start_step = None |
---|
| 49 | if ( len( args ) > 0 ): temp_dir = args[0] |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | ( version, tag, user, toolset, start_step ) = ( options.release_version |
---|
| 53 | , options.cvs_branch |
---|
| 54 | , options.sf_user |
---|
| 55 | , options.toolset |
---|
| 56 | , options.start_step ) |
---|
| 57 | |
---|
| 58 | if ( start_step is None ): start_step = "" |
---|
| 59 | |
---|
| 60 | def required( value, name ): |
---|
| 61 | if ( value is None ): |
---|
| 62 | print "%s should be specified." % name |
---|
| 63 | parser.print_help() |
---|
| 64 | sys.exit( 1 ) |
---|
| 65 | |
---|
| 66 | required( version, "version" ) |
---|
| 67 | required( tag, "tag" ) |
---|
| 68 | required( user, "user" ) |
---|
| 69 | required( temp_dir, "temp_dir" ) |
---|
| 70 | required( toolset, "toolset" ) |
---|
| 71 | |
---|
| 72 | return ( version, tag, user, toolset, temp_dir, start_step ) |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | def remove_directory( directory ): |
---|
| 76 | if os.path.exists( directory ): |
---|
| 77 | print " Removing directory %s" % directory |
---|
| 78 | os.system( 'rd /s /q "%s"' % directory ) |
---|
| 79 | |
---|
| 80 | def clean_directory( directory ): |
---|
| 81 | remove_directory( directory ) |
---|
| 82 | print " Creating directory %s" % directory |
---|
| 83 | os.makedirs( directory ) |
---|
| 84 | |
---|
| 85 | def listdir_recursively( root, path="" ): |
---|
| 86 | # recursive listdir |
---|
| 87 | files = [] |
---|
| 88 | try: |
---|
| 89 | for file in os.listdir(os.path.join(root, path)): |
---|
| 90 | pathname = os.path.join(path, file) |
---|
| 91 | if os.path.isdir(os.path.join(root, pathname)): |
---|
| 92 | files.extend(listdir_recursively(root, pathname)) |
---|
| 93 | else: |
---|
| 94 | files.append(pathname) |
---|
| 95 | except OSError: |
---|
| 96 | pass |
---|
| 97 | return files |
---|
| 98 | |
---|
| 99 | def find_file( root, name ): |
---|
| 100 | print root |
---|
| 101 | files = listdir_recursively( root ) |
---|
| 102 | for file in files: |
---|
| 103 | # print file |
---|
| 104 | if os.path.basename( file ) == name: |
---|
| 105 | return os.path.join( root, file ) |
---|
| 106 | return None |
---|
| 107 | |
---|
| 108 | start_dir = os.getcwd() |
---|
| 109 | |
---|
| 110 | class make_tarballs( utils.step_controller ): |
---|
| 111 | def __init__( self, release_version, cvs_tag, sf_user, toolset, temp_dir, start_step ): |
---|
| 112 | utils.step_controller.__init__( self, start_step ) |
---|
| 113 | self.release_version_ = release_version |
---|
| 114 | self.cvs_tag_ = cvs_tag |
---|
| 115 | self.sf_user_ = sf_user |
---|
| 116 | self.toolset_ = toolset |
---|
| 117 | self.temp_dir_ = temp_dir |
---|
| 118 | |
---|
| 119 | def run( self ): |
---|
| 120 | archives = [] |
---|
| 121 | |
---|
| 122 | win_build_results = self.build_win( self.release_version_ |
---|
| 123 | , self.cvs_tag_ |
---|
| 124 | , self.sf_user_ |
---|
| 125 | , self.temp_dir_ ) |
---|
| 126 | archives.extend( win_build_results[1] ) |
---|
| 127 | |
---|
| 128 | archives.extend( self.build_unix( self.release_version_ |
---|
| 129 | , self.cvs_tag_ |
---|
| 130 | , self.sf_user_ |
---|
| 131 | , self.temp_dir_ |
---|
| 132 | , win_build_results[0] ) ) |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | # os.chdir( start_dir ) |
---|
| 136 | # for archive in archives: |
---|
| 137 | # shutil.copy( archive, start_dir ) |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | def make_temp_platform( self, temp, platform ): |
---|
| 141 | temp_platform = os.path.join( temp, platform ) |
---|
| 142 | if not self.is_skipping(): |
---|
| 143 | clean_directory( temp_platform ) |
---|
| 144 | return temp_platform |
---|
| 145 | |
---|
| 146 | def cvs_export( self, sf_user, cvs_tag, release_version, shell = "%s" ): |
---|
| 147 | if not self.is_skipping(): |
---|
| 148 | print " Exporting..." |
---|
| 149 | cvs_export_template = 'cvs -d:ext:%(user)s@cvs.sourceforge.net:/cvsroot/boost -z9 export -r %(branch)s boost' |
---|
| 150 | |
---|
| 151 | cmd = cvs_export_template % { "user": sf_user |
---|
| 152 | , "branch" : cvs_tag } |
---|
| 153 | |
---|
| 154 | print cmd |
---|
| 155 | os.system( shell % cmd ) |
---|
| 156 | os.system( "del /S/F/Q .cvsignore >nul" ) |
---|
| 157 | # have to use mv instead of os.rename - cygwin cvs sets strange directory permssions |
---|
| 158 | # which Windows rename or Python's os.rename cannot deal with |
---|
| 159 | os.system( "mv boost boost_%s" % release_version ) |
---|
| 160 | return "boost_%s" % release_version |
---|
| 161 | |
---|
| 162 | def build_win( self, release_version, cvs_tag, sf_user, temp_dir ): |
---|
| 163 | |
---|
| 164 | if "win.export": |
---|
| 165 | self.start_step( "win.export", "Exporting windows copy" ) |
---|
| 166 | |
---|
| 167 | temp_win = self.make_temp_platform( temp_dir, "win" ) |
---|
| 168 | os.chdir( temp_win ) |
---|
| 169 | |
---|
| 170 | exported_dir = self.cvs_export( sf_user, cvs_tag, release_version ) |
---|
| 171 | self.finish_step( "win.export" ) |
---|
| 172 | |
---|
| 173 | self.make_docs( os.path.abspath( exported_dir ), temp_dir ) |
---|
| 174 | |
---|
| 175 | if self.start_step( "win.make_readonly", "Making all files writable" ): |
---|
| 176 | os.chdir( temp_win ) |
---|
| 177 | utils.checked_system( [ "attrib /S -R *.*" ] ) |
---|
| 178 | self.finish_step( "win.make_readonly" ) |
---|
| 179 | |
---|
| 180 | zip_name = "boost_%s.zip" % release_version |
---|
| 181 | os.chdir( temp_win ) |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | if self.start_step( "win.zip", " Zipping" ): |
---|
| 185 | print " Zipping" |
---|
| 186 | if os.path.exists( zip_name ): os.unlink( zip_name ) |
---|
| 187 | |
---|
| 188 | utils.checked_system( ["7z a -r -tzip %s %s\* > %s" % ( zip_name, "boost_%s" % release_version, zip_name + ".log" ) ] ) |
---|
| 189 | self.finish_step( "win.zip" ) |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | return ( os.path.abspath( exported_dir ), [ os.path.abspath( zip_name ) ] ) |
---|
| 193 | |
---|
| 194 | def make_docs( self, boost_directory, temp_dir ): |
---|
| 195 | boostbook_temp = os.path.join( boost_directory, "bin.v2" ) |
---|
| 196 | tools_directory = os.path.join( temp_dir, "tools" ) |
---|
| 197 | if not os.path.exists( tools_directory ): |
---|
| 198 | os.makedirs( tools_directory ) |
---|
| 199 | |
---|
| 200 | if self.start_step( "win.make_docs.setup_tools", "Setting up BoostBook tools" ): |
---|
| 201 | sys.path.append( sys.path[0] + "/../boostbook" ) |
---|
| 202 | print sys.path |
---|
| 203 | import setup_boostbook |
---|
| 204 | os.environ[ "BOOST_ROOT" ] = boost_directory |
---|
| 205 | setup_boostbook.setup_boostbook( os.path.join( temp_dir, "tools" ) ) |
---|
| 206 | |
---|
| 207 | if self.start_step( "win.make_docs.clean", "Clearing \"bin.v2" ): |
---|
| 208 | if os.path.exists( boostbook_temp ): |
---|
| 209 | shutil.rmtree( boostbook_temp ) |
---|
| 210 | self.finish_step( "win.make_docs.clean" ) |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | cd = os.getcwd() |
---|
| 214 | os.chdir( os.path.join( boost_directory, "doc" ) ) |
---|
| 215 | |
---|
| 216 | if self.start_step( "win.make_docs.correct_permissions", "Making html's writable" ): |
---|
| 217 | utils.checked_system( |
---|
| 218 | [ |
---|
| 219 | "cd html" |
---|
| 220 | , "attrib -R *" |
---|
| 221 | , "cd .." |
---|
| 222 | ] ) |
---|
| 223 | self.finish_step( "win.make_docs.correct_permissions" ) |
---|
| 224 | |
---|
| 225 | def generate( output_format ): |
---|
| 226 | if self.start_step( "win.make_docs.%s" % output_format, ' Generating %s' % output_format ): |
---|
| 227 | utils.checked_system( [ |
---|
| 228 | # "set HOME=%s" % my_location |
---|
| 229 | "%s -d2 --v2 %s " % ( bjam_path(), output_format ) |
---|
| 230 | ] ) |
---|
| 231 | self.finish_step( "win.make_docs.%s" % output_format ) |
---|
| 232 | |
---|
| 233 | generate( "html" ) |
---|
| 234 | generate( "docbook" ) |
---|
| 235 | generate( "fo" ) |
---|
| 236 | |
---|
| 237 | if self.start_step( "win.make_docs.copy_docs", "Copying docs into doc directory" ): |
---|
| 238 | shutil.copy( os.path.join( boostbook_temp, "doc", self.toolset_, "debug", "boost.docbook" ), "boost.docbook" ) |
---|
| 239 | shutil.copy( os.path.join( boostbook_temp, "doc", self.toolset_, "debug", "boost.fo" ), "boost.fo" ) |
---|
| 240 | self.finish_step( "win.make_docs.copy_docs" ) |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | if self.start_step( "win.make_docs.clean2", "Copying docs into doc directory" ): |
---|
| 244 | shutil.rmtree( boostbook_temp ) |
---|
| 245 | shutil.rmtree( "xml" ) |
---|
| 246 | self.finish_step( "win.make_docs.clean2" ) |
---|
| 247 | |
---|
| 248 | if self.start_step( "win.make_docs.bb_userman", "Creating Boost.Build user manual" ): |
---|
| 249 | os.chdir( os.path.join( boost_directory, "tools", "build", "v2", "doc" ) ) |
---|
| 250 | |
---|
| 251 | utils.checked_system( [ |
---|
| 252 | # "set HOME=%s" % my_location |
---|
| 253 | "%s -d2 --v2 pdf" % bjam_path() |
---|
| 254 | ] ) |
---|
| 255 | |
---|
| 256 | for f in [ "userman.pdf" ]: |
---|
| 257 | shutil.copy( find_file( os.path.join( boostbook_temp ), f ), f ) |
---|
| 258 | |
---|
| 259 | shutil.rmtree( boostbook_temp ) |
---|
| 260 | self.finish_step( "win.make_docs.bb_userman" ) |
---|
| 261 | |
---|
| 262 | if self.start_step( "win.make_docs.clean3", boost_directory ): |
---|
| 263 | for i in os.walk( boost_directory ): |
---|
| 264 | for f in i[2]: |
---|
| 265 | full_path = os.path.join( i[0], f ) |
---|
| 266 | if os.path.splitext( f )[1] in [ ".boostbook" ] \ |
---|
| 267 | and os.access( full_path, os.W_OK ): |
---|
| 268 | os.unlink( full_path ) |
---|
| 269 | self.finish_step( "win.make_docs.clean3" ) |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | def correct_executable_permissions( self, path ): |
---|
| 273 | if not self.is_skipping(): |
---|
| 274 | print " Correcting permissions" |
---|
| 275 | for i in os.walk( path ): |
---|
| 276 | for f in i[2]: |
---|
| 277 | if os.path.splitext( f )[1] in ( ".css", ".hpp", ".cpp",\ |
---|
| 278 | ".html", ".htm", ".rst", \ |
---|
| 279 | ".pdf", ".xml", ".png",\ |
---|
| 280 | ".jpg", ".vcproj", ".pattern2", \ |
---|
| 281 | ".jam", ".bat", ".sty", ".diff" ) \ |
---|
| 282 | or os.path.basename( f ).lower() in ( "jamfile", "todo", "makefile", "jamrules", "gnumakefile" ): |
---|
| 283 | print os.path.join( i[0], f ) |
---|
| 284 | os.system( "chmod a-x %s" % os.path.join( i[0], f ) ) |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | def build_unix( self, release_version, cvs_tag, sf_user, temp_dir, win_build_dir ): |
---|
| 288 | |
---|
| 289 | self.start_step( "unix.export", "Exporting unix copy" ) |
---|
| 290 | |
---|
| 291 | temp_unix = self.make_temp_platform( temp_dir, "unix" ) |
---|
| 292 | os.chdir( temp_unix ) |
---|
| 293 | |
---|
| 294 | exported_dir = self.cvs_export( sf_user, cvs_tag, release_version, "bash -c \"/usr/bin/%s\"" ) |
---|
| 295 | self.correct_executable_permissions( "." ) |
---|
| 296 | self.finish_step( "unix.export" ) |
---|
| 297 | |
---|
| 298 | self.copy_docs_to_unix( os.path.abspath( exported_dir ) |
---|
| 299 | , win_build_dir ) |
---|
| 300 | |
---|
| 301 | if self.start_step( "unix.make_readonly", "Making all files readonly" ): |
---|
| 302 | utils.checked_system( [ "chmod -R a-w+r,u+w %s" % temp_unix ] ) |
---|
| 303 | utils.checked_system( [ "bash -c /usr/bin/find %s -type d -exec chmod u+w {} ;" % temp_unix ] ) |
---|
| 304 | self.finish_step( "unix.make_readonly" ) |
---|
| 305 | |
---|
| 306 | gz_archive_name = "boost_%s" % release_version + ".tar.gz" |
---|
| 307 | if self.start_step( "unix.gz", " Making .gz" ): |
---|
| 308 | if os.path.exists( gz_archive_name ): os.unlink( gz_archive_name ) |
---|
| 309 | os.system( "tar cfz %s %s" % ( gz_archive_name, "boost_%s" % release_version ) ) |
---|
| 310 | self.finish_step( "unix.gz" ) |
---|
| 311 | |
---|
| 312 | bz2_archive_name = "boost_%s" % release_version + ".tar.bz2" |
---|
| 313 | if self.start_step( "unix.bz2", " Making .bz2" ): |
---|
| 314 | if os.path.exists( bz2_archive_name ): os.unlink( bz2_archive_name ) |
---|
| 315 | os.system( 'bash -c "gunzip -c %s | bzip2 > %s"' % ( gz_archive_name, bz2_archive_name ) ) |
---|
| 316 | self.finish_step( "unix.bz2" ) |
---|
| 317 | |
---|
| 318 | return [ os.path.abspath( x ) for x in ( gz_archive_name, bz2_archive_name ) ] |
---|
| 319 | |
---|
| 320 | def remove_x_permission( self, directory ): |
---|
| 321 | for i in os.walk( directory ): |
---|
| 322 | for f in i[1]: |
---|
| 323 | os.system( "chmod a=xr,u=rwx %s" % os.path.join( i[0], f ) ) |
---|
| 324 | for f in i[2]: |
---|
| 325 | os.system( "chmod a=r,u=rw %s" % os.path.join( i[0], f ) ) |
---|
| 326 | |
---|
| 327 | def copy_docs_to_unix( self, unix_boost_directory, win_boost_directory ): |
---|
| 328 | if self.start_step( "unix.copy_docs", "Copying docs to unix copy" ): |
---|
| 329 | doc_directory = os.path.join( unix_boost_directory, "doc" ) |
---|
| 330 | doc_html_directory = os.path.join( doc_directory, "html" ) |
---|
| 331 | remove_directory( doc_html_directory ) |
---|
| 332 | utils.checked_system( [ |
---|
| 333 | "cp -R %s %s " % ( os.path.join( win_boost_directory, "doc", "html" ) |
---|
| 334 | , doc_html_directory ) |
---|
| 335 | ] ) |
---|
| 336 | for f in [ "boost.docbook", "boost.fo" ]: |
---|
| 337 | utils.checked_system( [ |
---|
| 338 | "cp %s %s" % ( os.path.join( win_boost_directory, "doc", f ) |
---|
| 339 | , os.path.join( doc_directory, f ) ) |
---|
| 340 | ] ) |
---|
| 341 | |
---|
| 342 | self.remove_x_permission( doc_directory ) |
---|
| 343 | |
---|
| 344 | boost_build_doc_directory = os.path.join( unix_boost_directory, "tools", "build", "v2", "doc" ) |
---|
| 345 | boost_build_doc_html_directory = os.path.join( boost_build_doc_directory, "html" ) |
---|
| 346 | |
---|
| 347 | remove_directory( boost_build_doc_html_directory ) |
---|
| 348 | utils.checked_system( [ |
---|
| 349 | "cp -R %s %s " % ( os.path.join( win_boost_directory, "tools", "build", "v2", "doc", "html" ) |
---|
| 350 | , boost_build_doc_html_directory ) ] ) |
---|
| 351 | |
---|
| 352 | for f in [ "userman.pdf" ]: |
---|
| 353 | utils.checked_system( [ |
---|
| 354 | "cp %s %s " % ( os.path.join( win_boost_directory, "tools", "build", "v2", "doc", f ) |
---|
| 355 | , os.path.join( boost_build_doc_directory, f ) ) ] ) |
---|
| 356 | |
---|
| 357 | self.remove_x_permission( boost_build_doc_directory ) |
---|
| 358 | self.finish_step( "unix.copy_docs" ) |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | def bjam_path(): |
---|
| 362 | if os.path.exists( os.path.join( my_location, "bjam.exe" ) ): |
---|
| 363 | return os.path.join( my_location, "bjam.exe" ) |
---|
| 364 | else: |
---|
| 365 | return "bjam.exe" |
---|
| 366 | |
---|
| 367 | def main(): |
---|
| 368 | ( release_version, cvs_tag, sf_user, toolset, temp_dir, start_step ) = accept_args( sys.argv[ 1: ] ) |
---|
| 369 | |
---|
| 370 | make_tarballs( release_version, cvs_tag, sf_user, toolset, temp_dir, start_step ).run() |
---|
| 371 | |
---|
| 372 | if __name__ == "__main__": |
---|
| 373 | main() |
---|