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