SVN: toys/tools/cleanbuild/findunusedbr
sparky
sparky at pld-linux.org
Tue Feb 2 18:52:00 CET 2010
Author: sparky
Date: Tue Feb 2 18:51:59 2010
New Revision: 11124
Added:
toys/tools/cleanbuild/findunusedbr (contents, props changed)
Log:
- NEW: script for finding unused BRs:
1. before building run with -c to reset access time of all files
of build-required packages
2. after building checks which packages have all files with unchanged
access time - those are unused packages
NOTE: won't work with noatime; relatime is OK
Added: toys/tools/cleanbuild/findunusedbr
==============================================================================
--- (empty file)
+++ toys/tools/cleanbuild/findunusedbr Tue Feb 2 18:51:59 2010
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+die "Arguments missing: $0 [-c] <chroot> <spec>\n" unless @ARGV;
+my $clear;
+if ( $ARGV[0] eq "-c" ) {
+ $clear = 1;
+ shift @ARGV;
+}
+my $chroot = shift @ARGV or die "chroot directory not specified\n";
+my $spec = shift @ARGV or die "Spec file not specified\n";
+
+-d $chroot or die "chroot '$chroot' is not a directory\n";
+-r $spec or die "spec file '$spec' is not readable\n";
+
+my @rpms;
+open F_IN, "<", $spec or die "Cannot open '$spec'\n";
+while ( <F_IN> ) {
+ if ( /^\s*(?:%{.*)?BuildRequires:\s*(\S+)/i ) {
+ local $_ = $1;
+ s/}$//;
+ push @rpms, $_;
+ } elsif ( /^%(prep|build|changelog)/ ) {
+ last;
+ }
+}
+close F_IN;
+
+sub clear_files
+{
+ my $rpm = shift;
+ my $files = shift;
+ foreach my $file ( @$files ) {
+ chop $file;
+ my $f = $chroot.$file;
+
+ # XXX: this truncates mtime to its low resolution value
+ my $mtime = (stat $f)[9];
+ warn "Mtime failed on $f" unless $mtime;
+ utime 0, $mtime, $f;
+ }
+}
+
+sub check_files
+{
+ my $rpm = shift;
+ my $files = shift;
+ #my $used = 0;
+ foreach my $file ( @$files ) {
+ chop $file;
+ my $f = $chroot.$file;
+
+ my $atime = (stat $f)[8];
+ if ( $atime > 0 ) {
+ #print "$rpm: $file accessed\n";
+ #$used = 1;
+ return;
+ } else {
+ #print "$rpm: $file NOT accessed !\n";
+ }
+ }
+ print "$rpm may be superfluous !\n";# unless $used;
+}
+
+
+foreach my $rpm ( @rpms ) {
+ my @files = qx/rpm --root=$chroot -ql --what-provides "$rpm"/;
+ next if $files[0] =~ /^no package provides/;
+ #print "*** $rpm ***\n";
+ if ( $clear ) {
+ clear_files( $rpm, \@files );
+ } else {
+ check_files( $rpm, \@files );
+ }
+ #print "\n\n";
+}
More information about the pld-cvs-commit
mailing list