Skip to content

Commit

Permalink
SpecCheck: Add new check for openmpi-devel-macros correct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Jan 23, 2024
1 parent dcd771d commit a2de430
Show file tree
Hide file tree
Showing 4 changed files with 513 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rpmlint/checks/SpecCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def re_tag_compile(tag):
python_module_def_regex = re.compile(r'^[^#]*%{\?!python_module:%define python_module()')
python_sitelib_glob_regex = re.compile(r'^[^#]*%{python_site(lib|arch)}/\*\s*$')

# openmpi requirement check
requires_mpi_regex = re.compile(r'^(Build)?Requires\s*:\s*openmpi(-(libs|devel))?\s*$', re.IGNORECASE)
requires_libmpi_regex = re.compile(r'^Requires\s*:\s*openmpi[0-9]+-libs\s*$', re.IGNORECASE)
requires_openmpi_macros_regex = re.compile(r'^BuildRequires\s*:\s*openmpi[0-9]*-macros-devel\s*$', re.IGNORECASE)

UNICODE_NBSP = '\xa0'


Expand Down Expand Up @@ -139,6 +144,8 @@ def _default_state(self):
self.indent_spaces = 0
self.indent_tabs = 0
self.section = {}
self.requires_openmpi_macros = False
self.requires_libmpi = False

self.current_section = 'package'
# None == main package
Expand Down Expand Up @@ -192,6 +199,9 @@ def check_spec(self, pkg):
# And initialize the SpecCheck instance for following checks
self._check_lines(spec_lines)

# check openmi condition
self._check_libmpi(pkg)

# Run checks for whole package
self._check_no_buildroot_tag(pkg, self.buildroot)
self._check_no_s_section(pkg, self.section)
Expand Down Expand Up @@ -283,6 +293,11 @@ def _check_mixed_use_of_space_and_tabs(self, pkg, indent_spaces, indent_tabs):
(indent_spaces, indent_tabs))
pkg.current_linenum = None

def _check_libmpi(self, pkg):
if self.requires_libmpi and not self.requires_openmpi_macros:
message = 'requirement on openmpi-libs without usage of openmpi-macros-devel'
self.output.add_info('W', self.pkg, 'libmpi-req-compat', message)

def check_ifarch_and_not_applied_patches(self, pkg, patches_auto_applied,
patches, applied_patches_ifarch, applied_patches):
"""Check if specfile has a patch applied inside an %ifarch block.
Expand Down Expand Up @@ -693,6 +708,8 @@ def _checkline_package(self, line):

self._checkline_forbidden_controlchars(line)

self._checkline_package_libmpi(line)

def _checkline_changelog(self, line):
if self.current_section == 'changelog':
deptoken = Pkg.has_forbidden_controlchars(line)
Expand Down Expand Up @@ -796,3 +813,25 @@ def _checkline_forbidden_controlchars(self, line):
# https://github.com/rpm-software-management/rpmlint/issues/1067
if Pkg.has_forbidden_controlchars(line):
self.output.add_info('W', self.pkg, 'forbidden-controlchar-found')

def _checkline_package_libmpi(self, line):
"""
Look for openmpi requirement in package
* No BuildRequires/Requires to openmpi|openmpi-libs|openmpi-devel ever
in any package
* If package has a dependency to libmpi.so.40:
* it has to BuildRequire: openmpi[0-9]*-macros-devel
"""

res = requires_mpi_regex.search(line)
if res:
_, post, _all = res.groups()
message = f'openmpi{post} in requirements, use openmpi-macros-devel'
self.output.add_info('W', self.pkg, 'libmpi-req-compat', message)

if requires_openmpi_macros_regex.search(line):
self.requires_openmpi_macros = True

if requires_libmpi_regex.search(line):
self.requires_libmpi = True
Loading

0 comments on commit a2de430

Please sign in to comment.