Skip to contentSkip to conversation

kbuild: deb-pkg: remove the fakeroot builds support

PATCH Superseded Masahiro Yamada 2 participants 4 messages Nov 28, 2023 – Nov 30, 2023 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kbuild: deb-pkg: remove the fakeroot builds support

In 2017, the dpkg suite introduced the rootless builds support with the following commits:

- 2436807c87b0 ("dpkg-deb: Add support for rootless builds")
- fca1bfe84068 ("dpkg-buildpackage: Add support for rootless builds")

This feature is available in the default dpkg on Debian 10 and Ubuntu 20.04.

Remove the old method.

Additionally, export DEB_RULES_REQUIRES_ROOT=no in case debian/rules is invoked without dpkg-buildpackage. This change aligns with the Debian kernel commit 65206e29f378 ("Allow to run d/rules.real without root"). While the upstream kernel currently does not run dh_testroot, it may be useful in the future.

---

Changes in v2:
- add DEB_RULES_REQUIRES_ROOT=no to debian/rules

 scripts/Makefile.package     | 4 +---
 scripts/package/builddeb     | 8 +-------
 scripts/package/debian/rules | 2 ++
 3 files changed, 4 insertions(+), 10 deletions(-)
scripts/Makefile.package +1 -3
index 0c3adc48dfe8..a81dfb1f5181 100644
@@ -109,8 +109,6 @@ debian-orig: linux.tar$(debian-orig-suffix) debian
 		cp $< ../$(orig-name); \
 	fi
 
-KBUILD_PKG_ROOTCMD ?= 'fakeroot -u'
-
 PHONY += deb-pkg srcdeb-pkg bindeb-pkg
 
 deb-pkg:    private build-type := source,binary
@@ -125,7 +123,7 @@ deb-pkg srcdeb-pkg bindeb-pkg:
 	$(if $(findstring source, $(build-type)), \
 		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
 	$(if $(findstring binary, $(build-type)), \
-		-R'$(MAKE) -f debian/rules' -j1 -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
+		-R'$(MAKE) -f debian/rules' -j1 -a$$(cat debian/arch), \
 		--no-check-builddeps) \
 	$(DPKG_FLAGS))
 
scripts/package/builddeb +1 -7
index d7dd0d04c70c..2fe51e6919da 100755
@@ -36,19 +36,13 @@ create_package() {
 	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
 		| xargs -r0 md5sum > DEBIAN/md5sums"
 
-	# Fix ownership and permissions
-	if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
-		dpkg_deb_opts="--root-owner-group"
-	else
-		chown -R root:root "$pdir"
-	fi
 	# a+rX in case we are in a restrictive umask environment like 0077
 	# ug-s in case we build in a setuid/setgid directory
 	chmod -R go-w,a+rX,ug-s "$pdir"
 
 	# Create the package
 	dpkg-gencontrol -p$pname -P"$pdir"
-	dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
+	dpkg-deb --root-owner-group ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
 }
 
 install_linux_image () {
scripts/package/debian/rules +2 -0
index 3dafa9496c63..f23d97087948 100755
@@ -5,6 +5,8 @@ include debian/rules.vars
 
 srctree ?= .
 
+export DEB_RULES_REQUIRES_ROOT := no
+
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
     MAKEFLAGS += -j$(NUMJOBS)
Signature · 1 line
2.40.1
#1 lore raw
Quoted 10 lines · Masahiro Yamada

In 2017, the dpkg suite introduced the rootless builds support with the following commits:

- 2436807c87b0 ("dpkg-deb: Add support for rootless builds")
- fca1bfe84068 ("dpkg-buildpackage: Add support for rootless builds")

This feature is available in the default dpkg on Debian 10 and Ubuntu 20.04.

Remove the old method.

This seems reasonable.

Quoted 3 lines

Additionally, export DEB_RULES_REQUIRES_ROOT=no in case debian/rules is invoked without dpkg-buildpackage. This change aligns with the Debian kernel commit 65206e29f378 ("Allow to run d/rules.real without root").

The Debian linux package has multiple makefiles used recursively (rather than included). The referenced commit is kind of a hack to make rootless builds of a subset of binary packages work when invoking one of the lower-level makefiles directly.

It works because the package runs dh_builddeb, which checks DEB_RULES_REQUIRES_ROOT. But setting DEB_RULES_REQUIRES_ROOT has absolutely zero effect on dpkg-deb or other low-level tools.

Quoted 2 lines

While the upstream kernel currently does not run dh_testroot, it may be useful in the future.

We can do one of:

1. Ignore DEB_RULES_REQUIRES_ROOT, assume that dpkg-deb supports --root-owner-group and use it unconditionally (your v1).
2. Check DEB_RULES_REQUIRES_ROOT, do either fakeroot and chown or dpkg-deb --root-owner-group (current behaviour), and maybe also do the equivalent of dh_testroot.
3. Delegate this to dh_builddeb. Since we use dh_listpackages now, debhelper is already required and this would make things a lot simpler.

But the combination of changes in v2 does not make sense to me.

Ben.

Quoted 71 lines

---

Changes in v2:
- add DEB_RULES_REQUIRES_ROOT=no to debian/rules

 scripts/Makefile.package     | 4 +---
 scripts/package/builddeb     | 8 +-------
 scripts/package/debian/rules | 2 ++
 3 files changed, 4 insertions(+), 10 deletions(-)
scripts/Makefile.package +1 -3
index 0c3adc48dfe8..a81dfb1f5181 100644
@@ -109,8 +109,6 @@ debian-orig: linux.tar$(debian-orig-suffix) debian
 		cp $< ../$(orig-name); \
 	fi
 
-KBUILD_PKG_ROOTCMD ?= 'fakeroot -u'
-
 PHONY += deb-pkg srcdeb-pkg bindeb-pkg
 
 deb-pkg:    private build-type := source,binary
@@ -125,7 +123,7 @@ deb-pkg srcdeb-pkg bindeb-pkg:
 	$(if $(findstring source, $(build-type)), \
 		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
 	$(if $(findstring binary, $(build-type)), \
-		-R'$(MAKE) -f debian/rules' -j1 -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
+		-R'$(MAKE) -f debian/rules' -j1 -a$$(cat debian/arch), \
 		--no-check-builddeps) \
 	$(DPKG_FLAGS))
 
scripts/package/builddeb +1 -7
index d7dd0d04c70c..2fe51e6919da 100755
@@ -36,19 +36,13 @@ create_package() {
 	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
 		| xargs -r0 md5sum > DEBIAN/md5sums"
 
-	# Fix ownership and permissions
-	if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
-		dpkg_deb_opts="--root-owner-group"
-	else
-		chown -R root:root "$pdir"
-	fi
 	# a+rX in case we are in a restrictive umask environment like 0077
 	# ug-s in case we build in a setuid/setgid directory
 	chmod -R go-w,a+rX,ug-s "$pdir"
 
 	# Create the package
 	dpkg-gencontrol -p$pname -P"$pdir"
-	dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
+	dpkg-deb --root-owner-group ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
 }
 
 install_linux_image () {
scripts/package/debian/rules +2 -0
index 3dafa9496c63..f23d97087948 100755
@@ -5,6 +5,8 @@ include debian/rules.vars
 
 srctree ?= .
 
+export DEB_RULES_REQUIRES_ROOT := no
+
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
     MAKEFLAGS += -j$(NUMJOBS)
Signature · 3 lines
Ben Hutchings
For every complex problem
there is a solution that is simple, neat, and wrong.
#2 lore raw
Quoted 16 lines · Ben Hutchings
Quoted 10 lines · Masahiro Yamada

In 2017, the dpkg suite introduced the rootless builds support with the following commits:

- 2436807c87b0 ("dpkg-deb: Add support for rootless builds")
- fca1bfe84068 ("dpkg-buildpackage: Add support for rootless builds")

This feature is available in the default dpkg on Debian 10 and Ubuntu 20.04.

Remove the old method.

This seems reasonable.

Quoted 8 lines
Quoted 3 lines

Additionally, export DEB_RULES_REQUIRES_ROOT=no in case debian/rules is invoked without dpkg-buildpackage. This change aligns with the Debian kernel commit 65206e29f378 ("Allow to run d/rules.real without root").

The Debian linux package has multiple makefiles used recursively (rather than included). The referenced commit is kind of a hack to make rootless builds of a subset of binary packages work when invoking one of the lower-level makefiles directly.

The upstream kernel does not support individual package build since it is implemented in scripts/package/builddeb shell script.

Is the direct execution of debian/rules still worth supporting in the upstream kernel?

If the answer is no, "export DEB_RULES_REQUIRES_ROOT=no" is meaningless.

Quoted 3 lines

It works because the package runs dh_builddeb, which checks DEB_RULES_REQUIRES_ROOT. But setting DEB_RULES_REQUIRES_ROOT has absolutely zero effect on dpkg-deb or other low-level tools.

Please let me clarify your statement.

Do you mean this? ("is needed" ?)

"It is needed because the package runs dh_builddeb, which checks
DEB_RULES_REQUIRES_ROOT."

Quoted 14 lines
Quoted 2 lines

While the upstream kernel currently does not run dh_testroot, it may be useful in the future.

We can do one of:

1. Ignore DEB_RULES_REQUIRES_ROOT, assume that dpkg-deb supports --root-owner-group and use it unconditionally (your v1).
2. Check DEB_RULES_REQUIRES_ROOT, do either fakeroot and chown or dpkg-deb --root-owner-group (current behaviour), and maybe also do the equivalent of dh_testroot.
3. Delegate this to dh_builddeb. Since we use dh_listpackages now, debhelper is already required and this would make things a lot simpler.

Quoted 1 line

But the combination of changes in v2 does not make sense to me.

I like 1 or 3.

If I go with 3.,
does splitting it into two patches make sense?

1/2: remove fakeroot (just like v1)
2/2: dh_* conversion + "export DEB_RULES_REQUIRES_ROOT=no"

--
Best Regards
Masahiro Yamada

#3 lore raw
Quoted 27 lines · Masahiro Yamada
Quoted 16 lines · Ben Hutchings
Quoted 10 lines · Masahiro Yamada

In 2017, the dpkg suite introduced the rootless builds support with the following commits:

- 2436807c87b0 ("dpkg-deb: Add support for rootless builds")
- fca1bfe84068 ("dpkg-buildpackage: Add support for rootless builds")

This feature is available in the default dpkg on Debian 10 and Ubuntu 20.04.

Remove the old method.

This seems reasonable.

Quoted 8 lines
Quoted 3 lines

Additionally, export DEB_RULES_REQUIRES_ROOT=no in case debian/rules is invoked without dpkg-buildpackage. This change aligns with the Debian kernel commit 65206e29f378 ("Allow to run d/rules.real without root").

The Debian linux package has multiple makefiles used recursively (rather than included). The referenced commit is kind of a hack to make rootless builds of a subset of binary packages work when invoking one of the lower-level makefiles directly.

Quoted 6 lines

The upstream kernel does not support individual package build since it is implemented in scripts/package/builddeb shell script.

Is the direct execution of debian/rules still worth supporting in the upstream kernel?

I don't have an opinion on that.

Quoted 8 lines

If the answer is no, "export DEB_RULES_REQUIRES_ROOT=no" is meaningless.

Quoted 3 lines

It works because the package runs dh_builddeb, which checks DEB_RULES_REQUIRES_ROOT. But setting DEB_RULES_REQUIRES_ROOT has absolutely zero effect on dpkg-deb or other low-level tools.

Quoted 6 lines

Please let me clarify your statement.

Do you mean this? ("is needed" ?)

"It is needed because the package runs dh_builddeb, which checks
DEB_RULES_REQUIRES_ROOT."

Yes.

Quoted 22 lines
Quoted 14 lines
Quoted 2 lines

While the upstream kernel currently does not run dh_testroot, it may be useful in the future.

We can do one of:

1. Ignore DEB_RULES_REQUIRES_ROOT, assume that dpkg-deb supports --root-owner-group and use it unconditionally (your v1).
2. Check DEB_RULES_REQUIRES_ROOT, do either fakeroot and chown or dpkg-deb --root-owner-group (current behaviour), and maybe also do the equivalent of dh_testroot.
3. Delegate this to dh_builddeb. Since we use dh_listpackages now, debhelper is already required and this would make things a lot simpler.

Quoted 1 line

But the combination of changes in v2 does not make sense to me.

I like 1 or 3.

Quoted 6 lines

If I go with 3.,
does splitting it into two patches make sense?

1/2: remove fakeroot (just like v1)
2/2: dh_* conversion + "export DEB_RULES_REQUIRES_ROOT=no"

Yes, that makes sense to me.

Ben.

Signature · 3 lines
Ben Hutchings
It is easier to write an incorrect program
than to understand a correct one.