Re: [OE-core] [PATCH v2] update-alternatives: Allow using relative symlinks

2018-11-14 Thread Peter Kjellerstedt
> -Original Message-
> From: openembedded-core-boun...@lists.openembedded.org  core-boun...@lists.openembedded.org> On Behalf Of Böszörményi Zoltán
> via Openembedded-core
> Sent: den 14 november 2018 14:22
> To: openembedded-core@lists.openembedded.org
> Subject: [OE-core] [PATCH v2] update-alternatives: Allow using relative
> symlinks
> 
> The alternative links are invalid during do_rootfs.
> 
> Add a new ALTERNATIVE_TARGET_RELATIVE family of variables to
> conditionally make these links valid.
> 
> v2: Fix the case when the link source and target are not in
> the same directory.

The v2 information should go below the --- as it doesn't relate to the 
commit as such, but rather to the review process.

> Signed-off-by: Böszörményi Zoltán 
> ---
>  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

//Peter

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v2] update-alternatives: Allow using relative symlinks

2018-11-14 Thread Böszörményi Zoltán via 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.

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

Signed-off-by: Böszörményi Zoltán 
---
 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_[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

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core