diff options
Diffstat (limited to 'gr-utils/modtool/core/rm.py')
-rw-r--r-- | gr-utils/modtool/core/rm.py | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/gr-utils/modtool/core/rm.py b/gr-utils/modtool/core/rm.py index 6c0746aba4..b65465cd16 100644 --- a/gr-utils/modtool/core/rm.py +++ b/gr-utils/modtool/core/rm.py @@ -1,5 +1,5 @@ # -# Copyright 2013, 2018, 2019 Free Software Foundation, Inc. +# Copyright 2013, 2018-2020 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -18,7 +18,7 @@ import sys import glob import logging -from ..tools import remove_pattern_from_file, CMakeFileEditor +from ..tools import remove_pattern_from_file, CMakeFileEditor, CPPFileEditor from .base import ModTool, ModToolException logger = logging.getLogger(__name__) @@ -90,30 +90,31 @@ class ModToolRemove(ModTool): ed.delete_entry('GR_ADD_TEST', filebase) ed.remove_double_newlines() - def _make_swig_regex(filename): - filebase = os.path.splitext(filename)[0] - pyblockname = filebase.replace(self.info['modname'] + '_', '') - regexp = r'(^\s*GR_SWIG_BLOCK_MAGIC2?\({},\s*{}\);|^\s*.include\s*"({}/)?{}"\s*)'.format \ - (self.info['modname'], pyblockname, self.info['modname'], filename) - return regexp # Go, go, go! if not self.skip_subdirs['lib']: self._run_subdir('lib', ('*.cc', '*.h'), ('add_library', 'list'), cmakeedit_func=_remove_cc_test_case) if not self.skip_subdirs['include']: incl_files_deleted = self._run_subdir(self.info['includedir'], ('*.h',), ('install',)) - if not self.skip_subdirs['swig']: - swig_files_deleted = self._run_subdir('swig', ('*.i',), ('install',)) - for f in incl_files_deleted + swig_files_deleted: - # TODO do this on all *.i files - remove_pattern_from_file(self._file['swig'], _make_swig_regex(f)) - self.scm.mark_file_updated(self._file['swig']) if not self.skip_subdirs['python']: py_files_deleted = self._run_subdir('python', ('*.py',), ('GR_PYTHON_INSTALL',), cmakeedit_func=_remove_py_test_case) for f in py_files_deleted: remove_pattern_from_file(self._file['pyinit'], fr'.*import\s+{f[:-3]}.*') remove_pattern_from_file(self._file['pyinit'], fr'.*from\s+{f[:-3]}\s+import.*\n') + + pb_files_deleted = self._run_subdir('python/bindings', ('*.cc',), ('list',)) + + pbdoc_files_deleted = self._run_subdir('python/bindings/docstrings', ('*.h',), ('',)) + + # Update python_bindings.cc + ed = CPPFileEditor(self._file['ccpybind']) + ed.remove_value('// BINDING_FUNCTION_PROTOTYPES(', '// ) END BINDING_FUNCTION_PROTOTYPES', + 'void bind_' + self.info['blockname'] + '(py::module& m);') + ed.remove_value('// BINDING_FUNCTION_CALLS(', '// ) END BINDING_FUNCTION_CALLS', + 'bind_' + self.info['blockname'] + '(m);') + ed.write() + if not self.skip_subdirs['grc']: self._run_subdir('grc', ('*.yml',), ('install',)) @@ -132,7 +133,7 @@ class ModToolRemove(ModTool): for g in globs: files = files + sorted(glob.glob(f"{path}/{g}")) files_filt = [] - logger.info("Searching for matching files in {path}/:") + logger.info(f"Searching for matching files in {path}/:") for f in files: if re.search(self.info['pattern'], os.path.basename(f)) is not None: files_filt.append(f) @@ -141,7 +142,6 @@ class ModToolRemove(ModTool): return [] # 2. Delete files, Makefile entries and other occurrences files_deleted = [] - ed = CMakeFileEditor(f'{path}/CMakeLists.txt') yes = self.info['yes'] for f in files_filt: b = os.path.basename(f) @@ -157,11 +157,15 @@ class ModToolRemove(ModTool): logger.info(f"Deleting {f}.") self.scm.remove_file(f) os.unlink(f) - logger.info(f"Deleting occurrences of {b} from {path}/CMakeLists.txt...") - for var in makefile_vars: - ed.remove_value(var, b) - if cmakeedit_func is not None: - cmakeedit_func(b, ed) - ed.write() - self.scm.mark_files_updated((f'{path}/CMakeLists.txt')) + + if (os.path.exists(f'{path}/CMakeLists.txt')): + ed = CMakeFileEditor(f'{path}/CMakeLists.txt') + logger.info(f"Deleting occurrences of {b} from {path}/CMakeLists.txt...") + for var in makefile_vars: + ed.remove_value(var, b) + if cmakeedit_func is not None: + cmakeedit_func(b, ed) + ed.write() + self.scm.mark_files_updated((f'{path}/CMakeLists.txt')) + return files_deleted |