
def get_filespath_extra(d, subpath):
	metaroot = next((p for p in d.getVar('BBPATH').split(':') if os.path.basename(p) == 'meta'), None)
	if metaroot:
		return os.path.join(metaroot, subpath) + ":"
	return ""

# TODO: improve this, since it is very hacky that this recipe need to build tunctl.
# include the existing qemu-helper-native
require recipes-devtools/qemu/qemu-helper-native_1.0.bb
# get the path to tunctl.c
FILESEXTRAPATHS_prepend := "${@get_filespath_extra(d, 'recipes-devtools/qemu/qemu-helper')}"

# provide it, to replace the existing
PROVIDES += "qemu-helper-native"

# replace qemu with qemu-xilinx
DEPENDS_remove = "qemu-native"
DEPENDS_append = " qemu-xilinx-native"



python () {
    if d.getVar("PREFERRED_PROVIDER_qemu-helper-native") != d.getVar("PN"):
        raise bb.parse.SkipRecipe("Set qemu-helper-native provider to use this recipe")
}

def get_filespath_extra(d, subpath):
    metaroot = next((p for p in d.getVar('BBPATH').split(':') if os.path.basename(p) == 'meta'), None)
    if metaroot:
        return os.path.join(metaroot, subpath) + ":"
    return ""

# TODO: improve this, since it is very hacky that this recipe need to build tunctl.
# include the existing qemu-helper-native
require recipes-devtools/qemu/qemu-helper-native_1.0.bb
# get the path to tunctl.c
FILESEXTRAPATHS_prepend := "${@get_filespath_extra(d, 'recipes-devtools/qemu/qemu-helper')}"

# provide it, to replace the existing
PROVIDES += "qemu-helper-native"

# replace qemu with qemu-xilinx
DEPENDS_remove = "qemu-native"
DEPENDS_append = " qemu-xilinx-native"


Clean up preferred provider message
qemu-xilinx-helper-native: Clean up preferred provider message

Due to this recipe being added there are two providers for
qemu-helper-native, but by default one is never selected. This generates
a message during the build that informs the user to select a provider.
This is unnecessary as the only machines that care about setting the
provider is currently zcu102-zynqmp due to its requirement for
qemu-xilinx all other qemu machines should be using the
qemu-helper-native recipe and non-qemu machines don't use the recipe.

To prevent the message, only make the qemu-xilinx-helper-native recipe
available when it is selected as the preferred provider otherwise skip
it.

Signed-off-by: Nathan Rossi <2e8aa918660411855c6d44d5bb2da677aa033255@nathanrossi.com>
Acked-by: Alistair Francis <52ecf00b70a50079ae8d5fa09b9af6904950b63c@xilinx.com>
