Przeglądaj źródła

dpkg-buildflags: Add --status action to describe the flag settings

It's hard to see from a build log file what values should have been
used and why. The new --status action added by this patch tries to
output all meaningful information in a way useful for human consumption
and for automatic log parsers.

[guillem@debian.org:
 - Mark dpkg-buildflags as bold in man page and escape dash.
 - Use report("status", string). ]

Closes: #664058

Signed-off-by: Bernhard R. Link <brlink@debian.org>
Signed-off-by: Guillem Jover <guillem@debian.org>
Bernhard R. Link 14 lat temu
rodzic
commit
ae43199360
3 zmienionych plików z 54 dodań i 2 usunięć
  1. 4 0
      debian/changelog
  2. 10 0
      man/dpkg-buildflags.1
  3. 40 2
      scripts/dpkg-buildflags.pl

+ 4 - 0
debian/changelog

@@ -15,6 +15,10 @@ dpkg (1.16.5) UNRELEASED; urgency=low
     patches to be kept applied after build (used by formats "2.0" and "3.0
     patches to be kept applied after build (used by formats "2.0" and "3.0
     (quilt)"). Closes: #643043
     (quilt)"). Closes: #643043
 
 
+  [ Guillem Jover ]
+  * Add a dpkg-buildflags --status action to describe the flag settings.
+    Thanks to Bernhard R. Link <brlink@debian.org>. Closes: #664058
+
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * Swedish (Peter Krefting).
   * Swedish (Peter Krefting).
 
 

+ 10 - 0
man/dpkg-buildflags.1

@@ -72,6 +72,16 @@ Print the list of flags supported by the current vendor
 (one per line). See the \fBSUPPORTED FLAGS\fP section for more
 (one per line). See the \fBSUPPORTED FLAGS\fP section for more
 information about them.
 information about them.
 .TP
 .TP
+.BI \-\-status
+Display any information that can be useful to explain the behaviour of
+\fBdpkg\-buildflags\fP: relevant environment variables, current vendor,
+state of all feature flags. Also print the resulting compiler flags with
+their origin.
+
+This is intended to be run from \fBdebian/rules\fP, so that the build log
+keeps a clear trace of the build flags used. This can be useful to diagnose
+problems related to them.
+.TP
 .BI \-\-export= format
 .BI \-\-export= format
 Print to standard output shell (if \fIformat\fP is \fBsh\fP) or make
 Print to standard output shell (if \fIformat\fP is \fBsh\fP) or make
 (if \fIformat\fP is \fBmake\fP) commands that can be used to export
 (if \fIformat\fP is \fBmake\fP) commands that can be used to export

+ 40 - 2
scripts/dpkg-buildflags.pl

@@ -22,8 +22,9 @@ use warnings;
 
 
 use Dpkg;
 use Dpkg;
 use Dpkg::Gettext;
 use Dpkg::Gettext;
-use Dpkg::ErrorHandling;
+use Dpkg::ErrorHandling qw(report);
 use Dpkg::BuildFlags;
 use Dpkg::BuildFlags;
+use Dpkg::Vendor qw(get_current_vendor);
 
 
 textdomain("dpkg-dev");
 textdomain("dpkg-dev");
 
 
@@ -52,6 +53,9 @@ sub usage {
                      compilation flags in a shell script, in make,
                      compilation flags in a shell script, in make,
                      or on a ./configure command line.
                      or on a ./configure command line.
   --dump             output all compilation flags with their values
   --dump             output all compilation flags with their values
+  --status           print a synopsis with all parameters affecting the
+                     behaviour of dpkg-buildflags and the resulting flags
+                     and their origin.
   --help             show this help message.
   --help             show this help message.
   --version          show the version.
   --version          show the version.
 "), $progname;
 "), $progname;
@@ -72,7 +76,7 @@ while (@ARGV) {
             if defined($action);
             if defined($action);
         my $type = $1 || "sh";
         my $type = $1 || "sh";
         $action = "export-$type";
         $action = "export-$type";
-    } elsif (m/^--(list|dump)$/) {
+    } elsif (m/^--(list|status|dump)$/) {
         usageerr(_g("two commands specified: --%s and --%s"), $1, $action)
         usageerr(_g("two commands specified: --%s and --%s"), $1, $action)
             if defined($action);
             if defined($action);
         $action = $1;
         $action = $1;
@@ -143,6 +147,40 @@ if ($action eq "get") {
 	print "$flag=$value\n";
 	print "$flag=$value\n";
     }
     }
     exit(0);
     exit(0);
+} elsif ($action eq "status") {
+    # Prefix everything with "dpkg-buildflags: status: " to allow easy
+    # extraction from a build log. Thus we use report with a non-translated
+    # type string.
+
+    # First print all environment variables that might have changed the
+    # results (only existing ones, might make sense to add an option to
+    # also show which ones could have set to modify it).
+    my @envvars = Dpkg::BuildEnv::list_accessed();
+    for my $envvar (@envvars) {
+	if (exists $ENV{$envvar}) {
+	    printf report("status", "environment variable %s=%s",
+	           $envvar, $ENV{$envvar});
+	}
+    }
+    my $vendor = Dpkg::Vendor::get_current_vendor() || "undefined";
+    print report("status", "vendor is $vendor");
+    # Then the resulting features:
+    foreach my $area (sort $build_flags->get_feature_areas()) {
+	my $fs;
+	my %features = $build_flags->get_features($area);
+	foreach my $feature (sort keys %features) {
+	    $fs .= sprintf(" %s=%s", $feature, $features{$feature} ? "yes" : "no");
+	}
+	print report("status", "$area features:$fs");
+    }
+    # Then the resulting values (with their origin):
+    foreach my $flag ($build_flags->list()) {
+	my $value = $build_flags->get($flag);
+	my $origin = $build_flags->get_origin($flag);
+	my $maintainer = $build_flags->is_maintainer_modified($flag) ? "+maintainer" : "";
+	print report("status", "$flag [$origin$maintainer]: $value");
+    }
+    exit(0);
 }
 }
 
 
 exit(1);
 exit(1);