diff options
Diffstat (limited to 'external/poky/meta/classes/update-alternatives.bbclass')
-rw-r--r-- | external/poky/meta/classes/update-alternatives.bbclass | 130 |
1 files changed, 90 insertions, 40 deletions
diff --git a/external/poky/meta/classes/update-alternatives.bbclass b/external/poky/meta/classes/update-alternatives.bbclass index a7f1a6fd..8c2b66e7 100644 --- a/external/poky/meta/classes/update-alternatives.bbclass +++ b/external/poky/meta/classes/update-alternatives.bbclass @@ -89,15 +89,21 @@ def ua_extend_depends(d): if not 'virtual/update-alternatives' in d.getVar('PROVIDES'): d.appendVar('DEPENDS', ' virtual/${MLPREFIX}update-alternatives') -python __anonymous() { +def update_alternatives_enabled(d): # Update Alternatives only works on target packages... if bb.data.inherits_class('native', d) or \ bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d) or \ bb.data.inherits_class('cross-canadian', d): - return + return False # Disable when targeting mingw32 (no target support) if d.getVar("TARGET_OS") == "mingw32": + return False + + return True + +python __anonymous() { + if not update_alternatives_enabled(d): return # compute special vardeps @@ -125,9 +131,21 @@ def gen_updatealternativesvars(d): populate_packages[vardeps] += "${UPDALTVARS} ${@gen_updatealternativesvars(d)}" # We need to do the rename after the image creation step, but before -# the split and strip steps.. packagecopy seems to be the earliest reasonable -# place. -python perform_packagecopy_append () { +# the split and strip steps.. PACKAGE_PREPROCESS_FUNCS is the right +# place for that. +PACKAGE_PREPROCESS_FUNCS += "apply_update_alternative_renames" +python apply_update_alternative_renames () { + if not update_alternatives_enabled(d): + return + + import re + + def update_files(alt_target, alt_target_rename, pkg, d): + f = d.getVar('FILES_' + pkg) + if f: + f = re.sub(r'(^|\s)%s(\s|$)' % re.escape (alt_target), r'\1%s\2' % alt_target_rename, f) + d.setVar('FILES_' + pkg, f) + # Check for deprecated usage... pn = d.getVar('BPN') if d.getVar('ALTERNATIVE_LINKS') != None: @@ -137,7 +155,7 @@ python perform_packagecopy_append () { pkgdest = d.getVar('PKGD') for pkg in (d.getVar('PACKAGES') or "").split(): # If the src == dest, we know we need to rename the dest by appending ${BPN} - link_rename = {} + link_rename = [] for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name) if not alt_link: @@ -163,10 +181,11 @@ python perform_packagecopy_append () { elif os.path.lexists(src): if os.path.islink(src): # Delay rename of links - link_rename[alt_target] = alt_target_rename + link_rename.append((alt_target, alt_target_rename)) else: bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename)) os.rename(src, dest) + update_files(alt_target, alt_target_rename, pkg, d) else: bb.warn("%s: alternative target (%s or %s) does not exist, skipping..." % (pn, alt_target, alt_target_rename)) continue @@ -174,61 +193,85 @@ python perform_packagecopy_append () { # Process delayed link names # Do these after other renames so we can correct broken links - for alt_target in link_rename: + for (alt_target, alt_target_rename) in link_rename: src = '%s/%s' % (pkgdest, alt_target) - dest = '%s/%s' % (pkgdest, link_rename[alt_target]) - link = os.readlink(src) + dest = '%s/%s' % (pkgdest, alt_target_rename) link_target = oe.path.realpath(src, pkgdest, True) if os.path.lexists(link_target): # Ok, the link_target exists, we can rename - bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, link_rename[alt_target])) + bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, alt_target_rename)) os.rename(src, dest) else: # Try to resolve the broken link to link.${BPN} link_maybe = '%s.%s' % (os.readlink(src), pn) if os.path.lexists(os.path.join(os.path.dirname(src), link_maybe)): # Ok, the renamed link target exists.. create a new link, and remove the original - bb.note('%s: Creating new link %s -> %s' % (pn, link_rename[alt_target], link_maybe)) + bb.note('%s: Creating new link %s -> %s' % (pn, alt_target_rename, link_maybe)) os.symlink(link_maybe, dest) os.unlink(src) else: bb.warn('%s: Unable to resolve dangling symlink: %s' % (pn, alt_target)) + continue + update_files(alt_target, alt_target_rename, pkg, d) } +def update_alternatives_alt_targets(d, pkg): + """ + Returns the update-alternatives metadata for a package. + + The returned format is a list of tuples where the tuple contains: + alt_name: The binary name + alt_link: The path for the binary (Shared by different packages) + alt_target: The path for the renamed binary (Unique per package) + alt_priority: The priority of the alt_target + + All the alt_targets will be installed into the sysroot. The alt_link is + a symlink pointing to the alt_target with the highest priority. + """ + + pn = d.getVar('BPN') + pkgdest = d.getVar('PKGD') + updates = list() + for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): + alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name) + alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or \ + d.getVarFlag('ALTERNATIVE_TARGET', alt_name) or \ + d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or \ + d.getVar('ALTERNATIVE_TARGET') or \ + alt_link + alt_priority = d.getVarFlag('ALTERNATIVE_PRIORITY_%s' % pkg, alt_name) or \ + d.getVarFlag('ALTERNATIVE_PRIORITY', alt_name) or \ + d.getVar('ALTERNATIVE_PRIORITY_%s' % pkg) or \ + d.getVar('ALTERNATIVE_PRIORITY') + + # This shouldn't trigger, as it should have been resolved earlier! + if alt_link == alt_target: + bb.note('alt_link == alt_target: %s == %s -- correcting, this should not happen!' % (alt_link, alt_target)) + alt_target = '%s.%s' % (alt_target, pn) + + if not os.path.lexists('%s/%s' % (pkgdest, alt_target)): + bb.warn('%s: NOT adding alternative provide %s: %s does not exist' % (pn, alt_link, alt_target)) + continue + + alt_target = os.path.normpath(alt_target) + updates.append( (alt_name, alt_link, alt_target, alt_priority) ) + + return updates + PACKAGESPLITFUNCS_prepend = "populate_packages_updatealternatives " python populate_packages_updatealternatives () { - pn = d.getVar('BPN') + if not update_alternatives_enabled(d): + return # Do actual update alternatives processing - pkgdest = d.getVar('PKGD') for pkg in (d.getVar('PACKAGES') or "").split(): # Create post install/removal scripts alt_setup_links = "" alt_remove_links = "" - for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): - alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name) - alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name) - alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET') or alt_link - # Sometimes alt_target is specified as relative to the link name. - alt_target = os.path.join(os.path.dirname(alt_link), alt_target) - - alt_priority = d.getVarFlag('ALTERNATIVE_PRIORITY_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_PRIORITY', alt_name) - alt_priority = alt_priority or d.getVar('ALTERNATIVE_PRIORITY_%s' % pkg) or d.getVar('ALTERNATIVE_PRIORITY') - - # This shouldn't trigger, as it should have been resolved earlier! - if alt_link == alt_target: - bb.note('alt_link == alt_target: %s == %s -- correcting, this should not happen!' % (alt_link, alt_target)) - alt_target = '%s.%s' % (alt_target, pn) - - if not os.path.lexists('%s/%s' % (pkgdest, alt_target)): - bb.warn('%s: NOT adding alternative provide %s: %s does not exist' % (pn, alt_link, alt_target)) - continue - - # Default to generate shell script.. eventually we may want to change this... - alt_target = os.path.normpath(alt_target) - + updates = update_alternatives_alt_targets(d, pkg) + for alt_name, alt_link, alt_target, alt_priority in updates: alt_setup_links += '\tupdate-alternatives --install %s %s %s %s\n' % (alt_link, alt_name, alt_target, alt_priority) alt_remove_links += '\tupdate-alternatives --remove %s %s\n' % (alt_name, alt_target) @@ -241,8 +284,11 @@ python populate_packages_updatealternatives () { bb.note('adding update-alternatives calls to postinst/prerm for %s' % pkg) bb.note('%s' % alt_setup_links) - postinst = d.getVar('pkg_postinst_%s' % pkg) or '#!/bin/sh\n' - postinst += alt_setup_links + postinst = d.getVar('pkg_postinst_%s' % pkg) + if postinst: + postinst = alt_setup_links + postinst + else: + postinst = '#!/bin/sh\n' + alt_setup_links d.setVar('pkg_postinst_%s' % pkg, postinst) bb.note('%s' % alt_remove_links) @@ -252,10 +298,15 @@ python populate_packages_updatealternatives () { } python package_do_filedeps_append () { + if update_alternatives_enabled(d): + apply_update_alternative_provides(d) +} + +def apply_update_alternative_provides(d): pn = d.getVar('BPN') pkgdest = d.getVar('PKGDEST') - for pkg in packages.split(): + for pkg in d.getVar('PACKAGES').split(): for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name) alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name) @@ -273,5 +324,4 @@ python package_do_filedeps_append () { d.appendVar('FILERPROVIDES_%s_%s' % (trans_target, pkg), " " + alt_link) if not trans_target in (d.getVar('FILERPROVIDESFLIST_%s' % pkg) or ""): d.appendVar('FILERPROVIDESFLIST_%s' % pkg, " " + trans_target) -} |