Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | # |
| 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 | |
| 14 | import os |
| 15 | |
| 16 | full_input_name = os.environ["SCRIPT_INPUT_FILE_1"]; |
| 17 | full_output_name = full_input_name + ".edited" |
| 18 | |
| 19 | try: |
| 20 | f_in = open (full_input_name, 'r') |
| 21 | except IOError: |
| 22 | print "Error: Unable to open file for reading: " + full_input_name |
| 23 | else: |
| 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" |