blob: dbb5e4cbbc7025e4f242852853f65e868909b92b [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"""
44 machine = d.getVar("MACHINE", True)
45 filespathpkg = d.getVar("FILESPATHPKG", True).split(":")
46 for basepath in d.getVar("FILESPATHBASE", True).split(":"):
47 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))
55 srcuri = d.getVar("SRC_URI", True).split()
56 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`
267 cat <<END >$cmd
268#!/bin/bash
269realpath=\`readlink -fn \$0\`
270exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $@ "\$@"
271END
272 chmod +x $cmd
273}
274
275create_wrapper () {
276 # Create a wrapper script where extra environment variables are needed
277 #
278 # These are useful to work around relocation issues, by setting environment
279 # variables which point to paths in the filesystem.
280 #
281 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
282
283 cmd=$1
284 shift
285
286 echo "Generating wrapper script for $cmd"
287
288 mv $cmd $cmd.real
289 cmdname=`basename $cmd`
290 cat <<END >$cmd
291#!/bin/bash
292realpath=\`readlink -fn \$0\`
293export $@
294exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@"
295END
296 chmod +x $cmd
297}
298
299# Copy files/directories from $1 to $2 but using hardlinks
300# (preserve symlinks)
301hardlinkdir () {
302 from=$1
303 to=$2
304 (cd $from; find . -print0 | cpio --null -pdlu $to)
305}
306
307
308def check_app_exists(app, d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600309 app = d.expand(app).strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 path = d.getVar('PATH', d, True)
311 return bool(bb.utils.which(path, app))
312
313def explode_deps(s):
314 return bb.utils.explode_deps(s)
315
316def base_set_filespath(path, d):
317 filespath = []
318 extrapaths = (d.getVar("FILESEXTRAPATHS", True) or "")
319 # Remove default flag which was used for checking
320 extrapaths = extrapaths.replace("__default:", "")
321 # Don't prepend empty strings to the path list
322 if extrapaths != "":
323 path = extrapaths.split(":") + path
324 # The ":" ensures we have an 'empty' override
325 overrides = (":" + (d.getVar("FILESOVERRIDES", True) or "")).split(":")
326 overrides.reverse()
327 for o in overrides:
328 for p in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600329 if p != "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330 filespath.append(os.path.join(p, o))
331 return ":".join(filespath)
332
333def extend_variants(d, var, extend, delim=':'):
334 """Return a string of all bb class extend variants for the given extend"""
335 variants = []
336 whole = d.getVar(var, True) or ""
337 for ext in whole.split():
338 eext = ext.split(delim)
339 if len(eext) > 1 and eext[0] == extend:
340 variants.append(eext[1])
341 return " ".join(variants)
342
343def multilib_pkg_extend(d, pkg):
344 variants = (d.getVar("MULTILIB_VARIANTS", True) or "").split()
345 if not variants:
346 return pkg
347 pkgs = pkg
348 for v in variants:
349 pkgs = pkgs + " " + v + "-" + pkg
350 return pkgs
351
352def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
353 """Return a string of all ${var} in all multilib tune configuration"""
354 values = []
355 value = d.getVar(var, True) or ""
356 if value != "":
357 if need_split:
358 for item in value.split(delim):
359 values.append(item)
360 else:
361 values.append(value)
362 variants = d.getVar("MULTILIB_VARIANTS", True) or ""
363 for item in variants.split():
364 localdata = bb.data.createCopy(d)
365 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
366 localdata.setVar("OVERRIDES", overrides)
367 localdata.setVar("MLPREFIX", item + "-")
368 bb.data.update_data(localdata)
369 value = localdata.getVar(var, True) or ""
370 if value != "":
371 if need_split:
372 for item in value.split(delim):
373 values.append(item)
374 else:
375 values.append(value)
376 if unique:
377 #we do this to keep order as much as possible
378 ret = []
379 for value in values:
380 if not value in ret:
381 ret.append(value)
382 else:
383 ret = values
384 return " ".join(ret)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600385
386def all_multilib_tune_list(vars, d):
387 """
388 Return a list of ${VAR} for each variable VAR in vars from each
389 multilib tune configuration.
390 Is safe to be called from a multilib recipe/context as it can
391 figure out the original tune and remove the multilib overrides.
392 """
393 values = {}
394 for v in vars:
395 values[v] = []
396
397 localdata = bb.data.createCopy(d)
398 overrides = localdata.getVar("OVERRIDES", False).split(":")
399 newoverrides = []
400 for o in overrides:
401 if not o.startswith("virtclass-multilib-"):
402 newoverrides.append(o)
403 localdata.setVar("OVERRIDES", ":".join(newoverrides))
404 localdata.setVar("MLPREFIX", "")
405 origdefault = localdata.getVar("DEFAULTTUNE_MULTILIB_ORIGINAL", True)
406 if origdefault:
407 localdata.setVar("DEFAULTTUNE", origdefault)
408 bb.data.update_data(localdata)
409 values['ml'] = ['']
410 for v in vars:
411 values[v].append(localdata.getVar(v, True))
412 variants = d.getVar("MULTILIB_VARIANTS", True) or ""
413 for item in variants.split():
414 localdata = bb.data.createCopy(d)
415 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
416 localdata.setVar("OVERRIDES", overrides)
417 localdata.setVar("MLPREFIX", item + "-")
418 bb.data.update_data(localdata)
419 values[v].append(localdata.getVar(v, True))
420 values['ml'].append(item)
421 return values
422
423# If the user hasn't set up their name/email, set some defaults
424check_git_config() {
425 if ! git config user.email > /dev/null ; then
426 git config --local user.email "${PATCH_GIT_USER_EMAIL}"
427 fi
428 if ! git config user.name > /dev/null ; then
429 git config --local user.name "${PATCH_GIT_USER_NAME}"
430 fi
431}