blob: e0efb49f1a7c51c017c0f953b28e5b4e77513309 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001#
2# edit-swig-python-wrapper-file.py
3#
4# This script performs some post-processing editing on the C++ file that
5# SWIG generates for python, after running on 'lldb.swig'. In
Caroline Tice5790e062010-10-28 21:51:20 +00006# particular, on Apple systems we want to include the Python.h file that
7# is used in the /System/Library/Frameworks/Python.framework, but on other
8# systems we want to include plain <Python.h>. So we need to replace:
9#
10# #include <Python.h>
11#
12# with:
13#
14# #if defined (__APPLE__)
15# #include <Python/Python.h>
16# #else
17# #include <Python.h>
18# #endif
19#
20# That's what this python script does.
Chris Lattner24943d22010-06-08 16:52:24 +000021#
22
Chris Lattner24943d22010-06-08 16:52:24 +000023import os
24
Johnny Chen8c2e28d2011-05-27 21:58:22 +000025include_python = '#include <Python.h>'
26include_python_ifdef = '''#if defined (__APPLE__)
27#include <Python/Python.h>
28#else
29#include <Python.h>
30#endif
31'''
32
Caroline Tice5790e062010-10-28 21:51:20 +000033input_dir_name = os.environ["SRCROOT"]
34full_input_name = input_dir_name + "/source/LLDBWrapPython.cpp"
Chris Lattner24943d22010-06-08 16:52:24 +000035full_output_name = full_input_name + ".edited"
36
Johnny Chen8c2e28d2011-05-27 21:58:22 +000037with open(full_input_name, 'r') as f_in:
38 with open(full_output_name, 'w') as f_out:
39 include_python_found = False
40 for line in f_in:
41 if not include_python_found:
42 if line.startswith(include_python):
43 # Write out the modified lines.
44 f_out.write(include_python_ifdef)
45 include_python_found = True
46 continue
Chris Lattner24943d22010-06-08 16:52:24 +000047
Johnny Chen8c2e28d2011-05-27 21:58:22 +000048 # Otherwise, copy the line verbatim to the output file.
49 f_out.write(line)