Re: [OE-core] [PATCH v2 1/4] update-alternatives.bbclass: Add function to get metadata

2019-04-08 Thread richard . purdie
On Sun, 2019-04-07 at 21:23 -0500, Mariano Lopez wrote:
> On 4/7/19 4:32 PM, Richard Purdie wrote:
> > On Sun, 2019-04-07 at 12:15 -0500, Mariano Lopez wrote:
> > > -
> > > -# 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)
> > > +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)
> > I think the above is three whitespaces, not four? I know its minor
> > but
> > it jumped out as I was comparing the code before/after!
> > 
> > Cheers,
> > 
> > Richard
> > 
> 
> Good catch! I have sent the the fixed version but I messed up with
> the 
> cover letter, you can find the correct version here:
> https://patchwork.openembedded.org/patch/160236/
> 
> 
> I think I don't even need to put that link there :)

Thanks, unfortunately nativesdk-util-linux fails to build :(

https://autobuilder.yoctoproject.org/typhoon/#/builders/20/builds/711

Cheers,

Richard

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


Re: [OE-core] [PATCH v2 1/4] update-alternatives.bbclass: Add function to get metadata

2019-04-07 Thread Mariano Lopez



On 4/7/19 4:32 PM, Richard Purdie wrote:

On Sun, 2019-04-07 at 12:15 -0500, Mariano Lopez wrote:

-
-# 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)
+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)

I think the above is three whitespaces, not four? I know its minor but
it jumped out as I was comparing the code before/after!

Cheers,

Richard



Good catch! I have sent the the fixed version but I messed up with the 
cover letter, you can find the correct version here:

https://patchwork.openembedded.org/patch/160236/


I think I don't even need to put that link there :)

Thanks,

Mariano

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


Re: [OE-core] [PATCH v2 1/4] update-alternatives.bbclass: Add function to get metadata

2019-04-07 Thread Richard Purdie
On Sun, 2019-04-07 at 12:15 -0500, Mariano Lopez wrote:
>  python populate_packages_updatealternatives () {
>  if not update_alternatives_enabled(d):
>  return
>  
> -pn = d.getVar('BPN')
> -
>  # 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)
> -
> -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)
> +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)

I think the above is three whitespaces, not four? I know its minor but
it jumped out as I was comparing the code before/after!

Cheers,

Richard


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


[OE-core] [PATCH v2 1/4] update-alternatives.bbclass: Add function to get metadata

2019-04-07 Thread Mariano Lopez
This adds update_alternatives_alt_targets function to get the metadata
for a package. This is for code reuse because the metadata would help
other classes that needs to be aware of how update-alternatives modify
the final package.

[YOCTO #12597]
[YOCTO #13238]

Signed-off-by: Mariano Lopez 
---
 meta/classes/update-alternatives.bbclass | 74 +++-
 1 file changed, 47 insertions(+), 27 deletions(-)

diff --git a/meta/classes/update-alternatives.bbclass 
b/meta/classes/update-alternatives.bbclass
index 537e85d9a3..bc19373348 100644
--- a/meta/classes/update-alternatives.bbclass
+++ b/meta/classes/update-alternatives.bbclass
@@ -216,44 +216,64 @@ python apply_update_alternative_renames () {
 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 () {
 if not update_alternatives_enabled(d):
 return
 
-pn = d.getVar('BPN')
-
 # 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)
-
-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