[Lldb-commits] [PATCH] D14718: Insert the SWIG version into LLDB's __init__.py
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 16 11:08:37 PST 2015
zturner created this revision.
zturner added a reviewer: tfiala.
zturner added a subscriber: lldb-commits.
The goal here is to allow us to add expectedFailure / etc decorators
based on SWIG version.
The end result of this is that patch is that after running SWIG generation
you will have a line such as the following at the top of your `__init__.py`.
swig_version = (3,0,7)
http://reviews.llvm.org/D14718
Files:
scripts/Python/modify-python-lldb.py
Index: scripts/Python/modify-python-lldb.py
===================================================================
--- scripts/Python/modify-python-lldb.py
+++ scripts/Python/modify-python-lldb.py
@@ -44,6 +44,11 @@
# print "output_name is '" + output_name + "'"
#
+# Version string
+#
+version_line = "swig_version = %s"
+
+#
# Residues to be removed.
#
c_endif_swig = "#endif"
@@ -308,6 +313,9 @@
with open(output_name, 'r') as f_in:
content = f_in.read()
+# The pattern for recognizing the SWIG Version string
+version_pattern = re.compile("^# Version:? (.*)$")
+
# The pattern for recognizing the beginning of an SB class definition.
class_pattern = re.compile("^class (SB.*)\(_object\):$")
@@ -318,10 +326,11 @@
isvalid_pattern = re.compile("^ def IsValid\(")
# These define the states of our finite state machine.
-NORMAL = 0
-DEFINING_ITERATOR = 1
-DEFINING_EQUALITY = 2
-CLEANUP_DOCSTRING = 4
+EXPECTING_VERSION = 0
+NORMAL = 1
+DEFINING_ITERATOR = 2
+DEFINING_EQUALITY = 4
+CLEANUP_DOCSTRING = 8
# The lldb_iter_def only needs to be inserted once.
lldb_iter_defined = False;
@@ -343,13 +352,16 @@
# The FSM, in all possible states, also checks the current input for IsValid()
# definition, and inserts a __nonzero__() method definition to implement truth
# value testing and the built-in operation bool().
-state = NORMAL
+state = EXPECTING_VERSION
+
+swig_version_tuple = None
for line in content.splitlines():
# Handle the state transition into CLEANUP_DOCSTRING state as it is possible
# to enter this state from either NORMAL or DEFINING_ITERATOR/EQUALITY.
#
# If ' """' is the sole line, prepare to transition to the
# CLEANUP_DOCSTRING state or out of it.
+
if line == toggle_docstring_cleanup_line:
if state & CLEANUP_DOCSTRING:
# Special handling of the trailing blank line right before the '"""'
@@ -359,6 +371,19 @@
else:
state |= CLEANUP_DOCSTRING
+ if state == EXPECTING_VERSION:
+ # We haven't read the version yet, read it now.
+ if swig_version_tuple is None:
+ match = version_pattern.search(line)
+ if match:
+ v = match.group(1)
+ swig_version_tuple = tuple(map(int, (v.split("."))))
+ elif not line.startswith('#'):
+ # This is the first non-comment line after the header. Inject the version
+ new_line = version_line % str(swig_version_tuple)
+ new_content.add_line(new_line)
+ state = NORMAL
+
if state == NORMAL:
match = class_pattern.search(line)
# Inserts lldb_helpers and the lldb_iter() definition before the first
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14718.40315.patch
Type: text/x-patch
Size: 2713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151116/4d3f266f/attachment.bin>
More information about the lldb-commits
mailing list