merge of '3f2a27262036d4f6ceb75b07aa81c14e4b0fdcf0'
[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_app_exists(app, d):
28         from bb import which, data
29
30         app = data.expand(app, d)
31         path = data.getVar('PATH', d)
32         return len(which(path, app)) != 0
33
34
35 def check_sanity(e):
36         from bb import note, error, data, __version__
37         from bb.event import Handled, NotHandled, getName
38         try:
39                 from distutils.version import LooseVersion
40         except ImportError:
41                 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
42         import os
43
44         # Check the bitbake version meets minimum requirements
45         minversion = data.getVar('BB_MIN_VERSION', e.data , True)
46         if not minversion:
47                 # Hack: BB_MIN_VERSION hasn't been parsed yet so return 
48                 # and wait for the next call
49                 print "Foo %s" % minversion
50                 return
51
52         if 0 == os.getuid():
53                 raise_sanity_error("Do not use Bitbake as root.")
54
55         messages = ""
56
57         if (LooseVersion(__version__) < LooseVersion(minversion)):
58                 messages = messages + 'Bitbake version %s is required and version %s was found\n' % (minversion, __version__)
59
60         # Check TARGET_ARCH is set
61         if data.getVar('TARGET_ARCH', e.data, True) == 'INVALID':
62                 messages = messages + 'Please set TARGET_ARCH directly, or choose a MACHINE or DISTRO that does so.\n'
63         
64         # Check TARGET_OS is set
65         if data.getVar('TARGET_OS', e.data, True) == 'INVALID':
66                 messages = messages + 'Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.\n'
67
68         # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf
69         if "diffstat-native" not in data.getVar('ASSUME_PROVIDED', e.data, True).split():
70                 messages = messages + 'Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf\n'
71         
72         # Check that the MACHINE is valid
73         if not check_conf_exists("conf/machine/${MACHINE}.conf", e.data):
74                 messages = messages + 'Please set a valid MACHINE in your local.conf\n'
75         
76         # Check that the DISTRO is valid
77         # need to take into account DISTRO renaming DISTRO
78         if not ( check_conf_exists("conf/distro/${DISTRO}.conf", e.data) or check_conf_exists("conf/distro/include/${DISTRO}.inc", e.data) ):
79                 messages = messages + "DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % data.getVar("DISTRO", e.data, True )
80
81         missing = ""
82
83         if not check_app_exists("${MAKE}", e.data):
84                 missing = missing + "GNU make,"
85
86         if not check_app_exists('${BUILD_PREFIX}gcc', e.data):
87                 missing = missing + "C Compiler (${BUILD_PREFIX}gcc),"
88
89         if not check_app_exists('${BUILD_PREFIX}g++', e.data):
90                 missing = missing + "C++ Compiler (${BUILD_PREFIX}g++),"
91
92         required_utilities = "patch help2man diffstat texi2html makeinfo cvs svn bzip2 tar gzip gawk md5sum"
93
94         for util in required_utilities.split():
95                 if not check_app_exists( util, e.data ):
96                         missing = missing + "%s," % util
97
98         if missing != "":
99                 missing = missing.rstrip(',')
100                 messages = messages + "Please install following missing utilities: %s\n" % missing
101
102         oes_bb_conf = data.getVar( 'OES_BITBAKE_CONF', e.data, True )
103         if not oes_bb_conf:
104                 messages = messages + 'You do not include OpenEmbeddeds version of conf/bitbake.conf\n'
105
106         if messages != "":
107                 raise_sanity_error(messages)
108
109 addhandler check_sanity_eventhandler
110 python check_sanity_eventhandler() {
111     from bb import note, error, data, __version__
112     from bb.event import getName
113
114     try:
115         from distutils.version import LooseVersion
116     except ImportError:
117         def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
118
119     if (LooseVersion(bb.__version__) > LooseVersion("1.8.6")):
120         if getName(e) == "ConfigParsed":
121             check_sanity(e)
122         return NotHandled
123
124     if getName(e) == "BuildStarted":
125         check_sanity(e)
126
127     return NotHandled
128 }