| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # For compatibility | 
|  | 2 | def base_path_join(a, *p): | 
|  | 3 | return oe.path.join(a, *p) | 
|  | 4 |  | 
|  | 5 | def base_path_relative(src, dest): | 
|  | 6 | return oe.path.relative(src, dest) | 
|  | 7 |  | 
|  | 8 | def base_path_out(path, d): | 
|  | 9 | return oe.path.format_display(path, d) | 
|  | 10 |  | 
|  | 11 | def base_read_file(filename): | 
|  | 12 | return oe.utils.read_file(filename) | 
|  | 13 |  | 
|  | 14 | def base_ifelse(condition, iftrue = True, iffalse = False): | 
|  | 15 | return oe.utils.ifelse(condition, iftrue, iffalse) | 
|  | 16 |  | 
|  | 17 | def base_conditional(variable, checkvalue, truevalue, falsevalue, d): | 
|  | 18 | return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d) | 
|  | 19 |  | 
|  | 20 | def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d): | 
|  | 21 | return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d) | 
|  | 22 |  | 
|  | 23 | def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d): | 
|  | 24 | return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d) | 
|  | 25 |  | 
|  | 26 | def base_contains(variable, checkvalues, truevalue, falsevalue, d): | 
|  | 27 | return bb.utils.contains(variable, checkvalues, truevalue, falsevalue, d) | 
|  | 28 |  | 
|  | 29 | def base_both_contain(variable1, variable2, checkvalue, d): | 
|  | 30 | return oe.utils.both_contain(variable1, variable2, checkvalue, d) | 
|  | 31 |  | 
|  | 32 | def base_prune_suffix(var, suffixes, d): | 
|  | 33 | return oe.utils.prune_suffix(var, suffixes, d) | 
|  | 34 |  | 
|  | 35 | def oe_filter(f, str, d): | 
|  | 36 | return oe.utils.str_filter(f, str, d) | 
|  | 37 |  | 
|  | 38 | def oe_filter_out(f, str, d): | 
|  | 39 | return oe.utils.str_filter_out(f, str, d) | 
|  | 40 |  | 
|  | 41 | def machine_paths(d): | 
|  | 42 | """List any existing machine specific filespath directories""" | 
|  | 43 | machine = d.getVar("MACHINE", True) | 
|  | 44 | filespathpkg = d.getVar("FILESPATHPKG", True).split(":") | 
|  | 45 | for basepath in d.getVar("FILESPATHBASE", True).split(":"): | 
|  | 46 | for pkgpath in filespathpkg: | 
|  | 47 | machinepath = os.path.join(basepath, pkgpath, machine) | 
|  | 48 | if os.path.isdir(machinepath): | 
|  | 49 | yield machinepath | 
|  | 50 |  | 
|  | 51 | def is_machine_specific(d): | 
|  | 52 | """Determine whether the current recipe is machine specific""" | 
|  | 53 | machinepaths = set(machine_paths(d)) | 
|  | 54 | srcuri = d.getVar("SRC_URI", True).split() | 
|  | 55 | for url in srcuri: | 
|  | 56 | fetcher = bb.fetch2.Fetch([srcuri], d) | 
|  | 57 | if url.startswith("file://"): | 
|  | 58 | if any(fetcher.localpath(url).startswith(mp + "/") for mp in machinepaths): | 
|  | 59 | return True | 
|  | 60 |  | 
|  | 61 | oe_soinstall() { | 
|  | 62 | # Purpose: Install shared library file and | 
|  | 63 | #          create the necessary links | 
|  | 64 | # Example: | 
|  | 65 | # | 
|  | 66 | # oe_ | 
|  | 67 | # | 
|  | 68 | #bbnote installing shared library $1 to $2 | 
|  | 69 | # | 
|  | 70 | libname=`basename $1` | 
|  | 71 | install -m 755 $1 $2/$libname | 
|  | 72 | sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` | 
|  | 73 | solink=`echo $libname | sed -e 's/\.so\..*/.so/'` | 
|  | 74 | ln -sf $libname $2/$sonamelink | 
|  | 75 | ln -sf $libname $2/$solink | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | oe_libinstall() { | 
|  | 79 | # Purpose: Install a library, in all its forms | 
|  | 80 | # Example | 
|  | 81 | # | 
|  | 82 | # oe_libinstall libltdl ${STAGING_LIBDIR}/ | 
|  | 83 | # oe_libinstall -C src/libblah libblah ${D}/${libdir}/ | 
|  | 84 | dir="" | 
|  | 85 | libtool="" | 
|  | 86 | silent="" | 
|  | 87 | require_static="" | 
|  | 88 | require_shared="" | 
|  | 89 | staging_install="" | 
|  | 90 | while [ "$#" -gt 0 ]; do | 
|  | 91 | case "$1" in | 
|  | 92 | -C) | 
|  | 93 | shift | 
|  | 94 | dir="$1" | 
|  | 95 | ;; | 
|  | 96 | -s) | 
|  | 97 | silent=1 | 
|  | 98 | ;; | 
|  | 99 | -a) | 
|  | 100 | require_static=1 | 
|  | 101 | ;; | 
|  | 102 | -so) | 
|  | 103 | require_shared=1 | 
|  | 104 | ;; | 
|  | 105 | -*) | 
|  | 106 | bbfatal "oe_libinstall: unknown option: $1" | 
|  | 107 | ;; | 
|  | 108 | *) | 
|  | 109 | break; | 
|  | 110 | ;; | 
|  | 111 | esac | 
|  | 112 | shift | 
|  | 113 | done | 
|  | 114 |  | 
|  | 115 | libname="$1" | 
|  | 116 | shift | 
|  | 117 | destpath="$1" | 
|  | 118 | if [ -z "$destpath" ]; then | 
|  | 119 | bbfatal "oe_libinstall: no destination path specified" | 
|  | 120 | fi | 
|  | 121 | if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null | 
|  | 122 | then | 
|  | 123 | staging_install=1 | 
|  | 124 | fi | 
|  | 125 |  | 
|  | 126 | __runcmd () { | 
|  | 127 | if [ -z "$silent" ]; then | 
|  | 128 | echo >&2 "oe_libinstall: $*" | 
|  | 129 | fi | 
|  | 130 | $* | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | if [ -z "$dir" ]; then | 
|  | 134 | dir=`pwd` | 
|  | 135 | fi | 
|  | 136 |  | 
|  | 137 | dotlai=$libname.lai | 
|  | 138 |  | 
|  | 139 | # Sanity check that the libname.lai is unique | 
|  | 140 | number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l` | 
|  | 141 | if [ $number_of_files -gt 1 ]; then | 
|  | 142 | bbfatal "oe_libinstall: $dotlai is not unique in $dir" | 
|  | 143 | fi | 
|  | 144 |  | 
|  | 145 |  | 
|  | 146 | dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"` | 
|  | 147 | olddir=`pwd` | 
|  | 148 | __runcmd cd $dir | 
|  | 149 |  | 
|  | 150 | lafile=$libname.la | 
|  | 151 |  | 
|  | 152 | # If such file doesn't exist, try to cut version suffix | 
|  | 153 | if [ ! -f "$lafile" ]; then | 
|  | 154 | libname1=`echo "$libname" | sed 's/-[0-9.]*$//'` | 
|  | 155 | lafile1=$libname.la | 
|  | 156 | if [ -f "$lafile1" ]; then | 
|  | 157 | libname=$libname1 | 
|  | 158 | lafile=$lafile1 | 
|  | 159 | fi | 
|  | 160 | fi | 
|  | 161 |  | 
|  | 162 | if [ -f "$lafile" ]; then | 
|  | 163 | # libtool archive | 
|  | 164 | eval `cat $lafile|grep "^library_names="` | 
|  | 165 | libtool=1 | 
|  | 166 | else | 
|  | 167 | library_names="$libname.so* $libname.dll.a $libname.*.dylib" | 
|  | 168 | fi | 
|  | 169 |  | 
|  | 170 | __runcmd install -d $destpath/ | 
|  | 171 | dota=$libname.a | 
|  | 172 | if [ -f "$dota" -o -n "$require_static" ]; then | 
|  | 173 | rm -f $destpath/$dota | 
|  | 174 | __runcmd install -m 0644 $dota $destpath/ | 
|  | 175 | fi | 
|  | 176 | if [ -f "$dotlai" -a -n "$libtool" ]; then | 
|  | 177 | rm -f $destpath/$libname.la | 
|  | 178 | __runcmd install -m 0644 $dotlai $destpath/$libname.la | 
|  | 179 | fi | 
|  | 180 |  | 
|  | 181 | for name in $library_names; do | 
|  | 182 | files=`eval echo $name` | 
|  | 183 | for f in $files; do | 
|  | 184 | if [ ! -e "$f" ]; then | 
|  | 185 | if [ -n "$libtool" ]; then | 
|  | 186 | bbfatal "oe_libinstall: $dir/$f not found." | 
|  | 187 | fi | 
|  | 188 | elif [ -L "$f" ]; then | 
|  | 189 | __runcmd cp -P "$f" $destpath/ | 
|  | 190 | elif [ ! -L "$f" ]; then | 
|  | 191 | libfile="$f" | 
|  | 192 | rm -f $destpath/$libfile | 
|  | 193 | __runcmd install -m 0755 $libfile $destpath/ | 
|  | 194 | fi | 
|  | 195 | done | 
|  | 196 | done | 
|  | 197 |  | 
|  | 198 | if [ -z "$libfile" ]; then | 
|  | 199 | if  [ -n "$require_shared" ]; then | 
|  | 200 | bbfatal "oe_libinstall: unable to locate shared library" | 
|  | 201 | fi | 
|  | 202 | elif [ -z "$libtool" ]; then | 
|  | 203 | # special case hack for non-libtool .so.#.#.# links | 
|  | 204 | baselibfile=`basename "$libfile"` | 
|  | 205 | if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then | 
|  | 206 | sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` | 
|  | 207 | solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'` | 
|  | 208 | if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then | 
|  | 209 | __runcmd ln -sf $baselibfile $destpath/$sonamelink | 
|  | 210 | fi | 
|  | 211 | __runcmd ln -sf $baselibfile $destpath/$solink | 
|  | 212 | fi | 
|  | 213 | fi | 
|  | 214 |  | 
|  | 215 | __runcmd cd "$olddir" | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | oe_machinstall() { | 
|  | 219 | # Purpose: Install machine dependent files, if available | 
|  | 220 | #          If not available, check if there is a default | 
|  | 221 | #          If no default, just touch the destination | 
|  | 222 | # Example: | 
|  | 223 | #                $1  $2   $3         $4 | 
|  | 224 | # oe_machinstall -m 0644 fstab ${D}/etc/fstab | 
|  | 225 | # | 
|  | 226 | # TODO: Check argument number? | 
|  | 227 | # | 
|  | 228 | filename=`basename $3` | 
|  | 229 | dirname=`dirname $3` | 
|  | 230 |  | 
|  | 231 | for o in `echo ${OVERRIDES} | tr ':' ' '`; do | 
|  | 232 | if [ -e $dirname/$o/$filename ]; then | 
|  | 233 | bbnote $dirname/$o/$filename present, installing to $4 | 
|  | 234 | install $1 $2 $dirname/$o/$filename $4 | 
|  | 235 | return | 
|  | 236 | fi | 
|  | 237 | done | 
|  | 238 | #	bbnote overrides specific file NOT present, trying default=$3... | 
|  | 239 | if [ -e $3 ]; then | 
|  | 240 | bbnote $3 present, installing to $4 | 
|  | 241 | install $1 $2 $3 $4 | 
|  | 242 | else | 
|  | 243 | bbnote $3 NOT present, touching empty $4 | 
|  | 244 | touch $4 | 
|  | 245 | fi | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | create_cmdline_wrapper () { | 
|  | 249 | # Create a wrapper script where commandline options are needed | 
|  | 250 | # | 
|  | 251 | # These are useful to work around relocation issues, by passing extra options | 
|  | 252 | # to a program | 
|  | 253 | # | 
|  | 254 | # Usage: create_cmdline_wrapper FILENAME <extra-options> | 
|  | 255 |  | 
|  | 256 | cmd=$1 | 
|  | 257 | shift | 
|  | 258 |  | 
|  | 259 | echo "Generating wrapper script for $cmd" | 
|  | 260 |  | 
|  | 261 | mv $cmd $cmd.real | 
|  | 262 | cmdname=`basename $cmd` | 
|  | 263 | cat <<END >$cmd | 
|  | 264 | #!/bin/bash | 
|  | 265 | realpath=\`readlink -fn \$0\` | 
|  | 266 | exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $@ "\$@" | 
|  | 267 | END | 
|  | 268 | chmod +x $cmd | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | create_wrapper () { | 
|  | 272 | # Create a wrapper script where extra environment variables are needed | 
|  | 273 | # | 
|  | 274 | # These are useful to work around relocation issues, by setting environment | 
|  | 275 | # variables which point to paths in the filesystem. | 
|  | 276 | # | 
|  | 277 | # Usage: create_wrapper FILENAME [[VAR=VALUE]..] | 
|  | 278 |  | 
|  | 279 | cmd=$1 | 
|  | 280 | shift | 
|  | 281 |  | 
|  | 282 | echo "Generating wrapper script for $cmd" | 
|  | 283 |  | 
|  | 284 | mv $cmd $cmd.real | 
|  | 285 | cmdname=`basename $cmd` | 
|  | 286 | cat <<END >$cmd | 
|  | 287 | #!/bin/bash | 
|  | 288 | realpath=\`readlink -fn \$0\` | 
|  | 289 | export $@ | 
|  | 290 | exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@" | 
|  | 291 | END | 
|  | 292 | chmod +x $cmd | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | # Copy files/directories from $1 to $2 but using hardlinks | 
|  | 296 | # (preserve symlinks) | 
|  | 297 | hardlinkdir () { | 
|  | 298 | from=$1 | 
|  | 299 | to=$2 | 
|  | 300 | (cd $from; find . -print0 | cpio --null -pdlu $to) | 
|  | 301 | } | 
|  | 302 |  | 
|  | 303 |  | 
|  | 304 | def check_app_exists(app, d): | 
|  | 305 | app = d.expand(app) | 
|  | 306 | path = d.getVar('PATH', d, True) | 
|  | 307 | return bool(bb.utils.which(path, app)) | 
|  | 308 |  | 
|  | 309 | def explode_deps(s): | 
|  | 310 | return bb.utils.explode_deps(s) | 
|  | 311 |  | 
|  | 312 | def base_set_filespath(path, d): | 
|  | 313 | filespath = [] | 
|  | 314 | extrapaths = (d.getVar("FILESEXTRAPATHS", True) or "") | 
|  | 315 | # Remove default flag which was used for checking | 
|  | 316 | extrapaths = extrapaths.replace("__default:", "") | 
|  | 317 | # Don't prepend empty strings to the path list | 
|  | 318 | if extrapaths != "": | 
|  | 319 | path = extrapaths.split(":") + path | 
|  | 320 | # The ":" ensures we have an 'empty' override | 
|  | 321 | overrides = (":" + (d.getVar("FILESOVERRIDES", True) or "")).split(":") | 
|  | 322 | overrides.reverse() | 
|  | 323 | for o in overrides: | 
|  | 324 | for p in path: | 
|  | 325 | if p != "": | 
|  | 326 | filespath.append(os.path.join(p, o)) | 
|  | 327 | return ":".join(filespath) | 
|  | 328 |  | 
|  | 329 | def extend_variants(d, var, extend, delim=':'): | 
|  | 330 | """Return a string of all bb class extend variants for the given extend""" | 
|  | 331 | variants = [] | 
|  | 332 | whole = d.getVar(var, True) or "" | 
|  | 333 | for ext in whole.split(): | 
|  | 334 | eext = ext.split(delim) | 
|  | 335 | if len(eext) > 1 and eext[0] == extend: | 
|  | 336 | variants.append(eext[1]) | 
|  | 337 | return " ".join(variants) | 
|  | 338 |  | 
|  | 339 | def multilib_pkg_extend(d, pkg): | 
|  | 340 | variants = (d.getVar("MULTILIB_VARIANTS", True) or "").split() | 
|  | 341 | if not variants: | 
|  | 342 | return pkg | 
|  | 343 | pkgs = pkg | 
|  | 344 | for v in variants: | 
|  | 345 | pkgs = pkgs + " " + v + "-" + pkg | 
|  | 346 | return pkgs | 
|  | 347 |  | 
|  | 348 | def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '): | 
|  | 349 | """Return a string of all ${var} in all multilib tune configuration""" | 
|  | 350 | values = [] | 
|  | 351 | value = d.getVar(var, True) or "" | 
|  | 352 | if value != "": | 
|  | 353 | if need_split: | 
|  | 354 | for item in value.split(delim): | 
|  | 355 | values.append(item) | 
|  | 356 | else: | 
|  | 357 | values.append(value) | 
|  | 358 | variants = d.getVar("MULTILIB_VARIANTS", True) or "" | 
|  | 359 | for item in variants.split(): | 
|  | 360 | localdata = bb.data.createCopy(d) | 
|  | 361 | overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item | 
|  | 362 | localdata.setVar("OVERRIDES", overrides) | 
|  | 363 | localdata.setVar("MLPREFIX", item + "-") | 
|  | 364 | bb.data.update_data(localdata) | 
|  | 365 | value = localdata.getVar(var, True) or "" | 
|  | 366 | if value != "": | 
|  | 367 | if need_split: | 
|  | 368 | for item in value.split(delim): | 
|  | 369 | values.append(item) | 
|  | 370 | else: | 
|  | 371 | values.append(value) | 
|  | 372 | if unique: | 
|  | 373 | #we do this to keep order as much as possible | 
|  | 374 | ret = [] | 
|  | 375 | for value in values: | 
|  | 376 | if not value in ret: | 
|  | 377 | ret.append(value) | 
|  | 378 | else: | 
|  | 379 | ret = values | 
|  | 380 | return " ".join(ret) |