~russel/groovynativelauncher/trunk

« back to all changes in this revision

Viewing changes to tests/supportModule.py

  • Committer: akaranta
  • Date: 2010-04-16 12:30:01 UTC
  • Revision ID: svn-v4:a5544e8c-8a19-0410-ba12-f9af4593a198:trunk/groovy/modules/native_launcher:19870
added a python func to modify the swig generated c file so that not having debug version of python on windows does not stop the build. This functionality is not yet installed in the build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        files.remove( f )
94
94
    return files 
95
95
 
 
96
# Windows specific issue:
 
97
# Having _DEBUG will cause Python.h to try to use python26_d.lib which is not included
 
98
# in Python installer and thus the build fails. See e.g. 
 
99
#   http://old.nabble.com/please-include-python26_d.lib-in-the-installer-td22737890.html
 
100
#  http://old.nabble.com/MUD-Game-Programmming---Python-Modules-in-C%2B%2B-td25880983.html#a25882369
 
101
# for discussion on the topic. For some reason there is no issue about it in the 
 
102
# Python bug tracker.
 
103
 
104
# From MSDN docs: "The compiler defines _DEBUG when you specify the /MTd or /MDd option."
 
105
# Thus, to be able to perform a debug test build, we need to either:
 
106
#   * modify %PYTHON_HOME%\Include\pyconfig.h so python26.lib will be used instead of python26_d.lib
 
107
#   * compile ourselves a debug version of Python
 
108
#   * surround the #include <Python.h> in our source with #ifdef _DEBUG #undef _DEBUG #include <Python.h> style construct (see impl below)
 
109
# Of these options, the last one is the least intrusive and requires least hassle. 
 
110
 
 
111
# cfile needs to be opened and have write permissions. This func will not close it.
 
112
def surroundPythonHIncludeWithGuards( cfile ) :
 
113
    cfile.seek( 0 )
 
114
    lines = cfile.readlines()
 
115
    linenrOfPythonH = None
 
116
    try : 
 
117
      linenrOfPythonH = lines.index( '#include <Python.h>\n' )
 
118
    except ValueError : return
 
119
    
 
120
    if ( lines[ linenrOfPythonH - 2 ] == "#  undef _DEBUG\n" ) : return
 
121
 
 
122
    post = [ 
 
123
      "#if defined( _DEBUG_WAS_DEFINED )\n",
 
124
      "#  define _DEBUG\n",
 
125
      "#endif\n" ]
 
126
    post.reverse()
 
127
 
 
128
    for line in post : lines.insert( linenrOfPythonH + 1, line )
 
129
 
 
130
    pre = [ 
 
131
      "#if defined( _DEBUG )\n",
 
132
      "#  define _DEBUG_WAS_DEFINED\n",
 
133
      "#  undef _DEBUG\n",
 
134
      "#endif\n" ]
 
135
    pre.reverse()
 
136
    for line in pre : lines.insert( linenrOfPythonH, line )    
 
137
 
 
138
    cfile.truncate( 0 )
 
139
    cfile.seek( 0 )
 
140
    cfile.writelines( lines )
 
141
 
96
142
if __name__ == '__main__' :
97
143
    print 'Run tests using command "scons test".'
 
144
    
 
145
    
 
146