sourceipk: use ar to package ipk instead of tar
[openembedded.git] / classes / sanity.bbclass
blob1fd5fbb216a1d598f5d2477362728bc6f654ba44
2 # Sanity check the users setup for common misconfigurations
5 inherit qemu
7 def raise_sanity_error(msg):
8         import bb
9         bb.fatal(""" Openembedded's config sanity checker detected a potential misconfiguration.
10         Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
11         Following is the list of potential problems / advisories:
12         
13         %s""" % msg)
15 def check_conf_exists(fn, data):
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
27 def check_sanity(e):
28         from bb import note, error, data, __version__
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 commands
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
44         if 0 == os.getuid():
45                 raise_sanity_error("Do not use Bitbake as root.")
47         messages = ""
49         if (LooseVersion(__version__) < LooseVersion(minversion)):
50                 messages = messages + 'Bitbake version %s is required and version %s was found\n' % (minversion, __version__)
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'
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 )
75         missing = ""
77         if not check_app_exists("${MAKE}", e.data):
78                 missing = missing + "GNU make,"
80         if not check_app_exists('${BUILD_PREFIX}gcc', e.data):
81                 missing = missing + "C Compiler (${BUILD_PREFIX}gcc),"
83         if not check_app_exists('${BUILD_PREFIX}g++', e.data):
84                 missing = missing + "C++ Compiler (${BUILD_PREFIX}g++),"
86         required_utilities = "patch help2man diffstat texi2html makeinfo cvs svn bzip2 tar gzip gawk md5sum chrpath"
88         # If we'll be running qemu, perform some sanity checks
89         if data.getVar('ENABLE_BINARY_LOCALE_GENERATION', e.data, True):
90                 if "qemu-native" in assume_provided:
91                         required_utilities += " %s" % (qemu_target_binary(e.data))
93         for util in required_utilities.split():
94                 if not check_app_exists( util, e.data ):
95                         missing = missing + "%s," % util
97         if missing != "":
98                 missing = missing.rstrip(',')
99                 messages = messages + "Please install following missing utilities: %s\n" % missing
101         try:
102             if os.path.basename(os.readlink('/bin/sh')) == 'dash':
103                     messages = messages + "Using dash as /bin/sh causes various subtle build problems, please use bash instead.\n"
104         except:
105                 pass
107         omask = os.umask(022)
108         if omask & 0755:
109                 messages = messages + "Please use a umask which allows a+rx and u+rwx\n"
110         os.umask(omask)
112         oes_bb_conf = data.getVar( 'OES_BITBAKE_CONF', e.data, True )
113         if not oes_bb_conf:
114                 messages = messages + 'You do not include OpenEmbeddeds version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n'
116         #
117         # Check that TMPDIR hasn't changed location since the last time we were run
118         #
119         tmpdir = data.getVar('TMPDIR', e.data, True)
120         checkfile = os.path.join(tmpdir, "saved_tmpdir")
121         if os.path.exists(checkfile):
122                 f = file(checkfile, "r")
123                 oldpath = f.read().strip()
124                 if (oldpath != tmpdir):
125                         messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % oldpath
126         else:
127                 import bb
128                 bb.mkdirhier(tmpdir)
129                 f = file(checkfile, "w")
130                 f.write(tmpdir)
131         f.close()
133         #
134         # Check the 'ABI' of TMPDIR
135         #
136         current_abi = data.getVar('OELAYOUT_ABI', e.data, True)
137         abifile = data.getVar('SANITY_ABIFILE', e.data, True)
138         if os.path.exists(abifile):
139                 f = file(abifile, "r")
140                 abi = f.read().strip()
141                 if not abi.isdigit():
142                         f = file(abifile, "w")
143                         f.write(current_abi)
144                 elif abi == "3" and current_abi == "4":
145                         import bb
146                         bb.note("Converting staging from layout version 2 to layout version 3")
147                         os.system(bb.data.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots", e.data))
148                         os.system(bb.data.expand("ln -s sysroots ${TMPDIR}/staging", e.data))
149                         os.system(bb.data.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done", e.data))
150                         f = file(abifile, "w")
151                         f.write(current_abi)
152                 elif abi == "5" and current_abi != "5":
153                         messages = messages + "Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n"
154                 elif (abi != current_abi):
155                         # Code to convert from one ABI to another could go here if possible.
156                         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)
157         else:
158                 f = file(abifile, "w")
159                 f.write(current_abi)
160         f.close()
162         #
163         # Check the Distro PR value didn't change
164         #
165         distro_pr = data.getVar('DISTRO_PR', e.data, True)
166         prfile = data.getVar('SANITY_PRFILE', e.data, True)
167         if os.path.exists(prfile):
168                 f = file(prfile, "r")
169                 pr = f.read().strip()
170                 if (pr != distro_pr):
171                         # Code to convert from one ABI to another could go here if possible.
172                         messages = messages + "Error, DISTRO_PR has changed (%s to %s) which means all packages need to rebuild. Please remove your TMPDIR so this can happen. For autobuilder setups you can avoid this by using a TMPDIR that include DISTRO_PR in the path.\n" % (pr, distro_pr)
173         else:
174                 f = file(prfile, "w")
175                 f.write(distro_pr)
176         f.close()
179         #
180         # Check there aren't duplicates in PACKAGE_ARCHS
181         #
182         archs = data.getVar('PACKAGE_ARCHS', e.data, True).split()
183         for arch in archs:
184                 if archs.count(arch) != 1:
185                         messages = messages + "Error, Your PACKAGE_ARCHS field contains duplicates. Perhaps you set PACKAGE_EXTRA_ARCHS twice accidently through some tune file?\n"
186                         break
188         if messages != "":
189                 raise_sanity_error(messages)
191 python check_sanity_eventhandler() {
192     if isinstance(e, bb.event.BuildStarted):
193         check_sanity(e)
195 addhandler check_sanity_eventhandler