diff mbox series

kbuild: deb-pkg: don't set KBUILD_BUILD_VERSION indiscriminately

Message ID 20250305192536.1673099-1-alexandru.gagniuc@hp.com (mailing list archive)
State New
Headers show
Series kbuild: deb-pkg: don't set KBUILD_BUILD_VERSION indiscriminately | expand

Commit Message

Alexandru Gagniuc March 5, 2025, 7:25 p.m. UTC
In ThinPro, we use the convention <upstream_ver>+hp<patchlevel> for
the kernel package. This does not have a dash in the name or version.
This is built by editing ".version" before a build, and setting
EXTRAVERSION="+hp" and KDEB_PKGVERSION make variables:

    echo 68 > .version
    make -j<n> EXTRAVERSION="+hp" bindeb-pkg KDEB_PKGVERSION=6.6.6+hp69

    .deb name: linux-image-6.6.6+hp_6.6.6+hp69_amd64.deb

Since commit 7d4f07d5cb71 ("kbuild: deb-pkg: squash
scripts/package/deb-build-option to debian/rules"), this no longer
works. The deb build logic changed, even though, the commit message
implies that the logic should be unmodified.

Before, KBUILD_BUILD_VERSION was not set if the KDEB_PKGVERSION did
not contain a dash. After the change KBUILD_BUILD_VERSION is always
set to KDEB_PKGVERSION. Since this determines UTS_VERSION,the uname
output to look off:

    (now)      uname -a: version 6.6.6+hp ... #6.6.6+hp69
    (expected) uname -a: version 6.6.6+hp ... #69

Update the debian/rules logic to restore the original behavior.

Cc: <stable@vger.kernel.org> # v6.12+
Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")
Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@hp.com>
---
 scripts/package/debian/rules | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Nicolas Schier March 7, 2025, 4:36 p.m. UTC | #1
Hi Alexandru,

"indiscriminately" sounds a bit weird to me (but I am a non-native speaker); do
you mean "unconditionally"?

On Wed, Mar 05, 2025 at 07:25:36PM +0000 Alexandru Gagniuc wrote:
> 
> In ThinPro, we use the convention <upstream_ver>+hp<patchlevel> for
> the kernel package. This does not have a dash in the name or version.
> This is built by editing ".version" before a build, and setting
> EXTRAVERSION="+hp" and KDEB_PKGVERSION make variables:
> 
>     echo 68 > .version
>     make -j<n> EXTRAVERSION="+hp" bindeb-pkg KDEB_PKGVERSION=6.6.6+hp69
> 
>     .deb name: linux-image-6.6.6+hp_6.6.6+hp69_amd64.deb
> 
> Since commit 7d4f07d5cb71 ("kbuild: deb-pkg: squash
> scripts/package/deb-build-option to debian/rules"), this no longer
> works. The deb build logic changed, even though, the commit message
> implies that the logic should be unmodified.
> 
> Before, KBUILD_BUILD_VERSION was not set if the KDEB_PKGVERSION did
> not contain a dash. After the change KBUILD_BUILD_VERSION is always
> set to KDEB_PKGVERSION. Since this determines UTS_VERSION,the uname
> output to look off:
> 
>     (now)      uname -a: version 6.6.6+hp ... #6.6.6+hp69
>     (expected) uname -a: version 6.6.6+hp ... #69
> 
> Update the debian/rules logic to restore the original behavior.
> 
> Cc: <stable@vger.kernel.org> # v6.12+

Shouldn't this be v6.8, as 7d4f07d5cb71 got introduced there?

> Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")
> Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@hp.com>
> ---
>  scripts/package/debian/rules | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index ca07243bd5cd..bbc214f2e6bd 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -21,9 +21,13 @@ ifeq ($(origin KBUILD_VERBOSE),undefined)
>      endif
>  endif
>  
> -revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
> +debian_revision = $(shell dpkg-parsechangelog -S Version)
> +revision = $(lastword $(subst -, ,$(debian_revision)))
>  CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
> -make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
> +make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
> +ifneq ($(revision), $(debian_revision))
> +    make-opts+=KBUILD_BUILD_VERSION=$(revision)
> +endif
>  
>  binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
>  
> -- 
> 2.48.1
> 

Looks good to me.

Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Nathan Chancellor March 7, 2025, 8:56 p.m. UTC | #2
On Fri, Mar 07, 2025 at 05:36:26PM +0100, Nicolas Schier wrote:
> On Wed, Mar 05, 2025 at 07:25:36PM +0000 Alexandru Gagniuc wrote:
> > Cc: <stable@vger.kernel.org> # v6.12+
> 
> Shouldn't this be v6.8, as 7d4f07d5cb71 got introduced there?

Presumably this is because there are no supported kernel versions
between 6.8 and 6.12 anymore but I think the '# v6.12+' is entirely
superfluous because there is a fixes tag, so the stable folks will
figure out how far to backport it automatically based on that.

> > Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")

Cheers,
Nathan
Alexandru Gagniuc March 10, 2025, 6:53 p.m. UTC | #3
Hi Nathan and Nicholas,

On Fri, Mar 07, 2025 at 09:56:12PM +0100, Nathan Chancellor wrote:
> On Fri, Mar 07, 2025 at 05:36:26PM +0100, Nicolas Schier wrote:
> > On Wed, Mar 05, 2025 at 07:25:36PM +0000 Alexandru Gagniuc wrote:
> > > Cc: <stable@vger.kernel.org> # v6.12+
> > 
> > Shouldn't this be v6.8, as 7d4f07d5cb71 got introduced there?
> 
> Presumably this is because there are no supported kernel versions
> between 6.8 and 6.12 anymore but I think the '# v6.12+' is entirely
> superfluous because there is a fixes tag, so the stable folks will
> figure out how far to backport it automatically based on that.
> 
I'll just remove the '# v6.12+' then.
> > > Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")

I agree that "unconditionally" better conveys the idea behind the
patch. I'll make that change too.

Alex
Masahiro Yamada March 11, 2025, 6:05 p.m. UTC | #4
On Thu, Mar 6, 2025 at 4:27 AM Alexandru Gagniuc
<alexandru.gagniuc@hp.com> wrote:
>
> In ThinPro, we use the convention <upstream_ver>+hp<patchlevel> for
> the kernel package. This does not have a dash in the name or version.

So, the kernel is a native package in ThinPro, in contrast to
Debian and Ubuntu, where the kernel is a non-native package.

I think it is a little odd, but if you want to use a version number
without a hyphen, we can support this only for bindeb-pkg.

Please keep in mind that you still cannot do
"make deb-pkg" or "make srcdeb-pkg" in your way.


In Debian Policy [1], the version format is:

    [epoch:]upstream_version[-debian_revision]

[1]: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version


Here, the absence of the debian_revision indicates that the package is
a native package.

Because Kbuild uses the debian format 3.0 (quilt),
the debian_revision portion must be appended with a hyphen
when you generate a source package.



> This is built by editing ".version" before a build, and setting
> EXTRAVERSION="+hp" and KDEB_PKGVERSION make variables:
>
>     echo 68 > .version
>     make -j<n> EXTRAVERSION="+hp" bindeb-pkg KDEB_PKGVERSION=6.6.6+hp69

So, you are doing math.

You write a smaller number into .version by one
("68" into the .version file and set "+hp69" to the variable)
as the number in the .version file is incremented
during the kernel build.

Tricky, but seems to work.






>     .deb name: linux-image-6.6.6+hp_6.6.6+hp69_amd64.deb
>
> Since commit 7d4f07d5cb71 ("kbuild: deb-pkg: squash
> scripts/package/deb-build-option to debian/rules"), this no longer
> works. The deb build logic changed, even though, the commit message
> implies that the logic should be unmodified.
>
> Before, KBUILD_BUILD_VERSION was not set if the KDEB_PKGVERSION did
> not contain a dash. After the change KBUILD_BUILD_VERSION is always
> set to KDEB_PKGVERSION. Since this determines UTS_VERSION,the uname
> output to look off:
>
>     (now)      uname -a: version 6.6.6+hp ... #6.6.6+hp69
>     (expected) uname -a: version 6.6.6+hp ... #69
>
> Update the debian/rules logic to restore the original behavior.
>
> Cc: <stable@vger.kernel.org> # v6.12+
> Fixes: 7d4f07d5cb71 ("kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules")
> Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@hp.com>
> ---
>  scripts/package/debian/rules | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index ca07243bd5cd..bbc214f2e6bd 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -21,9 +21,13 @@ ifeq ($(origin KBUILD_VERBOSE),undefined)
>      endif
>  endif
>
> -revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
> +debian_revision = $(shell dpkg-parsechangelog -S Version)
> +revision = $(lastword $(subst -, ,$(debian_revision)))
>  CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
> -make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
> +make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
> +ifneq ($(revision), $(debian_revision))

dpkg-parsechangelog is invoked multiple times,
even for 'debian/rules clean'.


I would write the code like this:

revision = $(shell dpkg-parsechangelog -S Version | sed -n 's/.*-//p')
CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) $(addprefix
KBUILD_BUILD_VERSION=,$(revision)) $(addprefix
CROSS_COMPILE=,$(CROSS_COMPILE))



WIth this, dpkg-parsechangelog is invoked just one time
only when building the package.




> +    make-opts+=KBUILD_BUILD_VERSION=$(revision)
> +endif
>
>  binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
>
> --
> 2.48.1
>


--
Best Regards

Masahiro Yamada
diff mbox series

Patch

diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index ca07243bd5cd..bbc214f2e6bd 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -21,9 +21,13 @@  ifeq ($(origin KBUILD_VERBOSE),undefined)
     endif
 endif
 
-revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
+debian_revision = $(shell dpkg-parsechangelog -S Version)
+revision = $(lastword $(subst -, ,$(debian_revision)))
 CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
-make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
+make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
+ifneq ($(revision), $(debian_revision))
+    make-opts+=KBUILD_BUILD_VERSION=$(revision)
+endif
 
 binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)