All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mariano Lopez <just.another.mariano@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 1/3] update-alternatives.bbclass: Add function to get renamed binaries
Date: Fri,  5 Apr 2019 09:26:39 -0500	[thread overview]
Message-ID: <d370d05c79d7f49eaaee544d995343f77e6773eb.1554474048.git.just.another.mariano@gmail.com> (raw)
In-Reply-To: <cover.1554474048.git.just.another.mariano@gmail.com>

This adds a function to get the new name for renamed binaries by the
update-alternatives class. The function uses the build metadata because
some update-alternatives binaries/scripts lack the feature to provide
this information.

This also adds the function _ua_alt_target for code reuse.

[YOCTO #13238]

Signed-off-by: Mariano Lopez <just.another.mariano@gmail.com>
---
 meta/classes/update-alternatives.bbclass | 43 +++++++++++++++++++++---
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/meta/classes/update-alternatives.bbclass b/meta/classes/update-alternatives.bbclass
index 537e85d9a3..d601dfc700 100644
--- a/meta/classes/update-alternatives.bbclass
+++ b/meta/classes/update-alternatives.bbclass
@@ -216,6 +216,43 @@ python apply_update_alternative_renames () {
             update_files(alt_target, alt_target_rename, pkg, d)
 }
 
+def update_alternatives_get_alt_target(d, link):
+    """
+    Returns the renamed binary modified by update-alternatives class.
+
+    Unfortunately not all update-alternative binaries/scripts implement a way
+    to provide a list of binaries for a link, so we need to use the build
+    metadata to get the information.
+
+    NOTE: This function needs to run after apply_update_alternative_renames
+    """
+    for pkg in (d.getVar('PACKAGES') or "").split():
+        for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split():
+            alt_link   = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name)
+
+            # Just care for the link being asked for
+            if link != alt_link:
+                continue
+
+            alt_target = _ua_alt_target(d, alt_name, alt_link, pkg)
+            if alt_target != alt_link:
+                return alt_target
+            else:
+                return None
+
+    return None
+
+def _ua_alt_target(d, alt_name, alt_link, pkg):
+    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
+
+    # Sometimes alt_target is specified as relative to the link name.
+    alt_target   = os.path.join(os.path.dirname(alt_link), alt_target)
+    return alt_target
+
 PACKAGESPLITFUNCS_prepend = "populate_packages_updatealternatives "
 
 python populate_packages_updatealternatives () {
@@ -232,11 +269,7 @@ python populate_packages_updatealternatives () {
         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_target   = _ua_alt_target(d, alt_name, alt_link, pkg)
             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')
 
-- 
2.19.2



       reply	other threads:[~2019-04-05 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1554474048.git.just.another.mariano@gmail.com>
2019-04-05 14:26 ` Mariano Lopez [this message]
2019-04-05 14:26 ` [PATCH 2/3] ptest.bbclass: Add feature to populate a binary directory Mariano Lopez
2019-04-05 14:26 ` [PATCH 3/3] util-linux: Use PTEST " Mariano Lopez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d370d05c79d7f49eaaee544d995343f77e6773eb.1554474048.git.just.another.mariano@gmail.com \
    --to=just.another.mariano@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.