conf/distro/jlime-donkey.conf : Added parted & Dialog to distro_rdepends
[vuplus_openembedded] / classes / insane.bbclass
1 # BB Class inspired by ebuild.sh
2 #
3 # This class will test files after installation for certain
4 # security issues and other kind of issues.
5 #
6 # Checks we do:
7 #  -Check the ownership and permissions
8 #  -Check the RUNTIME path for the $TMPDIR
9 #  -Check if .la files wrongly point to workdir
10 #  -Check if .pc files wrongly point to workdir
11 #  -Check if packages contains .debug directories  or .so files where they should be in -dev or -dbg
12 #
13
14
15 #
16 # We need to have the scanelf utility as soon as
17 # possible and this is contained within the pax-utils-native
18 #
19
20
21 # We play a special package function
22 inherit package
23 PACKAGE_DEPENDS += "pax-utils-native"
24 PACKAGEFUNCS += " do_package_qa "
25
26 def package_qa_check_rpath(file,name,d):
27     """
28     Check for dangerous RPATHs
29     """
30     import bb, os
31     scanelf = os.path.join(bb.data.getVar('STAGING_BINDIR',d,True),'scanelf')
32     bad_dir = bb.data.getVar('TMPDIR', d, True) + "/work"
33     if not os.path.exists(scanelf):
34         bb.note("Can not check RPATH scanelf not found")
35     if not bad_dir in bb.data.getVar('WORKDIR', d, True):
36         bb.error("This class assumed that WORKDIR is ${TMPDIR}/work... Not doing any check")
37
38     output = os.popen("%s -Byr %s" % (scanelf,file))
39     txt    = output.readline().rsplit()
40     if bad_dir in txt:
41         bb.error("QA Issue package %s contains bad RPATH %s in file %s" % (name, txt, file))
42
43     pass
44
45 def package_qa_check_devdbg(path, name,d):
46     """
47     Check for debug remains inside the binary or
48     non dev packages containing
49     """
50
51     import bb
52     if not "-dev" in name:
53         if path[-3:] == ".so":
54             bb.error("QA Issue: non dev package contains .so: %s" % name)
55
56     if not "-dbg" in name:
57         if '.debug' in path:
58             bb.error("QA Issue: non debug package contains .debug directory: %s" % name)
59
60 def package_qa_check_perm(path,name,d):
61     """
62     Check the permission of files
63     """
64     pass
65
66 def package_qa_check_arch(path,name,d):
67     """
68     Check if archs are compatible
69     """
70     pass
71
72 def package_qa_check_pcla(path,name,d):
73     """
74     .pc and .la files should not point
75     """
76
77 def package_qa_check_staged(path,d):
78     """
79     Check staged la and pc files for sanity
80       -e.g. installed being false
81     """
82     pass
83
84 # Walk over all files in a directory and call func
85 def package_qa_walk(path, funcs, package,d):
86     import os
87     for root, dirs, files in os.walk(path):
88         for file in files:
89             path = os.path.join(root,file)
90             for func in funcs:
91                 func(path, package,d)
92
93
94 def package_qa_check_rdepends(pkg, workdir, d):
95     import bb   
96     if not "-dbg" in pkg and not "task-" in pkg and not "-image" in pkg:
97         # Copied from package_ipk.bbclass
98         # boiler plate to update the data
99         localdata = bb.data.createCopy(d)
100         root = "%s/install/%s" % (workdir, pkg)
101
102         bb.data.setVar('ROOT', '', localdata) 
103         bb.data.setVar('ROOT_%s' % pkg, root, localdata)
104         pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
105         if not pkgname:
106             pkgname = pkg
107         bb.data.setVar('PKG', pkgname, localdata)
108
109         overrides = bb.data.getVar('OVERRIDES', localdata)
110         if not overrides:
111             raise bb.build.FuncFailed('OVERRIDES not defined')
112         overrides = bb.data.expand(overrides, localdata)
113         bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
114
115         bb.data.update_data(localdata)
116
117         # Now check the RDEPENDS
118         rdepends = explode_deps(bb.data.getVar('RDEPENDS', localdata, True) or "")
119
120
121         # Now do the sanity check!!!
122         for rdepend in rdepends:
123             if "-dbg" in rdepend:
124                 bb.error("QA issue, koen give us a better msg!!!")
125
126 # The PACKAGE FUNC to scan each package
127 python do_package_qa () {
128     bb.note("DO PACKAGE QA")
129     workdir = bb.data.getVar('WORKDIR', d, True)
130     packages = bb.data.getVar('PACKAGES',d, True)
131
132     # no packages should be scanned
133     if not packages:
134         return
135
136     for package in packages.split():
137         bb.note("Package: %s" % package)
138         path = "%s/install/%s" % (workdir, package)
139         package_qa_walk(path, [package_qa_check_rpath, package_qa_check_devdbg, package_qa_check_perm, package_qa_check_arch], package, d)
140         package_qa_check_rdepends(package, workdir, d)
141
142 }
143
144
145 # The Staging Func, to check all staging
146 addtask qa_staging after do_populate_staging before do_build
147 python do_qa_staging() {
148     bb.note("Staged!")
149
150     package_qa_check_staged(bb.data.getVar('STAGING_DIR',d,True), d)
151 }