blob: 8e07eac07a39729ccbda48015d9ab063f55b31d8 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# For compatibility
2def base_path_join(a, *p):
3 return oe.path.join(a, *p)
4
5def base_path_relative(src, dest):
6 return oe.path.relative(src, dest)
7
8def base_path_out(path, d):
9 return oe.path.format_display(path, d)
10
11def base_read_file(filename):
12 return oe.utils.read_file(filename)
13
14def base_ifelse(condition, iftrue = True, iffalse = False):
15 return oe.utils.ifelse(condition, iftrue, iffalse)
16
17def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
18 return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
19
20def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
21 return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
22
23def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
24 return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
25
26def base_contains(variable, checkvalues, truevalue, falsevalue, d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027 bb.note('base_contains is deprecated, please use bb.utils.contains instead.')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 return bb.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
29
30def base_both_contain(variable1, variable2, checkvalue, d):
31 return oe.utils.both_contain(variable1, variable2, checkvalue, d)
32
33def base_prune_suffix(var, suffixes, d):
34 return oe.utils.prune_suffix(var, suffixes, d)
35
36def oe_filter(f, str, d):
37 return oe.utils.str_filter(f, str, d)
38
39def oe_filter_out(f, str, d):
40 return oe.utils.str_filter_out(f, str, d)
41
42def machine_paths(d):
43 """List any existing machine specific filespath directories"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 machine = d.getVar("MACHINE")
45 filespathpkg = d.getVar("FILESPATHPKG").split(":")
46 for basepath in d.getVar("FILESPATHBASE").split(":"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 for pkgpath in filespathpkg:
48 machinepath = os.path.join(basepath, pkgpath, machine)
49 if os.path.isdir(machinepath):
50 yield machinepath
51
52def is_machine_specific(d):
53 """Determine whether the current recipe is machine specific"""
54 machinepaths = set(machine_paths(d))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 srcuri = d.getVar("SRC_URI").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 for url in srcuri:
57 fetcher = bb.fetch2.Fetch([srcuri], d)
58 if url.startswith("file://"):
59 if any(fetcher.localpath(url).startswith(mp + "/") for mp in machinepaths):
60 return True
61
62oe_soinstall() {
63 # Purpose: Install shared library file and
64 # create the necessary links
Patrick Williamsc0f7c042017-02-23 20:41:17 -060065 # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 libname=`basename $1`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060067 case "$libname" in
68 *.so)
69 bbfatal "oe_soinstall: Shared library must haved versioned filename (e.g. libfoo.so.1.2.3)"
70 ;;
71 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 install -m 755 $1 $2/$libname
73 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 if [ -z $sonamelink ]; then
75 bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'."
76 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
78 ln -sf $libname $2/$sonamelink
79 ln -sf $libname $2/$solink
80}
81
82oe_libinstall() {
83 # Purpose: Install a library, in all its forms
84 # Example
85 #
86 # oe_libinstall libltdl ${STAGING_LIBDIR}/
87 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
88 dir=""
89 libtool=""
90 silent=""
91 require_static=""
92 require_shared=""
93 staging_install=""
94 while [ "$#" -gt 0 ]; do
95 case "$1" in
96 -C)
97 shift
98 dir="$1"
99 ;;
100 -s)
101 silent=1
102 ;;
103 -a)
104 require_static=1
105 ;;
106 -so)
107 require_shared=1
108 ;;
109 -*)
110 bbfatal "oe_libinstall: unknown option: $1"
111 ;;
112 *)
113 break;
114 ;;
115 esac
116 shift
117 done
118
119 libname="$1"
120 shift
121 destpath="$1"
122 if [ -z "$destpath" ]; then
123 bbfatal "oe_libinstall: no destination path specified"
124 fi
125 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
126 then
127 staging_install=1
128 fi
129
130 __runcmd () {
131 if [ -z "$silent" ]; then
132 echo >&2 "oe_libinstall: $*"
133 fi
134 $*
135 }
136
137 if [ -z "$dir" ]; then
138 dir=`pwd`
139 fi
140
141 dotlai=$libname.lai
142
143 # Sanity check that the libname.lai is unique
144 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
145 if [ $number_of_files -gt 1 ]; then
146 bbfatal "oe_libinstall: $dotlai is not unique in $dir"
147 fi
148
149
150 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
151 olddir=`pwd`
152 __runcmd cd $dir
153
154 lafile=$libname.la
155
156 # If such file doesn't exist, try to cut version suffix
157 if [ ! -f "$lafile" ]; then
158 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
159 lafile1=$libname.la
160 if [ -f "$lafile1" ]; then
161 libname=$libname1
162 lafile=$lafile1
163 fi
164 fi
165
166 if [ -f "$lafile" ]; then
167 # libtool archive
168 eval `cat $lafile|grep "^library_names="`
169 libtool=1
170 else
171 library_names="$libname.so* $libname.dll.a $libname.*.dylib"
172 fi
173
174 __runcmd install -d $destpath/
175 dota=$libname.a
176 if [ -f "$dota" -o -n "$require_static" ]; then
177 rm -f $destpath/$dota
178 __runcmd install -m 0644 $dota $destpath/
179 fi
180 if [ -f "$dotlai" -a -n "$libtool" ]; then
181 rm -f $destpath/$libname.la
182 __runcmd install -m 0644 $dotlai $destpath/$libname.la
183 fi
184
185 for name in $library_names; do
186 files=`eval echo $name`
187 for f in $files; do
188 if [ ! -e "$f" ]; then
189 if [ -n "$libtool" ]; then
190 bbfatal "oe_libinstall: $dir/$f not found."
191 fi
192 elif [ -L "$f" ]; then
193 __runcmd cp -P "$f" $destpath/
194 elif [ ! -L "$f" ]; then
195 libfile="$f"
196 rm -f $destpath/$libfile
197 __runcmd install -m 0755 $libfile $destpath/
198 fi
199 done
200 done
201
202 if [ -z "$libfile" ]; then
203 if [ -n "$require_shared" ]; then
204 bbfatal "oe_libinstall: unable to locate shared library"
205 fi
206 elif [ -z "$libtool" ]; then
207 # special case hack for non-libtool .so.#.#.# links
208 baselibfile=`basename "$libfile"`
209 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
210 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
211 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
212 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
213 __runcmd ln -sf $baselibfile $destpath/$sonamelink
214 fi
215 __runcmd ln -sf $baselibfile $destpath/$solink
216 fi
217 fi
218
219 __runcmd cd "$olddir"
220}
221
222oe_machinstall() {
223 # Purpose: Install machine dependent files, if available
224 # If not available, check if there is a default
225 # If no default, just touch the destination
226 # Example:
227 # $1 $2 $3 $4
228 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
229 #
230 # TODO: Check argument number?
231 #
232 filename=`basename $3`
233 dirname=`dirname $3`
234
235 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
236 if [ -e $dirname/$o/$filename ]; then
237 bbnote $dirname/$o/$filename present, installing to $4
238 install $1 $2 $dirname/$o/$filename $4
239 return
240 fi
241 done
242# bbnote overrides specific file NOT present, trying default=$3...
243 if [ -e $3 ]; then
244 bbnote $3 present, installing to $4
245 install $1 $2 $3 $4
246 else
247 bbnote $3 NOT present, touching empty $4
248 touch $4
249 fi
250}
251
252create_cmdline_wrapper () {
253 # Create a wrapper script where commandline options are needed
254 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600255 # These are useful to work around relocation issues, by passing extra options
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256 # to a program
257 #
258 # Usage: create_cmdline_wrapper FILENAME <extra-options>
259
260 cmd=$1
261 shift
262
263 echo "Generating wrapper script for $cmd"
264
265 mv $cmd $cmd.real
266 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500267 dirname=`dirname $cmd`
268 cmdoptions=$@
269 if [ "${base_prefix}" != "" ]; then
270 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
271 cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
272 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273 cat <<END >$cmd
274#!/bin/bash
275realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500276realdir=\`dirname \$realpath\`
277exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $cmdoptions "\$@"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278END
279 chmod +x $cmd
280}
281
282create_wrapper () {
283 # Create a wrapper script where extra environment variables are needed
284 #
285 # These are useful to work around relocation issues, by setting environment
286 # variables which point to paths in the filesystem.
287 #
288 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
289
290 cmd=$1
291 shift
292
293 echo "Generating wrapper script for $cmd"
294
295 mv $cmd $cmd.real
296 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500297 dirname=`dirname $cmd`
298 exportstring=$@
299 if [ "${base_prefix}" != "" ]; then
300 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
301 exportstring=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
302 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303 cat <<END >$cmd
304#!/bin/bash
305realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306realdir=\`dirname \$realpath\`
307export $exportstring
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@"
309END
310 chmod +x $cmd
311}
312
313# Copy files/directories from $1 to $2 but using hardlinks
314# (preserve symlinks)
315hardlinkdir () {
316 from=$1
317 to=$2
318 (cd $from; find . -print0 | cpio --null -pdlu $to)
319}
320
321
322def check_app_exists(app, d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500323 app = d.expand(app).split()[0].strip()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500324 path = d.getVar('PATH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325 return bool(bb.utils.which(path, app))
326
327def explode_deps(s):
328 return bb.utils.explode_deps(s)
329
330def base_set_filespath(path, d):
331 filespath = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332 extrapaths = (d.getVar("FILESEXTRAPATHS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 # Remove default flag which was used for checking
334 extrapaths = extrapaths.replace("__default:", "")
335 # Don't prepend empty strings to the path list
336 if extrapaths != "":
337 path = extrapaths.split(":") + path
338 # The ":" ensures we have an 'empty' override
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340 overrides.reverse()
341 for o in overrides:
342 for p in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600343 if p != "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500344 filespath.append(os.path.join(p, o))
345 return ":".join(filespath)
346
347def extend_variants(d, var, extend, delim=':'):
348 """Return a string of all bb class extend variants for the given extend"""
349 variants = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500350 whole = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 for ext in whole.split():
352 eext = ext.split(delim)
353 if len(eext) > 1 and eext[0] == extend:
354 variants.append(eext[1])
355 return " ".join(variants)
356
357def multilib_pkg_extend(d, pkg):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 variants = (d.getVar("MULTILIB_VARIANTS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359 if not variants:
360 return pkg
361 pkgs = pkg
362 for v in variants:
363 pkgs = pkgs + " " + v + "-" + pkg
364 return pkgs
365
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500366def get_multilib_datastore(variant, d):
367 localdata = bb.data.createCopy(d)
368 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + variant
369 localdata.setVar("OVERRIDES", overrides)
370 localdata.setVar("MLPREFIX", variant + "-")
371 return localdata
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500372get_multilib_datastore[vardepsexclude] = "OVERRIDES"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500373
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
375 """Return a string of all ${var} in all multilib tune configuration"""
376 values = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 value = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 if value != "":
379 if need_split:
380 for item in value.split(delim):
381 values.append(item)
382 else:
383 values.append(value)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500384 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500386 localdata = get_multilib_datastore(item, d)
387 value = localdata.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388 if value != "":
389 if need_split:
390 for item in value.split(delim):
391 values.append(item)
392 else:
393 values.append(value)
394 if unique:
395 #we do this to keep order as much as possible
396 ret = []
397 for value in values:
398 if not value in ret:
399 ret.append(value)
400 else:
401 ret = values
402 return " ".join(ret)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600403
404def all_multilib_tune_list(vars, d):
405 """
406 Return a list of ${VAR} for each variable VAR in vars from each
407 multilib tune configuration.
408 Is safe to be called from a multilib recipe/context as it can
409 figure out the original tune and remove the multilib overrides.
410 """
411 values = {}
412 for v in vars:
413 values[v] = []
414
415 localdata = bb.data.createCopy(d)
416 overrides = localdata.getVar("OVERRIDES", False).split(":")
417 newoverrides = []
418 for o in overrides:
419 if not o.startswith("virtclass-multilib-"):
420 newoverrides.append(o)
421 localdata.setVar("OVERRIDES", ":".join(newoverrides))
422 localdata.setVar("MLPREFIX", "")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500423 origdefault = localdata.getVar("DEFAULTTUNE_MULTILIB_ORIGINAL")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600424 if origdefault:
425 localdata.setVar("DEFAULTTUNE", origdefault)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600426 values['ml'] = ['']
427 for v in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500428 values[v].append(localdata.getVar(v))
429 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600430 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500431 localdata = get_multilib_datastore(item, d)
432 values[v].append(localdata.getVar(v))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600433 values['ml'].append(item)
434 return values
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500435all_multilib_tune_list[vardepsexclude] = "OVERRIDES"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600436
437# If the user hasn't set up their name/email, set some defaults
438check_git_config() {
439 if ! git config user.email > /dev/null ; then
440 git config --local user.email "${PATCH_GIT_USER_EMAIL}"
441 fi
442 if ! git config user.name > /dev/null ; then
443 git config --local user.name "${PATCH_GIT_USER_NAME}"
444 fi
445}