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