Bug#601203: #601203: tested patch for adding support for recursively including recommends (NORECOMMENDS=0)

2021-12-16 Thread Arnaud Rebillout
Thanks for the feedback! I also had the impression that it was a 
"backward step", but since I don't really understand anything in Perl, I 
didn't dare to touch it :)


Updated patch set attached. I also removed the hunk that came just after 
as it was another step backward.


I noticed (only now) that the second patch is titled 
"Also-pull-in-second-level-recommends", so maybe it works as intended. 
Before the patch, only the first level of recommends is pulled, and 
after the patch, the 1st and 2nd levels are pulled, I guess?


--
Arnaud Rebillout
From 84878a80ab0f0560e9a55b2d5956c8707fd7b74e Mon Sep 17 00:00:00 2001
From: Wolfgang Schweer 
Date: Fri, 1 Mar 2019 11:27:46 +0100
Subject: [PATCH 1/2] Enable to pull in Recommends recursively

To enable set NORECOMMENDS=0 in the build environment. (Closes: #601203)
---
 tools/sort_deps | 45 -
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/tools/sort_deps b/tools/sort_deps
index 2bdbfcf..8582b90 100755
--- a/tools/sort_deps
+++ b/tools/sort_deps
@@ -647,6 +647,7 @@ sub check_versions {
 # Check if a specific dependency package is installed already
 sub dep_pkg_included {
 	my $p = shift;
+	my $add_rec = shift;
 	my $check_backports = shift;
 	my $need_udeb = shift;
 	my %d = %$p;
@@ -754,17 +755,18 @@ sub fix_backport_depends {
 # dependency or any one of an OR array
 sub dep_satisfied {
 my $p = shift;
+my $add_rec = shift;
 my $check_backports = shift;
 my $need_udeb = shift;
 
 if ("ARRAY" eq ref $p) {
 	foreach (@{$p}) {
-	if (dep_pkg_included($_, $check_backports, $need_udeb)) {
+	if (dep_pkg_included($_, $add_rec, $check_backports, $need_udeb)) {
 		return 1;
 	}
 	}
 } elsif ("HASH" eq ref $p) {
-	return dep_pkg_included($p, $check_backports, $need_udeb);
+	return dep_pkg_included($p, $add_rec, $check_backports, $need_udeb);
 } else {
 }
 return 0;
@@ -878,7 +880,7 @@ sub add_package {
 	}
 	
 	# Get all dependencies (not yet included) of each package
-	my (@dep) = (get_missing ($p, $check_backports));
+	my (@dep) = (get_missing ($p, $add_rec, $check_backports));
 
 	# Stop here if apt failed
 	if (not scalar(@dep)) {
@@ -895,7 +897,7 @@ sub add_package {
 	msg(3, "  \@dep before checklist = " . dump_depend(\@dep) . "\n");
 	
 	# Check if all packages are allowed (fail if one cannot)
-	($ok, $reasons) = check_list (\@dep, 1, $check_backports);
+	($ok, $reasons) = check_list (\@dep, 1, $add_rec, $check_backports);
 	if (not $ok) {
 		msg(2, "Can't add $p ... one of the packages needed has " .
 		   "been refused. Reasons: $reasons\n"); 
@@ -905,12 +907,11 @@ sub add_package {
 	msg(3, "  \@dep after checklist = " . dump_depend(\@dep) . "\n");
 	
 	if ($add_rec) {
-		#TODO: Look for recommends (not yet included !!)
-		add_recommends (\@dep, $p, $check_backports);
+		add_recommends (\@dep, $p, $add_rec, $check_backports);
 		msg(3, "  \@dep after add_recommends = " . dump_depend(\@dep) . "\n");
 		# Check again but doesn't fail if one of the package cannot be
 		# installed, just ignore it (it will be removed from @dep)
-		($ok, $reasons) = check_list (\@dep, 0, $check_backports);
+		($ok, $reasons) = check_list (\@dep, 0, $add_rec, $check_backports);
 		if (not $ok) {
 			msg(0, "UNEXPECTED: It shouldn't fail here !\n");
 			return;
@@ -920,11 +921,11 @@ sub add_package {
 
 	if ($add_sug) {
 	#TODO: Look for suggests (not yet included !!)
-		add_suggests (\@dep, $p, $check_backports);
+		add_suggests (\@dep, $p, $add_rec, $check_backports);
 		msg(3, "  \@dep after add_suggests = " . dump_depend(\@dep) . "\n");
 # Check again but doesn't fail if one of the package cannot be
 # installed, just ignore it (it will be removed from @dep)
-($ok, $reasons) = check_list (\@dep, 0, $check_backports);
+($ok, $reasons) = check_list (\@dep, 0, $add_rec, $check_backports);
 if (not $ok) {
 msg(0, "UNEXPECTED: It shouldn't fail here !\n");
 return;
@@ -952,6 +953,7 @@ sub accepted {
 sub add_suggests {
 	my $deps_list = shift;
 	my $pkg = shift;
+my $add_rec = shift;
 	my $check_backports = shift;
 	my @parents = ($pkg);
 	my $p; # = shift;
@@ -960,13 +962,14 @@ sub add_suggests {
 	foreach $p (@copy) {
 		my %t = %$p;
 		my $pkgname = $t{"Package"};
-		add_missing($deps_list, $packages{$pkgname}{"Suggests"}, \%t, 1, \@parents, $check_backports);
+		add_missing($deps_list, $packages{$pkgname}{"Suggests"}, \%t, 1, \@parents, $add_rec, $check_backports);
 	}
 }
 
 sub add_recommends {
 	my $deps_list = shift;
 	my $pkg = shift;
+my $add_rec = shift;
 	my $check_backports = shift;
 	my @parents = ($pkg);
 	my $p; # = shift;
@@ -975,12 +978,13 @@ sub add_recommends {
 	foreach $p (@copy) {
 		my %t = %$p;
 		my $pkgname = $t{"Package"};
-		add_missing($deps_list, $packages{$pkgname}{"Recommends"}, \%t, 1, \@parents, $check_backports);
+		add_missing($deps_list, 

Bug#601203: #601203: tested patch for adding support for recursively including recommends (NORECOMMENDS=0)

2021-12-16 Thread Philip Hands
Hi

Skimming through this thread as a result of your mail, I noticed the
earlier patch replacing the || 1 with defined ... ? ... and was going to
point out that since 2007 perl's had the // operator for this sort of
thing, which should mean that this would do the trick these days:

  my $norecommends = $ENV{'NORECOMMENDS'} // 1;

but then I noticed that the latest patch includes this:

> -my $norecommends = read_env('NORECOMMENDS', 1);
> +my $norecommends = (defined $ENV{'NORECOMMENDS'} ? $ENV{'NORECOMMENDS'} : 1);

which replaces the use of read_env() with the earlier fix, which strikes
me as a backwards step, given that read_env is doing exactly what's
needed here:

=-=-=-
sub read_env {
my $env_var = shift;
my $default = shift;

if (exists($ENV{$env_var})) {
return $ENV{$env_var};
}
# else
return $default;
}
=-=-=-

Cheers, Phil.
-- 
|)|  Philip Hands  [+44 (0)20 8530 9560]  HANDS.COM Ltd.
|-|  http://www.hands.com/http://ftp.uk.debian.org/
|(|  Hugo-Klemm-Strasse 34,   21075 Hamburg,GERMANY