blob: a8c432394716f9a733081cc7e82ef770072ca431 [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
6# particular, the types SWIGTYPE_p_SBThread and SWIGTYPE_p_SBTarget are
7# being used, when the types that *should* be used are
8# SWIGTYPE_p_lldb__SBThread and SWIGTYPE_p_lldb__SBTarget.
9# This script goes through the C++ file SWIG generated, reading it in line
10# by line and doing a search-and-replace for these strings.
11#
12
13
14import os
15
16full_input_name = os.environ["SCRIPT_INPUT_FILE_1"];
17full_output_name = full_input_name + ".edited"
18
19try:
20 f_in = open (full_input_name, 'r')
21except IOError:
22 print "Error: Unable to open file for reading: " + full_input_name
23else:
24 try:
25 f_out = open (full_output_name, 'w')
26 except IOError:
27 print "Error: Unable to open file for writing: " + full_output_name
28 else:
29 target_typedef_found = False
30 thread_typedef_found = False
31
32 try:
33 line = f_in.readline()
34 except IOError:
35 print "Error occurred while reading file."
36 else:
37 while line:
38 #
39 #
40 if (line.find ("SWIGTYPE_p_SBTarget")):
41 if (line.find ("define") < 0):
42 line = line.replace ("SWIGTYPE_p_SBTarget",
43 "SWIGTYPE_p_lldb__SBTarget")
44 if (line.find ("SWIGTYPE_p_SBThread")):
45 if (line.find ("define") < 0):
46 line = line.replace ("SWIGTYPE_p_SBThread",
47 "SWIGTYPE_p_lldb__SBThread")
48 f_out.write (line)
49 try:
50 line = f_in.readline()
51 except IOError:
52 print "Error occurred while reading file."
53
54 try:
55 f_in.close()
56 f_out.close()
57 except:
58 print "Error occurred while closing files"