[dpkg] 04/06: dpkg-buildpackage: Setup and check rootcommand only if needed
Mattia Rizzolo
mattia at debian.org
Mon Oct 23 18:10:13 UTC 2017
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to annotated tag 1.19.0.3
in repository dpkg.
commit e16940da1af9f62f877840fb71e49eafea8a64fa
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>
(cherry picked from commit b4e46fab018e3d5ae813642b20b955d8a5327b1e)
---
debian/changelog | 2 ++
scripts/dpkg-buildpackage.pl | 46 +++++++++++++++++++++++++-------------------
2 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 8d2d63b..c63803c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,8 @@ dpkg (1.19.0.3) UNRELEASED; urgency=medium
* Pass the correct source stanza to the dpkg-buildpackage code parsing the
Rules-Requires-Root field. This meant the field was being ignored.
+ * Setup and check rootcommand in dpkg-buildpackage only if it is going to
+ be needed. Reported by Niels Thykier <niels at thykier.net>.
* Packaging:
- Comment out Rules-Requires-Root field until debhelper supports it.
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index df2e1bb..290b7c8 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -369,22 +369,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');
@@ -439,6 +423,10 @@ my $dir = basename($cwd);
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);
@@ -462,10 +450,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;
@@ -687,6 +671,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;
@@ -719,6 +721,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