Skip to content
Snippets Groups Projects
Select Git revision
  • fbb5102e2bf8b9392bc287f101ae12df6ba7577e
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

structure_analysis.py

Blame
  • cmake.py 2.50 KiB
    """
    Checking CMake files.
    """
    
    import re
    from .. import pm3_csc
    from . import base
    
    
    class Cmake(base.FileCheck):
        """
        Checking CMake setups/ code.
        """
        def __init__(self, filepath):
            base.FileCheck.__init__(self, filepath)
    
        def CheckClosingStatement(self, line):
            '''
            Check closing statement to carry identifier for the opening one.
            '''
            closers = ['endmacro']
            for close_stmnt in closers:
                fclose_stmnt = r'(?:^|\s)' + close_stmnt + r'\((.*)\)'
                m_stmnt = re.match(fclose_stmnt, line)
                if m_stmnt:
                    stmnt_id = m_stmnt.group(1)
                    if not len(stmnt_id):
                        pm3_csc.FailMsg("Line %d: " % self.current_line+
                                        "No identifier in closing statement. The "+
                                        "call to '%s()' should " % close_stmnt+
                                        "go by the same name as the statement "+
                                        "opening that block. That improves "+
                                        "readability plus future versions of "+
                                        "CMake will complain about this issue, "+
                                        "too", 15)
    
        def CheckWhitespace(self, line):
            '''
            Check that there is no white space between a function call and its
            opening parenthesis.
            '''
            openers = ['if', 'else', 'endif']
            for open_stmnt in openers:
                fopen_stmnt = r'(?:^|\s)' + open_stmnt + r'(\s*)\('
                m_stmnt = re.match(fopen_stmnt, line)
                if m_stmnt:
                    stmnt_ws = m_stmnt.group(1)
                    if len(stmnt_ws):
                        pm3_csc.FailMsg("Line %d: " % self.current_line+
                                        "White space(s) found between "+
                                        "call to '%s' and its " % open_stmnt+
                                        "opening parenthesis. Since in CMake "+
                                        "this is a function/ macro call, "+
                                        "omit the space", 16)
    
        def Check(self, ignore_line_width=False):
            #   for .cmake files: documentation of macros in index.rst
            for line in self.GetLine(ignore_line_width):
                line = line.strip()
                m_line = re.match(r'([^#]*)', line)
                ex_line = m_line.group(1)
                if len(ex_line):
                    self.CheckClosingStatement(ex_line)
                    self.CheckWhitespace(line)
    
    __all__ = ('Cmake', )