buildsystem.py 3.85 KB
Newer Older
Jonny Lamb's avatar
Jonny Lamb committed
1
2
3
4
# -*- coding: utf-8 -*-
#
#   buildsystem.py — buildsystem plugin
#
Arno Töll's avatar
Arno Töll committed
5
#   This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
Jonny Lamb's avatar
Jonny Lamb committed
6
#
Jonny Lamb's avatar
Jonny Lamb committed
7
#   Copyright © 2008 Jonny Lamb <jonny@debian.org>
8
#   Copyright © 2010 Jan Dittberner <jandd@debian.org>
9
#   Copyright © 2012 Nicolas Dandrimont <nicolas.dandrimont@crans.org>
10
#   Copyright © 2012 Clément Schreiner <clement@mux.me>
Jonny Lamb's avatar
Jonny Lamb committed
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
#
#   Permission is hereby granted, free of charge, to any person
#   obtaining a copy of this software and associated documentation
#   files (the "Software"), to deal in the Software without
#   restriction, including without limitation the rights to use,
#   copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following
#   conditions:
#
#   The above copyright notice and this permission notice shall be
#   included in all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#   OTHER DEALINGS IN THE SOFTWARE.

"""
Holds the buildsystem plugin.
"""

__author__ = 'Jonny Lamb'
38
39
40
41
__copyright__ = ', '.join([
        'Copyright © 2008 Jonny Lamb',
        'Copyright © 2010 Jan Dittberner',
        'Copyright © 2012 Nicolas Dandrimont',
42
        'Copyright © 2012 Clément Schreiner',
43
        ])
Jonny Lamb's avatar
Jonny Lamb committed
44
45
__license__ = 'MIT'

46
47
48
from debexpo.lib import constants
from debexpo.plugins.api import *

Jonny Lamb's avatar
Jonny Lamb committed
49
import logging
50
51
import os

52
from debian import deb822
Jonny Lamb's avatar
Jonny Lamb committed
53
54
55

log = logging.getLogger(__name__)

56
57
58
59
60
@test_result
class BuildsystemTest(PluginResult):
    """
    Result of the 'buildsystem' plugin.
    """
61

62
63
64
    @property
    def known(self):
        return self['buildsystem'] != 'unknown'
65

66
67
68
69
70
71
72
73
    def __str__(self):
        if self.known:
            msg = 'Package uses %s' % self['buildsystem']
        else:
            msg = 'Unknown'
        return 'Build system: %s' % msg

class BuildSystemPlugin(QAPlugin):
Jonny Lamb's avatar
Jonny Lamb committed
74

75
    @importercmd
Jonny Lamb's avatar
Jonny Lamb committed
76
77
78
79
    def test_build_system(self):
        """
        Finds the build system of the package.
        """
80
        log.debug("Finding the package's build system")
Jonny Lamb's avatar
Jonny Lamb committed
81

82
83
84
85
86
        log.debug('Opening dsc file in %s' % os.getcwd())
        dsc_path = os.path.join(self.changes.get_pool_path(),
                                self.changes.get_dsc())
        with open(dsc_path, 'r') as dsc_file:
            dsc = deb822.Dsc(dsc_file)
Jonny Lamb's avatar
Jonny Lamb committed
87

88
89
        build_depends = dsc.get('Build-Depends', '')

90
91
        result = self.new_test_result()

92
        if 'cdbs' in build_depends:
93
94
            result['buildsystem'] = 'cdbs'

95
        elif 'debhelper' in build_depends:
96
            result['buildsystem'] = 'debhelper'
97
98

            # Retrieve the debhelper compat level
99
100
101
102
103
104
105
106
            if hasattr(self, 'tempdir'):
                compatpath = os.path.join(self.tempdir, "extracted/debian/compat")
                try:
                    with open(compatpath, "rb") as f:
                        compat_level = int(f.read().strip())
                except IOError:
                    compat_level = 'unknown'
            else:
107
                compat_level = 'unknown'
108

109
            result['compat_level'] = compat_level
110
111
112

            # Warn on old compatibility levels
            if compat_level is None or compat_level <= 4:
113
                result['severity'] = constants.PLUGIN_SEVERITY_WARNING
Jonny Lamb's avatar
Jonny Lamb committed
114
        else:
115
116
117
            result['buildsystem'] = 'unknown'
            result['severity'] = constants.PLUGIN_SEVERITY_WARNING

118
plugin = BuildSystemPlugin
119
120
121
models = [
    BuildsystemTest,
    ]