Back to index

python3.2  3.2.2
Classes | Functions | Variables
checkextensions_win32 Namespace Reference

Classes

class  CExtension

Functions

def checkextensions
def get_extension_defn
def parse_dsp
def write_extension_table

Variables

 win32api = None
string ext_src_header
string ext_tab_header
string ext_tab_footer
string ext_src_footer

Detailed Description

Extension management for Windows.

Under Windows it is unlikely the .obj files are of use, as special compiler options
are needed (primarily to toggle the behavior of "public" symbols.

I dont consider it worth parsing the MSVC makefiles for compiler options.  Even if
we get it just right, a specific freeze application may have specific compiler
options anyway (eg, to enable or disable specific functionality)

So my basic strategy is:

* Have some Windows INI files which "describe" one or more extension modules.
  (Freeze comes with a default one for all known modules - but you can specify
  your own).
* This description can include:
  - The MSVC .dsp file for the extension.  The .c source file names
    are extraced from there.
  - Specific compiler/linker options
  - Flag to indicate if Unicode compilation is expected.

At the moment the name and location of this INI file is hardcoded,
but an obvious enhancement would be to provide command line options.

Function Documentation

def checkextensions_win32.checkextensions (   unknown,
  extra_inis,
  prefix 
)

Definition at line 57 of file checkextensions_win32.py.

00057 
00058 def checkextensions(unknown, extra_inis, prefix):
00059     # Create a table of frozen extensions
00060 
00061     defaultMapName = os.path.join( os.path.split(sys.argv[0])[0], "extensions_win32.ini")
00062     if not os.path.isfile(defaultMapName):
00063         sys.stderr.write("WARNING: %s can not be found - standard extensions may not be found\n" % defaultMapName)
00064     else:
00065         # must go on end, so other inis can override.
00066         extra_inis.append(defaultMapName)
00067 
00068     ret = []
00069     for mod in unknown:
00070         for ini in extra_inis:
00071 #                       print "Looking for", mod, "in", win32api.GetFullPathName(ini),"...",
00072             defn = get_extension_defn( mod, ini, prefix )
00073             if defn is not None:
00074 #                               print "Yay - found it!"
00075                 ret.append( defn )
00076                 break
00077 #                       print "Nope!"
00078         else: # For not broken!
00079             sys.stderr.write("No definition of module %s in any specified map file.\n" % (mod))
00080 
00081     return ret

Here is the call graph for this function:

Here is the caller graph for this function:

def checkextensions_win32.get_extension_defn (   moduleName,
  mapFileName,
  prefix 
)

Definition at line 82 of file checkextensions_win32.py.

00082 
00083 def get_extension_defn(moduleName, mapFileName, prefix):
00084     if win32api is None: return None
00085     os.environ['PYTHONPREFIX'] = prefix
00086     dsp = win32api.GetProfileVal(moduleName, "dsp", "", mapFileName)
00087     if dsp=="":
00088         return None
00089 
00090     # We allow environment variables in the file name
00091     dsp = win32api.ExpandEnvironmentStrings(dsp)
00092     # If the path to the .DSP file is not absolute, assume it is relative
00093     # to the description file.
00094     if not os.path.isabs(dsp):
00095         dsp = os.path.join( os.path.split(mapFileName)[0], dsp)
00096     # Parse it to extract the source files.
00097     sourceFiles = parse_dsp(dsp)
00098     if sourceFiles is None:
00099         return None
00100 
00101     module = CExtension(moduleName, sourceFiles)
00102     # Put the path to the DSP into the environment so entries can reference it.
00103     os.environ['dsp_path'] = os.path.split(dsp)[0]
00104     os.environ['ini_path'] = os.path.split(mapFileName)[0]
00105 
00106     cl_options = win32api.GetProfileVal(moduleName, "cl", "", mapFileName)
00107     if cl_options:
00108         module.AddCompilerOption(win32api.ExpandEnvironmentStrings(cl_options))
00109 
00110     exclude = win32api.GetProfileVal(moduleName, "exclude", "", mapFileName)
00111     exclude = exclude.split()
00112 
00113     if win32api.GetProfileVal(moduleName, "Unicode", 0, mapFileName):
00114         module.AddCompilerOption('/D UNICODE /D _UNICODE')
00115 
00116     libs = win32api.GetProfileVal(moduleName, "libs", "", mapFileName).split()
00117     for lib in libs:
00118         module.AddLinkerLib(win32api.ExpandEnvironmentStrings(lib))
00119 
00120     for exc in exclude:
00121         if exc in module.sourceFiles:
00122             modules.sourceFiles.remove(exc)
00123 
00124     return module
00125 
00126 # Given an MSVC DSP file, locate C source files it uses
# returns a list of source files.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 127 of file checkextensions_win32.py.

00127 
00128 def parse_dsp(dsp):
00129 #       print "Processing", dsp
00130     # For now, only support
00131     ret = []
00132     dsp_path, dsp_name = os.path.split(dsp)
00133     try:
00134         lines = open(dsp, "r").readlines()
00135     except IOError as msg:
00136         sys.stderr.write("%s: %s\n" % (dsp, msg))
00137         return None
00138     for line in lines:
00139         fields = line.strip().split("=", 2)
00140         if fields[0]=="SOURCE":
00141             if os.path.splitext(fields[1])[1].lower() in ['.cpp', '.c']:
00142                 ret.append( win32api.GetFullPathName(os.path.join(dsp_path, fields[1] ) ) )
00143     return ret

Here is the call graph for this function:

Here is the caller graph for this function:

def checkextensions_win32.write_extension_table (   fname,
  modules 
)

Definition at line 144 of file checkextensions_win32.py.

00144 
00145 def write_extension_table(fname, modules):
00146     fp = open(fname, "w")
00147     try:
00148         fp.write (ext_src_header)
00149         # Write fn protos
00150         for module in modules:
00151             # bit of a hack for .pyd's as part of packages.
00152             name = module.name.split('.')[-1]
00153             fp.write('extern void init%s(void);\n' % (name) )
00154         # Write the table
00155         fp.write (ext_tab_header)
00156         for module in modules:
00157             name = module.name.split('.')[-1]
00158             fp.write('\t{"%s", init%s},\n' % (name, name) )
00159 
00160         fp.write (ext_tab_footer)
00161         fp.write(ext_src_footer)
00162     finally:
00163         fp.close()
00164 

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 """\
00002 extern DL_IMPORT(int) PyImport_ExtendInittab(struct _inittab *newtab);
00003 
00004 int PyInitFrozenExtensions()
00005 {
00006         return PyImport_ExtendInittab(extensions);
00007 }
00008 
00009 """

Definition at line 180 of file checkextensions_win32.py.

Initial value:
00001 """\
00002 #include "Python.h"
00003 """

Definition at line 165 of file checkextensions_win32.py.

Initial value:
00001 """\
00002         /* Sentinel */
00003         {0, 0}
00004 };
00005 """

Definition at line 174 of file checkextensions_win32.py.

Initial value:
00001 """\
00002 
00003 static struct _inittab extensions[] = {
00004 """

Definition at line 169 of file checkextensions_win32.py.

Definition at line 29 of file checkextensions_win32.py.