[dpkg] 15/27: dpkg-buildpackage: Setup and check rootcommand only if needed

Mattia Rizzolo mattia at debian.org
Mon Oct 23 18:10:28 UTC 2017


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

mattia pushed a commit to branch master
in repository dpkg.

commit b4e46fab018e3d5ae813642b20b955d8a5327b1e
Author: Guillem Jover <guillem at debian.org>
Date:   Thu Oct 19 01:39:14 2017 +0200

    dpkg-buildpackage: Setup and check rootcommand only if needed
    
    When building in R³ mode or when the user requested to run a rule as
    root we should setup the rootcommand, otherwise we should ignore it.
    
    Reported-by: Niels Thykier <niels at thykier.net>
---
 debian/changelog             |  2 ++
 scripts/dpkg-buildpackage.pl | 46 +++++++++++++++++++++++++-------------------
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4841bbf..44b5512 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     Rules-Requires-Root field. This meant the field was being ignored.
   * Run dpkg-source directly from the current working directory in
     dpkg-buildpackage, instead of changing directory back and forth.
+  * Setup and check rootcommand in dpkg-buildpackage only if it is going to
+    be needed. Reported by Niels Thykier <niels at thykier.net>.
   * Documentation:
     - Update gettext minimal version in README.
   * Packaging:
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index 4bc25a2..3a9ba5b 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -368,22 +368,6 @@ if ($noclean) {
     $checkbuilddep = 0 if build_is(BUILD_SOURCE);
 }
 
-if ($< == 0) {
-    warning(g_('using a gain-root-command while being root')) if (@rootcommand);
-} else {
-    push @rootcommand, 'fakeroot' unless @rootcommand;
-}
-
-if (@rootcommand and not find_command($rootcommand[0])) {
-    if ($rootcommand[0] eq 'fakeroot' and $< != 0) {
-        error(g_("fakeroot not found, either install the fakeroot\n" .
-                 'package, specify a command with the -r option, ' .
-                 'or run this as root'));
-    } else {
-        error(g_("gain-root-command '%s' not found"), $rootcommand[0]);
-    }
-}
-
 if ($call_target_as_root and @call_target == 0) {
     error(g_('option %s is only meaningful with option %s'),
           '--as-root', '--rules-target');
@@ -435,6 +419,10 @@ set_build_profiles(@build_profiles) if @build_profiles;
 my $changelog = changelog_parse();
 my $ctrl = Dpkg::Control::Info->new();
 
+# Check whether we are doing some kind of rootless build, and sanity check
+# the fields values.
+my %rules_requires_root = parse_rules_requires_root($ctrl->get_source());
+
 my $pkg = mustsetvar($changelog->{source}, g_('source package'));
 my $version = mustsetvar($changelog->{version}, g_('source version'));
 my $v = Dpkg::Version->new($version);
@@ -458,10 +446,6 @@ if ($changedby) {
 # <https://reproducible-builds.org/specs/source-date-epoch/>
 $ENV{SOURCE_DATE_EPOCH} ||= $changelog->{timestamp} || time;
 
-# Check whether we are doing some kind of rootless build, and sanity check
-# the fields values.
-my %rules_requires_root = parse_rules_requires_root($ctrl->get_source());
-
 my @arch_opts;
 push @arch_opts, ('--host-arch', $host_arch) if $host_arch;
 push @arch_opts, ('--host-type', $host_type) if $host_type;
@@ -677,6 +661,24 @@ sub mustsetvar {
     return $var;
 }
 
+sub setup_rootcommand {
+    if ($< == 0) {
+        warning(g_('using a gain-root-command while being root')) if @rootcommand;
+    } else {
+        push @rootcommand, 'fakeroot' unless @rootcommand;
+    }
+
+    if (@rootcommand and not find_command($rootcommand[0])) {
+        if ($rootcommand[0] eq 'fakeroot' and $< != 0) {
+            error(g_("fakeroot not found, either install the fakeroot\n" .
+                     'package, specify a command with the -r option, ' .
+                     'or run this as root'));
+        } else {
+            error(g_("gain-root-command '%s' not found"), $rootcommand[0]);
+        }
+    }
+}
+
 sub parse_rules_requires_root {
     my $ctrl = shift;
 
@@ -709,6 +711,10 @@ sub parse_rules_requires_root {
         }
     }
 
+    if ($call_target_as_root or not exists $rrr{no}) {
+        setup_rootcommand();
+    }
+
     if ($keywords_base > 1 or $keywords_base and $keywords_impl) {
         error(g_('%s field contains both global and implementation specific keywords'),
               'Rules-Requires-Root');

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



More information about the Reproducible-commits mailing list