Hi, all

My company is trying to migrate a newer version of Yocto and in an effort to do 
that I am making changes to our current layer to facilitate an easier 
transition. One problem I encountered was SystemD 250 installs a target 
factory-reset.target, but we already have a recipe that installs a that same 
file. The recipe is as follows

```bitbake
LICENSE = "CLOSED"
SUMMARY = "A factory reset target"
DESCRIPTION = "A recipe which provides a common means of creating factory reset 
\
    tasks. Each application should attach to this target in order to perform \
    any tasks when the device needs to be reset."

SRC_URI = " \
    file://factory-reset.target \
    file://factory-reset-reboot.service \
"

SYSTEMD_SERVICE_${PN} = " \
    factory-reset.target \
    factory-reset-reboot.service \
"

do_install() {
    install -d ${D}/${systemd_system_unitdir}
    install -m 0644 \
        ${WORKDIR}/factory-reset.target \
        ${WORKDIR}/factory-reset-reboot.service \
        ${D}/${systemd_system_unitdir}
}

inherit systemd
```

I figured I could get the version of systemd through its installed pkg-config, 
but I'd need to modify the content of `SYSTEMD_SERVICE_${PN`, so I tried this

```bitbake
LICENSE = "CLOSED"
SUMMARY = "A factory reset target"
DESCRIPTION = "A recipe which provides a common means of creating factory reset 
\
    tasks. Each application should attach to this target in order to perform \
    any tasks when the device needs to be reset."

DEPENDS = "systemd"

SRC_URI = " \
    file://factory-reset.target \
    file://factory-reset-reboot.service \
"

python __anonymous() {
    import subprocess

    try:
        output = subprocess.check_output(["pkg-config", "--modversion", 
"systemd"]).decode("utf-8").strip()
        systemd_version = int(output.split('.')[0])
        d.setVar("SYSTEMD_VERSION", systemd_version)
    except (subprocess.CalledProcessError, ValueError):
        bb.warn("Could not determine systemd version. Assuming version < 250")
        d.setVar("SYSTEMD_VERSION", 249)  # Default to 249 if systemd version 
cannot be determined
}

SYSTEMD_SERVICE:${PN} = "factory-reset-reboot.service"
SYSTEMD_SERVICE:${PN}:append = "${@ ' factory-reset.target' if 
int(d.getVar('SYSTEMD_VERSION')) < 250 else '' }"

do_install() {
    # systemd 250 introduces factory-reset.target for the same reasons we 
created it in the first place
    if [ ${SYSTEMD_VERSION} -lt 250 ]; then
        install -d ${D}/${systemd_system_unitdir}
        install -m 0644 ${WORKDIR}/factory-reset.target 
${D}/${systemd_system_unitdir}
    fi

    install -d ${D}/${systemd_system_unitdir}
    install -m 0644 ${WORKDIR}/factory-reset-reboot.service 
${D}/${systemd_system_unitdir}
}

inherit systemd pkgconfig
```

Obviously, this has troubles at the parsing stage.. so, this won't work. I was 
wondering if there was a nice solution to this problem so I can make my recipe 
compatible with both layer versions during the migration.

Thank you,
Logan
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#64231): https://lists.yoctoproject.org/g/yocto/message/64231
Mute This Topic: https://lists.yoctoproject.org/mt/109446043/21656
Group Owner: yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to