Skip to content

Commit

Permalink
modtool: Fix bug where gr_modtool rm messes up the C++ QA section
Browse files Browse the repository at this point in the history
This bug was originally reported by chenzhubattg. Previously, C++
QA files weren't properly removed from lib/CMakeLists.txt, such
that the path to the file was left in the CMake file, making it
invalid.
This fixes a bug in the cmake_editor.py module, which previously
had a too lenient regex.
  • Loading branch information
mbr0wn authored and jmcorgan committed Jun 14, 2015
1 parent 5b34e51 commit f6bd3e6
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions gr-utils/python/modtool/cmakefile_editor.py
Expand Up @@ -39,8 +39,38 @@ def append_value(self, entry, value, to_ignore_start='', to_ignore_end=''):
return nsubs

def remove_value(self, entry, value, to_ignore_start='', to_ignore_end=''):
"""Remove a value from an entry."""
regexp = '^\s*(%s\(\s*%s[^()]*?\s*)%s\s*([^()]*%s\s*\))' % (entry, to_ignore_start, value, to_ignore_end)
"""
Remove a value from an entry.
Example: You want to remove file.cc from this list() entry:
list(SOURCES
file.cc
other_file.cc
)
Then run:
>>> C.remove_value('list', 'file.cc', 'SOURCES')
Returns the number of occurences of entry in the current file
that were removed.
"""
# In the case of the example above, these are cases we need to catch:
# - list(file.cc ...
# entry is right after the value parentheses, no whitespace. Can only happen
# when to_ignore_start is empty.
# - list(... file.cc)
# Other entries come first, then entry is preceded by whitespace.
# - list(SOURCES ... file.cc) # whitespace!
# When to_ignore_start is not empty, entry must always be preceded by whitespace.
if len(to_ignore_start) == 0:
regexp = r'^\s*({entry}\((?:[^()]*?\s+|)){value}\s*([^()]*{to_ignore_end}\s*\)){to_ignore_start}'
else:
regexp = r'^\s*({entry}\(\s*{to_ignore_start}[^()]*?\s+){value}\s*([^()]*{to_ignore_end}\s*\))'
regexp = regexp.format(
entry=entry,
to_ignore_start=to_ignore_start,
value=value,
to_ignore_end=to_ignore_end,
)
regexp = re.compile(regexp, re.MULTILINE)
(self.cfile, nsubs) = re.subn(regexp, r'\1\2', self.cfile, count=1)
return nsubs
Expand Down

0 comments on commit f6bd3e6

Please sign in to comment.