1 # like os.path.join but doesn't treat absolute RHS specially
2 def base_path_join(a, *p):
5 if path == '' or path.endswith('/'):
11 def base_path_relative(src, dest):
12 """ Return a relative path from src to dest.
14 >>> base_path_relative("/usr/bin", "/tmp/foo/bar")
17 >>> base_path_relative("/usr/bin", "/usr/lib")
20 >>> base_path_relative("/tmp", "/tmp/foo/bar")
23 from os.path import sep, pardir, normpath, commonprefix
25 destlist = normpath(dest).split(sep)
26 srclist = normpath(src).split(sep)
28 # Find common section of the path
29 common = commonprefix([destlist, srclist])
30 commonlen = len(common)
32 # Climb back to the point where they differentiate
33 relpath = [ pardir ] * (len(srclist) - commonlen)
34 if commonlen < len(destlist):
35 # Add remaining portion
36 relpath += destlist[commonlen:]
38 return sep.join(relpath)
40 def base_path_out(path, d):
41 """ Prepare a path for display to the user. """
42 rel = base_path_relative(d.getVar("TOPDIR", 1), path)
43 if len(rel) > len(path):
48 # for MD5/SHA handling
49 def base_chk_load_parser(config_paths):
51 parser = ConfigParser.ConfigParser()
52 if len(parser.read(config_paths)) < 1:
53 raise ValueError("no ini files could be found")
57 def base_chk_file_vars(parser, localpath, params, data):
63 md5flag = "%s.md5sum" % name
64 sha256flag = "%s.sha256sum" % name
67 sha256flag = "sha256sum"
68 want_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
69 want_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
71 if (want_sha256sum == None and want_md5sum == None):
72 # no checksums to check, nothing to do
75 if not os.path.exists(localpath):
76 localpath = base_path_out(localpath, data)
77 bb.note("The localpath does not exist '%s'" % localpath)
78 raise Exception("The path does not exist '%s'" % localpath)
82 md5pipe = os.popen('PATH=%s md5sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
83 md5data = (md5pipe.readline().split() or [ "" ])[0]
86 raise Exception("Executing md5sum failed")
87 if want_md5sum != md5data:
88 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (want_md5sum, md5data))
89 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (want_md5sum, md5data))
93 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
94 sha256data = (shapipe.readline().split() or [ "" ])[0]
97 raise Exception("Executing shasum failed")
98 if want_sha256sum != sha256data:
99 bb.note("The SHA256Sums did not match. Wanted: '%s' and Got: '%s'" % (want_sha256sum, sha256data))
100 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (want_sha256sum, sha256data))
105 def base_chk_file(parser, pn, pv, src_uri, localpath, data):
107 # Try PN-PV-SRC_URI first and then try PN-SRC_URI
108 # we rely on the get method to create errors
109 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
110 pn_src = "%s-%s" % (pn,src_uri)
111 if parser.has_section(pn_pv_src):
112 md5 = parser.get(pn_pv_src, "md5")
113 sha256 = parser.get(pn_pv_src, "sha256")
114 elif parser.has_section(pn_src):
115 md5 = parser.get(pn_src, "md5")
116 sha256 = parser.get(pn_src, "sha256")
117 elif parser.has_section(src_uri):
118 md5 = parser.get(src_uri, "md5")
119 sha256 = parser.get(src_uri, "sha256")
123 # md5 and sha256 should be valid now
124 if not os.path.exists(localpath):
125 localpath = base_path_out(localpath, data)
126 bb.note("The localpath does not exist '%s'" % localpath)
127 raise Exception("The path does not exist '%s'" % localpath)
130 # call md5(sum) and shasum
132 md5pipe = os.popen('PATH=%s md5sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
133 md5data = (md5pipe.readline().split() or [ "" ])[0]
136 raise Exception("Executing md5sum failed")
139 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
140 shadata = (shapipe.readline().split() or [ "" ])[0]
143 raise Exception("Executing shasum failed")
145 if no_checksum == True: # we do not have conf/checksums.ini entry
147 file = open("%s/checksums.ini" % bb.data.getVar("TMPDIR", data, 1), "a")
152 raise Exception("Creating checksums.ini failed")
154 file.write("[%s]\nmd5=%s\nsha256=%s\n\n" % (src_uri, md5data, shadata))
157 from string import maketrans
158 trtable = maketrans("", "")
159 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
162 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
167 raise Exception("Creating %s.sum failed" % uname)
169 ufile.write("SRC_URI = \"%s;name=%s\"\nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (src_uri, uname, uname, md5data, uname, shadata))
172 if not bb.data.getVar("OE_STRICT_CHECKSUMS",data, True):
173 bb.note("This package has no entry in checksums.ini, please add one")
174 bb.note("\n[%s]\nmd5=%s\nsha256=%s" % (src_uri, md5data, shadata))
175 bb.note("This package has no checksums in corresponding recipe, please add")
176 bb.note("SRC_URI = \"%s;name=%s\"\nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (src_uri, uname, uname, md5data, uname, shadata))
179 bb.note("Missing checksum")
182 if not md5 == md5data:
183 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (md5,md5data))
184 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
186 if not sha256 == shadata:
187 bb.note("The SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256,shadata))
188 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
192 def base_read_file(filename):
194 f = file( filename, "r" )
195 except IOError, reason:
196 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
198 return f.read().strip()
201 def base_ifelse(condition, iftrue = True, iffalse = False):
207 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
208 if bb.data.getVar(variable,d,1) == checkvalue:
213 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
214 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
219 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
220 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
226 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
227 val = bb.data.getVar(variable,d,1)
231 if type(checkvalues).__name__ == "str":
232 checkvalues = [checkvalues]
233 for value in checkvalues:
234 if val.find(value) != -1:
235 matches = matches + 1
236 if matches == len(checkvalues):
240 def base_both_contain(variable1, variable2, checkvalue, d):
241 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
246 def base_prune_suffix(var, suffixes, d):
247 # See if var ends with any of the suffixes listed and
249 for suffix in suffixes:
250 if var.endswith(suffix):
251 return var.replace(suffix, "")
254 def oe_filter(f, str, d):
256 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
258 def oe_filter_out(f, str, d):
260 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
264 echo "Usage: oedebug level \"message\""
268 test ${OEDEBUG:-0} -ge $1 && {
275 # Purpose: Install shared library file and
276 # create the necessary links
281 #oenote installing shared library $1 to $2
283 libname=`basename $1`
284 install -m 755 $1 $2/$libname
285 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
286 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
287 ln -sf $libname $2/$sonamelink
288 ln -sf $libname $2/$solink
292 # Purpose: Install a library, in all its forms
295 # oe_libinstall libltdl ${STAGING_LIBDIR}/
296 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
303 while [ "$#" -gt 0 ]; do
319 oefatal "oe_libinstall: unknown option: $1"
331 if [ -z "$destpath" ]; then
332 oefatal "oe_libinstall: no destination path specified"
334 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
340 if [ -z "$silent" ]; then
341 echo >&2 "oe_libinstall: $*"
346 if [ -z "$dir" ]; then
352 # Sanity check that the libname.lai is unique
353 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
354 if [ $number_of_files -gt 1 ]; then
355 oefatal "oe_libinstall: $dotlai is not unique in $dir"
359 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
365 # If such file doesn't exist, try to cut version suffix
366 if [ ! -f "$lafile" ]; then
367 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
369 if [ -f "$lafile1" ]; then
375 if [ -f "$lafile" ]; then
377 eval `cat $lafile|grep "^library_names="`
380 library_names="$libname.so* $libname.dll.a"
383 __runcmd install -d $destpath/
385 if [ -f "$dota" -o -n "$require_static" ]; then
386 __runcmd install -m 0644 $dota $destpath/
388 if [ -f "$dotlai" -a -n "$libtool" ]; then
389 if test -n "$staging_install"
391 # stop libtool using the final directory name for libraries
393 __runcmd rm -f $destpath/$libname.la
394 __runcmd sed -e 's/^installed=yes$/installed=no/' \
395 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
396 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
397 $dotlai >$destpath/$libname.la
399 __runcmd install -m 0644 $dotlai $destpath/$libname.la
403 for name in $library_names; do
404 files=`eval echo $name`
406 if [ ! -e "$f" ]; then
407 if [ -n "$libtool" ]; then
408 oefatal "oe_libinstall: $dir/$f not found."
410 elif [ -L "$f" ]; then
411 __runcmd cp -P "$f" $destpath/
412 elif [ ! -L "$f" ]; then
414 __runcmd install -m 0755 $libfile $destpath/
419 if [ -z "$libfile" ]; then
420 if [ -n "$require_shared" ]; then
421 oefatal "oe_libinstall: unable to locate shared library"
423 elif [ -z "$libtool" ]; then
424 # special case hack for non-libtool .so.#.#.# links
425 baselibfile=`basename "$libfile"`
426 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
427 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
428 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
429 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
430 __runcmd ln -sf $baselibfile $destpath/$sonamelink
432 __runcmd ln -sf $baselibfile $destpath/$solink
436 __runcmd cd "$olddir"
440 # Purpose: Install machine dependent files, if available
441 # If not available, check if there is a default
442 # If no default, just touch the destination
445 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
447 # TODO: Check argument number?
449 filename=`basename $3`
452 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
453 if [ -e $dirname/$o/$filename ]; then
454 oenote $dirname/$o/$filename present, installing to $4
455 install $1 $2 $dirname/$o/$filename $4
459 # oenote overrides specific file NOT present, trying default=$3...
461 oenote $3 present, installing to $4
464 oenote $3 NOT present, touching empty $4
469 def check_app_exists(app, d):
470 from bb import which, data
472 app = data.expand(app, d)
473 path = data.getVar('PATH', d, 1)
474 return len(which(path, app)) != 0
477 return bb.utils.explode_deps(s)
479 def base_set_filespath(path, d):
480 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
482 # The ":" ensures we have an 'empty' override
483 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
485 for o in overrides.split(":"):
486 filespath.append(os.path.join(p, o))
487 return ":".join(filespath)