diff options
Diffstat (limited to 'meta/classes/package.bbclass')
| -rw-r--r-- | meta/classes/package.bbclass | 1667 |
1 files changed, 971 insertions, 696 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 9885d94101..cc466bd1b2 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass @@ -39,9 +39,11 @@ # packaging steps inherit packagedata -inherit prserv inherit chrpath +# Need the package_qa_handle_error() in insane.bbclass +inherit insane + PKGD = "${WORKDIR}/package" PKGDEST = "${WORKDIR}/packages-split" @@ -52,6 +54,14 @@ ALL_MULTILIB_PACKAGE_ARCHS = "${@all_multilib_tune_values(d, 'PACKAGE_ARCHS')}" # rpm is used for the per-file dependency identification PACKAGE_DEPENDS += "rpm-native" + +# If your postinstall can execute at rootfs creation time rather than on +# target but depends on a native/cross tool in order to execute, you need to +# list that tool in PACKAGE_WRITE_DEPENDS. Target package dependencies belong +# in the package dependencies as normal, this is just for native/cross support +# tools at rootfs build time. +PACKAGE_WRITE_DEPS ??= "" + def legitimize_package_name(s): """ Make sure package names are legitimate strings @@ -61,7 +71,7 @@ def legitimize_package_name(s): def fixutf(m): cp = m.group(1) if cp: - return ('\u%s' % cp).decode('unicode_escape').encode('utf-8') + return ('\\u%s' % cp).encode('latin-1').decode('unicode_escape') # Handle unicode codepoints encoded as <U0123>, as in glibc locale files. s = re.sub('<U([0-9A-Fa-f]{1,4})>', fixutf, s) @@ -69,7 +79,7 @@ def legitimize_package_name(s): # Remaining package name validity fixes return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-') -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, aux_files_pattern_verbatim=None, allow_links=False): +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, aux_files_pattern_verbatim=None, allow_links=False, summary=None): """ Used in .bb files to split up dynamically generated subpackages of a given package, usually plugins or modules. @@ -113,17 +123,22 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst package name. Can be a single string item or a list of strings for multiple items. Must include %s. allow_links -- True to allow symlinks to be matched - default False + summary -- Summary to set for each package. Must include %s; + defaults to description if not set. """ - dvar = d.getVar('PKGD', True) + dvar = d.getVar('PKGD') + root = d.expand(root) + output_pattern = d.expand(output_pattern) + extra_depends = d.expand(extra_depends) # If the root directory doesn't exist, don't error out later but silently do # no splitting. if not os.path.exists(dvar + root): - return + return [] - ml = d.getVar("MLPREFIX", True) + ml = d.getVar("MLPREFIX") if ml: if not output_pattern.startswith(ml): output_pattern = ml + output_pattern @@ -138,7 +153,8 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst extra_depends = " ".join(newdeps) - packages = d.getVar('PACKAGES', True).split() + packages = d.getVar('PACKAGES').split() + split_packages = set() if postinst: postinst = '#!/bin/sh\n' + postinst + '\n' @@ -155,7 +171,10 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst objs.append(relpath) if extra_depends == None: - extra_depends = d.getVar("PN", True) + extra_depends = d.getVar("PN") + + if not summary: + summary = description for o in sorted(objs): import re, stat @@ -172,14 +191,20 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst continue on = legitimize_package_name(m.group(1)) pkg = output_pattern % on + split_packages.add(pkg) if not pkg in packages: if prepend: packages = [pkg] + packages else: packages.append(pkg) - oldfiles = d.getVar('FILES_' + pkg, True) + oldfiles = d.getVar('FILES_' + pkg) + newfile = os.path.join(root, o) + # These names will be passed through glob() so if the filename actually + # contains * or ? (rare, but possible) we need to handle that specially + newfile = newfile.replace('*', '[*]') + newfile = newfile.replace('?', '[?]') if not oldfiles: - the_files = [os.path.join(root, o)] + the_files = [newfile] if aux_files_pattern: if type(aux_files_pattern) is list: for fp in aux_files_pattern: @@ -193,53 +218,134 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst else: the_files.append(aux_files_pattern_verbatim % m.group(1)) d.setVar('FILES_' + pkg, " ".join(the_files)) - if extra_depends != '': - d.appendVar('RDEPENDS_' + pkg, ' ' + extra_depends) - d.setVar('DESCRIPTION_' + pkg, description % on) - if postinst: - d.setVar('pkg_postinst_' + pkg, postinst) - if postrm: - d.setVar('pkg_postrm_' + pkg, postrm) else: - d.setVar('FILES_' + pkg, oldfiles + " " + os.path.join(root, o)) + d.setVar('FILES_' + pkg, oldfiles + " " + newfile) + if extra_depends != '': + d.appendVar('RDEPENDS_' + pkg, ' ' + extra_depends) + if not d.getVar('DESCRIPTION_' + pkg): + d.setVar('DESCRIPTION_' + pkg, description % on) + if not d.getVar('SUMMARY_' + pkg): + d.setVar('SUMMARY_' + pkg, summary % on) + if postinst: + d.setVar('pkg_postinst_' + pkg, postinst) + if postrm: + d.setVar('pkg_postrm_' + pkg, postrm) if callable(hook): hook(f, pkg, file_regex, output_pattern, m.group(1)) d.setVar('PACKAGES', ' '.join(packages)) + return list(split_packages) PACKAGE_DEPENDS += "file-native" python () { - if d.getVar('PACKAGES', True) != '': + if d.getVar('PACKAGES') != '': deps = "" - for dep in (d.getVar('PACKAGE_DEPENDS', True) or "").split(): + for dep in (d.getVar('PACKAGE_DEPENDS') or "").split(): deps += " %s:do_populate_sysroot" % dep d.appendVarFlag('do_package', 'depends', deps) # shlibs requires any DEPENDS to have already packaged for the *.list files - d.appendVarFlag('do_package', 'deptask', " do_package") - - elif not bb.data.inherits_class('image', d): - d.setVar("PACKAGERDEPTASK", "") + d.appendVarFlag('do_package', 'deptask', " do_packagedata") } -def splitfile(file, debugfile, debugsrcdir, d): - # Function to split a single file, called from split_and_strip_files below - # A working 'file' (one which works on the target architecture) - # is split and the split off portions go to debugfile. +# Get a list of files from file vars by searching files under current working directory +# The list contains symlinks, directories and normal files. +def files_from_filevars(filevars): + import os,glob + cpath = oe.cachedpath.CachedPath() + files = [] + for f in filevars: + if os.path.isabs(f): + f = '.' + f + if not f.startswith("./"): + f = './' + f + globbed = glob.glob(f) + if globbed: + if [ f ] != globbed: + files += globbed + continue + files.append(f) + + symlink_paths = [] + for ind, f in enumerate(files): + # Handle directory symlinks. Truncate path to the lowest level symlink + parent = '' + for dirname in f.split('/')[:-1]: + parent = os.path.join(parent, dirname) + if dirname == '.': + continue + if cpath.islink(parent): + bb.warn("FILES contains file '%s' which resides under a " + "directory symlink. Please fix the recipe and use the " + "real path for the file." % f[1:]) + symlink_paths.append(f) + files[ind] = parent + f = parent + break + + if not cpath.islink(f): + if cpath.isdir(f): + newfiles = [ os.path.join(f,x) for x in os.listdir(f) ] + if newfiles: + files += newfiles + + return files, symlink_paths + +# Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files +def get_conffiles(pkg, d): + pkgdest = d.getVar('PKGDEST') + root = os.path.join(pkgdest, pkg) + cwd = os.getcwd() + os.chdir(root) + + conffiles = d.getVar('CONFFILES_%s' % pkg); + if conffiles == None: + conffiles = d.getVar('CONFFILES') + if conffiles == None: + conffiles = "" + conffiles = conffiles.split() + conf_orig_list = files_from_filevars(conffiles)[0] + + # Remove links and directories from conf_orig_list to get conf_list which only contains normal files + conf_list = [] + for f in conf_orig_list: + if os.path.isdir(f): + continue + if os.path.islink(f): + continue + if not os.path.exists(f): + continue + conf_list.append(f) + + # Remove the leading './' + for i in range(0, len(conf_list)): + conf_list[i] = conf_list[i][1:] + + os.chdir(cwd) + return conf_list + +def checkbuildpath(file, d): + tmpdir = d.getVar('TMPDIR') + with open(file) as f: + file_content = f.read() + if tmpdir in file_content: + return True + + return False + +def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): + # Function to split a single file into two components, one is the stripped + # target system binary, the other contains any debugging information. The + # two files are linked to reference each other. # - # The debug information is then processed for src references. These - # references are copied to debugsrcdir, if defined. + # sourcefile is also generated containing a list of debugsources - import commands, stat, subprocess + import stat - dvar = d.getVar('PKGD', True) - pathprefix = "export PATH=%s; " % d.getVar('PATH', True) - objcopy = d.getVar("OBJCOPY", True) - debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/bin/debugedit") - workdir = d.getVar("WORKDIR", True) - workparentdir = d.getVar("DEBUGSRC_OVERRIDE_PATH", True) or os.path.dirname(os.path.dirname(workdir)) - sourcefile = d.expand("${WORKDIR}/debugsources.list") + dvar = d.getVar('PKGD') + objcopy = d.getVar("OBJCOPY") + debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/debugedit") # We ignore kernel modules, we don't generate debug info files. if file.find("/lib/modules/") != -1 and file.endswith(".ko"): @@ -253,215 +359,228 @@ def splitfile(file, debugfile, debugsrcdir, d): # We need to extract the debug src information here... if debugsrcdir: - subprocess.call("%s'%s' -b '%s' -d '%s' -i -l '%s' '%s'" % (pathprefix, debugedit, workparentdir, debugsrcdir, sourcefile, file), shell=True) + cmd = "'%s' -i -l '%s' '%s'" % (debugedit, sourcefile, file) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("debugedit failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) - bb.mkdirhier(os.path.dirname(debugfile)) + bb.utils.mkdirhier(os.path.dirname(debugfile)) - subprocess.call("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile), shell=True) + cmd = "'%s' --only-keep-debug '%s' '%s'" % (objcopy, file, debugfile) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("objcopy failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) # Set the debuglink to have the view of the file path on the target - subprocess.call("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file), shell=True) + cmd = "'%s' --add-gnu-debuglink='%s' '%s'" % (objcopy, debugfile, file) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("objcopy failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) if newmode: os.chmod(file, origmode) return 0 -def splitfile2(debugsrcdir, d): - # Function to split a single file, called from split_and_strip_files below - # - # The debug src information processed in the splitfile2 is further procecessed +def copydebugsources(debugsrcdir, d): + # The debug src information written out to sourcefile is further procecessed # and copied to the destination here. - import commands, stat, subprocess + import stat sourcefile = d.expand("${WORKDIR}/debugsources.list") if debugsrcdir and os.path.isfile(sourcefile): - dvar = d.getVar('PKGD', True) - pathprefix = "export PATH=%s; " % d.getVar('PATH', True) - strip = d.getVar("STRIP", True) - objcopy = d.getVar("OBJCOPY", True) + dvar = d.getVar('PKGD') + strip = d.getVar("STRIP") + objcopy = d.getVar("OBJCOPY") debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/bin/debugedit") - workdir = d.getVar("WORKDIR", True) + workdir = d.getVar("WORKDIR") workparentdir = os.path.dirname(os.path.dirname(workdir)) workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir) + # If build path exists in sourcefile, it means toolchain did not use + # -fdebug-prefix-map to compile + if checkbuildpath(sourcefile, d): + localsrc_prefix = workparentdir + "/" + else: + localsrc_prefix = "/usr/src/debug/" + nosuchdir = [] basepath = dvar for p in debugsrcdir.split("/"): basepath = basepath + "/" + p - if not os.path.exists(basepath): + if not cpath.exists(basepath): nosuchdir.append(basepath) - bb.mkdirhier(basepath) + bb.utils.mkdirhier(basepath) + cpath.updatecache(basepath) - processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '(<internal>|<built-in>)$' | " + # Ignore files from the recipe sysroots (target and native) + processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " # We need to ignore files that are not actually ours # we do this by only paying attention to items from this package - processdebugsrc += "fgrep -z '%s' | " + processdebugsrc += "fgrep -zw '%s' | " + # Remove prefix in the source paths + processdebugsrc += "sed 's#%s##g' | " processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" - subprocess.call(processdebugsrc % (sourcefile, workbasedir, workparentdir, dvar, debugsrcdir), shell=True) + cmd = processdebugsrc % (sourcefile, workbasedir, localsrc_prefix, workparentdir, dvar, debugsrcdir) + (retval, output) = oe.utils.getstatusoutput(cmd) + # Can "fail" if internal headers/transient sources are attempted + #if retval: + # bb.fatal("debug source copy failed with exit code %s (cmd was %s)" % (retval, cmd)) + + # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced. + # Work around this by manually finding and copying any symbolic links that made it through. + cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s' 2>/dev/null)" % (dvar, debugsrcdir, dvar, debugsrcdir, workparentdir, dvar, debugsrcdir) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("debugsrc symlink fixup failed with exit code %s (cmd was %s)" % (retval, cmd)) # The copy by cpio may have resulted in some empty directories! Remove these - for root, dirs, files in os.walk("%s%s" % (dvar, debugsrcdir)): - for d in dirs: - dir = os.path.join(root, d) - #bb.note("rmdir -p %s" % dir) - subprocess.call("rmdir -p %s 2>/dev/null" % dir, shell=True) + cmd = "find %s%s -empty -type d -delete" % (dvar, debugsrcdir) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("empty directory removal failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) # Also remove debugsrcdir if its empty for p in nosuchdir[::-1]: if os.path.exists(p) and not os.listdir(p): os.rmdir(p) -def runstrip(file, elftype, d): - # Function to strip a single file, called from split_and_strip_files below - # A working 'file' (one which works on the target architecture) - # - # The elftype is a bit pattern (explained in split_and_strip_files) to tell - # us what type of file we're processing... - # 4 - executable - # 8 - shared library - - import commands, stat, subprocess - - pathprefix = "export PATH=%s; " % d.getVar('PATH', True) - strip = d.getVar("STRIP", True) - - # Handle kernel modules specifically - .debug directories here are pointless - if file.find("/lib/modules/") != -1 and file.endswith(".ko"): - return subprocess.call("%s'%s' --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates '%s'" % (pathprefix, strip, file), shell=True) - - newmode = None - if not os.access(file, os.W_OK) or os.access(file, os.R_OK): - origmode = os.stat(file)[stat.ST_MODE] - newmode = origmode | stat.S_IWRITE | stat.S_IREAD - os.chmod(file, newmode) - - extraflags = "" - - # split_and_strip_files is calling this with elf_type None, causing: - # TypeError: unsupported operand type(s) for &: 'NoneType' and 'int' - if elftype: - # .so and shared library - if ".so" in file and elftype & 8: - extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded" - # shared or executable: - elif elftype & 8 or elftype & 4: - extraflags = "--remove-section=.comment --remove-section=.note" - - stripcmd = "'%s' %s '%s'" % (strip, extraflags, file) - bb.debug(1, "runstrip: %s" % stripcmd) - - ret = subprocess.call("%s%s" % (pathprefix, stripcmd), shell=True) - - if newmode: - os.chmod(file, origmode) - - if ret: - bb.error("runstrip: '%s' strip command failed" % stripcmd) - - return 0 - # # Package data handling routines # -def get_package_mapping (pkg, d): +def get_package_mapping (pkg, basepkg, d): import oe.packagedata data = oe.packagedata.read_subpkgdata(pkg, d) key = "PKG_%s" % pkg if key in data: + # Have to avoid undoing the write_extra_pkgs(global_variants...) + if bb.data.inherits_class('allarch', d) and data[key] == basepkg: + return pkg return data[key] return pkg -def runtime_mapping_rename (varname, d): - #bb.note("%s before: %s" % (varname, d.getVar(varname, True))) +def get_package_additional_metadata (pkg_type, d): + base_key = "PACKAGE_ADD_METADATA" + for key in ("%s_%s" % (base_key, pkg_type.upper()), base_key): + if d.getVar(key, False) is None: + continue + d.setVarFlag(key, "type", "list") + if d.getVarFlag(key, "separator") is None: + d.setVarFlag(key, "separator", "\\n") + metadata_fields = [field.strip() for field in oe.data.typed_value(key, d)] + return "\n".join(metadata_fields).strip() + +def runtime_mapping_rename (varname, pkg, d): + #bb.note("%s before: %s" % (varname, d.getVar(varname))) new_depends = {} - deps = bb.utils.explode_dep_versions2(d.getVar(varname, True) or "") + deps = bb.utils.explode_dep_versions2(d.getVar(varname) or "") for depend in deps: - new_depend = get_package_mapping(depend, d) + new_depend = get_package_mapping(depend, pkg, d) new_depends[new_depend] = deps[depend] d.setVar(varname, bb.utils.join_deps(new_depends, commasep=False)) - #bb.note("%s after: %s" % (varname, d.getVar(varname, True))) + #bb.note("%s after: %s" % (varname, d.getVar(varname))) # # Package functions suitable for inclusion in PACKAGEFUNCS # python package_get_auto_pr() { - # per recipe PRSERV_HOST PRSERV_PORT - pn = d.getVar('PN', True) - host = d.getVar("PRSERV_HOST_" + pn, True) - port = d.getVar("PRSERV_PORT_" + pn, True) + import oe.prservice + import re + + # Support per recipe PRSERV_HOST + pn = d.getVar('PN') + host = d.getVar("PRSERV_HOST_" + pn) if not (host is None): d.setVar("PRSERV_HOST", host) - if not (port is None): - d.setVar("PRSERV_PORT", port) - if d.getVar('USE_PR_SERV', True) != "0": - try: - auto_pr=prserv_get_pr_auto(d) - except Exception as e: - bb.fatal("Can NOT get PRAUTO, exception %s" % str(e)) - return + + pkgv = d.getVar("PKGV") + + # PR Server not active, handle AUTOINC + if not d.getVar('PRSERV_HOST'): + if 'AUTOINC' in pkgv: + d.setVar("PKGV", pkgv.replace("AUTOINC", "0")) + return + + auto_pr = None + pv = d.getVar("PV") + version = d.getVar("PRAUTOINX") + pkgarch = d.getVar("PACKAGE_ARCH") + checksum = d.getVar("BB_TASKHASH") + + if d.getVar('PRSERV_LOCKDOWN'): + auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None if auto_pr is None: - if d.getVar('PRSERV_LOCKDOWN', True): - bb.fatal("Can NOT get PRAUTO from lockdown exported file") - else: - bb.fatal("Can NOT get PRAUTO from remote PR service") - return + bb.fatal("Can NOT get PRAUTO from lockdown exported file") d.setVar('PRAUTO',str(auto_pr)) - else: - pv = d.getVar("PV", True) - if 'AUTOINC' in pv: - d.setVar("PKGV", pv.replace("AUTOINC", "0")) + return + + try: + conn = d.getVar("__PRSERV_CONN") + if conn is None: + conn = oe.prservice.prserv_make_conn(d) + if conn is not None: + if "AUTOINC" in pkgv: + srcpv = bb.fetch2.get_srcrev(d) + base_ver = "AUTOINC-%s" % version[:version.find(srcpv)] + value = conn.getPR(base_ver, pkgarch, srcpv) + d.setVar("PKGV", pkgv.replace("AUTOINC", str(value))) + + auto_pr = conn.getPR(version, pkgarch, checksum) + except Exception as e: + bb.fatal("Can NOT get PRAUTO, exception %s" % str(e)) + if auto_pr is None: + bb.fatal("Can NOT get PRAUTO from remote PR service") + d.setVar('PRAUTO',str(auto_pr)) } LOCALEBASEPN ??= "${PN}" python package_do_split_locales() { - if (d.getVar('PACKAGE_NO_LOCALE', True) == '1'): + if (d.getVar('PACKAGE_NO_LOCALE') == '1'): bb.debug(1, "package requested not splitting locales") return - packages = (d.getVar('PACKAGES', True) or "").split() + packages = (d.getVar('PACKAGES') or "").split() - datadir = d.getVar('datadir', True) + datadir = d.getVar('datadir') if not datadir: bb.note("datadir not defined") return - dvar = d.getVar('PKGD', True) - pn = "%s%s" % (d.getVar('MLPREFIX', True) or "", d.getVar('LOCALEBASEPN', True)) + dvar = d.getVar('PKGD') + pn = d.getVar('LOCALEBASEPN') if pn + '-locale' in packages: packages.remove(pn + '-locale') localedir = os.path.join(dvar + datadir, 'locale') - if not os.path.isdir(localedir): + if not cpath.isdir(localedir): bb.debug(1, "No locale files in this package") return locales = os.listdir(localedir) - summary = d.getVar('SUMMARY', True) or pn - description = d.getVar('DESCRIPTION', True) or "" - locale_section = d.getVar('LOCALE_SECTION', True) - mlprefix = d.getVar('MLPREFIX', True) or "" - pndep = base_contains('PACKAGES', pn, '%s ' % pn, '', d) + summary = d.getVar('SUMMARY') or pn + description = d.getVar('DESCRIPTION') or "" + locale_section = d.getVar('LOCALE_SECTION') + mlprefix = d.getVar('MLPREFIX') or "" for l in sorted(locales): ln = legitimize_package_name(l) pkg = pn + '-locale-' + ln packages.append(pkg) d.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l)) - d.setVar('RRECOMMENDS_' + pkg, '%s%svirtual-locale-%s' % (pndep, mlprefix, ln)) + d.setVar('RRECOMMENDS_' + pkg, '%svirtual-locale-%s' % (mlprefix, ln)) d.setVar('RPROVIDES_' + pkg, '%s-locale %s%s-translation' % (pn, mlprefix, ln)) d.setVar('SUMMARY_' + pkg, '%s - %s translations' % (summary, l)) d.setVar('DESCRIPTION_' + pkg, '%s This package contains language translation files for the %s locale.' % (description, l)) @@ -476,28 +595,29 @@ python package_do_split_locales() { # glibc-localedata-translit* won't install as a dependency # for some other package which breaks meta-toolchain # Probably breaks since virtual-locale- isn't provided anywhere - #rdep = (d.getVar('RDEPENDS_%s' % pn, True) or d.getVar('RDEPENDS', True) or "").split() + #rdep = (d.getVar('RDEPENDS_%s' % pn) or "").split() #rdep.append('%s-locale*' % pn) #d.setVar('RDEPENDS_%s' % pn, ' '.join(rdep)) } python perform_packagecopy () { - import subprocess - dest = d.getVar('D', True) - dvar = d.getVar('PKGD', True) - - bb.mkdirhier(dvar) + dest = d.getVar('D') + dvar = d.getVar('PKGD') # Start by package population by taking a copy of the installed # files to operate on - subprocess.call('rm -rf %s/*' % (dvar), shell=True) # Preserve sparse files and hard links - subprocess.call('tar -cf - -C %s -ps . | tar -xf - -C %s' % (dest, dvar), shell=True) + cmd = 'tar -cf - -C %s -p . | tar -xf - -C %s' % (dest, dvar) + (retval, output) = oe.utils.getstatusoutput(cmd) + if retval: + bb.fatal("file copy failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) # replace RPATHs for the nativesdk binaries, to make them relocatable if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d): rpath_replace (dvar, d) } +perform_packagecopy[cleandirs] = "${PKGD}" +perform_packagecopy[dirs] = "${PKGD}" # We generate a master list of directories to process, we start by # seeding this list with reasonable defaults, then load from @@ -534,7 +654,8 @@ python fixup_perms () { elif len(lsplit) == 8: self._setdir(lsplit[0], lsplit[1], lsplit[2], lsplit[3], lsplit[4], lsplit[5], lsplit[6], lsplit[7]) else: - bb.error("Fixup Perms: invalid config line %s" % line) + msg = "Fixup Perms: invalid config line %s" % line + package_qa_handle_error("perm-config", msg, d) self.path = None self.link = None @@ -615,18 +736,20 @@ python fixup_perms () { # paths are resolved via BBPATH def get_fs_perms_list(d): str = "" - fs_perms_tables = d.getVar('FILESYSTEM_PERMS_TABLES', True) + bbpath = d.getVar('BBPATH') + fs_perms_tables = d.getVar('FILESYSTEM_PERMS_TABLES') if not fs_perms_tables: fs_perms_tables = 'files/fs-perms.txt' for conf_file in fs_perms_tables.split(): - str += " %s" % bb.which(d.getVar('BBPATH', True), conf_file) + str += " %s" % bb.utils.which(bbpath, conf_file) return str - dvar = d.getVar('PKGD', True) + dvar = d.getVar('PKGD') fs_perms_table = {} + fs_link_table = {} # By default all of the standard directories specified in # bitbake.conf will get 0755 root:root. @@ -652,10 +775,10 @@ python fixup_perms () { 'oldincludedir' ] for path in target_path_vars: - dir = d.getVar(path, True) or "" + dir = d.getVar(path) or "" if dir == "": continue - fs_perms_table[dir] = fs_perms_entry(bb.data.expand("%s 0755 root root false - - -" % (dir), d)) + fs_perms_table[dir] = fs_perms_entry(d.expand("%s 0755 root root false - - -" % (dir))) # Now we actually load from the configuration files for conf in get_fs_perms_list(d).split(): @@ -668,28 +791,37 @@ python fixup_perms () { if len(lsplit) == 0: continue if len(lsplit) != 8 and not (len(lsplit) == 3 and lsplit[1].lower() == "link"): - bb.error("Fixup perms: %s invalid line: %s" % (conf, line)) + msg = "Fixup perms: %s invalid line: %s" % (conf, line) + package_qa_handle_error("perm-line", msg, d) continue entry = fs_perms_entry(d.expand(line)) if entry and entry.path: - fs_perms_table[entry.path] = entry + if entry.link: + fs_link_table[entry.path] = entry + if entry.path in fs_perms_table: + fs_perms_table.pop(entry.path) + else: + fs_perms_table[entry.path] = entry + if entry.path in fs_link_table: + fs_link_table.pop(entry.path) f.close() # Debug -- list out in-memory table #for dir in fs_perms_table: # bb.note("Fixup Perms: %s: %s" % (dir, str(fs_perms_table[dir]))) + #for link in fs_link_table: + # bb.note("Fixup Perms: %s: %s" % (link, str(fs_link_table[link]))) # We process links first, so we can go back and fixup directory ownership # for any newly created directories - for dir in fs_perms_table: - if not fs_perms_table[dir].link: - continue - + # Process in sorted order so /run gets created before /run/lock, etc. + for entry in sorted(fs_link_table.values(), key=lambda x: x.link): + link = entry.link + dir = entry.path origin = dvar + dir - if not (os.path.exists(origin) and os.path.isdir(origin) and not os.path.islink(origin)): + if not (cpath.exists(origin) and cpath.isdir(origin) and not cpath.islink(origin)): continue - link = fs_perms_table[dir].link if link[0] == "/": target = dvar + link ptarget = link @@ -697,22 +829,20 @@ python fixup_perms () { target = os.path.join(os.path.dirname(origin), link) ptarget = os.path.join(os.path.dirname(dir), link) if os.path.exists(target): - bb.error("Fixup Perms: Unable to correct directory link, target already exists: %s -> %s" % (dir, ptarget)) + msg = "Fixup Perms: Unable to correct directory link, target already exists: %s -> %s" % (dir, ptarget) + package_qa_handle_error("perm-link", msg, d) continue # Create path to move directory to, move it, and then setup the symlink - bb.mkdirhier(os.path.dirname(target)) + bb.utils.mkdirhier(os.path.dirname(target)) #bb.note("Fixup Perms: Rename %s -> %s" % (dir, ptarget)) os.rename(origin, target) #bb.note("Fixup Perms: Link %s -> %s" % (dir, link)) os.symlink(link, origin) for dir in fs_perms_table: - if fs_perms_table[dir].link: - continue - origin = dvar + dir - if not (os.path.exists(origin) and os.path.isdir(origin)): + if not (cpath.exists(origin) and cpath.isdir(origin)): continue fix_perms(origin, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir) @@ -728,18 +858,27 @@ python fixup_perms () { } python split_and_strip_files () { - import commands, stat, errno, subprocess + import stat, errno - dvar = d.getVar('PKGD', True) - pn = d.getVar('PN', True) + dvar = d.getVar('PKGD') + pn = d.getVar('PN') + + oldcwd = os.getcwd() + os.chdir(dvar) # We default to '.debug' style - if d.getVar('PACKAGE_DEBUG_SPLIT_STYLE', True) == 'debug-file-directory': + if d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-file-directory': # Single debug-file-directory style debug info debugappend = ".debug" debugdir = "" debuglibdir = "/usr/lib/debug" debugsrcdir = "/usr/src/debug" + elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-without-src': + # Original OE-core, a.k.a. ".debug", style debug info, but without sources in /usr/src/debug + debugappend = "" + debugdir = "/.debug" + debuglibdir = "" + debugsrcdir = "" else: # Original OE-core, a.k.a. ".debug", style debug info debugappend = "" @@ -747,7 +886,8 @@ python split_and_strip_files () { debuglibdir = "" debugsrcdir = "/usr/src/debug" - os.chdir(dvar) + sourcefile = d.expand("${WORKDIR}/debugsources.list") + bb.utils.remove(sourcefile) # Return type (bits): # 0 - not elf @@ -755,13 +895,14 @@ python split_and_strip_files () { # 2 - stripped # 4 - executable # 8 - shared library + # 16 - kernel module def isELF(path): type = 0 - pathprefix = "export PATH=%s; " % d.getVar('PATH', True) - ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, path)) + ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) if ret: - bb.error("split_and_strip_files: 'file %s' failed" % path) + msg = "split_and_strip_files: 'file %s' failed" % path + package_qa_handle_error("split-strip", msg, d) return type # Not stripped @@ -779,130 +920,139 @@ python split_and_strip_files () { # # First lets figure out all of the files we may have to process ... do this only once! # - file_list = {} - file_links = {} - if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1') and \ - (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'): - for root, dirs, files in os.walk(dvar): + elffiles = {} + symlinks = {} + kernmods = [] + inodes = {} + libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir")) + baselibdir = os.path.abspath(dvar + os.sep + d.getVar("base_libdir")) + if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1' or \ + d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'): + for root, dirs, files in cpath.walk(dvar): for f in files: file = os.path.join(root, f) - # Only process files (and symlinks)... Skip files that are obviously debug files - if not (debugappend != "" and file.endswith(debugappend)) and \ - not (debugdir != "" and debugdir in os.path.dirname(file[len(dvar):])) and \ - os.path.isfile(file): - try: - s = os.stat(file) - except OSError, (err, strerror): - if err != errno.ENOENT: - raise - # Skip broken symlinks + if file.endswith(".ko") and file.find("/lib/modules/") != -1: + kernmods.append(file) + continue + + # Skip debug files + if debugappend and file.endswith(debugappend): + continue + if debugdir and debugdir in os.path.dirname(file[len(dvar):]): + continue + + try: + ltarget = cpath.realpath(file, dvar, False) + s = cpath.lstat(ltarget) + except OSError as e: + (err, strerror) = e.args + if err != errno.ENOENT: + raise + # Skip broken symlinks + continue + if not s: + continue + # Check its an excutable + if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ + or ((file.startswith(libdir) or file.startswith(baselibdir)) and (".so" in f or ".node" in f)): + # If it's a symlink, and points to an ELF file, we capture the readlink target + if cpath.islink(file): + target = os.readlink(file) + if isELF(ltarget): + #bb.note("Sym: %s (%d)" % (ltarget, isELF(ltarget))) + symlinks[file] = target continue - # Is the item excutable? Then we need to process it. - if (s[stat.ST_MODE] & stat.S_IXUSR) or \ - (s[stat.ST_MODE] & stat.S_IXGRP) or \ - (s[stat.ST_MODE] & stat.S_IXOTH): - # If it's a symlink, and points to an ELF file, we capture the readlink target - if os.path.islink(file): - target = os.readlink(file) - if not os.path.isabs(target): - ltarget = os.path.join(os.path.dirname(file), target) - else: - ltarget = target - if isELF(ltarget): - #bb.note("Sym: %s (%d)" % (ltarget, isELF(ltarget))) - file_list[file] = "sym: " + target + # It's a file (or hardlink), not a link + # ...but is it ELF, and is it already stripped? + elf_file = isELF(file) + if elf_file & 1: + if elf_file & 2: + if 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn) or "").split(): + bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dvar):], pn)) + else: + msg = "File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dvar):], pn) + package_qa_handle_error("already-stripped", msg, d) continue - # It's a file (or hardlink), not a link - # ...but is it ELF, and is it already stripped? - elf_file = isELF(file) - if elf_file & 1: - # Check if it's a hard link to something else - if s.st_nlink > 1: - file_reference = "%d_%d" % (s.st_dev, s.st_ino) - # Hard link to something else - file_list[file] = "hard: " + file_reference - continue - - file_list[file] = "ELF: %d" % elf_file + # At this point we have an unstripped elf file. We need to: + # a) Make sure any file we strip is not hardlinked to anything else outside this tree + # b) Only strip any hardlinked file once (no races) + # c) Track any hardlinks between files so that we can reconstruct matching debug file hardlinks + + # Use a reference of device ID and inode number to indentify files + file_reference = "%d_%d" % (s.st_dev, s.st_ino) + if file_reference in inodes: + os.unlink(file) + os.link(inodes[file_reference][0], file) + inodes[file_reference].append(file) + else: + inodes[file_reference] = [file] + # break hardlink + bb.utils.copyfile(file, file) + elffiles[file] = elf_file + # Modified the file so clear the cache + cpath.updatecache(file) # # First lets process debug splitting # - if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1'): - for file in file_list: + if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'): + for file in elffiles: src = file[len(dvar):] dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend fpath = dvar + dest - # Preserve symlinks in debug area... - if file_list[file].startswith("sym: "): - ltarget = file_list[file][5:] - lpath = os.path.dirname(ltarget) - lbase = os.path.basename(ltarget) - ftarget = "" - if lpath and lpath != ".": - ftarget += lpath + debugdir + "/" - ftarget += lbase + debugappend - if lpath.startswith(".."): - ftarget = os.path.join("..", ftarget) - bb.mkdirhier(os.path.dirname(fpath)) - #bb.note("Symlink %s -> %s" % (fpath, ftarget)) - os.symlink(ftarget, fpath) - continue - - # Preserve hard links in debug area... - file_reference = "" - if file_list[file].startswith("hard: "): - file_reference = file_list[file][6:] - if file_reference not in file_links: - # If this is a new file, add it as a reference, and - # update it's type, so we can fall through and split - file_list[file] = "ELF: %d" % (isELF(file)) - else: - target = file_links[file_reference][len(dvar):] - ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend - bb.mkdirhier(os.path.dirname(fpath)) - #bb.note("Link %s -> %s" % (fpath, ftarget)) - os.link(ftarget, fpath) - continue - # It's ELF... - if file_list[file].startswith("ELF: "): - elf_file = int(file_list[file][5:]) - if elf_file & 2: - bb.warn("File '%s' from %s was already stripped, this will prevent future debugging!" % (src, pn)) - continue + # Split the file... + bb.utils.mkdirhier(os.path.dirname(fpath)) + #bb.note("Split %s -> %s" % (file, fpath)) + # Only store off the hard link reference if we successfully split! + splitdebuginfo(file, fpath, debugsrcdir, sourcefile, d) - # Split the file... - bb.mkdirhier(os.path.dirname(fpath)) - #bb.note("Split %s -> %s" % (file, fpath)) - # Only store off the hard link reference if we successfully split! - if splitfile(file, fpath, debugsrcdir, d) == 0 and file_reference != "": - file_links[file_reference] = file - - # The above may have generated dangling symlinks, remove them! - # Dangling symlinks are a result of something NOT being split, such as a stripped binary. - # This should be a rare occurance, but we want to clean up anyway. - for file in file_list: - if file_list[file].startswith("sym: "): + # Hardlink our debug symbols to the other hardlink copies + for ref in inodes: + if len(inodes[ref]) == 1: + continue + for file in inodes[ref][1:]: src = file[len(dvar):] dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend fpath = dvar + dest - try: - s = os.stat(fpath) - except OSError, (err, strerror): - if err != errno.ENOENT: - raise - #bb.note("Remove dangling link %s -> %s" % (fpath, os.readlink(fpath))) - os.unlink(fpath) - # This could leave an empty debug directory laying around - # take care of the obvious case... - subprocess.call("rmdir %s 2>/dev/null" % os.path.dirname(fpath), shell=True) + target = inodes[ref][0][len(dvar):] + ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend + bb.utils.mkdirhier(os.path.dirname(fpath)) + #bb.note("Link %s -> %s" % (fpath, ftarget)) + os.link(ftarget, fpath) + + # Create symlinks for all cases we were able to split symbols + for file in symlinks: + src = file[len(dvar):] + dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend + fpath = dvar + dest + # Skip it if the target doesn't exist + try: + s = os.stat(fpath) + except OSError as e: + (err, strerror) = e.args + if err != errno.ENOENT: + raise + continue + + ltarget = symlinks[file] + lpath = os.path.dirname(ltarget) + lbase = os.path.basename(ltarget) + ftarget = "" + if lpath and lpath != ".": + ftarget += lpath + debugdir + "/" + ftarget += lbase + debugappend + if lpath.startswith(".."): + ftarget = os.path.join("..", ftarget) + bb.utils.mkdirhier(os.path.dirname(fpath)) + #bb.note("Symlink %s -> %s" % (fpath, ftarget)) + os.symlink(ftarget, fpath) # Process the debugsrcdir if requested... # This copies and places the referenced sources for later debugging... - splitfile2(debugsrcdir, d) + copydebugsources(debugsrcdir, d) # # End of debug splitting # @@ -910,89 +1060,86 @@ python split_and_strip_files () { # # Now lets go back over things and strip them # - if (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'): - for file in file_list: - if file_list[file].startswith("ELF: "): - elf_file = int(file_list[file][5:]) - #bb.note("Strip %s" % file) - runstrip(file, elf_file, d) + if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1'): + strip = d.getVar("STRIP") + sfiles = [] + for file in elffiles: + elf_file = int(elffiles[file]) + #bb.note("Strip %s" % file) + sfiles.append((file, elf_file, strip)) + for f in kernmods: + sfiles.append((f, 16, strip)) + + oe.utils.multiprocess_exec(sfiles, oe.package.runstrip) - - if (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'): - for root, dirs, files in os.walk(dvar): - for f in files: - if not f.endswith(".ko"): - continue - runstrip(os.path.join(root, f), 0, d) # # End of strip # + os.chdir(oldcwd) } python populate_packages () { - import glob, stat, errno, re, subprocess + import glob, re - workdir = d.getVar('WORKDIR', True) - outdir = d.getVar('DEPLOY_DIR', True) - dvar = d.getVar('PKGD', True) - packages = d.getVar('PACKAGES', True) - pn = d.getVar('PN', True) + workdir = d.getVar('WORKDIR') + outdir = d.getVar('DEPLOY_DIR') + dvar = d.getVar('PKGD') + packages = d.getVar('PACKAGES') + pn = d.getVar('PN') - bb.mkdirhier(outdir) + bb.utils.mkdirhier(outdir) os.chdir(dvar) + + autodebug = not (d.getVar("NOAUTOPACKAGEDEBUG") or False) - # Sanity check PACKAGES for duplicates and for LICENSE_EXCLUSION + # Sanity check PACKAGES for duplicates # Sanity should be moved to sanity.bbclass once we have the infrastucture package_list = [] for pkg in packages.split(): - if d.getVar('LICENSE_EXCLUSION-' + pkg, True): - bb.warn("%s has an incompatible license. Excluding from packaging." % pkg) - packages.remove(pkg) + if pkg in package_list: + msg = "%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg + package_qa_handle_error("packages-list", msg, d) + elif autodebug and pkg.endswith("-dbg"): + package_list.insert(0, pkg) else: - if pkg in package_list: - bb.error("%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg) - else: - package_list.append(pkg) + package_list.append(pkg) d.setVar('PACKAGES', ' '.join(package_list)) - pkgdest = d.getVar('PKGDEST', True) - subprocess.call('rm -rf %s' % pkgdest, shell=True) + pkgdest = d.getVar('PKGDEST') seen = [] + # os.mkdir masks the permissions with umask so we have to unset it first + oldumask = os.umask(0) + + debug = [] + for root, dirs, files in cpath.walk(dvar): + dir = root[len(dvar):] + if not dir: + dir = os.sep + for f in (files + dirs): + path = "." + os.path.join(dir, f) + if "/.debug/" in path or path.endswith("/.debug"): + debug.append(path) + for pkg in package_list: - localdata = bb.data.createCopy(d) root = os.path.join(pkgdest, pkg) - bb.mkdirhier(root) - - localdata.setVar('PKG', pkg) - overrides = localdata.getVar('OVERRIDES', True) - if not overrides: - raise bb.build.FuncFailed('OVERRIDES not defined') - localdata.setVar('OVERRIDES', overrides + ':' + pkg) - bb.data.update_data(localdata) - - filesvar = localdata.getVar('FILES', True) or "" - files = filesvar.split() - file_links = {} + bb.utils.mkdirhier(root) + + filesvar = d.getVar('FILES_%s' % pkg) or "" + if "//" in filesvar: + msg = "FILES variable for package %s contains '//' which is invalid. Attempting to fix this but you should correct the metadata.\n" % pkg + package_qa_handle_error("files-invalid", msg, d) + filesvar.replace("//", "/") + + origfiles = filesvar.split() + files, symlink_paths = files_from_filevars(origfiles) + + if autodebug and pkg.endswith("-dbg"): + files.extend(debug) + for file in files: - if file.find("//") != -1: - bb.warn("FILES variable for package %s contains '//' which is invalid. Attempting to fix this but you should correct the metadata.\n" % pkg) - file.replace("//", "/") - if os.path.isabs(file): - file = '.' + file - if not os.path.islink(file): - if os.path.isdir(file): - newfiles = [ os.path.join(file,x) for x in os.listdir(file) ] - if newfiles: - files += newfiles - continue - globbed = glob.glob(file) - if globbed: - if [ file ] != globbed: - files += globbed - continue - if (not os.path.islink(file)) and (not os.path.exists(file)): + if (not cpath.islink(file)) and (not cpath.exists(file)): continue if file in seen: continue @@ -1001,43 +1148,61 @@ python populate_packages () { def mkdir(src, dest, p): src = os.path.join(src, p) dest = os.path.join(dest, p) - bb.mkdirhier(dest) - fstat = os.stat(src) - os.chmod(dest, fstat.st_mode) + fstat = cpath.stat(src) + os.mkdir(dest, fstat.st_mode) os.chown(dest, fstat.st_uid, fstat.st_gid) if p not in seen: seen.append(p) + cpath.updatecache(dest) def mkdir_recurse(src, dest, paths): + if cpath.exists(dest + '/' + paths): + return while paths.startswith("./"): paths = paths[2:] p = "." for c in paths.split("/"): p = os.path.join(p, c) - if not os.path.exists(os.path.join(dest, p)): + if not cpath.exists(os.path.join(dest, p)): mkdir(src, dest, p) - if os.path.isdir(file) and not os.path.islink(file): + if cpath.isdir(file) and not cpath.islink(file): mkdir_recurse(dvar, root, file) continue mkdir_recurse(dvar, root, os.path.dirname(file)) fpath = os.path.join(root,file) - if not os.path.islink(file): + if not cpath.islink(file): os.link(file, fpath) - fstat = os.stat(file) - os.chmod(fpath, fstat.st_mode) - os.chown(fpath, fstat.st_uid, fstat.st_gid) continue - ret = bb.copyfile(file, fpath) + ret = bb.utils.copyfile(file, fpath) if ret is False or ret == 0: - raise bb.build.FuncFailed("File population failed") - - del localdata + bb.fatal("File population failed") + + # Check if symlink paths exist + for file in symlink_paths: + if not os.path.exists(os.path.join(root,file)): + bb.fatal("File '%s' cannot be packaged into '%s' because its " + "parent directory structure does not exist. One of " + "its parent directories is a symlink whose target " + "directory is not included in the package." % + (file, pkg)) + + os.umask(oldumask) os.chdir(workdir) + # Handle LICENSE_EXCLUSION + package_list = [] + for pkg in packages.split(): + if d.getVar('LICENSE_EXCLUSION-' + pkg): + msg = "%s has an incompatible license. Excluding from packaging." % pkg + package_qa_handle_error("incompatible-license", msg, d) + else: + package_list.append(pkg) + d.setVar('PACKAGES', ' '.join(package_list)) + unshipped = [] - for root, dirs, files in os.walk(dvar): + for root, dirs, files in cpath.walk(dvar): dir = root[len(dvar):] if not dir: dir = os.sep @@ -1047,94 +1212,112 @@ python populate_packages () { unshipped.append(path) if unshipped != []: - msg = pn + ": Files/directories were installed but not shipped" - if "installed_vs_shipped" in (d.getVar('INSANE_SKIP_' + pn, True) or "").split(): - bb.note("Package %s skipping QA tests: installed_vs_shipped" % pn) + msg = pn + ": Files/directories were installed but not shipped in any package:" + if "installed-vs-shipped" in (d.getVar('INSANE_SKIP_' + pn) or "").split(): + bb.note("Package %s skipping QA tests: installed-vs-shipped" % pn) else: for f in unshipped: msg = msg + "\n " + f - package_qa_handle_error("installed_vs_shipped", msg, d) - - bb.build.exec_func("package_name_hook", d) + msg = msg + "\nPlease set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.\n" + msg = msg + "%s: %d installed and not shipped files." % (pn, len(unshipped)) + package_qa_handle_error("installed-vs-shipped", msg, d) +} +populate_packages[dirs] = "${D}" - for pkg in package_list: - pkgname = d.getVar('PKG_%s' % pkg, True) - if pkgname is None: - d.setVar('PKG_%s' % pkg, pkg) +python package_fixsymlinks () { + import errno + pkgdest = d.getVar('PKGDEST') + packages = d.getVar("PACKAGES", False).split() dangling_links = {} pkg_files = {} - for pkg in package_list: + for pkg in packages: dangling_links[pkg] = [] pkg_files[pkg] = [] inst_root = os.path.join(pkgdest, pkg) - for root, dirs, files in os.walk(inst_root): - for f in files: - path = os.path.join(root, f) + for path in pkgfiles[pkg]: rpath = path[len(inst_root):] pkg_files[pkg].append(rpath) - try: - s = os.stat(path) - except OSError, (err, strerror): - if err != errno.ENOENT: - raise - target = os.readlink(path) - if target[0] != '/': - target = os.path.join(root[len(inst_root):], target) - dangling_links[pkg].append(os.path.normpath(target)) - - for pkg in package_list: - rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or d.getVar('RDEPENDS', True) or "") + rtarget = cpath.realpath(path, inst_root, True, assume_dir = True) + if not cpath.lexists(rtarget): + dangling_links[pkg].append(os.path.normpath(rtarget[len(inst_root):])) + newrdepends = {} + for pkg in dangling_links: for l in dangling_links[pkg]: found = False bb.debug(1, "%s contains dangling link %s" % (pkg, l)) - for p in package_list: - for f in pkg_files[p]: - if f == l: + for p in packages: + if l in pkg_files[p]: found = True bb.debug(1, "target found in %s" % p) if p == pkg: break - if p not in rdepends: - rdepends[p] = [] + if pkg not in newrdepends: + newrdepends[pkg] = [] + newrdepends[pkg].append(p) break if found == False: bb.note("%s contains dangling symlink to %s" % (pkg, l)) + + for pkg in newrdepends: + rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "") + for p in newrdepends[pkg]: + if p not in rdepends: + rdepends[p] = [] d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) } -populate_packages[dirs] = "${D}" + + +python package_package_name_hook() { + """ + A package_name_hook function can be used to rewrite the package names by + changing PKG. For an example, see debian.bbclass. + """ + pass +} + +EXPORT_FUNCTIONS package_name_hook + PKGDESTWORK = "${WORKDIR}/pkgdata" python emit_pkgdata() { from glob import glob + import json def write_if_exists(f, pkg, var): def encode(str): import codecs - c = codecs.getencoder("string_escape") - return c(str)[0] + c = codecs.getencoder("unicode_escape") + return c(str)[0].decode("latin1") - val = d.getVar('%s_%s' % (var, pkg), True) + val = d.getVar('%s_%s' % (var, pkg)) if val: f.write('%s_%s: %s\n' % (var, pkg, encode(val))) - return - val = d.getVar('%s' % (var), True) + return val + val = d.getVar('%s' % (var)) if val: f.write('%s: %s\n' % (var, encode(val))) - return - - def get_directory_size(dir): - if os.listdir(dir): - size = int(os.popen('du -sk %s' % dir).readlines()[0].split('\t')[0]) - else: - size = 0 - return size - - packages = d.getVar('PACKAGES', True) - pkgdest = d.getVar('PKGDEST', True) - pkgdatadir = d.getVar('PKGDESTWORK', True) + return val + + def write_extra_pkgs(variants, pn, packages, pkgdatadir): + for variant in variants: + with open("%s/%s-%s" % (pkgdatadir, variant, pn), 'w') as fd: + fd.write("PACKAGES: %s\n" % ' '.join( + map(lambda pkg: '%s-%s' % (variant, pkg), packages.split()))) + + def write_extra_runtime_pkgs(variants, packages, pkgdatadir): + for variant in variants: + for pkg in packages.split(): + ml_pkg = "%s-%s" % (variant, pkg) + subdata_file = "%s/runtime/%s" % (pkgdatadir, ml_pkg) + with open(subdata_file, 'w') as fd: + fd.write("PKG_%s: %s" % (ml_pkg, pkg)) + + packages = d.getVar('PACKAGES') + pkgdest = d.getVar('PKGDEST') + pkgdatadir = d.getVar('PKGDESTWORK') # Take shared lock since we're only reading, not writing lf = bb.utils.lockfile(d.expand("${PACKAGELOCK}"), True) @@ -1144,22 +1327,51 @@ python emit_pkgdata() { f.write("PACKAGES: %s\n" % packages) f.close() - workdir = d.getVar('WORKDIR', True) + pn = d.getVar('PN') + global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split() + variants = (d.getVar('MULTILIB_VARIANTS') or "").split() + + if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): + write_extra_pkgs(variants, pn, packages, pkgdatadir) + + if (bb.data.inherits_class('allarch', d) and not bb.data.inherits_class('packagegroup', d)): + write_extra_pkgs(global_variants, pn, packages, pkgdatadir) + + workdir = d.getVar('WORKDIR') for pkg in packages.split(): - subdata_file = pkgdatadir + "/runtime/%s" % pkg + pkgval = d.getVar('PKG_%s' % pkg) + if pkgval is None: + pkgval = pkg + d.setVar('PKG_%s' % pkg, pkg) + pkgdestpkg = os.path.join(pkgdest, pkg) + files = {} + total_size = 0 + seen = set() + for f in pkgfiles[pkg]: + relpth = os.path.relpath(f, pkgdestpkg) + fstat = os.lstat(f) + files[os.sep + relpth] = fstat.st_size + if fstat.st_ino not in seen: + seen.add(fstat.st_ino) + total_size += fstat.st_size + d.setVar('FILES_INFO', json.dumps(files)) + + subdata_file = pkgdatadir + "/runtime/%s" % pkg sf = open(subdata_file, 'w') write_if_exists(sf, pkg, 'PN') + write_if_exists(sf, pkg, 'PE') write_if_exists(sf, pkg, 'PV') write_if_exists(sf, pkg, 'PR') + write_if_exists(sf, pkg, 'PKGE') write_if_exists(sf, pkg, 'PKGV') write_if_exists(sf, pkg, 'PKGR') write_if_exists(sf, pkg, 'LICENSE') write_if_exists(sf, pkg, 'DESCRIPTION') write_if_exists(sf, pkg, 'SUMMARY') write_if_exists(sf, pkg, 'RDEPENDS') - write_if_exists(sf, pkg, 'RPROVIDES') + rprov = write_if_exists(sf, pkg, 'RPROVIDES') write_if_exists(sf, pkg, 'RRECOMMENDS') write_if_exists(sf, pkg, 'RSUGGESTS') write_if_exists(sf, pkg, 'RREPLACES') @@ -1168,39 +1380,53 @@ python emit_pkgdata() { write_if_exists(sf, pkg, 'PKG') write_if_exists(sf, pkg, 'ALLOW_EMPTY') write_if_exists(sf, pkg, 'FILES') + write_if_exists(sf, pkg, 'CONFFILES') write_if_exists(sf, pkg, 'pkg_postinst') write_if_exists(sf, pkg, 'pkg_postrm') write_if_exists(sf, pkg, 'pkg_preinst') write_if_exists(sf, pkg, 'pkg_prerm') write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') - for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg, True) or "").split(): + write_if_exists(sf, pkg, 'FILES_INFO') + for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split(): write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile) write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') - for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg, True) or "").split(): + for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split(): write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile) - sf.write('%s_%s: %s\n' % ('PKGSIZE', pkg, get_directory_size(pkgdest + "/%s" % pkg))) + sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size)) sf.close() - # Symlinks needed for reverse lookups (from the final package name) - pkgval = d.getVar('PKG_%s' % (pkg), True) - subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval - oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True) + # Symlinks needed for rprovides lookup + if rprov: + for p in rprov.strip().split(): + subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg) + bb.utils.mkdirhier(os.path.dirname(subdata_sym)) + oe.path.symlink("../../runtime/%s" % pkg, subdata_sym, True) - allow_empty = d.getVar('ALLOW_EMPTY_%s' % pkg, True) + allow_empty = d.getVar('ALLOW_EMPTY_%s' % pkg) if not allow_empty: - allow_empty = d.getVar('ALLOW_EMPTY', True) + allow_empty = d.getVar('ALLOW_EMPTY') root = "%s/%s" % (pkgdest, pkg) os.chdir(root) g = glob('*') if g or allow_empty == "1": + # Symlinks needed for reverse lookups (from the final package name) + subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval + oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True) + packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg - file(packagedfile, 'w').close() + open(packagedfile, 'w').close() + + if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): + write_extra_runtime_pkgs(variants, packages, pkgdatadir) + + if bb.data.inherits_class('allarch', d) and not bb.data.inherits_class('packagegroup', d): + write_extra_runtime_pkgs(global_variants, packages, pkgdatadir) bb.utils.unlockfile(lf) } -emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse" +emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides" ldconfig_postinst_fragment() { if [ x"$D" = "x" ]; then @@ -1208,7 +1434,7 @@ if [ x"$D" = "x" ]; then fi } -RPMDEPS = "${STAGING_LIBDIR_NATIVE}/rpm/bin/rpmdeps-oecore --macros ${STAGING_LIBDIR_NATIVE}/rpm/macros --define '_rpmfc_magic_path ${STAGING_DIR_NATIVE}${datadir_native}/misc/magic.mgc' --rpmpopt ${STAGING_LIBDIR_NATIVE}/rpm/rpmpopt" +RPMDEPS = "${STAGING_LIBDIR_NATIVE}/rpm/rpmdeps --rcfile ${STAGING_LIBDIR_NATIVE}/rpm/rpmrc --macros ${STAGING_LIBDIR_NATIVE}/rpm/macros --define '_rpmconfigdir ${STAGING_LIBDIR_NATIVE}/rpm/'" # Collect perfile run-time dependency metadata # Output: @@ -1219,159 +1445,125 @@ RPMDEPS = "${STAGING_LIBDIR_NATIVE}/rpm/bin/rpmdeps-oecore --macros ${STAGING_LI # FILERDEPENDS_filepath_pkg - per file dep python package_do_filedeps() { - import re - - if d.getVar('SKIP_FILEDEPS', True) == '1': + if d.getVar('SKIP_FILEDEPS') == '1': return - pkgdest = d.getVar('PKGDEST', True) - packages = d.getVar('PACKAGES', True) - - rpmdeps = d.expand("${RPMDEPS}") - r = re.compile(r'[<>=]+ +[^ ]*') - - def file_translate(file): - ft = file.replace("@", "@at@") - ft = ft.replace(" ", "@space@") - ft = ft.replace("\t", "@tab@") - ft = ft.replace("[", "@openbrace@") - ft = ft.replace("]", "@closebrace@") - ft = ft.replace("_", "@underscore@") - return ft - - # Quick routine to process the results of the rpmdeps call... - def process_deps(pipe, pkg, provides_files, requires_files): - provides = {} - requires = {} - - for line in pipe: - f = line.split(" ", 1)[0].strip() - line = line.split(" ", 1)[1].strip() - - if line.startswith("Requires:"): - i = requires - elif line.startswith("Provides:"): - i = provides - else: - continue - - file = f.replace(pkgdest + "/" + pkg, "") - file = file_translate(file) - value = line.split(":", 1)[1].strip() - value = r.sub(r'(\g<0>)', value) - - if value.startswith("rpmlib("): - continue - if value == "python": - continue - if file not in i: - i[file] = [] - i[file].append(value) - - for file in provides: - provides_files.append(file) - key = "FILERPROVIDES_" + file + "_" + pkg - d.setVar(key, " ".join(provides[file])) - - for file in requires: - requires_files.append(file) - key = "FILERDEPENDS_" + file + "_" + pkg - d.setVar(key, " ".join(requires[file])) + pkgdest = d.getVar('PKGDEST') + packages = d.getVar('PACKAGES') + rpmdeps = d.getVar('RPMDEPS') + magic = d.expand("${STAGING_DIR_NATIVE}${datadir_native}/misc/magic.mgc") def chunks(files, n): return [files[i:i+n] for i in range(0, len(files), n)] - # Determine dependencies + pkglist = [] for pkg in packages.split(): + if d.getVar('SKIP_FILEDEPS_' + pkg) == '1': + continue if pkg.endswith('-dbg') or pkg.endswith('-doc') or pkg.find('-locale-') != -1 or pkg.find('-localedata-') != -1 or pkg.find('-gconv-') != -1 or pkg.find('-charmap-') != -1 or pkg.startswith('kernel-module-'): continue + for files in chunks(pkgfiles[pkg], 100): + pkglist.append((pkg, files, rpmdeps, pkgdest, magic)) - provides_files = [] - requires_files = [] - rpfiles = [] - for root, dirs, files in os.walk(pkgdest + "/" + pkg): - for file in files: - rpfiles.append(os.path.join(root, file)) + processed = oe.utils.multiprocess_exec( pkglist, oe.package.filedeprunner) - for files in chunks(rpfiles, 100): - dep_pipe = os.popen(rpmdeps + " " + " ".join(files)) + provides_files = {} + requires_files = {} - process_deps(dep_pipe, pkg, provides_files, requires_files) + for result in processed: + (pkg, provides, requires) = result - d.setVar("FILERDEPENDSFLIST_" + pkg, " ".join(requires_files)) - d.setVar("FILERPROVIDESFLIST_" + pkg, " ".join(provides_files)) -} + if pkg not in provides_files: + provides_files[pkg] = [] + if pkg not in requires_files: + requires_files[pkg] = [] + + for file in provides: + provides_files[pkg].append(file) + key = "FILERPROVIDES_" + file + "_" + pkg + d.setVar(key, " ".join(provides[file])) + + for file in requires: + requires_files[pkg].append(file) + key = "FILERDEPENDS_" + file + "_" + pkg + d.setVar(key, " ".join(requires[file])) -def getshlibsdirs(d): - dirs = [] - triplets = (d.getVar("PKGTRIPLETS") or "").split() - for t in triplets: - dirs.append("${TMPDIR}/pkgdata/" + t + "/shlibs/") - return " ".join(dirs) -getshlibsdirs[vardepsexclude] = "PKGTRIPLETS" + for pkg in requires_files: + d.setVar("FILERDEPENDSFLIST_" + pkg, " ".join(requires_files[pkg])) + for pkg in provides_files: + d.setVar("FILERPROVIDESFLIST_" + pkg, " ".join(provides_files[pkg])) +} -SHLIBSDIRS = "${@getshlibsdirs(d)}" -SHLIBSDIR = "${TMPDIR}/pkgdata/${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}/shlibs" -SHLIBSWORKDIR = "${PKGDESTWORK}/shlibs" +SHLIBSDIRS = "${PKGDATA_DIR}/${MLPREFIX}shlibs2" +SHLIBSWORKDIR = "${PKGDESTWORK}/${MLPREFIX}shlibs2" python package_do_shlibs() { import re, pipes + import subprocess as sub - exclude_shlibs = d.getVar('EXCLUDE_FROM_SHLIBS', 0) + exclude_shlibs = d.getVar('EXCLUDE_FROM_SHLIBS', False) if exclude_shlibs: bb.note("not generating shlibs") return lib_re = re.compile("^.*\.so") - libdir_re = re.compile(".*/%s$" % d.getVar('baselib', True)) + libdir_re = re.compile(".*/%s$" % d.getVar('baselib')) - packages = d.getVar('PACKAGES', True) - targetos = d.getVar('TARGET_OS', True) + packages = d.getVar('PACKAGES') + targetos = d.getVar('TARGET_OS') - workdir = d.getVar('WORKDIR', True) + workdir = d.getVar('WORKDIR') - ver = d.getVar('PKGV', True) + ver = d.getVar('PKGV') if not ver: - bb.error("PKGV not defined") + msg = "PKGV not defined" + package_qa_handle_error("pkgv-undefined", msg, d) return - pkgdest = d.getVar('PKGDEST', True) + pkgdest = d.getVar('PKGDEST') - shlibs_dirs = d.getVar('SHLIBSDIRS', True).split() - shlibswork_dir = d.getVar('SHLIBSWORKDIR', True) + shlibswork_dir = d.getVar('SHLIBSWORKDIR') # Take shared lock since we're only reading, not writing lf = bb.utils.lockfile(d.expand("${PACKAGELOCK}")) - def linux_so(root, path, file): + def linux_so(file, needed, sonames, renames, pkgver): needs_ldconfig = False - cmd = d.getVar('OBJDUMP', True) + " -p " + pipes.quote(os.path.join(root, file)) + " 2>/dev/null" - cmd = "PATH=\"%s\" %s" % (d.getVar('PATH', True), cmd) + ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '') + cmd = d.getVar('OBJDUMP') + " -p " + pipes.quote(file) + " 2>/dev/null" fd = os.popen(cmd) lines = fd.readlines() fd.close() + rpath = [] + for l in lines: + m = re.match("\s+RPATH\s+([^\s]*)", l) + if m: + rpaths = m.group(1).replace("$ORIGIN", ldir).split(":") + rpath = list(map(os.path.normpath, rpaths)) for l in lines: m = re.match("\s+NEEDED\s+([^\s]*)", l) if m: - if m.group(1) not in needed[pkg]: - needed[pkg].append(m.group(1)) + dep = m.group(1) + if dep not in needed[pkg]: + needed[pkg].append((dep, file, rpath)) m = re.match("\s+SONAME\s+([^\s]*)", l) if m: this_soname = m.group(1) - if not this_soname in sonames: + prov = (this_soname, ldir, pkgver) + if not prov in sonames: # if library is private (only used by package) then do not build shlib for it - if not private_libs or -1 == private_libs.find(this_soname): - sonames.append(this_soname) - if libdir_re.match(root): + if not private_libs or this_soname not in private_libs: + sonames.append(prov) + if libdir_re.match(os.path.dirname(file)): needs_ldconfig = True - if snap_symlinks and (file != this_soname): - renames.append((os.path.join(root, file), os.path.join(root, this_soname))) + if snap_symlinks and (os.path.basename(file) != this_soname): + renames.append((file, os.path.join(os.path.dirname(file), this_soname))) return needs_ldconfig - def darwin_so(root, path, file): - fullpath = os.path.join(root, file) - if not os.path.exists(fullpath): + def darwin_so(file, needed, sonames, renames, pkgver): + if not os.path.exists(file): return + ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '') def get_combinations(base): # @@ -1388,132 +1580,126 @@ python package_do_shlibs() { if (file.endswith('.dylib') or file.endswith('.so')) and not pkg.endswith('-dev') and not pkg.endswith('-dbg'): # Drop suffix - name = file.rsplit(".",1)[0] + name = os.path.basename(file).rsplit(".",1)[0] # Find all combinations combos = get_combinations(name) for combo in combos: if not combo in sonames: - sonames.append(combo) + prov = (combo, ldir, pkgver) + sonames.append(prov) if file.endswith('.dylib') or file.endswith('.so'): - lafile = fullpath.replace(os.path.join(pkgdest, pkg), d.getVar('PKGD', True)) - # Drop suffix - lafile = lafile.rsplit(".",1)[0] - lapath = os.path.dirname(lafile) - lafile = os.path.basename(lafile) - # Find all combinations - combos = get_combinations(lafile) - for combo in combos: - if os.path.exists(lapath + '/' + combo + '.la'): - break - lafile = lapath + '/' + combo + '.la' - - #bb.note("Foo2: %s" % lafile) - #bb.note("Foo %s %s" % (file, fullpath)) - if os.path.exists(lafile): - fd = open(lafile, 'r') - lines = fd.readlines() - fd.close() - for l in lines: - m = re.match("\s*dependency_libs=\s*'(.*)'", l) - if m: - deps = m.group(1).split(" ") - for dep in deps: - #bb.note("Trying %s for %s" % (dep, pkg)) - name = None - if dep.endswith(".la"): - name = os.path.basename(dep).replace(".la", "") - elif dep.startswith("-l"): - name = dep.replace("-l", "lib") - if pkg not in needed: - needed[pkg] = [] - if name and name not in needed[pkg]: - needed[pkg].append(name) - #bb.note("Adding %s for %s" % (name, pkg)) - - if d.getVar('PACKAGE_SNAP_LIB_SYMLINKS', True) == "1": + rpath = [] + p = sub.Popen([d.expand("${HOST_PREFIX}otool"), '-l', file],stdout=sub.PIPE,stderr=sub.PIPE) + out, err = p.communicate() + # If returned successfully, process stdout for results + if p.returncode == 0: + for l in out.split("\n"): + l = l.strip() + if l.startswith('path '): + rpath.append(l.split()[1]) + + p = sub.Popen([d.expand("${HOST_PREFIX}otool"), '-L', file],stdout=sub.PIPE,stderr=sub.PIPE) + out, err = p.communicate() + # If returned successfully, process stdout for results + if p.returncode == 0: + for l in out.split("\n"): + l = l.strip() + if not l or l.endswith(":"): + continue + if "is not an object file" in l: + continue + name = os.path.basename(l.split()[0]).rsplit(".", 1)[0] + if name and name not in needed[pkg]: + needed[pkg].append((name, file, [])) + + def mingw_dll(file, needed, sonames, renames, pkgver): + if not os.path.exists(file): + return + + if file.endswith(".dll"): + # assume all dlls are shared objects provided by the package + sonames.append((os.path.basename(file), os.path.dirname(file).replace(pkgdest + "/" + pkg, ''), pkgver)) + + if (file.endswith(".dll") or file.endswith(".exe")): + # use objdump to search for "DLL Name: .*\.dll" + p = sub.Popen([d.expand("${HOST_PREFIX}objdump"), "-p", file], stdout = sub.PIPE, stderr= sub.PIPE) + out, err = p.communicate() + # process the output, grabbing all .dll names + if p.returncode == 0: + for m in re.finditer("DLL Name: (.*?\.dll)$", out.decode(), re.MULTILINE | re.IGNORECASE): + dllname = m.group(1) + if dllname: + needed[pkg].append((dllname, file, [])) + + if d.getVar('PACKAGE_SNAP_LIB_SYMLINKS') == "1": snap_symlinks = True else: snap_symlinks = False - if (d.getVar('USE_LDCONFIG', True) or "1") == "1": - use_ldconfig = True - else: - use_ldconfig = False + use_ldconfig = bb.utils.contains('DISTRO_FEATURES', 'ldconfig', True, False, d) needed = {} - shlib_provider = {} + shlib_provider = oe.package.read_shlib_providers(d) + for pkg in packages.split(): - private_libs = d.getVar('PRIVATE_LIBS_' + pkg, True) or d.getVar('PRIVATE_LIBS', True) + private_libs = d.getVar('PRIVATE_LIBS_' + pkg) or d.getVar('PRIVATE_LIBS') or "" + private_libs = private_libs.split() needs_ldconfig = False bb.debug(2, "calculating shlib provides for %s" % pkg) - pkgver = d.getVar('PKGV_' + pkg, True) + pkgver = d.getVar('PKGV_' + pkg) if not pkgver: - pkgver = d.getVar('PV_' + pkg, True) + pkgver = d.getVar('PV_' + pkg) if not pkgver: pkgver = ver needed[pkg] = [] sonames = list() renames = list() - top = os.path.join(pkgdest, pkg) - for root, dirs, files in os.walk(top): - for file in files: + for file in pkgfiles[pkg]: soname = None - path = os.path.join(root, file) - if os.path.islink(path): + if cpath.islink(file): continue if targetos == "darwin" or targetos == "darwin8": - darwin_so(root, dirs, file) - elif os.access(path, os.X_OK) or lib_re.match(file): - ldconfig = linux_so(root, dirs, file) + darwin_so(file, needed, sonames, renames, pkgver) + elif targetos.startswith("mingw"): + mingw_dll(file, needed, sonames, renames, pkgver) + elif os.access(file, os.X_OK) or lib_re.match(file): + ldconfig = linux_so(file, needed, sonames, renames, pkgver) needs_ldconfig = needs_ldconfig or ldconfig for (old, new) in renames: bb.note("Renaming %s to %s" % (old, new)) os.rename(old, new) + pkgfiles[pkg].remove(old) + shlibs_file = os.path.join(shlibswork_dir, pkg + ".list") - shver_file = os.path.join(shlibswork_dir, pkg + ".ver") if len(sonames): fd = open(shlibs_file, 'w') for s in sonames: - fd.write(s + '\n') - shlib_provider[s] = (pkg, pkgver) - fd.close() - fd = open(shver_file, 'w') - fd.write(pkgver + '\n') + if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]: + (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]] + if old_pkg != pkg: + bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver)) + bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0])) + fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n') + if s[0] not in shlib_provider: + shlib_provider[s[0]] = {} + shlib_provider[s[0]][s[1]] = (pkg, pkgver) fd.close() if needs_ldconfig and use_ldconfig: bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg) - postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True) + postinst = d.getVar('pkg_postinst_%s' % pkg) if not postinst: postinst = '#!/bin/sh\n' - postinst += d.getVar('ldconfig_postinst_fragment', True) + postinst += d.getVar('ldconfig_postinst_fragment') d.setVar('pkg_postinst_%s' % pkg, postinst) - - list_re = re.compile('^(.*)\.list$') - for dir in shlibs_dirs: - if not os.path.exists(dir): - continue - for file in os.listdir(dir): - m = list_re.match(file) - if m: - dep_pkg = m.group(1) - fd = open(os.path.join(dir, file)) - lines = fd.readlines() - fd.close() - ver_file = os.path.join(dir, dep_pkg + '.ver') - lib_ver = None - if os.path.exists(ver_file): - fd = open(ver_file) - lib_ver = fd.readline().rstrip() - fd.close() - for l in lines: - shlib_provider[l.rstrip()] = (dep_pkg, lib_ver) + bb.debug(1, 'LIBNAMES: pkg %s sonames %s' % (pkg, sonames)) bb.utils.unlockfile(lf) - assumed_libs = d.getVar('ASSUME_SHLIBS', True) + assumed_libs = d.getVar('ASSUME_SHLIBS') if assumed_libs: + libdir = d.getVar("libdir") for e in assumed_libs.split(): l, dep_pkg = e.split(":") lib_ver = None @@ -1521,29 +1707,50 @@ python package_do_shlibs() { if len(dep_pkg) == 2: lib_ver = dep_pkg[1] dep_pkg = dep_pkg[0] - shlib_provider[l] = (dep_pkg, lib_ver) + if l not in shlib_provider: + shlib_provider[l] = {} + shlib_provider[l][libdir] = (dep_pkg, lib_ver) + + libsearchpath = [d.getVar('libdir'), d.getVar('base_libdir')] for pkg in packages.split(): bb.debug(2, "calculating shlib requirements for %s" % pkg) deps = list() for n in needed[pkg]: - if n in shlib_provider.keys(): - (dep_pkg, ver_needed) = shlib_provider[n] + # if n is in private libraries, don't try to search provider for it + # this could cause problem in case some abc.bb provides private + # /opt/abc/lib/libfoo.so.1 and contains /usr/bin/abc depending on system library libfoo.so.1 + # but skipping it is still better alternative than providing own + # version and then adding runtime dependency for the same system library + if private_libs and n[0] in private_libs: + bb.debug(2, '%s: Dependency %s covered by PRIVATE_LIBS' % (pkg, n[0])) + continue + if n[0] in shlib_provider.keys(): + shlib_provider_path = [] + for k in shlib_provider[n[0]].keys(): + shlib_provider_path.append(k) + match = None + for p in n[2] + shlib_provider_path + libsearchpath: + if p in shlib_provider[n[0]]: + match = p + break + if match: + (dep_pkg, ver_needed) = shlib_provider[n[0]][match] - bb.debug(2, '%s: Dependency %s requires package %s' % (pkg, n, dep_pkg)) + bb.debug(2, '%s: Dependency %s requires package %s (used by files: %s)' % (pkg, n[0], dep_pkg, n[1])) - if dep_pkg == pkg: - continue + if dep_pkg == pkg: + continue - if ver_needed: - dep = "%s (>= %s)" % (dep_pkg, ver_needed) - else: - dep = dep_pkg - if not dep in deps: - deps.append(dep) - else: - bb.note("Couldn't find shared library provider for %s" % n) + if ver_needed: + dep = "%s (>= %s)" % (dep_pkg, ver_needed) + else: + dep = dep_pkg + if not dep in deps: + deps.append(dep) + continue + bb.note("Couldn't find shared library provider for %s, used by files: %s" % (n[0], n[1])) deps_file = os.path.join(pkgdest, pkg + ".shlibdeps") if os.path.exists(deps_file): @@ -1558,12 +1765,12 @@ python package_do_shlibs() { python package_do_pkgconfig () { import re - packages = d.getVar('PACKAGES', True) - workdir = d.getVar('WORKDIR', True) - pkgdest = d.getVar('PKGDEST', True) + packages = d.getVar('PACKAGES') + workdir = d.getVar('WORKDIR') + pkgdest = d.getVar('PKGDEST') - shlibs_dirs = d.getVar('SHLIBSDIRS', True).split() - shlibswork_dir = d.getVar('SHLIBSWORKDIR', True) + shlibs_dirs = d.getVar('SHLIBSDIRS').split() + shlibswork_dir = d.getVar('SHLIBSWORKDIR') pc_re = re.compile('(.*)\.pc$') var_re = re.compile('(.*)=(.*)') @@ -1574,18 +1781,15 @@ python package_do_pkgconfig () { for pkg in packages.split(): pkgconfig_provided[pkg] = [] pkgconfig_needed[pkg] = [] - top = os.path.join(pkgdest, pkg) - for root, dirs, files in os.walk(top): - for file in files: + for file in pkgfiles[pkg]: m = pc_re.match(file) if m: pd = bb.data.init() name = m.group(1) pkgconfig_provided[pkg].append(name) - path = os.path.join(root, file) - if not os.access(path, os.R_OK): + if not os.access(file, os.R_OK): continue - f = open(path, 'r') + f = open(file, 'r') lines = f.readlines() f.close() for l in lines: @@ -1598,7 +1802,7 @@ python package_do_pkgconfig () { m = field_re.match(l) if m: hdr = m.group(1) - exp = bb.data.expand(m.group(2), pd) + exp = pd.expand(m.group(2)) if hdr == 'Requires': pkgconfig_needed[pkg] += exp.replace(',', ' ').split() @@ -1613,7 +1817,8 @@ python package_do_pkgconfig () { f.write('%s\n' % p) f.close() - for dir in shlibs_dirs: + # Go from least to most specific since the last one found wins + for dir in reversed(shlibs_dirs): if not os.path.exists(dir): continue for file in os.listdir(dir): @@ -1650,13 +1855,13 @@ python package_do_pkgconfig () { def read_libdep_files(d): pkglibdeps = {} - packages = d.getVar('PACKAGES', True).split() + packages = d.getVar('PACKAGES').split() for pkg in packages: pkglibdeps[pkg] = {} for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": depsfile = d.expand("${PKGDEST}/" + pkg + extension) if os.access(depsfile, os.R_OK): - fd = file(depsfile) + fd = open(depsfile) lines = fd.readlines() fd.close() for l in lines: @@ -1670,9 +1875,9 @@ def read_libdep_files(d): python read_shlibdeps () { pkglibdeps = read_libdep_files(d) - packages = d.getVar('PACKAGES', True).split() + packages = d.getVar('PACKAGES').split() for pkg in packages: - rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, False) or d.getVar('RDEPENDS', False) or "") + rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "") for dep in pkglibdeps[pkg]: # Add the dep if it's not already there, or if no comparison is set if dep not in rdepends: @@ -1697,23 +1902,23 @@ python package_depchains() { package. """ - packages = d.getVar('PACKAGES', True) - postfixes = (d.getVar('DEPCHAIN_POST', True) or '').split() - prefixes = (d.getVar('DEPCHAIN_PRE', True) or '').split() + packages = d.getVar('PACKAGES') + postfixes = (d.getVar('DEPCHAIN_POST') or '').split() + prefixes = (d.getVar('DEPCHAIN_PRE') or '').split() def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d): #bb.note('depends for %s is %s' % (base, depends)) - rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg, True) or d.getVar('RRECOMMENDS', True) or "") + rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "") for depend in depends: if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'): #bb.note("Skipping %s" % depend) continue if depend.endswith('-dev'): - depend = depend.replace('-dev', '') + depend = depend[:-4] if depend.endswith('-dbg'): - depend = depend.replace('-dbg', '') + depend = depend[:-4] pkgname = getname(depend, suffix) #bb.note("Adding %s for %s" % (pkgname, depend)) if pkgname not in rreclist and pkgname != pkg: @@ -1725,16 +1930,16 @@ python package_depchains() { def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d): #bb.note('rdepends for %s is %s' % (base, rdepends)) - rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg, True) or d.getVar('RRECOMMENDS', True) or "") + rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "") for depend in rdepends: if depend.find('virtual-locale-') != -1: #bb.note("Skipping %s" % depend) continue if depend.endswith('-dev'): - depend = depend.replace('-dev', '') + depend = depend[:-4] if depend.endswith('-dbg'): - depend = depend.replace('-dbg', '') + depend = depend[:-4] pkgname = getname(depend, suffix) #bb.note("Adding %s for %s" % (pkgname, depend)) if pkgname not in rreclist and pkgname != pkg: @@ -1748,15 +1953,12 @@ python package_depchains() { list.append(dep) depends = [] - for dep in bb.utils.explode_deps(d.getVar('DEPENDS', True) or ""): + for dep in bb.utils.explode_deps(d.getVar('DEPENDS') or ""): add_dep(depends, dep) rdepends = [] - for dep in bb.utils.explode_deps(d.getVar('RDEPENDS', True) or ""): - add_dep(rdepends, dep) - for pkg in packages.split(): - for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + pkg, True) or ""): + for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + pkg) or ""): add_dep(rdepends, dep) #bb.note('rdepends is %s' % rdepends) @@ -1786,8 +1988,7 @@ python package_depchains() { for pkg in pkglibdeps: for k in pkglibdeps[pkg]: add_dep(pkglibdeplist, k) - # FIXME this should not look at PN once all task recipes inherit from task.bbclass - dbgdefaultdeps = ((d.getVar('DEPCHAIN_DBGDEFAULTDEPS', True) == '1') or (d.getVar('PN', True) or '').startswith('packagegroup-')) + dbgdefaultdeps = ((d.getVar('DEPCHAIN_DBGDEFAULTDEPS') == '1') or (bb.data.inherits_class('packagegroup', d))) for suffix in pkgs: for pkg in pkgs[suffix]: @@ -1804,32 +2005,44 @@ python package_depchains() { pkg_addrrecs(pkg, base, suffix, func, rdepends, d) else: rdeps = [] - for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + base, True) or d.getVar('RDEPENDS', True) or ""): + for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + base) or ""): add_dep(rdeps, dep) pkg_addrrecs(pkg, base, suffix, func, rdeps, d) } # Since bitbake can't determine which variables are accessed during package # iteration, we need to list them here: -PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR" +PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR USERADD_PARAM GROUPADD_PARAM CONFFILES SYSTEMD_SERVICE LICENSE SECTION pkg_preinst pkg_prerm RREPLACES GROUPMEMS_PARAM SYSTEMD_AUTO_ENABLE SKIP_FILEDEPS PRIVATE_LIBS" def gen_packagevar(d): ret = [] - pkgs = (d.getVar("PACKAGES", True) or "").split() - vars = (d.getVar("PACKAGEVARS", True) or "").split() + pkgs = (d.getVar("PACKAGES") or "").split() + vars = (d.getVar("PACKAGEVARS") or "").split() for p in pkgs: for v in vars: ret.append(v + "_" + p) + + # Ensure that changes to INCOMPATIBLE_LICENSE re-run do_package for + # affected recipes. + ret.append('LICENSE_EXCLUSION-%s' % p) return " ".join(ret) PACKAGE_PREPROCESS_FUNCS ?= "" -PACKAGEFUNCS ?= "package_get_auto_pr \ +# Functions for setting up PKGD +PACKAGEBUILDPKGD ?= " \ perform_packagecopy \ ${PACKAGE_PREPROCESS_FUNCS} \ - package_do_split_locales \ split_and_strip_files \ fixup_perms \ - populate_packages \ + " +# Functions which split PKGD up into separate packages +PACKAGESPLITFUNCS ?= " \ + package_do_split_locales \ + populate_packages" +# Functions which process metadata based on split packages +PACKAGEFUNCS += " \ + package_fixsymlinks \ + package_name_hook \ package_do_filedeps \ package_do_shlibs \ package_do_pkgconfig \ @@ -1844,36 +2057,93 @@ python do_package () { # as any change to rpmdeps requires this to be rerun. # PACKAGE_BBCLASS_VERSION = "1" - packages = (d.getVar('PACKAGES', True) or "").split() + # Init cachedpath + global cpath + cpath = oe.cachedpath.CachedPath() + + ########################################################################### + # Sanity test the setup + ########################################################################### + + packages = (d.getVar('PACKAGES') or "").split() if len(packages) < 1: bb.debug(1, "No packages to build, skipping do_package") return - workdir = d.getVar('WORKDIR', True) - outdir = d.getVar('DEPLOY_DIR', True) - dest = d.getVar('D', True) - dvar = d.getVar('PKGD', True) - pn = d.getVar('PN', True) + workdir = d.getVar('WORKDIR') + outdir = d.getVar('DEPLOY_DIR') + dest = d.getVar('D') + dvar = d.getVar('PKGD') + pn = d.getVar('PN') - if not workdir or not outdir or not dest or not dvar or not pn or not packages: - bb.error("WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package") + if not workdir or not outdir or not dest or not dvar or not pn: + msg = "WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package" + package_qa_handle_error("var-undefined", msg, d) return - for f in (d.getVar('PACKAGEFUNCS', True) or '').split(): + bb.build.exec_func("package_get_auto_pr", d) + + ########################################################################### + # Optimisations + ########################################################################### + + # Continually expanding complex expressions is inefficient, particularly + # when we write to the datastore and invalidate the expansion cache. This + # code pre-expands some frequently used variables + + def expandVar(x, d): + d.setVar(x, d.getVar(x)) + + for x in 'PN', 'PV', 'BPN', 'TARGET_SYS', 'EXTENDPRAUTO': + expandVar(x, d) + + ########################################################################### + # Setup PKGD (from D) + ########################################################################### + + for f in (d.getVar('PACKAGEBUILDPKGD') or '').split(): bb.build.exec_func(f, d) + + ########################################################################### + # Split up PKGD into PKGDEST + ########################################################################### + + cpath = oe.cachedpath.CachedPath() + + for f in (d.getVar('PACKAGESPLITFUNCS') or '').split(): + bb.build.exec_func(f, d) + + ########################################################################### + # Process PKGDEST + ########################################################################### + + # Build global list of files in each split package + global pkgfiles + pkgfiles = {} + packages = d.getVar('PACKAGES').split() + pkgdest = d.getVar('PKGDEST') + for pkg in packages: + pkgfiles[pkg] = [] + for walkroot, dirs, files in cpath.walk(pkgdest + "/" + pkg): + for file in files: + pkgfiles[pkg].append(walkroot + os.sep + file) + + for f in (d.getVar('PACKAGEFUNCS') or '').split(): + bb.build.exec_func(f, d) + + qa_sane = d.getVar("QA_SANE") + if not qa_sane: + bb.fatal("Fatal QA errors found, failing task.") } do_package[dirs] = "${SHLIBSWORKDIR} ${PKGDESTWORK} ${D}" -do_package[vardeps] += "${PACKAGEFUNCS} ${@gen_packagevar(d)}" -addtask package before do_build after do_install +do_package[vardeps] += "${PACKAGEBUILDPKGD} ${PACKAGESPLITFUNCS} ${PACKAGEFUNCS} ${@gen_packagevar(d)}" +addtask package after do_install PACKAGELOCK = "${STAGING_DIR}/package-output.lock" SSTATETASKS += "do_package" -do_package[sstate-name] = "package" -do_package[cleandirs] = "${PKGDESTWORK}" -do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}" -do_package[sstate-inputdirs] = "${PKGDESTWORK}" -do_package[sstate-outputdirs] = "${PKGDATA_DIR}" +do_package[cleandirs] = "${PKGDEST} ${PKGDESTWORK}" +do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST} ${PKGDESTWORK}" do_package[sstate-lockfile-shared] = "${PACKAGELOCK}" do_package_setscene[dirs] = "${STAGING_DIR}" @@ -1882,14 +2152,22 @@ python do_package_setscene () { } addtask do_package_setscene -# Dummy task to mark when all packaging is complete -do_package_write () { +do_packagedata () { : } -do_package_write[noexec] = "1" -PACKAGERDEPTASK = "do_package_write" -do_build[recrdeptask] += "${PACKAGERDEPTASK}" -addtask package_write before do_build after do_package + +addtask packagedata before do_build after do_package + +SSTATETASKS += "do_packagedata" +do_packagedata[sstate-inputdirs] = "${PKGDESTWORK}" +do_packagedata[sstate-outputdirs] = "${PKGDATA_DIR}" +do_packagedata[sstate-lockfile-shared] = "${PACKAGELOCK}" +do_packagedata[stamp-extra-info] = "${MACHINE}" + +python do_packagedata_setscene () { + sstate_setscene(d) +} +addtask do_packagedata_setscene # # Helper functions for the package writing classes @@ -1900,10 +2178,7 @@ def mapping_rename_hook(d): Rewrite variables to account for package renaming in things like debian.bbclass or manual PKG variable name changes """ - runtime_mapping_rename("RDEPENDS", d) - runtime_mapping_rename("RRECOMMENDS", d) - runtime_mapping_rename("RSUGGESTS", d) - runtime_mapping_rename("RPROVIDES", d) - runtime_mapping_rename("RREPLACES", d) - runtime_mapping_rename("RCONFLICTS", d) - + pkg = d.getVar("PKG") + runtime_mapping_rename("RDEPENDS", pkg, d) + runtime_mapping_rename("RRECOMMENDS", pkg, d) + runtime_mapping_rename("RSUGGESTS", pkg, d) |
