forked from openSUSE/rpmlint-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckBuildRoot.py
40 lines (33 loc) · 1.25 KB
/
CheckBuildRoot.py
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
# vim:sw=4:et
#############################################################################
# File : CheckBuildRoot.py
# Package : rpmlint
# Author : Dirk Mueller, Stephan Kulow
# Purpose : Check for files containing $RPM_BUILD_ROOT
#############################################################################
import AbstractCheck
import Config
import Filter
import re
import rpm
import stat
class BuildRootCheck(AbstractCheck.AbstractFilesCheck):
def __init__(self):
AbstractCheck.AbstractFilesCheck.__init__(self, "CheckBuildRoot", ".*")
t = rpm.expandMacro('%buildroot')
for m in ('name', 'version', 'release'):
t = t.replace("%%{%s}" % (m), "[\w\!-\.]{1,20}")
self.build_root_re = re.compile(t)
def check_file(self, pkg, filename):
if filename.startswith('/usr/lib/debug') or pkg.isSource():
return
if not stat.S_ISREG(pkg.files()[filename].mode):
return
if len(pkg.grep(self.build_root_re, filename)):
Filter.printError(pkg, "file-contains-buildroot", filename)
check = BuildRootCheck()
if Config.info:
Filter.addDetails(
'file-contains-buildroot',
"Your file contains traces of $RPM_BUILD_ROOT."
)