[debhelper-devel] [debhelper] 02/02: makefile.pm: Support R³ for calling make install as root

Niels Thykier nthykier at moszumanska.debian.org
Sat Sep 16 19:10:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch support-rrr
in repository debhelper.

commit 4c3725dbcf9c8a5c06de1ed5cd046483dbfb5932
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Sep 16 19:09:15 2017 +0000

    makefile.pm: Support R³ for calling make install as root
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 lib/Debian/Debhelper/Buildsystem/makefile.pm | 13 +++++++++++--
 lib/Debian/Debhelper/Dh_Lib.pm               |  9 ++++++++-
 t/buildsystems/debian/control                |  1 +
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/Debian/Debhelper/Buildsystem/makefile.pm b/lib/Debian/Debhelper/Buildsystem/makefile.pm
index 02008a2..49a368d 100644
--- a/lib/Debian/Debhelper/Buildsystem/makefile.pm
+++ b/lib/Debian/Debhelper/Buildsystem/makefile.pm
@@ -8,7 +8,8 @@ package Debian::Debhelper::Buildsystem::makefile;
 
 use strict;
 use warnings;
-use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value escape_shell clean_jobserver_makeflags is_cross_compiling compat);
+use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value escape_shell clean_jobserver_makeflags is_cross_compiling compat
+	should_use_root gain_root_cmd);
 use parent qw(Debian::Debhelper::Buildsystem);
 
 my %DEB_DEFAULT_TOOLS = (
@@ -81,7 +82,11 @@ sub do_make {
 	# Note that this will override any -j settings in MAKEFLAGS.
 	unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
 
-	$this->doit_in_builddir($this->{makecmd}, @_);
+	my @root_cmd;
+	if (exists($this->{_run_make_as_root}) and $this->{_run_make_as_root}) {
+		@root_cmd = gain_root_cmd();
+	}
+	$this->doit_in_builddir(@root_cmd, $this->{makecmd}, @_);
 }
 
 sub make_first_existing_target {
@@ -163,6 +168,10 @@ sub install {
 		$this->disable_parallel();
 	}
 
+	if (should_use_root('debhelper/upstream-make-install') and $< != 0) {
+		$this->{_run_make_as_root} = 1;
+	}
+
 	$this->make_first_existing_target(['install'],
 		"DESTDIR=$destdir",
 		"AM_UPDATE_INFO_DIR=no", @_);
diff --git a/lib/Debian/Debhelper/Dh_Lib.pm b/lib/Debian/Debhelper/Dh_Lib.pm
index 0371895..5e7f41e 100644
--- a/lib/Debian/Debhelper/Dh_Lib.pm
+++ b/lib/Debian/Debhelper/Dh_Lib.pm
@@ -65,7 +65,7 @@ our (@EXPORT, %dh);
 	    &glob_expand_error_handler_silently_ignore DH_BUILTIN_VERSION
 	    &print_and_complex_doit &default_sourcedir &qx_cmd
 	    &compute_doc_main_package &is_so_or_exec_elf_file
-	    &should_use_root
+	    &should_use_root &gain_root_cmd
 );
 
 # The Makefile changes this if debhelper is installed in a PREFIX.
@@ -1425,6 +1425,13 @@ sub should_use_root {
 	return 0;
 }
 
+# Returns the "gain root command" as a list suitable for passing as a part of the command to "doit()"
+sub gain_root_cmd {
+	my $raw_cmd = $ENV{DPKG_GAIN_ROOT_CMD};
+	return if not defined($raw_cmd) or $raw_cmd =~ m/^\s*+$/;
+	return split(' ', $raw_cmd);
+}
+
 sub root_requirements {
 	getpackages() if not %rrr;
 
diff --git a/t/buildsystems/debian/control b/t/buildsystems/debian/control
index 7edd806..d3225ee 100644
--- a/t/buildsystems/debian/control
+++ b/t/buildsystems/debian/control
@@ -3,6 +3,7 @@ Section: devel
 Priority: optional
 Maintainer: Test <testing at nowhere>
 Standards-Version: 3.8.1
+Rules-Requires-Root: no
 
 Package: testpackage
 Architecture: all

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list