Update drivers
[vuplus_openembedded] / classes / sanity.bbclass
1 #
2 # Sanity check the users setup for common misconfigurations
3 #
4
5 def raise_sanity_error(msg):
6         import bb
7         bb.fatal(""" Openembedded's config sanity checker detected a potential misconfiguration.
8         Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
9         Following is the list of potential problems / advisories:
10         
11         %s""" % msg)
12
13 def check_conf_exists(fn, data):
14         bbpath = []
15         fn = bb.data.expand(fn, data)
16         vbbpath = bb.data.getVar("BBPATH", data)
17         if vbbpath:
18                 bbpath += vbbpath.split(":")
19         for p in bbpath:
20                 currname = os.path.join(bb.data.expand(p, data), fn)
21                 if os.access(currname, os.R_OK):
22                         return True
23         return False
24
25 def check_sanity(e):
26         from bb import note, error, data, __version__
27
28         try:
29                 from distutils.version import LooseVersion
30         except ImportError:
31                 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
32         import commands
33
34         # Check the bitbake version meets minimum requirements
35         minversion = data.getVar('BB_MIN_VERSION', e.data , True)
36         if not minversion:
37                 # Hack: BB_MIN_VERSION hasn't been parsed yet so return 
38                 # and wait for the next call
39                 print "Foo %s" % minversion
40                 return
41
42         if 0 == os.getuid():
43                 raise_sanity_error("Do not use Bitbake as root.")
44
45         messages = ""
46
47         if (LooseVersion(__version__) < LooseVersion(minversion)):
48                 messages = messages + 'Bitbake version %s is required and version %s was found\n' % (minversion, __version__)
49
50         # Check TARGET_ARCH is set
51         if data.getVar('TARGET_ARCH', e.data, True) == 'INVALID':
52                 messages = messages + 'Please set TARGET_ARCH directly, or choose a MACHINE or DISTRO that does so.\n'
53         
54         # Check TARGET_OS is set
55         if data.getVar('TARGET_OS', e.data, True) == 'INVALID':
56                 messages = messages + 'Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.\n'
57
58         assume_provided = data.getVar('ASSUME_PROVIDED', e.data , True).split()
59         # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf
60         if "diffstat-native" not in assume_provided:
61                 messages = messages + 'Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf\n'
62         
63         # Check that the MACHINE is valid, if it is set
64         if data.getVar('MACHINE', e.data, True):
65                 if not check_conf_exists("conf/machine/${MACHINE}.conf", e.data):
66                         messages = messages + 'Please set a valid MACHINE in your local.conf\n'
67         
68         # Check that the DISTRO is valid
69         # need to take into account DISTRO renaming DISTRO
70         if not ( check_conf_exists("conf/distro/${DISTRO}.conf", e.data) or check_conf_exists("conf/distro/include/${DISTRO}.inc", e.data) ):
71                 messages = messages + "DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % data.getVar("DISTRO", e.data, True )
72
73         missing = ""
74
75         if not check_app_exists("${MAKE}", e.data):
76                 missing = missing + "GNU make,"
77
78         if not check_app_exists('${BUILD_PREFIX}gcc', e.data):
79                 missing = missing + "C Compiler (${BUILD_PREFIX}gcc),"
80
81         if not check_app_exists('${BUILD_PREFIX}g++', e.data):
82                 missing = missing + "C++ Compiler (${BUILD_PREFIX}g++),"
83
84         required_utilities = "patch help2man diffstat texi2html makeinfo cvs svn bzip2 tar gzip gawk md5sum sshpass"
85
86         if data.getVar('TARGET_ARCH', e.data, True) == "arm":
87                 # qemu-native needs gcc 3.x
88                 if "qemu-native" not in assume_provided and "gcc3-native" in assume_provided:
89                         gcc_version = commands.getoutput("${BUILD_PREFIX}gcc --version | head -n 1 | cut -f 3 -d ' '")
90
91                         if not check_gcc3(e.data) and gcc_version[0] != '3':
92                                 messages = messages + "gcc3-native was in ASSUME_PROVIDED but the gcc-3.x binary can't be found in PATH"
93                                 missing = missing + "gcc-3.x (needed for qemu-native),"
94
95                 if "qemu-native" in assume_provided:
96                         if not check_app_exists("qemu-arm", e.data):
97                                 messages = messages + "qemu-native was in ASSUME_PROVIDED but the QEMU binaries (qemu-arm) can't be found in PATH"
98
99                 try:
100                         if os.path.exists("/proc/sys/vm/mmap_min_addr"):
101                                 f = file("/proc/sys/vm/mmap_min_addr", "r")
102                                 if (f.read().strip() != "0"):
103                                         messages = messages + "/proc/sys/vm/mmap_min_addr is not 0. This will cause problems with qemu so please fix the value (as root).\n\nTo fix this in later reboots, set vm.mmap_min_addr = 0 in /etc/sysctl.conf.\n"
104                                 f.close()
105                 except:
106                         pass
107
108         for util in required_utilities.split():
109                 if not check_app_exists( util, e.data ):
110                         missing = missing + "%s," % util
111
112         if missing != "":
113                 missing = missing.rstrip(',')
114                 messages = messages + "Please install following missing utilities: %s\n" % missing
115
116         try:
117             if os.path.basename(os.readlink('/bin/sh')) == 'dash':
118                     print "WARNING: Using dash as /bin/sh causes various subtle build problems, please consider using bash instead."
119         except:
120                 pass
121
122         omask = os.umask(022)
123         if omask & 0755:
124                 messages = messages + "Please use a umask which allows a+rx and u+rwx\n"
125         os.umask(omask)
126
127         oes_bb_conf = data.getVar( 'OES_BITBAKE_CONF', e.data, True )
128         if not oes_bb_conf:
129                 messages = messages + 'You do not include OpenEmbeddeds version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n'
130
131         #
132         # Check that TMPDIR hasn't changed location since the last time we were run
133         #
134         tmpdir = data.getVar('TMPDIR', e.data, True)
135         checkfile = os.path.join(tmpdir, "saved_tmpdir")
136         if os.path.exists(checkfile):
137                 f = file(checkfile, "r")
138                 if (f.read().strip() != tmpdir):
139                         messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % tmpdir
140         else:
141                 import bb
142                 bb.mkdirhier(tmpdir)
143                 f = file(checkfile, "w")
144                 f.write(tmpdir)
145         f.close()
146
147         #
148         # Check the 'ABI' of TMPDIR
149         #
150         current_abi = data.getVar('OELAYOUT_ABI', e.data, True)
151         abifile = data.getVar('SANITY_ABIFILE', e.data, True)
152         if os.path.exists(abifile):
153                 f = file(abifile, "r")
154                 abi = f.read().strip()
155                 if not abi.isdigit():
156                         f = file(abifile, "w")
157                         f.write(current_abi)
158                 elif (abi != current_abi):
159                         # Code to convert from one ABI to another could go here if possible.
160                         messages = messages + "Error, TMPDIR has changed ABI (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi)
161         else:
162                 f = file(abifile, "w")
163                 f.write(current_abi)
164         f.close()
165
166         #
167         # Check the Distro PR value didn't change
168         #
169         distro_pr = data.getVar('DISTRO_PR', e.data, True)
170         prfile = data.getVar('SANITY_PRFILE', e.data, True)
171         if os.path.exists(prfile):
172                 f = file(prfile, "r")
173                 pr = f.read().strip()
174                 if (pr != distro_pr):
175                         # Code to convert from one ABI to another could go here if possible.
176                         messages = messages + "Error, DISTRO_PR has changed (%s to %s) which means all packages need to rebuild. Please remove your TMPDIR so this can happen. For autobuilder setups you can avoid this by using a TMPDIR that include DISTRO_PR in the path.\n" % (pr, distro_pr)
177         else:
178                 f = file(prfile, "w")
179                 f.write(distro_pr)
180         f.close()
181
182
183         #
184         # Check there aren't duplicates in PACKAGE_ARCHS
185         #
186         archs = data.getVar('PACKAGE_ARCHS', e.data, True).split()
187         for arch in archs:
188                 if archs.count(arch) != 1:
189                         messages = messages + "Error, Your PACKAGE_ARCHS field contains duplicates. Perhaps you set PACKAGE_EXTRA_ARCHS twice accidently through some tune file?\n"
190                         break
191
192         if messages != "":
193                 raise_sanity_error(messages)
194
195 addhandler check_sanity_eventhandler
196 python check_sanity_eventhandler() {
197     from bb.event import Handled, NotHandled
198     if bb.event.getName(e) == "ConfigParsed":
199         check_sanity(e)
200
201     return NotHandled
202 }