diff mbox series

os-release: do not add empty parentheses to VERSION

Message ID 20250912161917.844344-2-dwagenknecht@emlix.com
State New
Headers show
Series os-release: do not add empty parentheses to VERSION | expand

Commit Message

Daniel Wagenknecht Sept. 12, 2025, 4:17 p.m. UTC
Setting DISTRO_CODENAME to an empty string previously led to a VERSION
field in /etc/os-release containing empty parantheses, e.g.
   DISTRO_VERSION = "5.0.12"
   DISTRO_CODENAME = ""
   ==> /etc/os-release:
       VERSION="5.0.12 ()"

This is probably not what a user expects, especially since it is quite
common to set variables to empty strings to disable something in OE
based builds, but using `unset VARNAME` seems pretty uncommon.

Instead of adding the parentheses with the DISTRO_CODENAME if the
variable is in the datastore add them only if the variable is not empty.

Signed-off-by: Daniel Wagenknecht <dwagenknecht@emlix.com>
---
 meta/recipes-core/os-release/os-release.bb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Kjellerstedt Sept. 13, 2025, 10:28 a.m. UTC | #1
> -----Original Message-----
> From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Daniel Wagenknecht
> Sent: den 12 september 2025 18:18
> To: openembedded-core@lists.openembedded.org
> Cc: Daniel Wagenknecht <dwagenknecht@emlix.com>
> Subject: [OE-core] [PATCH] os-release: do not add empty parentheses to VERSION
> 
> Setting DISTRO_CODENAME to an empty string previously led to a VERSION
> field in /etc/os-release containing empty parantheses, e.g.
>    DISTRO_VERSION = "5.0.12"
>    DISTRO_CODENAME = ""
>    ==> /etc/os-release:
>        VERSION="5.0.12 ()"
> 
> This is probably not what a user expects, especially since it is quite
> common to set variables to empty strings to disable something in OE
> based builds, but using `unset VARNAME` seems pretty uncommon.
> 
> Instead of adding the parentheses with the DISTRO_CODENAME if the
> variable is in the datastore add them only if the variable is not empty.
> 
> Signed-off-by: Daniel Wagenknecht <dwagenknecht@emlix.com>
> ---
>  meta/recipes-core/os-release/os-release.bb | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meta/recipes-core/os-release/os-release.bb b/meta/recipes-core/os-release/os-release.bb
> index e1906d05d..65e63a342 100644
> --- a/meta/recipes-core/os-release/os-release.bb
> +++ b/meta/recipes-core/os-release/os-release.bb
> @@ -22,7 +22,7 @@ OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
> 
>  ID = "${DISTRO}"
>  NAME = "${DISTRO_NAME}"
> -VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}"
> +VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if d.getVar('DISTRO_CODENAME') != '' else ''}"

To cover all bases you should then use:

VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if (d.getVar('DISTRO_CODENAME') or '') != '' else ''}"

One thing I do not understand, and this is mostly a question for RP, 
is how the first DISTRO_CODENAME is actually expanded in the above 
definition. I would have expected it to be:

VERSION = "${DISTRO_VERSION}${@' (%s)' % d.getvar('DISTRO_CODENAME') if (d.getVar('DISTRO_CODENAME') or '') != '' else ''}"

Or are all variables in d somehow available as Python variables 
inside ${@...}? Because then a lot of such definitions could be 
simplified, like VERSION_CODENAME below which would become:
VERSION_CODENAME = "${@DISTRO_CODENAME or ''}".

(Though that also seems odd as it could just as well be:
VERSION_CODENAME = "${DISTRO_CODENAME}"
)

>  VERSION_ID = "${DISTRO_VERSION}"
>  VERSION_CODENAME = "${@d.getVar('DISTRO_CODENAME') or ''}"
>  PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
> --
> 2.50.1

//Peter
diff mbox series

Patch

diff --git a/meta/recipes-core/os-release/os-release.bb b/meta/recipes-core/os-release/os-release.bb
index e1906d05d..65e63a342 100644
--- a/meta/recipes-core/os-release/os-release.bb
+++ b/meta/recipes-core/os-release/os-release.bb
@@ -22,7 +22,7 @@  OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
 
 ID = "${DISTRO}"
 NAME = "${DISTRO_NAME}"
-VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}"
+VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if d.getVar('DISTRO_CODENAME') != '' else ''}"
 VERSION_ID = "${DISTRO_VERSION}"
 VERSION_CODENAME = "${@d.getVar('DISTRO_CODENAME') or ''}"
 PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"