summaryrefslogtreecommitdiff
path: root/parabola_repolint/linter_checks/pkgbuild_validity.py
blob: 99060b9f7c09289e583139e87c85fdc3e733fc9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'''
these are linter checks for PKGBUILD / .pkg.tar.xz / repo.db entry integrity
'''

from parabola_repolint.linter import LinterIssue, LinterCheckBase, LinterCheckType
from parabola_repolint.config import CONFIG


KNOWN_ARCHES = CONFIG.parabola.arches


# pylint: disable=no-self-use
class InvalidPkgbuild(LinterCheckBase):
    '''
  this check tests for syntactical problems with the PKGBUILD file itself,
  basically anything that makepkg would choke on. It reports an issue whenever a
  PKGBUILD file is found in the repo that does not produce a valid output when
  processed with `makepkg --printsrcinfo`.
'''

    name = 'invalid_pkgbuild'
    check_type = LinterCheckType.PKGBUILD

    header = 'invalid PKGBUILDs'

    def check(self, pkgbuild):
        ''' run the check '''
        if not pkgbuild.valid:
            raise LinterIssue(pkgbuild)

    def format(self, issues):
        ''' format the list of found issues '''
        result = []
        for issue in issues:
            result.append('    %s' % issue[0])
        return "\n".join(sorted(result))


# pylint: disable=no-self-use
class UnsupportedArches(LinterCheckBase):
    '''
  this check tests for PKGBUILD files that list archictectures in the `arch`
  array, that are not officially supported by parabola. This includes
  architectures that may have been supported in the past, but have since been
  dropped. The list of supported architectures is configurable in
  `parabola-repolint.conf` under the setting `parabola.arches`. The default
  setting is `('x86_64', 'i686', 'armv7h', 'ppc64le')`, which are, as of this
  writing, the architectures supported by parabola.
'''

    name = 'unsupported_arches'
    check_type = LinterCheckType.PKGBUILD

    header = 'PKGBUILDs with unsupported arches'

    def check(self, pkgbuild):
        ''' run the check '''
        if not pkgbuild.valid:
            return

        unsup = {}

        unsup_base = pkgbuild.arches.difference(KNOWN_ARCHES, ['any'])
        if unsup_base:
            unsup['pkgbase'] = unsup_base

        for arch in pkgbuild.srcinfo:
            for pkgname, pkginfo in pkgbuild.srcinfo[arch].pkginfo.items():
                if 'arch' not in pkginfo:
                    continue
                unsup_pkg = pkginfo['arch'].difference(unsup_base, KNOWN_ARCHES, ['any'])
                if unsup_pkg:
                    if pkgname not in unsup:
                        unsup[pkgname] = set()
                    unsup[pkgname] = unsup[pkgname].union(unsup_pkg)

        if unsup:
            unsup_str = '; '.join(['%s: %s' % (p, ','.join(u)) for p,u in unsup.items()])
            raise LinterIssue(pkgbuild, unsup_str)

    def format(self, issues):
        ''' format the list of found issues '''
        result = []
        for issue in issues:
            result.append('    %s (%s)' % (issue[0], issue[1]))
        return "\n".join(sorted(result))