#!/usr/bin/perl =head1 NAME dh_missing - check for missing files =cut use strict; use warnings; use File::Find; use Debian::Debhelper::Dh_Lib; =head1 SYNOPSIS B [B<-X>I] [B<--sourcedir=>I] [S>] =head1 DESCRIPTION B compares the list of installed files with the files in the source directory. If any of the files (and symlinks) in the source directory were not installed to somewhere, it will warn on stderr about that (B<--list-missing>) or fail (B<--fail-missing>). Please note that without either of these options, B will silently do nothing. This may be useful if you have a large package and want to make sure that you don't miss installing newly added files in new upstream releases. Remember to test different kinds of builds (dpkg-buildpackage -A/-B/...) as you may experience varying results when only a subset of the packages are built. =head1 FILES =over 4 =item debian/not-installed List the files that are deliberately not installed in I binary package. Paths listed in this file are ignored by B. However, it is B a method to exclude files from being installed by B. Please use the B<--exclude> B option for that. Please keep in mind that B will B expand wildcards in this file. =back =head1 OPTIONS =over 4 =item B<--list-missing> Warn on stderr about source files not installed to somewhere. Note that files that are excluded from being moved via the B<-X> option are not warned about. =item B<--fail-missing> This option is like B<--list-missing>, except if a file was missed, it will not only list the missing files, but also fail with a nonzero exit code. =back =cut init(options => { "list-missing" => \$dh{LIST_MISSING}, "fail-missing" => \$dh{FAIL_MISSING}, "sourcedir=s" => \$dh{SOURCEDIR}, }); my (@installed, %helpers); my $srcdir = '.'; $srcdir = $dh{SOURCEDIR} if defined $dh{SOURCEDIR}; if (!$dh{LIST_MISSING} && !$dh{FAIL_MISSING}) { exit 0; } # . as srcdir makes no sense, so this is a special case. if ($srcdir eq '.') { $srcdir='debian/tmp'; } if (! -d $srcdir) { if (scalar(getpackages()) == 1 && not defined($dh{SOURCEDIR})) { warning("$srcdir does not exist and there is only binary package."); warning("Assuming everything is installed directly into the package directory."); exit(0); } if (compat(10)) { # Prevent "dh $@ --list-missing --destdir=..." from failing in compat 10. warning("Cannot check if installation is missing files: $srcdir does not exist"); exit(0); } else { error("Cannot check if installation is missing files: $srcdir does not exist"); } } for my $file () { my ($target_pkg, $helper) = ('unknown', 'unknown'); my $had_files = 0; my %seen; if ($file =~ m@.*/([^/]+)/installed-by-(.*)@) { ($target_pkg, $helper) = ($1, $2); } open(my $fh, '<', $file) or die "could not open $file: $!"; while (my $line = <$fh>) { chomp($line); next if $line =~ m/^\s*$/; next if $seen{$line}++; # Ignore duplicates $had_files++; push(@installed, $line); } $helpers{$helper}{$target_pkg} = $had_files; close($fh); } my @missing; if ( -f 'debian/not-installed') { my @not_installed = filearray('debian/not-installed'); foreach (@not_installed) { s:^\s*:debian/tmp/: unless m:^\s*debian/tmp/:; } # Pretend that these are also installed. push(@installed, @not_installed); } my $installed=join("|", map { # Kill any extra slashes, for robustness. y:/:/:s; s:/+$::; s:^(\./)*::; "\Q$_\E\/.*|\Q$_\E"; } @installed); $installed=qr{^($installed)$}; find(sub { -f || -l || return; $_="$File::Find::dir/$_"; if (! /$installed/ && ! excludefile($_)) { my $file=$_; $file=~s/^\Q$srcdir\E\///; push @missing, $file; } }, $srcdir); if (@missing) { warning "$_ exists in $srcdir but is not installed to anywhere" foreach @missing; nonquiet_print("The following debhelper tools have reported what they installed (with files per package)"); for my $helper (sort(keys(%helpers))) { my $pkg_info = $helpers{$helper}; my @results; for my $pkg (sort(keys(%{$pkg_info}))) { my $no = $pkg_info->{$pkg}; push(@results, "${pkg} (${no})") } nonquiet_print(" * ${helper}: " . join(', ', @results)); } nonquiet_print("If the missing files are installed by another tool, please file a bug against it."); nonquiet_print("Be sure to test with dpkg-buildpackage -A/-B as the results may vary when only a subset is built"); nonquiet_print("For a short-term work-around: Add the files to debian/not-installed"); if ($dh{FAIL_MISSING}) { error("missing files, aborting"); } } =head1 SEE ALSO L This program is a part of debhelper. =head1 AUTHOR Michael Stapelberg =cut