1
0

make_tarballs.py 16 KB

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