All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] update-alternatives: Allow using relative symlinks
@ 2018-11-14 15:48 Böszörményi Zoltán
  0 siblings, 0 replies; only message in thread
From: Böszörményi Zoltán @ 2018-11-14 15:48 UTC (permalink / raw)
  To: openembedded-core

The alternative links are invalid during do_rootfs.

Add a new ALTERNATIVE_TARGET_RELATIVE family of variables to
conditionally make these links valid.

Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
---

v2: Fix the case when the link source and target are not in
    the same directory.

v3: Moved the patch version information here so it's not polluting
    the git history when applied.

 meta/classes/update-alternatives.bbclass | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/meta/classes/update-alternatives.bbclass b/meta/classes/update-alternatives.bbclass
index aa01058cf9..540bec94e2 100644
--- a/meta/classes/update-alternatives.bbclass
+++ b/meta/classes/update-alternatives.bbclass
@@ -47,6 +47,15 @@
 # the need to rename alternative files in the do_install step, but still
 # supports it if necessary for some reason.)
 #
+# The default to use relative link for all targets
+# ALTERNATIVE_TARGET_RELATIVE = "1"
+#
+# A non-default setting to use relative link for a target
+# ALTERNATIVE_TARGET_RELATIVE[name] = "1"
+#
+# A package specific setting to use relative link for a target
+# ALTERNATIVE_TARGET_RELATIVE_<pkg>[name] = "1"
+#
 # The default priority for any alternatives
 # ALTERNATIVE_PRIORITY = "priority"
 #
@@ -214,6 +223,10 @@ python populate_packages_updatealternatives () {
             # Sometimes alt_target is specified as relative to the link name.
             alt_target   = os.path.join(os.path.dirname(alt_link), alt_target)
 
+            # Whether to use relative symlink target
+            alt_relative = d.getVarFlag('ALTERNATIVE_TARGET_RELATIVE_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET_RELATIVE', alt_name)
+            alt_relative = alt_relative or d.getVar('ALTERNATIVE_TARGET_RELATIVE_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET_RELATIVE')
+
             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')
 
@@ -229,8 +242,15 @@ python populate_packages_updatealternatives () {
             # Default to generate shell script.. eventually we may want to change this...
             alt_target = os.path.normpath(alt_target)
 
-            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)
+            if alt_relative and os.path.dirname(alt_target) == os.path.dirname(alt_link):
+                alt_target_final = os.path.basename(alt_target)
+            elif alt_relative:
+                alt_target_final = os.path.join(os.path.join(*['..'] * len(list(filter(None, os.path.dirname(alt_link).split('/'))))), *list(filter(None, alt_target.split('/'))))
+            else:
+                alt_target_final = alt_target
+
+            alt_setup_links  += '\tupdate-alternatives --install %s %s %s %s\n' % (alt_link, alt_name, alt_target_final, alt_priority)
+            alt_remove_links += '\tupdate-alternatives --remove  %s %s\n' % (alt_name, alt_target_final)
 
         if alt_setup_links:
             # RDEPENDS setup
-- 
2.19.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-11-14 15:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 15:48 [PATCH v3] update-alternatives: Allow using relative symlinks Böszörményi Zoltán

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.