Example #1
0
 def _run_subdir(self, path, globs, makefile_vars, cmakeedit_func=None):
     """ Delete all files that match a certain pattern in path.
     path - The directory in which this will take place
     globs - A tuple of standard UNIX globs of files to delete (e.g. *.xml)
     makefile_vars - A tuple with a list of CMakeLists.txt-variables which
                     may contain references to the globbed files
     cmakeedit_func - If the CMakeLists.txt needs special editing, use this
     """
     # 1. Create a filtered list
     files = []
     for g in globs:
         files = files + sorted(glob.glob("%s/%s"% (path, g)))
     files_filt = []
     print "Searching for matching files in %s/:" % path
     for f in files:
         if re.search(self._info['pattern'], os.path.basename(f)) is not None:
             files_filt.append(f)
     if not files_filt:
         print "None found."
         return []
     # 2. Delete files, Makefile entries and other occurrences
     files_deleted = []
     ed = CMakeFileEditor('%s/CMakeLists.txt' % path)
     yes = self._info['yes']
     for f in files_filt:
         b = os.path.basename(f)
         if not yes:
             ans = raw_input("Really delete %s? [Y/n/a/q]: " % f).lower().strip()
             if ans == 'a':
                 yes = True
             if ans == 'q':
                 sys.exit(0)
             if ans == 'n':
                 continue
         files_deleted.append(b)
         print "Deleting %s." % f
         self.scm.remove_file(f)
         os.unlink(f)
         print "Deleting occurrences of %s from %s/CMakeLists.txt..." % (b, path)
         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(('%s/CMakeLists.txt' % path,))
     return files_deleted
 def _make_grc_xml_from_block_data(self, params, iosig, blockname):
     """ Take the return values from the parser and call the XML
     generator. Also, check the makefile if the .xml file is in there.
     If necessary, add. """
     fname_xml = '%s_%s.xml' % (self._info['modname'], blockname)
     # Some adaptions for the GRC
     for inout in ('in', 'out'):
         if iosig[inout]['max_ports'] == '-1':
             iosig[inout]['max_ports'] = '$num_%sputs' % inout
             params.append({
                 'key': 'num_%sputs' % inout,
                 'type': 'int',
                 'name': 'Num %sputs' % inout,
                 'default': '2',
                 'in_constructor': False
             })
     if os.path.isfile(os.path.join('grc', fname_xml)):
         # TODO add an option to keep
         print "Warning: Overwriting existing GRC file."
     grc_generator = GRCXMLGenerator(modname=self._info['modname'],
                                     blockname=blockname,
                                     params=params,
                                     iosig=iosig)
     grc_generator.save(os.path.join('grc', fname_xml))
     if not self._skip_subdirs['grc']:
         ed = CMakeFileEditor(self._file['cmgrc'])
         if re.search(fname_xml,
                      ed.cfile) is None and not ed.check_for_glob('*.xml'):
             print "Adding GRC bindings to grc/CMakeLists.txt..."
             ed.append_value('install', fname_xml, 'DESTINATION[^()]+')
             ed.write()
Example #3
0
 def _run_rfnoc(self):
     """ Do everything that needs doing in the subdir 'rfnoc' to add
     a GRC block control bindings XML file.
     - add .xml file
     - include in CMakeLists.txt
     - add verilog file
     - adds verilog name to Makefile.srcs
     - Calls _run_testbenches()
     - Runs build (test)
     """
     fname_rfnoc = self._info['blockname'] + '.xml'
     fname_rfnocv = 'noc_block_' +  self._info['blockname'] + '.v'
     self._write_tpl('rfnoc_xml', 'rfnoc/blocks', fname_rfnoc)
     self._write_tpl('rfnoc_v', 'rfnoc/fpga-src', fname_rfnocv)
     patt_v = re.escape('$(addprefix '+os.path.join(os.getcwd(),'rfnoc','fpga-src','')+', \\\n') #TODO can be replaced with a dummy, as the file is supposed to be empty
     append_re_line_sequence(self._file['rfnoc_mksrc'],
                                        patt_v,
                                        'noc_block_' + self._info['blockname'] + '.v \\')
     ed = CMakeFileEditor(self._file['cmrfnoc'], '\n    ')
     self._run_testbenches()
     self._build()
     if self._skip_cmakefiles or ed.check_for_glob('*.xml'):
         return
     print("Editing rfnoc/blocks/CMakeLists.txt...")
     ed.append_value('install', fname_rfnoc, to_ignore_end='DESTINATION[^()]+')
     ed.write()
     self.scm.mark_files_updated((self._file['cmrfnoc'],))
Example #4
0
 def _add_qa36():
     " Add C++ QA files for pre-3.7 API (not autotools) "
     fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
     self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
     if not self.options.skip_cmakefiles:
         open(self._file['cmlib'], 'a').write(
                 str(
                     Cheetah.Template.Template(
                         Templates['qa_cmakeentry36'],
                         searchList={'basename': os.path.splitext(fname_qa_cc)[0],
                                     'filename': fname_qa_cc,
                                     'modname': self._info['modname']
                                    }
                     )
                  )
         )
         ed = CMakeFileEditor(self._file['cmlib'])
         ed.remove_double_newlines()
         ed.write()
Example #5
0
 def _make_grc_xml_from_block_data(self, params, iosig, blockname):
     """ Take the return values from the parser and call the XML
     generator. Also, check the makefile if the .xml file is in there.
     If necessary, add. """
     fname_xml = '%s_%s.xml' % (self._info['modname'], blockname)
     # Some adaptions for the GRC
     for inout in ('in', 'out'):
         if iosig[inout]['max_ports'] == '-1':
             iosig[inout]['max_ports'] = '$num_%sputs' % inout
             params.append({'key': 'num_%sputs' % inout,
                            'type': 'int',
                            'name': 'Num %sputs' % inout,
                            'default': '2',
                            'in_constructor': False})
     if os.path.isfile(os.path.join('grc', fname_xml)):
         if not self._info['yes']:
             if not ask_yes_no('Overwrite existing GRC file?', False):
                 return
         else:
             print "Warning: Overwriting existing GRC file."
     grc_generator = GRCXMLGenerator(
             modname=self._info['modname'],
             blockname=blockname,
             params=params,
             iosig=iosig
     )
     grc_generator.save(os.path.join('grc', fname_xml))
     if not self._skip_subdirs['grc']:
         ed = CMakeFileEditor(self._file['cmgrc'])
         if re.search(fname_xml, ed.cfile) is None and not ed.check_for_glob('*.xml'):
             print "Adding GRC bindings to grc/CMakeLists.txt..."
             ed.append_value('install', fname_xml, to_ignore_end='DESTINATION[^()]+')
             ed.write()
Example #6
0
 def _run_python_qa(self):
     """ Do everything that needs doing in the subdir 'python' to add
     QA code.
     - add .py files
     - include in CMakeLists.txt
     """
     fname_py_qa = 'qa_' + self._info['blockname'] + '.py'
     self._write_tpl('qa_python', 'python', fname_py_qa)
     os.chmod(os.path.join('python', fname_py_qa), 0755)
     if self.options.skip_cmakefiles or CMakeFileEditor(self._file['cmpython']).check_for_glob('qa_*.py'):
         return
     print "Editing python/CMakeLists.txt..."
     open(self._file['cmpython'], 'a').write(
             'GR_ADD_TEST(qa_%s ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/%s)\n' % \
               (self._info['blockname'], fname_py_qa))
Example #7
0
 def _handle_cc_qa(cmake, fname):
     """ Do stuff for cc qa """
     if self._info['version'] == '37':
         cmake.comment_out_lines('\$\{CMAKE_CURRENT_SOURCE_DIR\}/'+fname)
         fname_base = os.path.splitext(fname)[0]
         ed = CMakeFileEditor(self._file['qalib']) # Abusing the CMakeFileEditor...
         ed.comment_out_lines('#include\s+"%s.h"' % fname_base, comment_str='//')
         ed.comment_out_lines('%s::suite\(\)' % fname_base, comment_str='//')
         ed.write()
     elif self._info['version'] == '36':
         cmake.comment_out_lines('add_executable.*'+fname)
         cmake.comment_out_lines('target_link_libraries.*'+os.path.splitext(fname)[0])
         cmake.comment_out_lines('GR_ADD_TEST.*'+os.path.splitext(fname)[0])
     return True
Example #8
0
 def _run_grc(self):
     """ Do everything that needs doing in the subdir 'grc' to add
     a GRC bindings XML file.
     - add .xml file
     - include in CMakeLists.txt
     """
     fname_grc = self._info['fullblockname'] + '.xml'
     self._write_tpl('grc_xml', 'grc', fname_grc)
     ed = CMakeFileEditor(self._file['cmgrc'], '\n    ')
     if self.options.skip_cmakefiles or ed.check_for_glob('*.xml'):
         return
     print "Editing grc/CMakeLists.txt..."
     ed.append_value('install', fname_grc, to_ignore_end='DESTINATION[^()]+')
     ed.write()
Example #9
0
 def _run_python_hierblock(self):
     """ Do everything that needs doing in the subdir 'python' to add
     a Python hier_block.
     - add .py file
     - include in CMakeLists.txt
     """
     print "Traversing python..."
     fname_py = self._info['blockname'] + '.py'
     self._write_tpl('hier_python', 'python', fname_py)
     ed = CMakeFileEditor('python/CMakeLists.txt')
     ed.append_value('GR_PYTHON_INSTALL', fname_py, 'DESTINATION[^()]+')
     ed.write()
Example #10
0
 def _handle_cc_qa(cmake, fname):
     """ Do stuff for cc qa """
     if self._info["version"] == "37":
         cmake.comment_out_lines("\$\{CMAKE_CURRENT_SOURCE_DIR\}/" + fname)
         fname_base = os.path.splitext(fname)[0]
         ed = CMakeFileEditor(self._file["qalib"])  # Abusing the CMakeFileEditor...
         ed.comment_out_lines('#include\s+"%s.h"' % fname_base, comment_str="//")
         ed.comment_out_lines("%s::suite\(\)" % fname_base, comment_str="//")
         ed.write()
         self.scm.mark_file_updated(self._file["qalib"])
     elif self._info["version"] == "36":
         cmake.comment_out_lines("add_executable.*" + fname)
         cmake.comment_out_lines("target_link_libraries.*" + os.path.splitext(fname)[0])
         cmake.comment_out_lines("GR_ADD_TEST.*" + os.path.splitext(fname)[0])
     self.scm.mark_file_updated(cmake.filename)
     return True
 def _handle_cc_qa(cmake, fname):
     """ Do stuff for cc qa """
     if self._info['version'] == '37':
         cmake.comment_out_lines('\$\{CMAKE_CURRENT_SOURCE_DIR\}/' +
                                 fname)
         fname_base = os.path.splitext(fname)[0]
         ed = CMakeFileEditor(
             self._file['qalib'])  # Abusing the CMakeFileEditor...
         ed.comment_out_lines('#include\s+"%s.h"' % fname_base,
                              comment_str='//')
         ed.comment_out_lines('%s::suite\(\)' % fname_base,
                              comment_str='//')
         ed.write()
     elif self._info['version'] == '36':
         cmake.comment_out_lines('add_executable.*' + fname)
         cmake.comment_out_lines('target_link_libraries.*' +
                                 os.path.splitext(fname)[0])
         cmake.comment_out_lines('GR_ADD_TEST.*' +
                                 os.path.splitext(fname)[0])
     return True
Example #12
0
 def _run_grc(self):
     """ Do everything that needs doing in the subdir 'grc' to add
     a GRC bindings XML file.
     - add .xml file
     - include in CMakeLists.txt
     """
     print "Traversing grc..."
     fname_grc = self._info['fullblockname'] + '.xml'
     self._write_tpl('grc_xml', 'grc', fname_grc)
     print "Editing grc/CMakeLists.txt..."
     ed = CMakeFileEditor('grc/CMakeLists.txt', '\n    ')
     ed.append_value('install', fname_grc, 'DESTINATION[^()]+')
     ed.write()
Example #13
0
 def _run_subdir(self, path, globs, makefile_vars, cmakeedit_func=None):
     """ Delete all files that match a certain pattern in path.
     path - The directory in which this will take place
     globs - A tuple of standard UNIX globs of files to delete (e.g. *.xml)
     makefile_vars - A tuple with a list of CMakeLists.txt-variables which
                     may contain references to the globbed files
     cmakeedit_func - If the CMakeLists.txt needs special editing, use this
     """
     # 1. Create a filtered list
     files = []
     for g in globs:
         files = files + glob.glob("%s/%s" % (path, g))
     files_filt = []
     print "Searching for matching files in %s/:" % path
     for f in files:
         if re.search(self._info['pattern'],
                      os.path.basename(f)) is not None:
             files_filt.append(f)
         if path is "swig":
             files_filt.append(f)
     if len(files_filt) == 0:
         print "None found."
         return []
     # 2. Delete files, Makefile entries and other occurences
     files_deleted = []
     ed = CMakeFileEditor('%s/CMakeLists.txt' % path)
     yes = self._info['yes']
     for f in files_filt:
         b = os.path.basename(f)
         if not yes:
             ans = raw_input("Really delete %s? [Y/n/a/q]: " %
                             f).lower().strip()
             if ans == 'a':
                 yes = True
             if ans == 'q':
                 sys.exit(0)
             if ans == 'n':
                 continue
         files_deleted.append(b)
         print "Deleting %s." % f
         os.unlink(f)
         print "Deleting occurrences of %s from %s/CMakeLists.txt..." % (
             b, path)
         for var in makefile_vars:
             ed.remove_value(var, b)
         if cmakeedit_func is not None:
             cmakeedit_func(b, ed)
     ed.write()
     return files_deleted
Example #14
0
 def _run_python(self):
     """ Do everything that needs doing in the subdir 'python' to add
     a Python block.
     - add .py file
     - include in CMakeLists.txt
     - include in __init__.py
     """
     fname_py = self._info['blockname'] + '.py'
     self._write_tpl('block_python', 'python', fname_py)
     append_re_line_sequence(self._file['pyinit'],
                             '(^from.*import.*\n|# import any pure.*\n)',
                             'from %s import %s' % (self._info['blockname'], self._info['blockname']))
     if self.options.skip_cmakefiles:
         return
     ed = CMakeFileEditor(self._file['cmpython'])
     ed.append_value('GR_PYTHON_INSTALL', fname_py, to_ignore_end='DESTINATION[^()]+')
     ed.write()
Example #15
0
 def _add_qa36():
     " Add C++ QA files for pre-3.7 API (not autotools) "
     fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
     self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
     if not self.options.skip_cmakefiles:
         open(self._file['cmlib'], 'a').write(
             str(
                 Cheetah.Template.Template(
                     Templates['qa_cmakeentry36'],
                     searchList={
                         'basename': os.path.splitext(fname_qa_cc)[0],
                         'filename': fname_qa_cc,
                         'modname': self._info['modname']
                     })))
         ed = CMakeFileEditor(self._file['cmlib'])
         ed.remove_double_newlines()
         ed.write()
Example #16
0
 def run(self):
     """ Go, go, go! """
     def _handle_py_qa(cmake, fname):
         """ Do stuff for py qa """
         cmake.comment_out_lines('GR_ADD_TEST.*'+fname)
         return True
     def _handle_py_mod(cmake, fname):
         """ Do stuff for py extra files """
         try:
             initfile = open(os.path.join('python', '__init__.py')).read()
         except IOError:
             return False
         pymodname = os.path.splitext(fname)[0]
         initfile = re.sub(r'((from|import)\s+\b'+pymodname+r'\b)', r'#\1', initfile)
         open(os.path.join('python', '__init__.py'), 'w').write(initfile)
         return False
     def _handle_cc_qa(cmake, fname):
         """ Do stuff for cc qa """
         print 'hello...'
         cmake.comment_out_lines('add_executable.*'+fname)
         cmake.comment_out_lines('target_link_libraries.*'+os.path.splitext(fname)[0])
         cmake.comment_out_lines('GR_ADD_TEST.*'+os.path.splitext(fname)[0])
         return True
     def _handle_h_swig(cmake, fname):
         """ Comment out include files from the SWIG file,
         as well as the block magic """
         swigfile = open(os.path.join('swig', self._get_mainswigfile())).read()
         (swigfile, nsubs) = re.subn('(.include\s+"'+fname+'")', r'//\1', swigfile)
         if nsubs > 0:
             print "Changing %s..." % self._get_mainswigfile()
         if nsubs > 1: # Need to find a single BLOCK_MAGIC
             blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0] # DEPRECATE 3.7
             (swigfile, nsubs) = re.subn('(GR_SWIG_BLOCK_MAGIC.+'+blockname+'.+;)', r'//\1', swigfile)
             if nsubs > 1:
                 print "Hm, something didn't go right while editing %s." % swigfile
         open(os.path.join('swig', self._get_mainswigfile()), 'w').write(swigfile)
         return False
     def _handle_i_swig(cmake, fname):
         """ Comment out include files from the SWIG file,
         as well as the block magic """
         swigfile = open(os.path.join('swig', self._get_mainswigfile())).read()
         blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0] # DEPRECATE 3.7
         swigfile = re.sub('(%include\s+"'+fname+'")', r'//\1', swigfile)
         print "Changing %s..." % self._get_mainswigfile()
         swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC.+'+blockname+'.+;)', r'//\1', swigfile)
         open(os.path.join('swig', self._get_mainswigfile()), 'w').write(swigfile)
         return False
     # List of special rules: 0: subdir, 1: filename re match, 2: function
     special_treatments = (
             ('python', 'qa.+py$', _handle_py_qa),
             ('python', '^(?!qa).+py$', _handle_py_mod),
             ('lib', 'qa.+\.cc$', _handle_cc_qa),
             ('include', '.+\.h$', _handle_h_swig),
             ('swig', '.+\.i$', _handle_i_swig)
     )
     for subdir in self._subdirs:
         if self._skip_subdirs[subdir]: continue
         print "Traversing %s..." % subdir
         cmake = CMakeFileEditor(os.path.join(subdir, 'CMakeLists.txt'))
         filenames = cmake.find_filenames_match(self._info['pattern'])
         yes = self._info['yes']
         for fname in filenames:
             file_disabled = False
             if not yes:
                 ans = raw_input("Really disable %s? [Y/n/a/q]: " % fname).lower().strip()
                 if ans == 'a':
                     yes = True
                 if ans == 'q':
                     sys.exit(0)
                 if ans == 'n':
                     continue
             for special_treatment in special_treatments:
                 if special_treatment[0] == subdir and re.match(special_treatment[1], fname):
                     file_disabled = special_treatment[2](cmake, fname)
             if not file_disabled:
                 cmake.disable_file(fname)
         cmake.write()
     print "Careful: gr_modtool disable does not resolve dependencies."
    def run(self):
        """ Go, go, go! """
        def _handle_py_qa(cmake, fname):
            """ Do stuff for py qa """
            cmake.comment_out_lines('GR_ADD_TEST.*' + fname)
            self.scm.mark_file_updated(cmake.filename)
            return True

        def _handle_py_mod(cmake, fname):
            """ Do stuff for py extra files """
            try:
                initfile = open(self._file['pyinit']).read()
            except IOError:
                print "Could not edit __init__.py, that might be a problem."
                return False
            pymodname = os.path.splitext(fname)[0]
            initfile = re.sub(r'((from|import)\s+\b' + pymodname + r'\b)',
                              r'#\1', initfile)
            open(self._file['pyinit'], 'w').write(initfile)
            self.scm.mark_file_updated(self._file['pyinit'])
            return False

        def _handle_cc_qa(cmake, fname):
            """ Do stuff for cc qa """
            if self._info['version'] == '37':
                cmake.comment_out_lines('\$\{CMAKE_CURRENT_SOURCE_DIR\}/' +
                                        fname)
                fname_base = os.path.splitext(fname)[0]
                ed = CMakeFileEditor(
                    self._file['qalib'])  # Abusing the CMakeFileEditor...
                ed.comment_out_lines('#include\s+"%s.h"' % fname_base,
                                     comment_str='//')
                ed.comment_out_lines('%s::suite\(\)' % fname_base,
                                     comment_str='//')
                ed.write()
                self.scm.mark_file_updated(self._file['qalib'])
            elif self._info['version'] == '36':
                cmake.comment_out_lines('add_executable.*' + fname)
                cmake.comment_out_lines('target_link_libraries.*' +
                                        os.path.splitext(fname)[0])
                cmake.comment_out_lines('GR_ADD_TEST.*' +
                                        os.path.splitext(fname)[0])
            self.scm.mark_file_updated(cmake.filename)
            return True

        def _handle_h_swig(cmake, fname):
            """ Comment out include files from the SWIG file,
            as well as the block magic """
            swigfile = open(self._file['swig']).read()
            (swigfile, nsubs) = re.subn(
                '(.include\s+"(%s/)?%s")' % (self._info['modname'], fname),
                r'//\1', swigfile)
            if nsubs > 0:
                print "Changing %s..." % self._file['swig']
            if nsubs > 1:  # Need to find a single BLOCK_MAGIC
                blockname = os.path.splitext(fname[len(self._info['modname']) +
                                                   1:])[0]
                if self._info['version'] == '37':
                    blockname = os.path.splitext(fname)[0]
                (swigfile,
                 nsubs) = re.subn('(GR_SWIG_BLOCK_MAGIC2?.+%s.+;)' % blockname,
                                  r'//\1', swigfile)
                if nsubs > 1:
                    print "Hm, changed more then expected while editing %s." % self._file[
                        'swig']
            open(self._file['swig'], 'w').write(swigfile)
            self.scm.mark_file_updated(self._file['swig'])
            return False

        def _handle_i_swig(cmake, fname):
            """ Comment out include files from the SWIG file,
            as well as the block magic """
            swigfile = open(self._file['swig']).read()
            blockname = os.path.splitext(fname[len(self._info['modname']) +
                                               1:])[0]
            if self._info['version'] == '37':
                blockname = os.path.splitext(fname)[0]
            swigfile = re.sub('(%include\s+"' + fname + '")', r'//\1',
                              swigfile)
            print "Changing %s..." % self._file['swig']
            swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC2?.+' + blockname + '.+;)',
                              r'//\1', swigfile)
            open(self._file['swig'], 'w').write(swigfile)
            self.scm.mark_file_updated(self._file['swig'])
            return False

        # List of special rules: 0: subdir, 1: filename re match, 2: callback
        special_treatments = (('python', 'qa.+py$', _handle_py_qa),
                              ('python', '^(?!qa).+py$', _handle_py_mod),
                              ('lib', 'qa.+\.cc$', _handle_cc_qa),
                              ('include/%s' % self._info['modname'], '.+\.h$',
                               _handle_h_swig), ('include', '.+\.h$',
                                                 _handle_h_swig),
                              ('swig', '.+\.i$', _handle_i_swig))
        for subdir in self._subdirs:
            if self._skip_subdirs[subdir]: continue
            if self._info['version'] == '37' and subdir == 'include':
                subdir = 'include/%s' % self._info['modname']
            try:
                cmake = CMakeFileEditor(os.path.join(subdir, 'CMakeLists.txt'))
            except IOError:
                continue
            print "Traversing %s..." % subdir
            filenames = cmake.find_filenames_match(self._info['pattern'])
            yes = self._info['yes']
            for fname in filenames:
                file_disabled = False
                if not yes:
                    ans = raw_input("Really disable %s? [Y/n/a/q]: " %
                                    fname).lower().strip()
                    if ans == 'a':
                        yes = True
                    if ans == 'q':
                        sys.exit(0)
                    if ans == 'n':
                        continue
                for special_treatment in special_treatments:
                    if special_treatment[0] == subdir and re.match(
                            special_treatment[1], fname):
                        file_disabled = special_treatment[2](cmake, fname)
                if not file_disabled:
                    cmake.disable_file(fname)
            cmake.write()
            self.scm.mark_files_updated((os.path.join(subdir,
                                                      'CMakeLists.txt'), ))
        print "Careful: 'gr_modtool disable' does not resolve dependencies."
Example #18
0
 def _run_lib(self):
     """ Do everything that needs doing in the subdir 'lib' and 'include'.
     - add .cc and .h files
     - include them into CMakeLists.txt
     - check if C++ QA code is req'd
     - if yes, create qa_*.{cc,h} and add them to CMakeLists.txt
     """
     def _add_qa():
         " Add C++ QA files for 3.7 API "
         fname_qa_h  = 'qa_%s.h'  % self._info['blockname']
         fname_qa_cc = 'qa_%s.cc' % self._info['blockname']
         self._write_tpl('qa_cpp', 'lib', fname_qa_cc)
         self._write_tpl('qa_h',   'lib', fname_qa_h)
         if not self.options.skip_cmakefiles:
             try:
                 append_re_line_sequence(self._file['cmlib'],
                                         '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'],
                                         '    ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname'])
                 append_re_line_sequence(self._file['qalib'],
                                         '#include.*\n',
                                         '#include "%s"' % fname_qa_h)
                 append_re_line_sequence(self._file['qalib'],
                                         '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)',
                                         '  s->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'],
                                                                                    self._info['blockname'])
                                         )
             except IOError:
                 print "Can't add C++ QA files."
     def _add_qa36():
         " Add C++ QA files for pre-3.7 API (not autotools) "
         fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
         self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
         if not self.options.skip_cmakefiles:
             open(self._file['cmlib'], 'a').write(
                     str(
                         Cheetah.Template.Template(
                             Templates['qa_cmakeentry36'],
                             searchList={'basename': os.path.splitext(fname_qa_cc)[0],
                                         'filename': fname_qa_cc,
                                         'modname': self._info['modname']
                                        }
                         )
                      )
             )
             ed = CMakeFileEditor(self._file['cmlib'])
             ed.remove_double_newlines()
             ed.write()
     fname_cc = None
     fname_h  = None
     if self._info['version']  == '37':
         fname_h  = self._info['blockname'] + '.h'
         fname_cc = self._info['blockname'] + '.cc'
         if self._info['blocktype'] in ('source', 'sink', 'sync', 'decimator',
                                        'interpolator', 'general', 'hier', 'tagged_stream'):
             fname_cc = self._info['blockname'] + '_impl.cc'
             self._write_tpl('block_impl_h',   'lib', self._info['blockname'] + '_impl.h')
         self._write_tpl('block_impl_cpp', 'lib', fname_cc)
         self._write_tpl('block_def_h',    self._info['includedir'], fname_h)
     else: # Pre-3.7 or autotools
         fname_h  = self._info['fullblockname'] + '.h'
         fname_cc = self._info['fullblockname'] + '.cc'
         self._write_tpl('block_h36',   self._info['includedir'], fname_h)
         self._write_tpl('block_cpp36', 'lib',                    fname_cc)
     if not self.options.skip_cmakefiles:
         ed = CMakeFileEditor(self._file['cmlib'])
         if not ed.append_value('list', fname_cc, to_ignore_start='APPEND %s_sources' % self._info['modname']):
             ed.append_value('add_library', fname_cc)
         ed.write()
         ed = CMakeFileEditor(self._file['cminclude'])
         ed.append_value('install', fname_h, to_ignore_end='DESTINATION[^()]+')
         ed.write()
     if self._add_cc_qa:
         if self._info['version'] == '37':
             _add_qa()
         elif self._info['version'] == '36':
             _add_qa36()
         elif self._info['version'] == 'autofoo':
             print "Warning: C++ QA files not supported for autotools."
Example #19
0
    def run(self):
        """ Go, go, go! """

        def _handle_py_qa(cmake, fname):
            """ Do stuff for py qa """
            cmake.comment_out_lines("GR_ADD_TEST.*" + fname)
            self.scm.mark_file_updated(cmake.filename)
            return True

        def _handle_py_mod(cmake, fname):
            """ Do stuff for py extra files """
            try:
                initfile = open(self._file["pyinit"]).read()
            except IOError:
                print "Could not edit __init__.py, that might be a problem."
                return False
            pymodname = os.path.splitext(fname)[0]
            initfile = re.sub(r"((from|import)\s+\b" + pymodname + r"\b)", r"#\1", initfile)
            open(self._file["pyinit"], "w").write(initfile)
            self.scm.mark_file_updated(self._file["pyinit"])
            return False

        def _handle_cc_qa(cmake, fname):
            """ Do stuff for cc qa """
            if self._info["version"] == "37":
                cmake.comment_out_lines("\$\{CMAKE_CURRENT_SOURCE_DIR\}/" + fname)
                fname_base = os.path.splitext(fname)[0]
                ed = CMakeFileEditor(self._file["qalib"])  # Abusing the CMakeFileEditor...
                ed.comment_out_lines('#include\s+"%s.h"' % fname_base, comment_str="//")
                ed.comment_out_lines("%s::suite\(\)" % fname_base, comment_str="//")
                ed.write()
                self.scm.mark_file_updated(self._file["qalib"])
            elif self._info["version"] == "36":
                cmake.comment_out_lines("add_executable.*" + fname)
                cmake.comment_out_lines("target_link_libraries.*" + os.path.splitext(fname)[0])
                cmake.comment_out_lines("GR_ADD_TEST.*" + os.path.splitext(fname)[0])
            self.scm.mark_file_updated(cmake.filename)
            return True

        def _handle_h_swig(cmake, fname):
            """ Comment out include files from the SWIG file,
            as well as the block magic """
            swigfile = open(self._file["swig"]).read()
            (swigfile, nsubs) = re.subn('(.include\s+"(%s/)?%s")' % (self._info["modname"], fname), r"//\1", swigfile)
            if nsubs > 0:
                print "Changing %s..." % self._file["swig"]
            if nsubs > 1:  # Need to find a single BLOCK_MAGIC
                blockname = os.path.splitext(fname[len(self._info["modname"]) + 1 :])[0]
                if self._info["version"] == "37":
                    blockname = os.path.splitext(fname)[0]
                (swigfile, nsubs) = re.subn("(GR_SWIG_BLOCK_MAGIC2?.+%s.+;)" % blockname, r"//\1", swigfile)
                if nsubs > 1:
                    print "Hm, changed more then expected while editing %s." % self._file["swig"]
            open(self._file["swig"], "w").write(swigfile)
            self.scm.mark_file_updated(self._file["swig"])
            return False

        def _handle_i_swig(cmake, fname):
            """ Comment out include files from the SWIG file,
            as well as the block magic """
            swigfile = open(self._file["swig"]).read()
            blockname = os.path.splitext(fname[len(self._info["modname"]) + 1 :])[0]
            if self._info["version"] == "37":
                blockname = os.path.splitext(fname)[0]
            swigfile = re.sub('(%include\s+"' + fname + '")', r"//\1", swigfile)
            print "Changing %s..." % self._file["swig"]
            swigfile = re.sub("(GR_SWIG_BLOCK_MAGIC2?.+" + blockname + ".+;)", r"//\1", swigfile)
            open(self._file["swig"], "w").write(swigfile)
            self.scm.mark_file_updated(self._file["swig"])
            return False

        # List of special rules: 0: subdir, 1: filename re match, 2: callback
        special_treatments = (
            ("python", "qa.+py$", _handle_py_qa),
            ("python", "^(?!qa).+py$", _handle_py_mod),
            ("lib", "qa.+\.cc$", _handle_cc_qa),
            ("include/%s" % self._info["modname"], ".+\.h$", _handle_h_swig),
            ("include", ".+\.h$", _handle_h_swig),
            ("swig", ".+\.i$", _handle_i_swig),
        )
        for subdir in self._subdirs:
            if self._skip_subdirs[subdir]:
                continue
            if self._info["version"] == "37" and subdir == "include":
                subdir = "include/%s" % self._info["modname"]
            try:
                cmake = CMakeFileEditor(os.path.join(subdir, "CMakeLists.txt"))
            except IOError:
                continue
            print "Traversing %s..." % subdir
            filenames = cmake.find_filenames_match(self._info["pattern"])
            yes = self._info["yes"]
            for fname in filenames:
                file_disabled = False
                if not yes:
                    ans = raw_input("Really disable %s? [Y/n/a/q]: " % fname).lower().strip()
                    if ans == "a":
                        yes = True
                    if ans == "q":
                        sys.exit(0)
                    if ans == "n":
                        continue
                for special_treatment in special_treatments:
                    if special_treatment[0] == subdir and re.match(special_treatment[1], fname):
                        file_disabled = special_treatment[2](cmake, fname)
                if not file_disabled:
                    cmake.disable_file(fname)
            cmake.write()
            self.scm.mark_files_updated((os.path.join(subdir, "CMakeLists.txt"),))
        print "Careful: 'gr_modtool disable' does not resolve dependencies."
Example #20
0
 def run(self):
     """ Go, go, go! """
     def _handle_py_qa(cmake, fname):
         """ Do stuff for py qa """
         cmake.comment_out_lines('GR_ADD_TEST.*'+fname)
         return True
     def _handle_py_mod(cmake, fname):
         """ Do stuff for py extra files """
         try:
             initfile = open(self._file['pyinit']).read()
         except IOError:
             print "Could not edit __init__.py, that might be a problem."
             return False
         pymodname = os.path.splitext(fname)[0]
         initfile = re.sub(r'((from|import)\s+\b'+pymodname+r'\b)', r'#\1', initfile)
         open(self._file['pyinit'], 'w').write(initfile)
         return False
     def _handle_cc_qa(cmake, fname):
         """ Do stuff for cc qa """
         if self._info['version'] == '37':
             cmake.comment_out_lines('\$\{CMAKE_CURRENT_SOURCE_DIR\}/'+fname)
             fname_base = os.path.splitext(fname)[0]
             ed = CMakeFileEditor(self._file['qalib']) # Abusing the CMakeFileEditor...
             ed.comment_out_lines('#include\s+"%s.h"' % fname_base, comment_str='//')
             ed.comment_out_lines('%s::suite\(\)' % fname_base, comment_str='//')
             ed.write()
         elif self._info['version'] == '36':
             cmake.comment_out_lines('add_executable.*'+fname)
             cmake.comment_out_lines('target_link_libraries.*'+os.path.splitext(fname)[0])
             cmake.comment_out_lines('GR_ADD_TEST.*'+os.path.splitext(fname)[0])
         return True
     def _handle_h_swig(cmake, fname):
         """ Comment out include files from the SWIG file,
         as well as the block magic """
         swigfile = open(self._file['swig']).read()
         (swigfile, nsubs) = re.subn('(.include\s+"(%s/)?%s")' % (
                                     self._info['modname'], fname),
                                     r'//\1', swigfile)
         if nsubs > 0:
             print "Changing %s..." % self._file['swig']
         if nsubs > 1: # Need to find a single BLOCK_MAGIC
             blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0]
             if self._info['version'] == '37':
                 blockname = os.path.splitext(fname)[0]
             (swigfile, nsubs) = re.subn('(GR_SWIG_BLOCK_MAGIC2?.+%s.+;)' % blockname, r'//\1', swigfile)
             if nsubs > 1:
                 print "Hm, changed more then expected while editing %s." % self._file['swig']
         open(self._file['swig'], 'w').write(swigfile)
         return False
     def _handle_i_swig(cmake, fname):
         """ Comment out include files from the SWIG file,
         as well as the block magic """
         swigfile = open(self._file['swig']).read()
         blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0]
         if self._info['version'] == '37':
             blockname = os.path.splitext(fname)[0]
         swigfile = re.sub('(%include\s+"'+fname+'")', r'//\1', swigfile)
         print "Changing %s..." % self._file['swig']
         swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC2?.+'+blockname+'.+;)', r'//\1', swigfile)
         open(self._file['swig'], 'w').write(swigfile)
         return False
     # List of special rules: 0: subdir, 1: filename re match, 2: callback
     special_treatments = (
             ('python', 'qa.+py$', _handle_py_qa),
             ('python', '^(?!qa).+py$', _handle_py_mod),
             ('lib', 'qa.+\.cc$', _handle_cc_qa),
             ('include/%s' % self._info['modname'], '.+\.h$', _handle_h_swig),
             ('include', '.+\.h$', _handle_h_swig),
             ('swig', '.+\.i$', _handle_i_swig)
     )
     for subdir in self._subdirs:
         if self._skip_subdirs[subdir]: continue
         if self._info['version'] == '37' and subdir == 'include':
             subdir = 'include/%s' % self._info['modname']
         try:
             cmake = CMakeFileEditor(os.path.join(subdir, 'CMakeLists.txt'))
         except IOError:
             continue
         print "Traversing %s..." % subdir
         filenames = cmake.find_filenames_match(self._info['pattern'])
         yes = self._info['yes']
         for fname in filenames:
             file_disabled = False
             if not yes:
                 ans = raw_input("Really disable %s? [Y/n/a/q]: " % fname).lower().strip()
                 if ans == 'a':
                     yes = True
                 if ans == 'q':
                     sys.exit(0)
                 if ans == 'n':
                     continue
             for special_treatment in special_treatments:
                 if special_treatment[0] == subdir and re.match(special_treatment[1], fname):
                     file_disabled = special_treatment[2](cmake, fname)
             if not file_disabled:
                 cmake.disable_file(fname)
         cmake.write()
     print "Careful: 'gr_modtool disable' does not resolve dependencies."
Example #21
0
 def _run_lib(self):
     """ Do everything that needs doing in the subdir 'lib' and 'include'.
     - add .cc and .h files
     - include them into CMakeLists.txt
     - check if C++ QA code is req'd
     - if yes, create qa_*.{cc,h} and add them to CMakeLists.txt
     """
     def _add_qa():
         " Add C++ QA files for 3.7 API "
         fname_qa_h  = 'qa_%s.h'  % self._info['blockname']
         fname_qa_cc = 'qa_%s.cc' % self._info['blockname']
         self._write_tpl('qa_cpp', 'lib', fname_qa_cc)
         self._write_tpl('qa_h',   'lib', fname_qa_h)
         if not self._skip_cmakefiles:
             try:
                 append_re_line_sequence(self._file['cmlib'],
                                         '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'],
                                         '    ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname'])
                 append_re_line_sequence(self._file['qalib'],
                                         '#include.*\n',
                                         '#include "%s"' % fname_qa_h)
                 append_re_line_sequence(self._file['qalib'],
                                         '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)',
                                         '  s->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'],
                                                                                    self._info['blockname'])
                                         )
                 self.scm.mark_files_updated((self._file['qalib'],))
             except IOError:
                 print("Can't add C++ QA files.")
     def _add_qa36():
         " Add C++ QA files for pre-3.7 API (not autotools) "
         fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
         self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
         if not self._skip_cmakefiles:
             open(self._file['cmlib'], 'a').write(
                 str(
                     Cheetah.Template.Template(
                         Templates['qa_cmakeentry36'],
                         searchList={'basename': os.path.splitext(fname_qa_cc)[0],
                                     'upperbasename': os.path.splitext(fname_qa_cc)[0].upper(),
                                     'filename': fname_qa_cc,
                                     'modname': self._info['modname']
                                    }
                     )
                  )
             )
             ed = CMakeFileEditor(self._file['cmlib'])
             ed.remove_double_newlines()
             ed.write()
     fname_cc = None
     fname_h  = None
     if self._info['version']  == '37':
         #RFNoC block Interface
         if(self._skip_block_interface == False):
             fname_h  = self._info['blockname'] + '.h'
             fname_cc = self._info['blockname'] + '.cc'
             fname_cc = self._info['blockname'] + '_impl.cc'
             self._write_tpl('block_impl_h',   'lib', self._info['blockname'] + '_impl.h')
             self._write_tpl('block_impl_cpp', 'lib', fname_cc)
             self._write_tpl('block_def_h',    self._info['includedir'], fname_h)
             if not self._skip_cmakefiles:
                 ed = CMakeFileEditor(self._file['cmlib'])
                 cmake_list_var = '[a-z]*_?' + self._info['modname'] + '_sources'
                 if not ed.append_value('list', fname_cc, to_ignore_start='APPEND ' + cmake_list_var):
                     ed.append_value('add_library', fname_cc)
                 ed.write()
                 ed = CMakeFileEditor(self._file['cminclude'])
                 ed.append_value('install', fname_h, to_ignore_end='DESTINATION[^()]+')
                 ed.write()
                 self.scm.mark_files_updated((self._file['cminclude'], self._file['cmlib']))
         #RFNoC block Controllers
         if (self._skip_block_ctrl == False):
             fname_ctrl_cpp = self._info['blockname'] + '_block_ctrl_impl.cpp'
             fname_ctrl_hpp = self._info['blockname'] + '_block_ctrl.hpp'
             self._write_tpl('block_ctrl_hpp',    self._info['includedir'], fname_ctrl_hpp)
             self._write_tpl('block_ctrl_cpp', 'lib', fname_ctrl_cpp)
             if not self._skip_cmakefiles:
                 ed = CMakeFileEditor(self._file['cmlib'])
                 cmake_list_var = '[a-z]*_?' + self._info['modname'] + '_sources'
                 ed.append_value('list', fname_ctrl_cpp, to_ignore_start='APPEND ' + cmake_list_var)
                 ed.write()
                 ed = CMakeFileEditor(self._file['cminclude'])
                 ed.append_value('install', fname_ctrl_hpp, to_ignore_end='DESTINATION[^()]+')
                 ed.write()
                 self.scm.mark_files_updated((self._file['cminclude'], self._file['cmlib']))
     else: # Pre-3.7 or autotools
         fname_h  = self._info['fullblockname'] + '.h'
         fname_cc = self._info['fullblockname'] + '.cc'
         self._write_tpl('block_h36',   self._info['includedir'], fname_h)
         self._write_tpl('block_cpp36', 'lib',                    fname_cc)
     if self._add_cc_qa:
         if self._info['version'] == '37':
             _add_qa()
         elif self._info['version'] == '36':
             _add_qa36()
         elif self._info['version'] == 'autofoo':
             print("Warning: C++ QA files not supported for autotools.")
Example #22
0
    def _run_lib(self):
        """ Do everything that needs doing in the subdir 'lib' and 'include'.
        - add .cc and .h files
        - include them into CMakeLists.txt
        - check if C++ QA code is req'd
        - if yes, create qa_*.{cc,h} and add them to CMakeLists.txt
        """
        print "Traversing lib..."
        fname_h = self._info['fullblockname'] + '.h'
        fname_cc = self._info['fullblockname'] + '.cc'
        if self._info['blocktype'] in ('source', 'sink', 'sync', 'decimator',
                                       'interpolator', 'general', 'hiercpp'):
            self._write_tpl('block_h', 'include', fname_h)
            self._write_tpl('block_cpp', 'lib', fname_cc)
        elif self._info['blocktype'] == 'impl':
            self._write_tpl('impl_h', 'include', fname_h)
            self._write_tpl('impl_cpp', 'lib', fname_cc)
        if not self.options.skip_cmakefiles:
            ed = CMakeFileEditor('lib/CMakeLists.txt')
            ed.append_value('add_library', fname_cc)
            ed.write()
            ed = CMakeFileEditor('include/CMakeLists.txt', '\n    ')
            ed.append_value('install', fname_h, 'DESTINATION[^()]+')
            ed.write()

        if not self._add_cc_qa:
            return
        fname_qa_cc = 'qa_%s' % fname_cc
        self._write_tpl('qa_cpp', 'lib', fname_qa_cc)
        if not self.options.skip_cmakefiles:
            open('lib/CMakeLists.txt', 'a').write(Template.substitute(Templates['qa_cmakeentry'],
                                          {'basename': os.path.splitext(fname_qa_cc)[0],
                                           'filename': fname_qa_cc,
                                           'modname': self._info['modname']}))
            ed = CMakeFileEditor('lib/CMakeLists.txt')
            ed.remove_double_newlines()
            ed.write()