summaryrefslogtreecommitdiff
path: root/conf/noarch/entropy/packages/packages.server.qa.exec
blob: 7ec8f1adbfc8783ef4feab4708fb3312b7d85034 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/python
#
# Entropy Server QA executable hook.
# This file doesn't strictly need to be a shell script, but just an executable
# file (r-xr-xr-x) and (mandatory) owned by root:root.
# Please rename this file by stripping the .example part
#
# It is used by Entropy Server QA routines to perform package metadata
# validation.
# Metadata is export in environmental variables form, and include:
#
# REPOSITORY_ID = repository identifier
# PKG_ID = package identifier
# PKG_ATOM = package atom
# PKG_NAME = package name
# PKG_VERSION = package version
# PKG_TAG = package version tag
# PKG_DESCRIPTION = package description
# PKG_CATEGORY = package category
# PKG_CHOST = package CHOST
# PKG_CFLAGS = package CFLAGS
# PKG_CXXFLAGS = package CXXFLAGS
# PKG_HOMEPAGE = package homepage
# PKG_LICENSE = package license
# PKG_BRANCH = package license
# PKG_DOWNLOAD = package relative download URL
# PKG_KEYWORDS = package keywords, space separated
# PKG_MD5 = package file md5 hash
# PKG_SLOT = package slot
# PKG_ETPAPI = package Entropy API
# PKG_DATE = package creation date (in unix time)
# PKG_SIZE = package size, in bytes
# PKG_REVISION = package entropy revision
# PKG_DEPS = list (\n separated) of package dependencies and conflicts
# PKG_NEEDED_LIBS = list (\n separated) of SONAMES required by package,
#    including ELF class, so each item will look like this:
#     <soname>|<elfclass>
# PKG_PROVIDED_LIBS = list (\n separated) of SONAMES provided by package,
#    note: elf class and path are also provided,
#    so each item will look like this:
#     <soname>|<path of soname>|<elfclass>
#
# The executable must return 0 for success, 1 for warning, 2 for critical error

import sys
sys.path.insert(0, "/usr/lib/entropy/lib")
import os
import entropy.dep

def write_attention_msg(msg):
    sys.stderr.write("\nATTENTION ATTENTION ATTENTION\n")
    sys.stderr.write(msg + "\n")
    sys.stderr.write("ATTENTION ATTENTION ATTENTION\n\n")

def write_warning_msg(msg):
    sys.stderr.write("\nWARNING WARNING WARNING\n")
    sys.stderr.write(msg + "\n")
    sys.stderr.write("\nWARNING WARNING WARNING\n")

def check_unwanted_deps():
    """
    Check against forbidden dependencies, those we consider meta packages,
    placeholders just to keep Gentoo compatibility, which, if listed as dep in,
    would cause the whole world to be pulled in.
    """
    pkg_deps = os.getenv("PKG_DEPS", "")
    pkg_deps = pkg_deps.split()
    if not pkg_deps:
        return 0

    pkg_atom = os.getenv("PKG_ATOM")
    pkg_keywords = os.getenv("PKG_KEYWORDS")

    # You can only declare key or key:slot
    unwanted_deps = ["app-admin/packagekit", "app-text/poppler",
        "kde-base/kde-l10n", "net-dns/avahi", "net-p2p/transmission",
        "app-crypt/pinentry", "dev-python/pygobject:3", "x11-misc/lightdm"]
    warning_deps = ["media-libs/jpeg",
        "dev-lang/gnat-gcc", "dev-lang/gcc", "x11-drivers/nvidia-drivers",
        "x11-drivers/ati-drivers"]
    func_rc = 0

    pkg_deps_map = dict(
        (entropy.dep.dep_getkey(x), (entropy.dep.dep_getslot(x), x)) \
            for x in pkg_deps if not x.startswith("!"))

    pkg_deps_map = {}
    for pkg_dep in pkg_deps:
        if pkg_dep.startswith("!"):
            continue
        key = entropy.dep.dep_getkey(pkg_dep)
        obj = pkg_deps_map.setdefault(key, [])
        val = entropy.dep.dep_getslot(pkg_dep), pkg_dep
        obj.append(val)

    for unwanted_dep in unwanted_deps:
        unwanted_slot = entropy.dep.dep_getslot(unwanted_dep)
        if unwanted_slot:
            unwanted_dep = entropy.dep.remove_slot(unwanted_dep)

        dep_data_list = pkg_deps_map.get(unwanted_dep)
        if dep_data_list is None:
            continue

        for dep_data in dep_data_list:
            dep_slot, dep = dep_data

            if not unwanted_slot:
                unwanted_slot = dep_slot

            if dep_slot == unwanted_slot:
                write_attention_msg(
                    "%s contains forbidden dependency against %s" % (
                        pkg_atom, dep))
                func_rc = 2

    for warning_dep in warning_deps:

        warning_slot = entropy.dep.dep_getslot(warning_dep)
        if warning_slot:
            warning_dep = entropy.dep.remove_slot(warning_dep)

        dep_data_list = pkg_deps_map.get(warning_dep)
        if dep_data_list is None:
            continue

        for dep_data in dep_data_list:
            dep_slot, dep = dep_data

            if not warning_slot:
                unwanted_slot = dep_slot

            if dep_slot == warning_slot:
                write_attention_msg(
                    "%s contains a weirdo dependency against %s" % (
                        pkg_atom, dep))
                if func_rc == 0:
                    func_rc = 1

    if pkg_keywords is not None:
        keywords = pkg_keywords.split()
        if not keywords or ("**" in keywords and len(keywords) == 1):
            write_attention_msg("%s is masked by default, keywords: %s" % (
                pkg_atom, pkg_keywords))
            if func_rc == 0:
                func_rc = 1

    return func_rc

def warn_perl5_bump():
    """
    Warn in case of bumping dev-lang/perl. Developer should not
    forget about running perl-cleaner.
    """
    pkg_key = "%s/%s" % (os.getenv("PKG_CATEGORY", ""),
                         os.getenv("PKG_NAME", ""))
    pkg_version = os.getenv("PKG_VERSION", "")

    if pkg_key == "dev-lang/perl" and pkg_version.startswith("5"):
        perl_dir = "/usr/lib/perl5/vendor_perl"
        try:
            perl_versions = os.listdir(perl_dir)
        except (OSError, IOError):
            perl_versions = []

        if len(perl_versions) > 1:
            write_warning_msg(
                "Adding dev-lang/perl but you forgot to run perl-cleaner?\n"
                "These are the versions detected in %s:\n"
                "%s" % (perl_dir, ", ".join(perl_versions)))
            return 1

    return 0

def warn_portage_bump():
    """
    Wheneger Portage is bumped, its packages.db.critical entry in build.git
    must be raised.
    """
    pkg_key = "%s/%s" % (os.getenv("PKG_CATEGORY", ""),
                         os.getenv("PKG_NAME", ""))

    if pkg_key == "sys-apps/portage":
        write_warning_msg(
            "So you bumped Portage they told me...\n"
            "Have you raised the portage version in packages.db.critical?\n"
            "It is inside build.git.")
        return 1

    return 0

def warn_sip_bump():
    """
    Wheneger Sip is bumped, we need to manually bump the reverse dependencies.
    """
    pkg_key = "%s/%s" % (os.getenv("PKG_CATEGORY", ""),
                         os.getenv("PKG_NAME", ""))

    if pkg_key == "dev-python/sip":
        write_warning_msg(
            "So you bumped Sip they told me...\n"
            "Have you rebuilt its reverse dependencies?\n"
            "# qfile -e /usr/lib/python2.7/site-packages/PyQt4")
        return 1

    return 0

def warn_binutils_bump():
    """
    Whenever binutils is bumped, we should rebuild packages
    linking explicitly to libbfd-<ver>.so :( sigh.
    """
    pkg_key = "%s/%s" % (os.getenv("PKG_CATEGORY", ""),
                         os.getenv("PKG_NAME", ""))

    if pkg_key == "sys-devel/binutils":
        write_warning_msg(
            "So you bumped binutils they told me...\n"
            "Please, no wait... FUCKING CHECK that packages linking to\n"
            "libbfd-<old_ver>.so have been rebuilt. You can use:\n"
            " # eit query required libbfd-*.so\n")
        return 1

    return 0

def warn_haskell_bump():
    """
    Warn in case of bumping dev-lang/ghc. Developer should not
    forget about running haskell-updater.
    """
    pkg_key = "%s/%s" % (os.getenv("PKG_CATEGORY", ""),
                         os.getenv("PKG_NAME", ""))
    pkg_version = os.getenv("PKG_VERSION", "")

    if pkg_key == "dev-lang/ghc":
        write_warning_msg(
            "Bumping dev-lang/ghc !!!\n"
            "Make sure to run 'haskell-updater' !\n")
        return 1

    return 0

if __name__ == "__main__":

    exit_st = 0
    rc = check_unwanted_deps()
    if rc != 0:
        exit_st = rc

    rc = warn_portage_bump()
    if rc != 0 and rc > exit_st:
        exit_st = rc

    rc = warn_perl5_bump()
    if rc != 0 and rc > exit_st:
        exit_st = rc

    rc = warn_haskell_bump()
    if rc != 0 and rc > exit_st:
        exit_st = rc

    rc = warn_binutils_bump()
    if rc != 0 and rc > exit_st:
        exit_st = rc

    rc = warn_sip_bump()
    if rc != 0 and rc > exit_st:
        exit_st = rc

    # more tests here

    raise SystemExit(exit_st)