2 # Sanity check the users setup for common misconfigurations
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.
12 SANITY_ABIFILE = "${TMPDIR}/abi_version"
14 def raise_sanity_error(msg):
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:
22 def check_conf_exists(fn, data):
26 fn = bb.data.expand(fn, data)
27 vbbpath = bb.data.getVar("BBPATH", data)
29 bbpath += vbbpath.split(":")
31 currname = os.path.join(bb.data.expand(p, data), fn)
32 if os.access(currname, os.R_OK):
37 from bb import note, error, data, __version__
38 from bb.event import Handled, NotHandled, getName
40 from distutils.version import LooseVersion
42 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
45 # Check the bitbake version meets minimum requirements
46 minversion = data.getVar('BB_MIN_VERSION', e.data , True)
48 # Hack: BB_MIN_VERSION hasn't been parsed yet so return
49 # and wait for the next call
50 print "Foo %s" % minversion
54 raise_sanity_error("Do not use Bitbake as root.")
58 if (LooseVersion(__version__) < LooseVersion(minversion)):
59 messages = messages + 'Bitbake version %s is required and version %s was found\n' % (minversion, __version__)
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'
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'
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'
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'
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 )
86 if not check_app_exists("${MAKE}", e.data):
87 missing = missing + "GNU make,"
89 if not check_app_exists('${BUILD_PREFIX}gcc', e.data):
90 missing = missing + "C Compiler (${BUILD_PREFIX}gcc),"
92 if not check_app_exists('${BUILD_PREFIX}g++', e.data):
93 missing = missing + "C++ Compiler (${BUILD_PREFIX}g++),"
95 required_utilities = "patch help2man diffstat texi2html makeinfo cvs svn bzip2 tar gzip gawk md5sum"
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 ' '")
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),"
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"
110 for util in required_utilities.split():
111 if not check_app_exists( util, e.data ):
112 missing = missing + "%s," % util
115 missing = missing.rstrip(',')
116 messages = messages + "Please install following missing utilities: %s\n" % missing
118 omask = os.umask(022)
120 messages = messages + "Please use a umask which allows a+rx and u+rwx\n"
123 oes_bb_conf = data.getVar( 'OES_BITBAKE_CONF', e.data, True )
125 messages = messages + 'You do not include OpenEmbeddeds version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n'
128 # Check that TMPDIR hasn't changed location since the last time we were run
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
137 f = file(checkfile, "w")
142 # Check the 'ABI' of TMPDIR
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)
153 f = file(abifile, "w")
158 raise_sanity_error(messages)
160 addhandler check_sanity_eventhandler
161 python check_sanity_eventhandler() {
162 from bb import note, error, data, __version__
163 from bb.event import getName
166 from distutils.version import LooseVersion
168 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
170 if getName(e) == "ConfigParsed":