sanity.bbclass: Add ABI version number and checks so we can warn users when the ...
[vuplus_openembedded] / classes / sanity.bbclass
1 #
2 # Sanity check the users setup for common misconfigurations
3 #
4
5 #
6 # SANITY_ABI allows us to notify users when the format of TMPDIR changes in 
7 # an incompatible way. Such changes should usually be detailed in the commit
8 # that breaks the format and have been previously discussed on the mailing list 
9 # with general agreement from the core team.
10 #
11 SANITY_ABI = "0"
12 SANITY_ABIFILE = "${TMPDIR}/abi_version"
13
14 def raise_sanity_error(msg):
15         import bb
16         bb.fatal(""" Openembedded's config sanity checker detected a potential misconfiguration.
17         Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
18         Following is the list of potential problems / advisories:
19         
20         %s""" % msg)
21
22 def check_conf_exists(fn, data):
23         import bb, os
24
25         bbpath = []
26         fn = bb.data.expand(fn, data)
27         vbbpath = bb.data.getVar("BBPATH", data)
28         if vbbpath:
29                 bbpath += vbbpath.split(":")
30         for p in bbpath:
31                 currname = os.path.join(bb.data.expand(p, data), fn)
32                 if os.access(currname, os.R_OK):
33                         return True
34         return False
35
36 def check_sanity(e):
37         from bb import note, error, data, __version__
38         from bb.event import Handled, NotHandled, getName
39         try:
40                 from distutils.version import LooseVersion
41         except ImportError:
42                 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
43         import os, commands
44
45         # Check the bitbake version meets minimum requirements
46         minversion = data.getVar('BB_MIN_VERSION', e.data , True)
47         if not minversion:
48                 # Hack: BB_MIN_VERSION hasn't been parsed yet so return 
49                 # and wait for the next call
50                 print "Foo %s" % minversion
51                 return
52
53         if 0 == os.getuid():
54                 raise_sanity_error("Do not use Bitbake as root.")
55
56         messages = ""
57
58         if (LooseVersion(__version__) < LooseVersion(minversion)):
59                 messages = messages + 'Bitbake version %s is required and version %s was found\n' % (minversion, __version__)
60
61         # Check TARGET_ARCH is set
62         if data.getVar('TARGET_ARCH', e.data, True) == 'INVALID':
63                 messages = messages + 'Please set TARGET_ARCH directly, or choose a MACHINE or DISTRO that does so.\n'
64         
65         # Check TARGET_OS is set
66         if data.getVar('TARGET_OS', e.data, True) == 'INVALID':
67                 messages = messages + 'Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.\n'
68
69         assume_provided = data.getVar('ASSUME_PROVIDED', e.data , True).split()
70         # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf
71         if "diffstat-native" not in assume_provided:
72                 messages = messages + 'Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf\n'
73         
74         # Check that the MACHINE is valid, if it is set
75         if data.getVar('MACHINE', e.data, True):
76                 if not check_conf_exists("conf/machine/${MACHINE}.conf", e.data):
77                         messages = messages + 'Please set a valid MACHINE in your local.conf\n'
78         
79         # Check that the DISTRO is valid
80         # need to take into account DISTRO renaming DISTRO
81         if not ( check_conf_exists("conf/distro/${DISTRO}.conf", e.data) or check_conf_exists("conf/distro/include/${DISTRO}.inc", e.data) ):
82                 messages = messages + "DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % data.getVar("DISTRO", e.data, True )
83
84         missing = ""
85
86         if not check_app_exists("${MAKE}", e.data):
87                 missing = missing + "GNU make,"
88
89         if not check_app_exists('${BUILD_PREFIX}gcc', e.data):
90                 missing = missing + "C Compiler (${BUILD_PREFIX}gcc),"
91
92         if not check_app_exists('${BUILD_PREFIX}g++', e.data):
93                 missing = missing + "C++ Compiler (${BUILD_PREFIX}g++),"
94
95         required_utilities = "patch help2man diffstat texi2html makeinfo cvs svn bzip2 tar gzip gawk md5sum"
96
97         if data.getVar('TARGET_ARCH', e.data, True) == "arm":
98                 # qemu-native needs gcc 3.x
99                 if "qemu-native" not in assume_provided and "gcc3-native" in assume_provided:
100                         gcc_version = commands.getoutput("${BUILD_PREFIX}gcc --version | head -n 1 | cut -f 3 -d ' '")
101
102                         if not check_gcc3(e.data) and gcc_version[0] != '3':
103                                 messages = messages + "gcc3-native was in ASSUME_PROVIDED but the gcc-3.x binary can't be found in PATH"
104                                 missing = missing + "gcc-3.x (needed for qemu-native),"
105
106                 if "qemu-native" in assume_provided:
107                         if not check_app_exists("qemu-arm", e.data):
108                                 messages = messages + "qemu-native was in ASSUME_PROVIDED but the QEMU binaries (qemu-arm) can't be found in PATH"
109
110         for util in required_utilities.split():
111                 if not check_app_exists( util, e.data ):
112                         missing = missing + "%s," % util
113
114         if missing != "":
115                 missing = missing.rstrip(',')
116                 messages = messages + "Please install following missing utilities: %s\n" % missing
117
118         omask = os.umask(022)
119         if omask & 0755:
120                 messages = messages + "Please use a umask which allows a+rx and u+rwx\n"
121         os.umask(omask)
122
123         oes_bb_conf = data.getVar( 'OES_BITBAKE_CONF', e.data, True )
124         if not oes_bb_conf:
125                 messages = messages + 'You do not include OpenEmbeddeds version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n'
126
127         #
128         # Check that TMPDIR hasn't changed location since the last time we were run
129         #
130         tmpdir = data.getVar('TMPDIR', e.data, True)
131         checkfile = os.path.join(tmpdir, "saved_tmpdir")
132         if os.path.exists(checkfile):
133                 f = file(checkfile, "r")
134                 if (f.read().strip() != tmpdir):
135                         messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % tmpdir
136         else:
137                 f = file(checkfile, "w")
138                 f.write(tmpdir)
139         f.close()
140
141         #
142         # Check the 'ABI' of TMPDIR
143         #
144         current_abi = data.getVar('SANITY_ABI', e.data, True)
145         abifile = data.getVar('SANITY_ABIFILE', e.data, True)
146         if os.path.exists(abifile):
147                 f = file(abifile, "r")
148                 abi = f.read().strip()
149                 if (abi != current_abi):
150                         # Code to convert from one ABI to another could go here if possible.
151                         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)
152         else:
153                 f = file(abifile, "w")
154                 f.write(current_abi)
155         f.close()
156
157         if messages != "":
158                 raise_sanity_error(messages)
159
160 addhandler check_sanity_eventhandler
161 python check_sanity_eventhandler() {
162     from bb import note, error, data, __version__
163     from bb.event import getName
164
165     try:
166         from distutils.version import LooseVersion
167     except ImportError:
168         def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
169
170     if getName(e) == "ConfigParsed":
171         check_sanity(e)
172
173     return NotHandled
174 }