make_tarballs.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. return ( args[0], args[1], args[2], args[3], args[4] )
  14. def remove_directory( directory ):
  15. if os.path.exists( directory ):
  16. print " Removing directory %s" % directory
  17. os.system( 'rd /s /q "%s"' % directory )
  18. def clean_directory( directory ):
  19. remove_directory( directory )
  20. print " Creating directory %s" % directory
  21. os.makedirs( directory )
  22. start_dir = os.getcwd()
  23. class make_tarballs( utils.step_controller ):
  24. def __init__( self, release_version, cvs_tag, sf_user, temp_dir, start_step ):
  25. utils.step_controller.__init__( self, start_step )
  26. self.release_version_ = release_version
  27. self.cvs_tag_ = cvs_tag
  28. self.sf_user_ = sf_user
  29. self.temp_dir_ = temp_dir
  30. def run( self ):
  31. archives = []
  32. win_build_results = self.build_win( self.release_version_
  33. , self.cvs_tag_
  34. , self.sf_user_
  35. , self.temp_dir_ )
  36. archives.extend( win_build_results[1] )
  37. archives.extend( self.build_unix( self.release_version_
  38. , self.cvs_tag_
  39. , self.sf_user_
  40. , self.temp_dir_
  41. , win_build_results[0] ) )
  42. # os.chdir( start_dir )
  43. # for archive in archives:
  44. # shutil.copy( archive, start_dir )
  45. def make_temp_platform( self, temp, platform ):
  46. temp_platform = os.path.join( temp, platform )
  47. if not self.is_skipping():
  48. clean_directory( temp_platform )
  49. return temp_platform
  50. def cvs_export( self, sf_user, cvs_tag, release_version, shell = "%s" ):
  51. if not self.is_skipping():
  52. print " Exporting..."
  53. cvs_export_template = 'cvs -d:ext:%(user)s@cvs.sourceforge.net:/cvsroot/boost -z9 export -r %(branch)s boost'
  54. cmd = cvs_export_template % { "user": sf_user
  55. , "branch" : cvs_tag }
  56. os.system( shell % cmd )
  57. os.system( "del /S/F/Q .cvsignore >nul" )
  58. os.rename( "boost", "boost_%s" % release_version )
  59. return "boost_%s" % release_version
  60. def build_win( self, release_version, cvs_tag, sf_user, temp_dir ):
  61. if "win.export":
  62. self.start_step( "win.export", "Exporting windows copy" )
  63. temp_win = self.make_temp_platform( temp_dir, "win" )
  64. os.chdir( temp_win )
  65. exported_dir = self.cvs_export( sf_user, cvs_tag, release_version )
  66. self.finish_step( "win.export" )
  67. self.make_docs( os.path.abspath( exported_dir ) )
  68. if self.start_step( "win.make_readonly", "Making all files writable" ):
  69. os.chdir( temp_win )
  70. utils.checked_system( [ "attrib /S -R *.*" ] )
  71. self.finish_step( "win.make_readonly" )
  72. zip_name = "boost_%s.zip" % release_version
  73. os.chdir( temp_win )
  74. if self.start_step( "win.zip", " Zipping" ):
  75. print " Zipping"
  76. if os.path.exists( zip_name ): os.unlink( zip_name )
  77. os.system( "7z a -r -tzip %s %s\* > %s" % ( os.path.splitext( zip_name )[0], "boost_%s" % release_version, zip_name + ".log" ) )
  78. self.finish_step( "win.zip" )
  79. return ( os.path.abspath( exported_dir ), [ os.path.abspath( zip_name ) ] )
  80. def make_docs( self, boost_directory ):
  81. boostbook_temp = os.path.join( boost_directory, "bin.v2" )
  82. if self.start_step( "win.make_docs.clean", "Clearing \"bin.v2" ):
  83. if os.path.exists( boostbook_temp ):
  84. shutil.rmtree( boostbook_temp )
  85. self.finish_step( "win.make_docs.clean" )
  86. cd = os.getcwd()
  87. os.chdir( os.path.join( boost_directory, "doc" ) )
  88. if self.start_step( "win.make_docs.correct_permissions", "Making html's writable" ):
  89. utils.checked_system(
  90. [
  91. "cd html"
  92. , "attrib -R *"
  93. , "cd .."
  94. ] )
  95. self.finish_step( "win.make_docs.correct_permissions" )
  96. def generate( output_format ):
  97. if self.start_step( "win.make_docs.%s" % output_format, ' Generating %s' % output_format ):
  98. utils.checked_system( [
  99. "set HOME=%s" % my_location
  100. , "%s -d2 --v2 %s" % ( bjam_path(), output_format )
  101. ] )
  102. self.finish_step( "win.make_docs.%s" % output_format )
  103. generate( "html" )
  104. generate( "docbook" )
  105. generate( "fo" )
  106. if self.start_step( "win.make_docs.copy_docs", "Copying docs into doc directory" ):
  107. shutil.copy( os.path.join( boostbook_temp, "doc", "debug", "boost.docbook" ), "boost.docbook" )
  108. shutil.copy( os.path.join( boostbook_temp, "doc", "debug", "boost.fo" ), "boost.fo" )
  109. self.finish_step( "win.make_docs.copy_docs" )
  110. if self.start_step( "win.make_docs.clean2", "Copying docs into doc directory" ):
  111. shutil.rmtree( boostbook_temp )
  112. shutil.rmtree( "xml" )
  113. self.finish_step( "win.make_docs.clean2" )
  114. if self.start_step( "win.make_docs.bb_userman", "Creating Boost.Build user manual" ):
  115. os.chdir( os.path.join( boost_directory, "tools", "build", "v2", "doc" ) )
  116. utils.checked_system( [
  117. "set HOME=%s" % my_location
  118. , "%s -d2 --v2 pdf" % bjam_path()
  119. ] )
  120. for f in [ "userman.pdf" ]:
  121. shutil.copy( os.path.join( boostbook_temp, "tools", "build", "v2", "doc", "debug", f ), f )
  122. shutil.rmtree( boostbook_temp )
  123. self.finish_step( "win.make_docs.bb_userman" )
  124. if self.start_step( "win.make_docs.clean3", boost_directory ):
  125. for i in os.walk( boost_directory ):
  126. for f in i[2]:
  127. full_path = os.path.join( i[0], f )
  128. if os.path.splitext( f )[1] in [ ".boostbook" ] \
  129. and os.access( full_path, os.W_OK ):
  130. os.unlink( full_path )
  131. def correct_executable_permissions( self, path ):
  132. if not self.is_skipping():
  133. print " Correcting permissions"
  134. for i in os.walk( path ):
  135. for f in i[2]:
  136. if os.path.splitext( f )[1] in ( ".css", ".hpp", ".cpp",\
  137. ".html", ".htm", ".rst", \
  138. ".pdf", ".xml", ".png",\
  139. ".jpg", ".vcproj", ".pattern2", \
  140. ".jam", ".bat", ".sty", ".diff" ) \
  141. or os.path.basename( f ).lower() in ( "jamfile", "todo", "makefile", "jamrules", "gnumakefile" ):
  142. print os.path.join( i[0], f )
  143. os.system( "chmod a-x %s" % os.path.join( i[0], f ) )
  144. def build_unix( self, release_version, cvs_tag, sf_user, temp_dir, win_build_dir ):
  145. self.start_step( "unix.export", "Exporting unix copy" )
  146. temp_unix = self.make_temp_platform( temp_dir, "unix" )
  147. os.chdir( temp_unix )
  148. exported_dir = self.cvs_export( sf_user, cvs_tag, release_version, "bash -c \"%s\"" )
  149. self.correct_executable_permissions( "." )
  150. self.finish_step( "unix.export" )
  151. self.copy_docs_to_unix( os.path.abspath( exported_dir )
  152. , win_build_dir )
  153. if self.start_step( "unix.make_readonly", "Making all files readonly" ):
  154. utils.checked_system( [ "chmod -R a-w+r,u+w %s" % temp_unix ] )
  155. utils.checked_system( [ "lfind %s -type d -exec chmod u+w {} ;" % temp_unix ] )
  156. self.finish_step( "unix.make_readonly" )
  157. gz_archive_name = "boost_%s" % release_version + ".tar.gz"
  158. if self.start_step( "unix.gz", " Making .gz" ):
  159. if os.path.exists( gz_archive_name ): os.unlink( gz_archive_name )
  160. os.system( "tar cfz %s %s" % ( gz_archive_name, "boost_%s" % release_version ) )
  161. self.finish_step( "unix.gz" )
  162. bz2_archive_name = "boost_%s" % release_version + ".tar.bz2"
  163. if self.start_step( "unix.bz2", " Making .bz2" ):
  164. if os.path.exists( bz2_archive_name ): os.unlink( bz2_archive_name )
  165. os.system( 'bash -c "gunzip -c %s | bzip2 > %s"' % ( gz_archive_name, bz2_archive_name ) )
  166. self.finish_step( "unix.bz2" )
  167. return [ os.path.abspath( x ) for x in ( gz_archive_name, bz2_archive_name ) ]
  168. def remove_x_permission( self, directory ):
  169. for i in os.walk( directory ):
  170. for f in i[1]:
  171. os.system( "chmod a=xr,u=rwx %s" % os.path.join( i[0], f ) )
  172. for f in i[2]:
  173. os.system( "chmod a=r,u=rw %s" % os.path.join( i[0], f ) )
  174. def copy_docs_to_unix( self, unix_boost_directory, win_boost_directory ):
  175. if self.start_step( "unix.copy_docs", "Copying docs to unix copy" ):
  176. doc_directory = os.path.join( unix_boost_directory, "doc" )
  177. doc_html_directory = os.path.join( doc_directory, "html" )
  178. remove_directory( doc_html_directory )
  179. utils.checked_system( [
  180. "cp -R %s %s " % ( os.path.join( win_boost_directory, "doc", "html" )
  181. , doc_html_directory )
  182. ] )
  183. for f in [ "boost.docbook", "boost.fo", "catalog.xml" ]:
  184. utils.checked_system( [
  185. "cp %s %s" % ( os.path.join( win_boost_directory, "doc", f )
  186. , os.path.join( doc_directory, f ) )
  187. ] )
  188. self.remove_x_permission( doc_directory )
  189. boost_build_doc_directory = os.path.join( unix_boost_directory, "tools", "build", "v2", "doc" )
  190. boost_build_doc_html_directory = os.path.join( boost_build_doc_directory, "html" )
  191. remove_directory( boost_build_doc_html_directory )
  192. utils.checked_system( [
  193. "cp -R %s %s " % ( os.path.join( win_boost_directory, "tools", "build", "v2", "doc", "html" )
  194. , boost_build_doc_html_directory ) ] )
  195. for f in [ "userman.pdf" ]:
  196. utils.checked_system( [
  197. "cp %s %s " % ( os.path.join( win_boost_directory, "tools", "build", "v2", "doc", f )
  198. , os.path.join( boost_build_doc_directory, f ) ) ] )
  199. self.remove_x_permission( boost_build_doc_directory )
  200. self.finish_step( "unix.copy_docs" )
  201. def bjam_path():
  202. if os.path.exists( os.path.join( my_location, "bjam.exe" ) ):
  203. return os.path.join( my_location, "bjam.exe" )
  204. else:
  205. return "bjam.exe"
  206. def main():
  207. ( release_version, cvs_tag, sf_user, temp_dir, start_step ) = accept_args( sys.argv[ 1: ] )
  208. make_tarballs( release_version, cvs_tag, sf_user, temp_dir, start_step ).run()
  209. if __name__ == "__main__":
  210. main()
粤ICP备19079148号