blob: 96463ab323f9d2577a97d846ce15ad5ecc144e1f [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):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600323 app = d.expand(app).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
372
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
374 """Return a string of all ${var} in all multilib tune configuration"""
375 values = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500376 value = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377 if value != "":
378 if need_split:
379 for item in value.split(delim):
380 values.append(item)
381 else:
382 values.append(value)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500383 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500385 localdata = get_multilib_datastore(item, d)
386 value = localdata.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387 if value != "":
388 if need_split:
389 for item in value.split(delim):
390 values.append(item)
391 else:
392 values.append(value)
393 if unique:
394 #we do this to keep order as much as possible
395 ret = []
396 for value in values:
397 if not value in ret:
398 ret.append(value)
399 else:
400 ret = values
401 return " ".join(ret)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600402
403def all_multilib_tune_list(vars, d):
404 """
405 Return a list of ${VAR} for each variable VAR in vars from each
406 multilib tune configuration.
407 Is safe to be called from a multilib recipe/context as it can
408 figure out the original tune and remove the multilib overrides.
409 """
410 values = {}
411 for v in vars:
412 values[v] = []
413
414 localdata = bb.data.createCopy(d)
415 overrides = localdata.getVar("OVERRIDES", False).split(":")
416 newoverrides = []
417 for o in overrides:
418 if not o.startswith("virtclass-multilib-"):
419 newoverrides.append(o)
420 localdata.setVar("OVERRIDES", ":".join(newoverrides))
421 localdata.setVar("MLPREFIX", "")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500422 origdefault = localdata.getVar("DEFAULTTUNE_MULTILIB_ORIGINAL")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600423 if origdefault:
424 localdata.setVar("DEFAULTTUNE", origdefault)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600425 values['ml'] = ['']
426 for v in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500427 values[v].append(localdata.getVar(v))
428 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600429 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500430 localdata = get_multilib_datastore(item, d)
431 values[v].append(localdata.getVar(v))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600432 values['ml'].append(item)
433 return values
434
435# If the user hasn't set up their name/email, set some defaults
436check_git_config() {
437 if ! git config user.email > /dev/null ; then
438 git config --local user.email "${PATCH_GIT_USER_EMAIL}"
439 fi
440 if ! git config user.name > /dev/null ; then
441 git config --local user.name "${PATCH_GIT_USER_NAME}"
442 fi
443}