[pygccxml-commit] SF.net SVN: pygccxml:[1588]
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2009-01-18 21:12:47
|
Revision: 1588 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1588&view=rev Author: roman_yakovenko Date: 2009-01-18 21:12:45 +0000 (Sun, 18 Jan 2009) Log Message: ----------- adding command line utility to generate ctypes wrapper from .dll or .so file Modified Paths: -------------- pygccxml_dev/pygccxml/parser/__init__.py pygccxml_dev/pygccxml/parser/config.py pygccxml_dev/pygccxml/utils/__init__.py Added Paths: ----------- pyplusplus_dev/scripts/wrap_library.py Modified: pygccxml_dev/pygccxml/parser/__init__.py =================================================================== --- pygccxml_dev/pygccxml/parser/__init__.py 2009-01-18 07:40:49 UTC (rev 1587) +++ pygccxml_dev/pygccxml/parser/__init__.py 2009-01-18 21:12:45 UTC (rev 1588) @@ -9,6 +9,7 @@ from config import config_t from config import gccxml_configuration_t from config import load_gccxml_configuration +from config import gccxml_configuration_example from project_reader import COMPILATION_MODE from project_reader import project_reader_t Modified: pygccxml_dev/pygccxml/parser/config.py =================================================================== --- pygccxml_dev/pygccxml/parser/config.py 2009-01-18 07:40:49 UTC (rev 1587) +++ pygccxml_dev/pygccxml/parser/config.py 2009-01-18 21:12:45 UTC (rev 1588) @@ -196,35 +196,37 @@ config_t = gccxml_configuration_t #backward computability +gccxml_configuration_example = \ +"""[gccxml] +#path to gccxml executable file - optional, if not provided, os.environ['PATH'] +#variable is used to find it +gccxml_path= +#gccxml working directory - optional, could be set to your source code directory +working_directory= +#additional include directories, separated by ';' or ':' +include_paths= +#gccxml has a nice algorithms, which selects what C++ compiler to emulate. +#You can explicitly set what compiler it should emulate. +#Valid options are: g++, msvc6, msvc7, msvc71, msvc8, cl. +compiler= +#GCC-XML site: http://gccxml.org/ +""" + def load_gccxml_configuration( configuration, **defaults ): """loads GCC-XML configuration from a file Configuration file sceleton: >>> start <<< - - [gccxml] - #path to gccxml executable file - optional, if not provided, os.environ['PATH'] - #variable is used to find it - gccxml_path= - #gccxml working directory - optional, could be set to your source code directory - working_directory= - #additional include directories, separated by ';' or ':' - include_paths= - #gccxml has a nice algorithms, which selects what C++ compiler to emulate. - #You can explicitly set what compiler it should emulate. - #Valid options are: g++, msvc6, msvc7, msvc71, msvc8, cl. - compiler= - - #GCC-XML site: http://gccxml.org/ - + + %s + >>> end <<< - configuration could be string( configuration file path ) or instance of ConfigParser.SafeConfigParser class - """ + """ % gccxml_configuration_example parser = configuration if isinstance( configuration, types.StringTypes ): from ConfigParser import SafeConfigParser Modified: pygccxml_dev/pygccxml/utils/__init__.py =================================================================== --- pygccxml_dev/pygccxml/utils/__init__.py 2009-01-18 07:40:49 UTC (rev 1587) +++ pygccxml_dev/pygccxml/utils/__init__.py 2009-01-18 21:12:45 UTC (rev 1588) @@ -162,8 +162,9 @@ def get_version(): if 'win' not in sys.platform: return None #not implemented yet - from distutils import msvccompiler - return ( 'msvc', str( msvccompiler.get_build_version() ) ) + else: + from distutils import msvccompiler + return ( 'msvc', str( msvccompiler.get_build_version() ) ) @staticmethod def get_gccxml_compiler(): Added: pyplusplus_dev/scripts/wrap_library.py =================================================================== --- pyplusplus_dev/scripts/wrap_library.py (rev 0) +++ pyplusplus_dev/scripts/wrap_library.py 2009-01-18 21:12:45 UTC (rev 1588) @@ -0,0 +1,86 @@ +import os +import sys +import types + +try: + import pygccxml +except ImportError, err: + sys.path.append( '../../pygccxml_dev' ) + import pygccxml + +try: + import pyplusplus +except ImportError, err: + sys.path.append( '..' ) + import pyplusplus + +import optparse + +parser = optparse.OptionParser() +parser.add_option( '-c' + , '--compiler-config' + , dest="compiler_config" + , help="pygccxml configuration file for GCCXML" + , type="string" + , action="store" + , default=os.path.abspath( os.path.join( os.curdir, 'gccxml.cfg' ) ) ) + +parser.add_option( '-g' + , '--generate-config' + , dest="generate_config" + , help="generates an example of the compiler configuration file (gccxml.cfg) in the current working directory" + , action="store_true" + , default=False ) + +parser.add_option( '-s' + , '--source-file' + , dest="source_file" + , help="source file name - should be specified" + , type="string" + , action="store" ) + +parser.add_option( '-d' + , '--shared-library' + , dest="shared_library" + , help=r"shared\dynamic library file name - should be specified" + , type="string" + , action="store" ) + +parser.add_option( '-o' + , '--output-file' + , dest="output_file" + , help="output file name, if not specified stdout will be used" + , type="string" + , action="store" + , default=sys.stdout ) + +def generate_code( options ): + gccxml = pygccxml.parser.load_gccxml_configuration( options.compiler_config ) + #~ import pdb + #~ pdb.set_trace() + fc = pygccxml.parser.create_source_fc( options.source_file ) + mb = pyplusplus.module_builder.ctypes_module_builder_t( [ fc ], options.shared_library, gccxml ) + mb.build_code_creator( options.shared_library ) + if isinstance( options.output_file, types.StringTypes ): + mb.write_module( options.output_file ) + else: + print mb.code_creator.create() + +if __name__ == '__main__': + options, unused = parser.parse_args(sys.argv[1:]) + + if options.generate_config: + f_path = os.path.abspath( os.path.join( os.curdir, 'gccxml.cfg' ) ) + f = file( f_path, 'w+' ) + f.write( pygccxml.parser.gccxml_configuration_example ) + f.close() + print 'file: "%s" was generated' % f_path + else: + if None is options.source_file: + parser.error("You have to specify source file") + if None is options.shared_library: + parser.error(r"You have to specify shared\dynamic library file") + else: + generate_code( options ) + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |