preprocess.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright Aleksey Gurtovoy 2001-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. # See http://www.boost.org/libs/mpl for documentation.
  8. # $Id$
  9. # $Date$
  10. # $Revision$
  11. import pp
  12. import shutil
  13. import os.path
  14. import os
  15. import string
  16. import sys
  17. preprocess_cmd = open( "preprocess.cmd" ).readlines()[0]
  18. def process( file, boost_root, dst_dir, mode ):
  19. file_path = "%s.hpp" % os.path.splitext( file )[0]
  20. os.system( preprocess_cmd % {
  21. 'boost_root': boost_root
  22. , 'mode': mode
  23. , 'file': file
  24. , 'file_path': file_path
  25. } )
  26. os.rename( file_path, "%s.tmp" % file_path )
  27. pp.main( "%s.tmp" % file_path, file_path )
  28. os.remove( "%s.tmp" % file_path )
  29. filename = os.path.basename(file_path)
  30. dst_dir = os.path.join( dst_dir, mode )
  31. dst_file = os.path.join( dst_dir, filename )
  32. if os.path.exists( dst_file ):
  33. shutil.copymode( filename, dst_file )
  34. shutil.copy( filename, dst_dir )
  35. os.remove( filename )
  36. def process_all( root, boost_root, dst_dir, mode ):
  37. files = os.listdir( root )
  38. for file in files:
  39. path = os.path.join( root, file )
  40. if os.path.splitext( file )[1] == ".cpp":
  41. process( path, boost_root, dst_dir, mode )
  42. else:
  43. if os.path.isdir( path ):
  44. process_all( path, boost_root, dst_dir, mode )
  45. def main( all_modes, src_dir, dst_dir ):
  46. if len( sys.argv ) < 2:
  47. print "\nUsage:\n\t %s <mode> <boost_root> [<source_file>]" % os.path.basename( sys.argv[0] )
  48. print "\nPurpose:\n\t updates preprocessed version(s) of the header(s) in \"%s\" directory" % dst_dir
  49. print "\nExample:\n\t the following command will re-generate and update all 'apply.hpp' headers:"
  50. print "\n\t\t %s all f:\\cvs\\boost apply.cpp" % os.path.basename( sys.argv[0] )
  51. sys.exit( -1 )
  52. if sys.argv[1] == "all":
  53. modes = all_modes
  54. else:
  55. modes = [sys.argv[1]]
  56. boost_root = sys.argv[2]
  57. dst_dir = os.path.join( boost_root, dst_dir )
  58. for mode in modes:
  59. if len( sys.argv ) > 3:
  60. file = os.path.join( os.path.join( os.getcwd(), src_dir ), sys.argv[3] )
  61. process( file, boost_root, dst_dir, mode )
  62. else:
  63. process_all( os.path.join( os.getcwd(), src_dir ), boost_root, dst_dir, mode )
  64. if __name__ == '__main__':
  65. main(
  66. ["bcc", "bcc551", "gcc", "mwcw", "dmc", "no_ttp", "plain"]
  67. , "src"
  68. , os.path.join( "boost", "mpl", "aux_", "preprocessed" )
  69. )