[yocto] ALTERNATIVE_TARGET, ALTERNATIVE_PRIORITY problem

Mark Hatle mark.hatle at windriver.com
Tue Jan 27 08:53:12 PST 2015


On 1/27/15 9:37 AM, Joseph Andrew de la Peña wrote:
> Good day Yocto Community,
> 
> I would like to ask what's wrong with my implementation with update-alternatives:

I think that you have some of the variables confused below.  I've quoted bits of
the class's header (internal documentation):

# List all of the alternatives needed by a package:
# ALTERNATIVE_<pkg> = "name1 name2 name3 ..."

# The pathname of the link
# ALTERNATIVE_LINK_NAME[name] = "target"

# NOTE: If ALTERNATIVE_LINK_NAME is not defined, it defaults to ${bindir}/name


# The default link to create for all targets
# ALTERNATIVE_TARGET = "target"

or

# A non-default link to create for a target
# ALTERNATIVE_TARGET[name] = "target"

# A package specific link for a target
# ALTERNATIVE_TARGET_<pkg>[name] = "target"
#
#   This is useful when a recipe provides multiple alternatives for the
#   same item.


So if you have a single binary called 'bar', and want it to show up as bar1,
bar2 and bar3 using the alternatives you would do:

PACKAGES =+ "${PN}-bar1 ${PN}-bar2 ${PN}-bar3"
ALTERNATIVE_${PN}-bar1 = "bar1"
ALTERNATIVE_${PN}-bar2 = "bar2"
ALTERNATIVE_${PN}-bar3 = "bar3"

ALTERNATIVE_TARGET = "/bin/bar"

ALTERNATIVE_LINK_NAME[bar1] = "/bin/bar1"
ALTERNATIVE_LINK_NAME[bar2] = "/bin/bar2"
ALTERNATIVE_LINK_NAME[bar3] = "/bin/bar3"

FILES_${PN} = "/bin/bar"

The result would be:

package ${PN} contains /bin/bar

package ${PN}-bar1 would create a link /bin/bar1 -> /bin/bar
package ${PN}-bar2 would create a link /bin/bar2 -> /bin/bar
package ${PN}-bar3 would create a link /bin/bar3 -> /bin/bar


If you want to do the other way around, have three packages that all provide
'bar'.  You would do:

PACKAGES =+ "${PN}-bar1 ${PN}-bar2 ${PN}-bar3"
ALTERNATIVE_${PN}-bar1 = "bar"
ALTERNATIVE_${PN}-bar2 = "bar"
ALTERNATIVE_${PN}-bar3 = "bar"

ALTERNATIVE_LINK_NAME[bar] = "/bin/bar"

ALTERNATIVE_TARGET_${PN}-bar1 = "/bin/bar1"
ALTERNATIVE_TARGET_${PN}-bar2 = "/bin/bar2"
ALTERNATIVE_TARGET_${PN}-bar3 = "/bin/bar3"

FILES_${PN}-bar1 = "/bin/bar1"
FILES_${PN}-bar2 = "/bin/bar2"
FILES_${PN}-bar3 = "/bin/bar3"


package ${PN}-bar1 would own a file /bin/bar1 and link it to /bin/bar
package ${PN}-bar2 would own a file /bin/bar2 and link it to /bin/bar
package ${PN}-bar3 would own a file /bin/bar3 and link it to /bin/bar


(You can verify the above by looking at the package data, if using RPM, rpm -qp
<package> --scripts will show you the logic for adding the alternative.)


As for the install time, the packaging system will "choose" to install a package
that meets the dependency you select.  If you don't specifically name ${PN}-bar1
in your install, it may not be selected in favor of one of the other providers.
 The PRIORITY only affects if multiple packages are installed, which one takes
priority over the others.

--Mark

> =================
> 
> *bar_git.bb <http://bar_git.bb/>:*
> 
> PACKAGES =+ "${PN}-bar1 ${PN}-bar2 ${PN}-bar3"
> RPROVIDES_${PN}-bar1 = "bar"
> RPROVIDES_${PN}-bar2 = "bar"
> RPROVIDES_${PN}-bar3 = "bar"
> 
> ALTERNATIVE_LINK_NAME[bar] = "${datadir}/foo/bar"
> 
> ALTERNATIVE_${PN}-bar1 = "bar"
> ALTERNATIVE_TARGET_${PN}-bar1 = "${datadir}/foo/bar1"
> ALTERNATIVE_PRIORITY_${PN}-bar1 = "99"
> 
> ALTERNATIVE_${PN}-bar2 = "bar"
> ALTERNATIVE_TARGET_${PN}-bar2 = "${datadir}/foo/bar2"
> ALTERNATIVE_PRIORITY_${PN}-bar2 = "98"
> 
> ALTERNATIVE_${PN}-bar3 = "bar"
> ALTERNATIVE_TARGET_${PN}-bar3 = "${datadir}/foo/bar3"
> ALTERNATIVE_PRIORITY_${PN}-bar3 = "97"
> 
> inherit update-alternatives
> 
> *packagegroup-foobar.bb <http://packagegroup-foobar.bb/>:*
> 
> RDEPENDS_foobar = "bar"
> 
> =================
> 
> The end result is always bar3 is present and bar is pointing to bar3. I never
> get bar1 being present which is the result I want.
> 
> Please do recommend how will I properly use ALTERNATIVE_TARGET and
> ALTERNATIVE_PRIORITY.
> 
> Thanks,
> Joseph
> 
> 




More information about the yocto mailing list