Select Git revision
python_shell.cc
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', )