[12] | 1 | |
---|
| 2 | # Copyright Aleksey Gurtovoy 2001-2004 |
---|
| 3 | # |
---|
| 4 | # Distributed under the Boost Software License, Version 1.0. |
---|
| 5 | # (See accompanying file LICENSE_1_0.txt or copy at |
---|
| 6 | # http://www.boost.org/LICENSE_1_0.txt) |
---|
| 7 | # |
---|
| 8 | # See http://www.boost.org/libs/mpl for documentation. |
---|
| 9 | |
---|
| 10 | # $Source: /cvsroot/boost/boost/libs/mpl/preprocessed/preprocess.py,v $ |
---|
| 11 | # $Date: 2004/09/02 15:41:30 $ |
---|
| 12 | # $Revision: 1.4 $ |
---|
| 13 | |
---|
| 14 | import shutil |
---|
| 15 | import os.path |
---|
| 16 | import os |
---|
| 17 | import sys |
---|
| 18 | |
---|
| 19 | def process( file, boost_root, dst_dir, mode ): |
---|
| 20 | file_path = "%s.hpp" % os.path.splitext( file )[0] |
---|
| 21 | |
---|
| 22 | os.system( "preprocess %s %s %s %s" % ( boost_root, mode, file, file_path ) ) |
---|
| 23 | os.rename( file_path, "%s.tmp" % file_path ) |
---|
| 24 | os.system( "python pp.py %s.tmp %s" % ( file_path, file_path ) ) |
---|
| 25 | os.remove( "%s.tmp" % file_path ) |
---|
| 26 | |
---|
| 27 | filename = os.path.basename(file_path) |
---|
| 28 | dst_dir = os.path.join( dst_dir, mode ) |
---|
| 29 | dst_file = os.path.join( dst_dir, filename ) |
---|
| 30 | |
---|
| 31 | if os.path.exists( dst_file ): |
---|
| 32 | shutil.copymode( filename, dst_file ) |
---|
| 33 | |
---|
| 34 | shutil.copy( filename, dst_dir ) |
---|
| 35 | os.remove( filename ) |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | def process_all( root, boost_root, dst_dir, mode ): |
---|
| 39 | files = os.listdir( root ) |
---|
| 40 | for file in files: |
---|
| 41 | path = os.path.join( root, file ) |
---|
| 42 | if os.path.splitext( file )[1] == ".cpp": |
---|
| 43 | process( path, boost_root, dst_dir, mode ) |
---|
| 44 | else: |
---|
| 45 | if os.path.isdir( path ): |
---|
| 46 | process_all( path, boost_root, dst_dir, mode ) |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | def main( all_modes, src_dir, dst_dir ): |
---|
| 50 | if len( sys.argv ) < 2: |
---|
| 51 | print "\nUsage:\n\t %s <mode> <boost_root> [<source_file>]" % os.path.basename( sys.argv[0] ) |
---|
| 52 | print "\nPurpose:\n\t updates preprocessed version(s) of the header(s) in \"%s\" directory" % dst_dir |
---|
| 53 | print "\nExample:\n\t the following command will re-generate and update all 'apply.hpp' headers:" |
---|
| 54 | print "\n\t\t %s all f:\\cvs\\boost apply.cpp" % os.path.basename( sys.argv[0] ) |
---|
| 55 | sys.exit( -1 ) |
---|
| 56 | |
---|
| 57 | if sys.argv[1] == "all": |
---|
| 58 | modes = all_modes |
---|
| 59 | else: |
---|
| 60 | modes = [sys.argv[1]] |
---|
| 61 | |
---|
| 62 | boost_root = sys.argv[2] |
---|
| 63 | dst_dir = os.path.join( boost_root, dst_dir ) |
---|
| 64 | |
---|
| 65 | for mode in modes: |
---|
| 66 | if len( sys.argv ) > 3: |
---|
| 67 | file = os.path.join( os.path.join( os.getcwd(), src_dir ), sys.argv[3] ) |
---|
| 68 | process( file, boost_root, dst_dir, mode ) |
---|
| 69 | else: |
---|
| 70 | process_all( os.path.join( os.getcwd(), src_dir ), boost_root, dst_dir, mode ) |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | if __name__ == '__main__': |
---|
| 74 | |
---|
| 75 | main( |
---|
| 76 | ["bcc", "bcc551", "gcc", "msvc60", "msvc70", "mwcw", "dmc", "no_ctps", "no_ttp", "plain"] |
---|
| 77 | , "src" |
---|
| 78 | , "boost\\mpl\\aux_\\preprocessed" |
---|
| 79 | ) |
---|