blob: d64c0b408164c1e2ef11af086f0a90be7e6a7476 [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
Charles Davis5420ec82011-06-01 02:33:12 +000023import os, sys
Chris Lattner24943d22010-06-08 16:52:24 +000024
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
Charles Davis5420ec82011-06-01 02:33:12 +000033if len (sys.argv) > 1:
34 input_dir_name = sys.argv[1]
35 full_input_name = input_dir_name + "/LLDBWrapPython.cpp"
36else:
37 input_dir_name = os.environ["SRCROOT"]
38 full_input_name = input_dir_name + "/source/LLDBWrapPython.cpp"
Chris Lattner24943d22010-06-08 16:52:24 +000039full_output_name = full_input_name + ".edited"
40
Johnny Chen8c2e28d2011-05-27 21:58:22 +000041with open(full_input_name, 'r') as f_in:
42 with open(full_output_name, 'w') as f_out:
43 include_python_found = False
44 for line in f_in:
45 if not include_python_found:
46 if line.startswith(include_python):
47 # Write out the modified lines.
48 f_out.write(include_python_ifdef)
49 include_python_found = True
50 continue
Chris Lattner24943d22010-06-08 16:52:24 +000051
Johnny Chen8c2e28d2011-05-27 21:58:22 +000052 # Otherwise, copy the line verbatim to the output file.
53 f_out.write(line)