summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openembedded/classes/sanity.bbclass69
-rw-r--r--openembedded/conf/bitbake.conf1
-rw-r--r--openembedded/conf/sanity.conf8
3 files changed, 78 insertions, 0 deletions
diff --git a/openembedded/classes/sanity.bbclass b/openembedded/classes/sanity.bbclass
new file mode 100644
index 0000000000..f82af18d74
--- /dev/null
+++ b/openembedded/classes/sanity.bbclass
@@ -0,0 +1,69 @@
1#
2# Sanity check the users setup for common misconfigurations
3#
4
5BB_MIN_VERSION = "1.3.3"
6
7def raise_sanity_error(msg):
8 import bb
9 bb.fatal("Openembedded's config sanity checker detected a potential misconfiguration.\nEither fix cause of this error or at your own risk disable the checker (see sanity.conf).\n%s" % msg)
10
11def check_conf_exists(fn, data):
12 import bb, os
13
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
25addhandler check_sanity_eventhandler
26python check_sanity_eventhandler() {
27 from bb import note, error, data, __version__
28 from bb.event import Handled, NotHandled, getName
29 from distutils.version import LooseVersion
30 import os
31
32 sanity_checked = bb.data.getVar('SANITY_CHECKED', e.data)
33 if sanity_checked == "1":
34 return
35
36 # Check the bitbake version meets minimum requirements
37 minversion = bb.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 return
42
43 if (LooseVersion(bb.__version__) < LooseVersion(minversion)):
44 raise_sanity_error('Bitbake version %s is required and version %s was found' % (minversion, bb.__version__))
45
46 # Check TARGET_ARCH is set
47 if bb.data.getVar('TARGET_ARCH', e.data, True) == 'INVALID':
48 raise_sanity_error('Please set TARGET_ARCH directly, or choose a MACHINE or DISTRO that does so.')
49
50 # Check TARGET_OS is set
51 if bb.data.getVar('TARGET_OS', e.data, True) == 'INVALID':
52 raise_sanity_error('Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.')
53
54 # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf
55 if "diffstat-native" not in bb.data.getVar('ASSUME_PROVIDED', e.data, True).split():
56 raise_sanity_error('Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf')
57
58 # Check the MACHINE is valid
59 if not check_conf_exists("conf/machine/${MACHINE}.conf", e.data):
60 raise_sanity_error('Please set a valid MACHINE in your local.conf')
61
62 # Check the distro is valid
63 if not check_conf_exists("conf/distro/${DISTRO}.conf", e.data):
64 raise_sanity_error('Please set a valid DISTRO in your local.conf')
65
66 bb.data.setVar('SANITY_CHECKED', "1", e.data)
67 return
68}
69
diff --git a/openembedded/conf/bitbake.conf b/openembedded/conf/bitbake.conf
index 71dc101f0f..9d8ce784b3 100644
--- a/openembedded/conf/bitbake.conf
+++ b/openembedded/conf/bitbake.conf
@@ -393,3 +393,4 @@ include conf/target/${TARGET_SYS}.conf
393include conf/machine/${MACHINE}.conf 393include conf/machine/${MACHINE}.conf
394include conf/distro/${DISTRO}.conf 394include conf/distro/${DISTRO}.conf
395include conf/documentation.conf 395include conf/documentation.conf
396require conf/sanity.conf
diff --git a/openembedded/conf/sanity.conf b/openembedded/conf/sanity.conf
new file mode 100644
index 0000000000..df2ec3e82a
--- /dev/null
+++ b/openembedded/conf/sanity.conf
@@ -0,0 +1,8 @@
1# Sanity checks for common user misconfigurations
2#
3# See sanity.bbclass
4#
5# Expert users can confirm their sanity with "touch conf/sanity.conf"
6
7INHERIT += "sanity"
8