1 def legitimize_package_name(s):
2 return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-')
4 def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False):
7 dvar = oe.data.getVar('D', d, 1)
9 oe.error("D not defined")
12 packages = oe.data.getVar('PACKAGES', d, 1).split()
18 postinst = '#!/bin/sh\n' + postinst
20 postrm = '#!/bin/sh\n' + postrm
22 objs = os.listdir(dvar + root)
25 for walkroot, dirs, files in os.walk(dvar + root):
27 relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
31 if extra_depends == None:
32 extra_depends = oe.data.getVar('PKG_' + packages[0], d, 1) or packages[0]
37 m = re.match(file_regex, o)
39 m = re.match(file_regex, os.path.basename(o))
43 f = os.path.join(dvar + root, o)
44 mode = os.lstat(f).st_mode
45 if not (stat.S_ISREG(mode) or (allow_dirs and stat.S_ISDIR(mode))):
47 on = legitimize_package_name(m.group(1))
48 pkg = output_pattern % on
49 if not pkg in packages:
51 packages = [pkg] + packages
54 the_files = [os.path.join(root, o)]
56 if type(aux_files_pattern) is list:
57 for fp in aux_files_pattern:
58 the_files.append(fp % on)
60 the_files.append(aux_files_pattern % on)
61 oe.data.setVar('FILES_' + pkg, " ".join(the_files), d)
62 if extra_depends != '':
63 oe.data.setVar('RDEPENDS_' + pkg, extra_depends, d)
64 oe.data.setVar('DESCRIPTION_' + pkg, description % on, d)
66 oe.data.setVar('pkg_postinst_' + pkg, postinst, d)
68 oe.data.setVar('pkg_postrm_' + pkg, postrm, d)
70 oldfiles = oe.data.getVar('FILES_' + pkg, d, 1)
72 oe.fatal("Package '%s' exists but has no files" % pkg)
73 oe.data.setVar('FILES_' + pkg, oldfiles + " " + os.path.join(root, o), d)
75 hook(f, pkg, file_regex, output_pattern, m.group(1))
77 oe.data.setVar('PACKAGES', ' '.join(packages), d)
79 def package_frob_arch(d):
81 machine = oe.data.getVar('MACHINE', d, 1)
83 # can't specialise if MACHINE not defined
85 old_arch = oe.data.getVar('PACKAGE_ARCH', d, 1)
86 if (old_arch == machine):
90 for p in [ "${FILE_DIRNAME}/${PF}", "${FILE_DIRNAME}/${P}", "${FILE_DIRNAME}/${PN}", "${FILE_DIRNAME}/files", "${FILE_DIRNAME}" ]:
91 paths.append(oe.data.expand(os.path.join(p, machine), d))
92 for s in oe.data.getVar('SRC_URI', d, 1).split():
93 local = oe.data.expand(oe.fetch.localpath(s, d), d)
95 if local.startswith(mp):
96 oe.note("overriding PACKAGE_ARCH from %s to %s" % (old_arch, machine))
97 oe.data.setVar('PACKAGE_ARCH', machine, d)
100 python populate_packages () {
101 import glob, copy, stat, errno, re
103 workdir = oe.data.getVar('WORKDIR', d, 1)
105 oe.error("WORKDIR not defined, unable to package")
108 import os # path manipulations
109 outdir = oe.data.getVar('DEPLOY_DIR', d, 1)
111 oe.error("DEPLOY_DIR not defined, unable to package")
115 dvar = oe.data.getVar('D', d, 1)
117 oe.error("D not defined, unable to package")
121 packages = oe.data.getVar('PACKAGES', d, 1)
123 oe.debug(1, "PACKAGES not defined, nothing to package")
126 pn = oe.data.getVar('PN', d, 1)
128 oe.error("PN not defined")
138 except (os.error, AttributeError):
140 return (s[stat.ST_MODE] & stat.S_IEXEC)
142 for pkg in packages.split():
143 localdata = copy.deepcopy(d)
144 root = os.path.join(workdir, "install", pkg)
146 os.system('rm -rf %s' % root)
148 oe.data.setVar('ROOT', '', localdata)
149 oe.data.setVar('ROOT_%s' % pkg, root, localdata)
150 pkgname = oe.data.getVar('PKG_%s' % pkg, localdata, 1)
153 oe.data.setVar('PKG', pkgname, localdata)
155 overrides = oe.data.getVar('OVERRIDES', localdata, 1)
157 raise oe.build.FuncFailed('OVERRIDES not defined')
158 oe.data.setVar('OVERRIDES', overrides+':'+pkg, localdata)
160 oe.data.update_data(localdata)
162 root = oe.data.getVar('ROOT', localdata, 1)
164 filesvar = oe.data.getVar('FILES', localdata, 1) or ""
165 files = filesvar.split()
168 if os.path.isabs(file):
170 if not os.path.islink(file):
171 if os.path.isdir(file):
172 newfiles = [ os.path.join(file,x) for x in os.listdir(file) ]
176 globbed = glob.glob(file)
178 if [ file ] != globbed:
181 if (not os.path.islink(file)) and (not os.path.exists(file)):
183 fpath = os.path.join(root,file)
184 dpath = os.path.dirname(fpath)
186 if (oe.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1') and not os.path.islink(file) and isexec(file):
187 stripfunc += "${STRIP} %s || : ;\n" % fpath
188 ret = oe.movefile(file,fpath)
189 if ret is None or ret == 0:
190 raise oe.build.FuncFailed("File population failed")
191 if not stripfunc == "":
194 oe.data.setVar('RUNSTRIP', '%s\nreturn 0' % stripfunc, localdata)
195 oe.data.setVarFlag('RUNSTRIP', 'func', 1, localdata)
196 oe.build.exec_func('RUNSTRIP', localdata)
201 for root, dirs, files in os.walk(dvar):
203 path = os.path.join(root[len(dvar):], f)
204 unshipped.append(path)
207 oe.note("the following files were installed but not shipped in any package:")
211 oe.build.exec_func("package_name_hook", d)
213 for pkg in packages.split():
214 if oe.data.getVar('PKG_%s' % pkg, d, 1) is None:
215 oe.data.setVar('PKG_%s' % pkg, pkg, d)
219 for pkg in packages.split():
220 dangling_links[pkg] = []
222 inst_root = os.path.join(workdir, "install", pkg)
223 for root, dirs, files in os.walk(inst_root):
225 path = os.path.join(root, f)
226 rpath = path[len(inst_root):]
227 pkg_files[pkg].append(rpath)
230 except OSError, (err, strerror):
231 if err != errno.ENOENT:
233 target = os.readlink(path)
235 target = os.path.join(root[len(inst_root):], target)
236 dangling_links[pkg].append(os.path.normpath(target))
238 for pkg in packages.split():
239 rdepends = explode_deps(oe.data.getVar('RDEPENDS_' + pkg, d, 1) or oe.data.getVar('RDEPENDS', d, 1) or "")
240 for l in dangling_links[pkg]:
242 oe.debug(1, "%s contains dangling link %s" % (pkg, l))
243 for p in packages.split():
244 for f in pkg_files[p]:
247 oe.debug(1, "target found in %s" % p)
248 dp = oe.data.getVar('PKG_' + p, d, 1) or p
249 if not dp in rdepends:
253 oe.note("%s contains dangling symlink to %s" % (pkg, l))
254 oe.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
256 def write_if_exists(f, pkg, var):
259 c = codecs.getencoder("string_escape")
262 val = oe.data.getVar('%s_%s' % (var, pkg), d, 1)
264 f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
266 data_file = os.path.join(workdir, "install", pn + ".package")
267 f = open(data_file, 'w')
268 f.write("PACKAGES: %s\n" % packages)
269 for pkg in packages.split():
270 write_if_exists(f, pkg, 'DESCRIPTION')
271 write_if_exists(f, pkg, 'RDEPENDS')
272 write_if_exists(f, pkg, 'RPROVIDES')
273 write_if_exists(f, pkg, 'PKG')
274 write_if_exists(f, pkg, 'ALLOW_EMPTY')
275 write_if_exists(f, pkg, 'FILES')
276 write_if_exists(f, pkg, 'pkg_postinst')
277 write_if_exists(f, pkg, 'pkg_postrm')
279 oe.build.exec_func("read_subpackage_metadata", d)
282 ldconfig_postinst_fragment() {
283 if [ x"$D" = "x" ]; then
288 python package_do_shlibs() {
289 import os, re, os.path
291 lib_re = re.compile("^lib.*\.so")
292 libdir_re = re.compile(".*/lib$")
294 packages = oe.data.getVar('PACKAGES', d, 1)
296 oe.debug(1, "no packages to build; not calculating shlibs")
299 workdir = oe.data.getVar('WORKDIR', d, 1)
301 oe.error("WORKDIR not defined")
304 staging = oe.data.getVar('STAGING_DIR', d, 1)
306 oe.error("STAGING_DIR not defined")
309 ver = oe.data.getVar('PV', d, 1)
311 oe.error("PV not defined")
314 target_sys = oe.data.getVar('TARGET_SYS', d, 1)
316 oe.error("TARGET_SYS not defined")
319 shlibs_dir = os.path.join(staging, target_sys, "shlibs")
320 old_shlibs_dir = os.path.join(staging, "shlibs")
321 oe.mkdirhier(shlibs_dir)
324 for pkg in packages.split():
325 needs_ldconfig = False
326 oe.debug(2, "calculating shlib provides for %s" % pkg)
328 pkgname = oe.data.getVar('PKG_%s' % pkg, d, 1)
334 top = os.path.join(workdir, "install", pkg)
335 for root, dirs, files in os.walk(top):
338 path = os.path.join(root, file)
339 if os.access(path, os.X_OK) or lib_re.match(file):
340 cmd = (oe.data.getVar('BUILD_PREFIX', d, 1) or "") + "objdump -p " + path + " 2>/dev/null"
342 lines = fd.readlines()
345 m = re.match("\s+NEEDED\s+([^\s]*)", l)
347 needed[pkg].append(m.group(1))
348 m = re.match("\s+SONAME\s+([^\s]*)", l)
349 if m and not m.group(1) in sonames:
350 sonames.append(m.group(1))
351 if m and libdir_re.match(root):
352 needs_ldconfig = True
353 shlibs_file = os.path.join(shlibs_dir, pkgname + ".list")
354 if os.path.exists(shlibs_file):
355 os.remove(shlibs_file)
356 shver_file = os.path.join(shlibs_dir, pkgname + ".ver")
357 if os.path.exists(shver_file):
358 os.remove(shver_file)
360 fd = open(shlibs_file, 'w')
364 fd = open(shver_file, 'w')
368 oe.note('adding ldconfig call to postinst for %s' % pkg)
369 postinst = oe.data.getVar('pkg_postinst_%s' % pkg, d, 1) or oe.data.getVar('pkg_postinst', d, 1)
371 postinst = '#!/bin/sh\n'
372 postinst += oe.data.getVar('ldconfig_postinst_fragment', d, 1)
373 oe.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
376 list_re = re.compile('^(.*)\.list$')
377 for dir in [shlibs_dir, old_shlibs_dir]:
378 if not os.path.exists(dir):
380 for file in os.listdir(dir):
381 m = list_re.match(file)
384 fd = open(os.path.join(dir, file))
385 lines = fd.readlines()
387 ver_file = os.path.join(dir, dep_pkg + '.ver')
389 if os.path.exists(ver_file):
391 lib_ver = fd.readline().rstrip()
394 shlib_provider[l.rstrip()] = (dep_pkg, lib_ver)
397 for pkg in packages.split():
398 oe.debug(2, "calculating shlib requirements for %s" % pkg)
401 for n in needed[pkg]:
402 if n in shlib_provider.keys():
403 (dep_pkg, ver_needed) = shlib_provider[n]
406 dep = "%s (>= %s)" % (dep_pkg, ver_needed)
412 oe.note("Couldn't find shared library provider for %s" % n)
415 deps_file = os.path.join(workdir, "install", pkg + ".shlibdeps")
416 if os.path.exists(deps_file):
419 fd = open(deps_file, 'w')
425 python package_do_pkgconfig () {
428 packages = oe.data.getVar('PACKAGES', d, 1)
430 oe.debug(1, "no packages to build; not calculating pkgconfig dependencies")
433 workdir = oe.data.getVar('WORKDIR', d, 1)
435 oe.error("WORKDIR not defined")
438 staging = oe.data.getVar('STAGING_DIR', d, 1)
440 oe.error("STAGING_DIR not defined")
443 pc_re = re.compile('(.*)\.pc$')
444 var_re = re.compile('(.*)=(.*)')
445 field_re = re.compile('(.*): (.*)')
447 pkgconfig_provided = {}
448 pkgconfig_needed = {}
449 for pkg in packages.split():
450 pkgconfig_provided[pkg] = []
451 pkgconfig_needed[pkg] = []
452 top = os.path.join(workdir, "install", pkg)
453 for root, dirs, files in os.walk(top):
455 m = pc_re.match(file)
459 pkgconfig_provided[pkg].append(name)
460 path = os.path.join(root, file)
461 if not os.access(path, os.R_OK):
464 lines = f.readlines()
471 oe.data.setVar(name, oe.data.expand(val, pd), pd)
473 m = field_re.match(l)
476 exp = oe.data.expand(m.group(2), pd)
477 if hdr == 'Requires':
478 pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
480 shlibs_dir = os.path.join(staging, "shlibs")
481 oe.mkdirhier(shlibs_dir)
483 for pkg in packages.split():
484 pkgs_file = os.path.join(shlibs_dir, pkg + ".pclist")
485 if os.path.exists(pkgs_file):
487 if pkgconfig_provided[pkg] != []:
488 f = open(pkgs_file, 'w')
489 for p in pkgconfig_provided[pkg]:
493 for file in os.listdir(shlibs_dir):
494 m = re.match('^(.*)\.pclist$', file)
497 fd = open(os.path.join(shlibs_dir, file))
498 lines = fd.readlines()
500 pkgconfig_provided[pkg] = []
502 pkgconfig_provided[pkg].append(l.rstrip())
504 for pkg in packages.split():
506 for n in pkgconfig_needed[pkg]:
508 for k in pkgconfig_provided.keys():
509 if n in pkgconfig_provided[k]:
510 if k != pkg and not (k in deps):
514 oe.note("couldn't find pkgconfig module '%s' in any package" % n)
515 deps_file = os.path.join(workdir, "install", pkg + ".pcdeps")
516 if os.path.exists(deps_file):
519 fd = open(deps_file, 'w')
525 python package_do_split_locales() {
528 if (oe.data.getVar('PACKAGE_NO_LOCALE', d, 1) == '1'):
529 oe.debug(1, "package requested not splitting locales")
532 packages = (oe.data.getVar('PACKAGES', d, 1) or "").split()
534 oe.debug(1, "no packages to build; not splitting locales")
537 datadir = oe.data.getVar('datadir', d, 1)
539 oe.note("datadir not defined")
542 dvar = oe.data.getVar('D', d, 1)
544 oe.error("D not defined")
547 pn = oe.data.getVar('PN', d, 1)
549 oe.error("PN not defined")
552 if pn + '-locale' in packages:
553 packages.remove(pn + '-locale')
555 localedir = os.path.join(dvar + datadir, 'locale')
557 if not os.path.isdir(localedir):
558 oe.note("No locale files in this package")
561 locales = os.listdir(localedir)
563 mainpkg = packages[0]
566 ln = legitimize_package_name(l)
567 pkg = pn + '-locale-' + ln
569 oe.data.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l), d)
570 oe.data.setVar('RDEPENDS_' + pkg, '${PKG_%s} virtual-locale-%s' % (mainpkg, ln), d)
571 oe.data.setVar('RPROVIDES_' + pkg, '%s-locale %s-translation' % (pn, ln), d)
572 oe.data.setVar('DESCRIPTION_' + pkg, '%s translation for %s' % (l, pn), d)
574 oe.data.setVar('PACKAGES', ' '.join(packages), d)
576 rrec = (oe.data.getVar('RRECOMMENDS_%s' % mainpkg, d, 1) or oe.data.getVar('RRECOMMENDS', d, 1) or "").split()
577 rrec.append('%s-locale*' % pn)
578 oe.data.setVar('RRECOMMENDS_%s' % mainpkg, ' '.join(rrec), d)
581 python package_do_package () {
582 oe.build.exec_func('do_install', d)
583 oe.build.exec_func('package_do_split_locales', d)
584 oe.build.exec_func('populate_packages', d)
585 oe.build.exec_func('package_do_shlibs', d)
586 oe.build.exec_func('package_do_pkgconfig', d)
587 oe.build.exec_func('read_shlibdeps', d)
590 do_package[dirs] = "${D}"
591 populate_packages[dirs] = "${D}"
592 EXPORT_FUNCTIONS do_package do_shlibs do_split_locales
593 addtask package before do_build after do_populate_staging