summaryrefslogtreecommitdiffstats
path: root/meta/classes/utils.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-03-19 23:12:06 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-19 23:12:06 +0000
commit9c5386c1fd74d832cf6e2acad3c69b1cc90de6b2 (patch)
treeaa2db23da10e883f0f8627f5993cd2cfade2e705 /meta/classes/utils.bbclass
parent185cb38f1319856b4bdaaf4d9a73b5056be53d54 (diff)
downloadpoky-9c5386c1fd74d832cf6e2acad3c69b1cc90de6b2.tar.gz
base.bbclass: Split up as per the patch in OE.dev by Chris Larson making code more readable and modularised
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'meta/classes/utils.bbclass')
-rw-r--r--meta/classes/utils.bbclass340
1 files changed, 340 insertions, 0 deletions
diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
new file mode 100644
index 0000000000..c2d323235b
--- /dev/null
+++ b/meta/classes/utils.bbclass
@@ -0,0 +1,340 @@
1# like os.path.join but doesn't treat absolute RHS specially
2def base_path_join(a, *p):
3 path = a
4 for b in p:
5 if path == '' or path.endswith('/'):
6 path += b
7 else:
8 path += '/' + b
9 return path
10
11# for MD5/SHA handling
12def base_chk_load_parser(config_path):
13 import ConfigParser
14 parser = ConfigParser.ConfigParser()
15 if not len(parser.read(config_path)) == 1:
16 bb.note("Can not open the '%s' ini file" % config_path)
17 raise Exception("Can not open the '%s'" % config_path)
18
19 return parser
20
21def base_chk_file(parser, pn, pv, src_uri, localpath, data):
22 no_checksum = False
23 # Try PN-PV-SRC_URI first and then try PN-SRC_URI
24 # we rely on the get method to create errors
25 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
26 pn_src = "%s-%s" % (pn,src_uri)
27 if parser.has_section(pn_pv_src):
28 md5 = parser.get(pn_pv_src, "md5")
29 sha256 = parser.get(pn_pv_src, "sha256")
30 elif parser.has_section(pn_src):
31 md5 = parser.get(pn_src, "md5")
32 sha256 = parser.get(pn_src, "sha256")
33 elif parser.has_section(src_uri):
34 md5 = parser.get(src_uri, "md5")
35 sha256 = parser.get(src_uri, "sha256")
36 else:
37 no_checksum = True
38
39 # md5 and sha256 should be valid now
40 if not os.path.exists(localpath):
41 bb.note("The localpath does not exist '%s'" % localpath)
42 raise Exception("The path does not exist '%s'" % localpath)
43
44
45 # Calculate the MD5 and 256-bit SHA checksums
46 md5data = bb.utils.md5_file(localpath)
47 shadata = bb.utils.sha256_file(localpath)
48
49 # sha256_file() can return None if we are running on Python 2.4 (hashlib is
50 # 2.5 onwards, sha in 2.4 is 160-bit only), so check for this and call the
51 # standalone shasum binary if required.
52 if shadata is None:
53 try:
54 shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
55 shadata = (shapipe.readline().split() or [ "" ])[0]
56 shapipe.close()
57 except OSError:
58 raise Exception("Executing shasum failed, please build shasum-native")
59
60 if no_checksum == True: # we do not have conf/checksums.ini entry
61 try:
62 file = open("%s/checksums.ini" % bb.data.getVar("TMPDIR", data, 1), "a")
63 except:
64 return False
65
66 if not file:
67 raise Exception("Creating checksums.ini failed")
68
69 file.write("[%s]\nmd5=%s\nsha256=%s\n\n" % (src_uri, md5data, shadata))
70 file.close()
71 return False
72
73 if not md5 == md5data:
74 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (md5,md5data))
75 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
76
77 if not sha256 == shadata:
78 bb.note("The SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256,shadata))
79 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
80
81 return True
82
83def base_read_file(filename):
84 try:
85 f = file( filename, "r" )
86 except IOError, reason:
87 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
88 else:
89 return f.read().strip()
90 return None
91
92def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
93 if bb.data.getVar(variable,d,1) == checkvalue:
94 return truevalue
95 else:
96 return falsevalue
97
98def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
99 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
100 return truevalue
101 else:
102 return falsevalue
103
104def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
105 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
106 if result <= 0:
107 return truevalue
108 else:
109 return falsevalue
110
111def base_contains(variable, checkvalues, truevalue, falsevalue, d):
112 matches = 0
113 if type(checkvalues).__name__ == "str":
114 checkvalues = [checkvalues]
115 for value in checkvalues:
116 if bb.data.getVar(variable,d,1).find(value) != -1:
117 matches = matches + 1
118 if matches == len(checkvalues):
119 return truevalue
120 return falsevalue
121
122def base_both_contain(variable1, variable2, checkvalue, d):
123 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
124 return checkvalue
125 else:
126 return ""
127
128def base_prune_suffix(var, suffixes, d):
129 # See if var ends with any of the suffixes listed and
130 # remove it if found
131 for suffix in suffixes:
132 if var.endswith(suffix):
133 return var.replace(suffix, "")
134 return var
135
136def oe_filter(f, str, d):
137 from re import match
138 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
139
140def oe_filter_out(f, str, d):
141 from re import match
142 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
143
144oe_soinstall() {
145 # Purpose: Install shared library file and
146 # create the necessary links
147 # Example:
148 #
149 # oe_
150 #
151 #oenote installing shared library $1 to $2
152 #
153 libname=`basename $1`
154 install -m 755 $1 $2/$libname
155 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
156 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
157 ln -sf $libname $2/$sonamelink
158 ln -sf $libname $2/$solink
159}
160
161oe_libinstall() {
162 # Purpose: Install a library, in all its forms
163 # Example
164 #
165 # oe_libinstall libltdl ${STAGING_LIBDIR}/
166 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
167 dir=""
168 libtool=""
169 silent=""
170 require_static=""
171 require_shared=""
172 staging_install=""
173 while [ "$#" -gt 0 ]; do
174 case "$1" in
175 -C)
176 shift
177 dir="$1"
178 ;;
179 -s)
180 silent=1
181 ;;
182 -a)
183 require_static=1
184 ;;
185 -so)
186 require_shared=1
187 ;;
188 -*)
189 oefatal "oe_libinstall: unknown option: $1"
190 ;;
191 *)
192 break;
193 ;;
194 esac
195 shift
196 done
197
198 libname="$1"
199 shift
200 destpath="$1"
201 if [ -z "$destpath" ]; then
202 oefatal "oe_libinstall: no destination path specified"
203 fi
204 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
205 then
206 staging_install=1
207 fi
208
209 __runcmd () {
210 if [ -z "$silent" ]; then
211 echo >&2 "oe_libinstall: $*"
212 fi
213 $*
214 }
215
216 if [ -z "$dir" ]; then
217 dir=`pwd`
218 fi
219
220 dotlai=$libname.lai
221
222 # Sanity check that the libname.lai is unique
223 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
224 if [ $number_of_files -gt 1 ]; then
225 oefatal "oe_libinstall: $dotlai is not unique in $dir"
226 fi
227
228
229 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
230 olddir=`pwd`
231 __runcmd cd $dir
232
233 lafile=$libname.la
234
235 # If such file doesn't exist, try to cut version suffix
236 if [ ! -f "$lafile" ]; then
237 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
238 lafile1=$libname.la
239 if [ -f "$lafile1" ]; then
240 libname=$libname1
241 lafile=$lafile1
242 fi
243 fi
244
245 if [ -f "$lafile" ]; then
246 # libtool archive
247 eval `cat $lafile|grep "^library_names="`
248 libtool=1
249 else
250 library_names="$libname.so* $libname.dll.a"
251 fi
252
253 __runcmd install -d $destpath/
254 dota=$libname.a
255 if [ -f "$dota" -o -n "$require_static" ]; then
256 rm -f $destpath/$dota
257 __runcmd install -m 0644 $dota $destpath/
258 fi
259 if [ -f "$dotlai" -a -n "$libtool" ]; then
260 if test -n "$staging_install"
261 then
262 # stop libtool using the final directory name for libraries
263 # in staging:
264 __runcmd rm -f $destpath/$libname.la
265 __runcmd sed -e 's/^installed=yes$/installed=no/' \
266 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
267 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
268 $dotlai >$destpath/$libname.la
269 else
270 rm -f $destpath/$libname.la
271 __runcmd install -m 0644 $dotlai $destpath/$libname.la
272 fi
273 fi
274
275 for name in $library_names; do
276 files=`eval echo $name`
277 for f in $files; do
278 if [ ! -e "$f" ]; then
279 if [ -n "$libtool" ]; then
280 oefatal "oe_libinstall: $dir/$f not found."
281 fi
282 elif [ -L "$f" ]; then
283 __runcmd cp -P "$f" $destpath/
284 elif [ ! -L "$f" ]; then
285 libfile="$f"
286 rm -f $destpath/$libfile
287 __runcmd install -m 0755 $libfile $destpath/
288 fi
289 done
290 done
291
292 if [ -z "$libfile" ]; then
293 if [ -n "$require_shared" ]; then
294 oefatal "oe_libinstall: unable to locate shared library"
295 fi
296 elif [ -z "$libtool" ]; then
297 # special case hack for non-libtool .so.#.#.# links
298 baselibfile=`basename "$libfile"`
299 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
300 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
301 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
302 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
303 __runcmd ln -sf $baselibfile $destpath/$sonamelink
304 fi
305 __runcmd ln -sf $baselibfile $destpath/$solink
306 fi
307 fi
308
309 __runcmd cd "$olddir"
310}
311
312oe_machinstall() {
313 # Purpose: Install machine dependent files, if available
314 # If not available, check if there is a default
315 # If no default, just touch the destination
316 # Example:
317 # $1 $2 $3 $4
318 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
319 #
320 # TODO: Check argument number?
321 #
322 filename=`basename $3`
323 dirname=`dirname $3`
324
325 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
326 if [ -e $dirname/$o/$filename ]; then
327 oenote $dirname/$o/$filename present, installing to $4
328 install $1 $2 $dirname/$o/$filename $4
329 return
330 fi
331 done
332# oenote overrides specific file NOT present, trying default=$3...
333 if [ -e $3 ]; then
334 oenote $3 present, installing to $4
335 install $1 $2 $3 $4
336 else
337 oenote $3 NOT present, touching empty $4
338 touch $4
339 fi
340}