[Collab-qa-commits] r308 - tools/debcmp
lucas at alioth.debian.org
lucas at alioth.debian.org
Thu Jul 5 16:33:52 UTC 2007
Author: lucas
Date: 2007-07-05 16:33:52 +0000 (Thu, 05 Jul 2007)
New Revision: 308
Modified:
tools/debcmp/debcmp.rb
Log:
untested changes to debcmp
Modified: tools/debcmp/debcmp.rb
===================================================================
--- tools/debcmp/debcmp.rb 2007-07-05 13:46:39 UTC (rev 307)
+++ tools/debcmp/debcmp.rb 2007-07-05 16:33:52 UTC (rev 308)
@@ -13,6 +13,7 @@
dir_b = nil
$verbose = false
$arch = 'i386'
+$nocleanup = false
pool = false
tmpbase = '/scratch/grenoble/lnussbaum/tmp'
@@ -42,6 +43,10 @@
$verbose = true
end
+ opts.on("", "--no-cleanup", "Don't remove the temporary directory") do
+ $nocleanup = true
+ end
+
opts.on("", "--arch ARCH", "Architecture") do |a|
$arch = a
end
@@ -58,7 +63,7 @@
if [ package, version, dir_a, dir_b ].include?(nil)
puts "Missing mandatory argument"
- exit(1)
+ clean_exit(1)
end
# determine upstream version
@@ -72,6 +77,8 @@
$wd = `mktemp -d #{tmpbase}/debcmp.XXXXXX`.chomp
system("mkdir -p #{$wd}/a #{$wd}/b")
+puts "# Working dir: #{$wd}" if $verbose
+
# determine source dirs
if pool
if package =~ /^lib/
@@ -86,14 +93,39 @@
sdir_b = dir_b
end
+def clean_exit(n)
+ system("rm -rf #{$wd}") unless $nocleanup
+ exit(n)
+end
+
puts "Comparing #{package} #{version} (#{sversion})" if $verbose
def systemr(cmd)
raise "Command failed: #{cmd}" if not system(cmd)
end
+puts "# Copying files to local tmp dir..." if $verbose
+
+# determine upstream version
+if Dir::glob("#{sdir_b}/*_#{version}.diff.gz")
+ native = false
+ if version =~ /-/
+ sversion = version.gsub(/-[^-]*$/,'')
+ else
+ sversion = version
+ end
+else
+ native = true
+ sversion = version
+end
+
+if Dir::glob("#{sdir_b}/*_#{version}_*.deb").length == 0
+ puts "E: No .deb files found! Build probably failed."
+ clean_exit(1)
+end
+
# copy files to local tmp dir
-if sversion == version
+if native
systemr("cp #{sdir_a}/*_#{sversion}.tar.gz #{sdir_a}/*_#{version}.dsc #{$wd}/a")
systemr("cp #{sdir_b}/*_#{sversion}.tar.gz #{sdir_b}/*_#{version}.dsc #{$wd}/b")
l = Dir::glob("#{sdir_a}/*_#{version}_*.deb").reject { |e| e !~ /_(#{$arch}|all).deb/ }
@@ -109,9 +141,9 @@
systemr("cp #{l.join(' ')} #{$wd}/b")
end
-#############################
-# compare orig.tar.gz files
-if sversion == version
+# compare orig.tar.gz and .diff.gz files
+puts "# Comparing .orig.tar.gz and .diff.gz files..." if $verbose
+if native
if not system("cmp #{$wd}/a/*.tar.gz #{$wd}/b/*.tar.gz &>/dev/null")
puts "E: .tar.gz files differ (native package)."
end
@@ -121,15 +153,17 @@
end
end
-#############################
-# Compare .diff.gz files
-if sversion != version
+if not native
# extract .diff.gz files and compare them
systemr("mkdir -p #{$wd}/diffs")
systemr("zcat #{$wd}/a/*.diff.gz > #{$wd}/diffs/a.diff")
systemr("zcat #{$wd}/b/*.diff.gz > #{$wd}/diffs/b.diff")
s = `bash -c "interdiff #{$wd}/diffs/{a,b}.diff 2>&1"`.chomp
+ if $? != 0
+ puts "Interdiff failed."
+ clean_exit(1)
+ end
if s.length != 0
puts "E: .diff.gz files differ. Interdiff:"
puts s
@@ -137,18 +171,22 @@
end
# compare list of .debs
+puts "# Comparing list of .debs ..." if $verbose
debs_a = Dir::glob("#{$wd}/a/*.deb").map { |f| File::basename(f) }.sort
debs_b = Dir::glob("#{$wd}/b/*.deb").map { |f| File::basename(f) }.sort
if debs_a != debs_b
puts "E: different debs in dirs:"
puts "E: A: #{debs_a.join(' ')}"
puts "E: B: #{debs_b.join(' ')}"
+ puts "E: in A, notin B: #{(debs_a - debs_b).join(' ')}"
+ puts "E: in B, notin A: #{(debs_b - debs_a).join(' ')}"
end
debstrip_a = debs_a.map { |d| d.gsub(/_.*/,'') }
debstrip_b = debs_b.map { |d| d.gsub(/_.*/,'') }
# Extract control files and packages
+puts "# Extracting control files and packages, and comparing them ..." if $verbose
systemr("mkdir -p #{$wd}/c_a #{$wd}/c_b #{$wd}/p_a #{$wd}/p_b")
# dpkg-deb creates the target dir if needed
debs_a.each do |d|
@@ -165,9 +203,24 @@
# Compare control files
# We ignore the Installed-Size line
debstrip_a.each do |d|
- s = `bash -c "diff -u <(grep -v -e '^Installed-Size: ' #{$wd}/c_a/#{d}/control) <(grep -v -e '^Installed-Size: ' #{$wd}/c_b/#{d}/control)"`.chomp
+ s1 = `bash -c "diff -u <(grep -v -e '^Installed-Size: ' #{$wd}/c_a/#{d}/control) <(grep -v -e '^Installed-Size: ' #{$wd}/c_b/#{d}/control)"`.chomp
+ s2 = `bash -c "diff -u <(grep -v -e '^Installed-Size: ' #{$wd}/c_a/#{d}/control | sed -e '/^Depends:/ s/([^)]*)//g') <(grep -v -e '^Installed-Size: ' #{$wd}/c_b/#{d}/control | sed -e '/^Depends:/ s/([^)]*)//g')"`.chomp
+ if s2.length != 0
+ puts "E: control files for #{d} differ, even stripped. Stripped version:"
+ puts s2
+ puts "E: unstripped version:"
+ puts s1
+ elsif s1.length != 0
+ puts "W: unstripped control files for #{d} differ:"
+ puts s1
+ end
+end
+
+# compare other control files
+debstrip_a.each do |d|
+ s = `bash -c "diff -bur --exclude='control' --exclude='md5sums' #{$wd}/c_a #{$wd}/c_b"`.chomp
if s.length != 0
- puts "E: control files for #{d} differ:"
+ puts "E: other control files for #{d} differ:"
puts s
end
end
@@ -222,7 +275,7 @@
end
def equalfiles?(d, base_a, base_b, f, verbose = true)
- s = `diff -u #{base_a}/#{f} #{base_b}/#{f}`
+ s = `diff -u \"#{base_a}/#{f}\" \"#{base_b}/#{f}\"`
if s.length != 0
if verbose
puts "E: #{d}: #{f} differs:"
@@ -238,13 +291,13 @@
if t == 'application/x-not-regular-file'
# nothing to do
elsif t == 'application/octet-stream'
- s = `file -b #{base_a}/#{f}`.chomp
+ s = `file -b "#{base_a}/#{f}"`.chomp
if s =~ /gzip compressed data/
- systemr("zcat #{base_a}/#{f} > #{base_a}/#{f}.ungzipped")
- systemr("zcat #{base_b}/#{f} > #{base_b}/#{f}.ungzipped")
- t = `file -ib #{base_a}/#{f}.ungzipped`.chomp
+ systemr("zcat \"#{base_a}/#{f}\" > \"#{base_a}/#{f}.ungzipped\"")
+ systemr("zcat \"#{base_b}/#{f}\" > \"#{base_b}/#{f}.ungzipped\"")
+ t = `file -ib "#{base_a}/#{f}.ungzipped"`.chomp
filecmp(d, base_a, base_b, "#{f}.ungzipped", t)
- systemr("rm -f #{base_a}/#{f}.ungzipped #{base_b}/#{f}.ungzipped")
+ systemr("rm -f \"#{base_a}/#{f}.ungzipped\" \"#{base_b}/#{f}.ungzipped\"")
elsif [ 'data' ].include?(t)
cmpsize(d, base_a, base_b, f)
elsif s =~ /GNU message catalog/
@@ -257,45 +310,45 @@
end
elsif t =~ /^application\/x-sharedlib/
- system("objdump -p #{base_a}/#{f} |grep NEEDED > #{base_a}/#{f}.objdumpp")
- system("objdump -p #{base_b}/#{f} |grep NEEDED > #{base_b}/#{f}.objdumpp")
+ system("objdump -p \"#{base_a}/#{f}\" |grep NEEDED > \"#{base_a}/#{f}.objdumpp\"")
+ system("objdump -p \"#{base_b}/#{f}\" |grep NEEDED > \"#{base_b}/#{f}.objdumpp\"")
s = `diff -u #{base_a}/#{f}.objdumpp #{base_a}/#{f}.objdumpp`.chomp
if s.length != 0
puts "E: #{d}: #{f} NEEDED in headers differ:"
puts s
end
- systemr("objdump -T #{base_a}/#{f} | grep '*UND*' | cut -c 34- > #{base_a}/#{f}.undef")
- systemr("objdump -T #{base_b}/#{f} | grep '*UND*' | cut -c 34- > #{base_b}/#{f}.undef")
+ systemr("objdump -T \"#{base_a}/#{f}\" | grep '*UND*' | cut -c 34- > \"#{base_a}/#{f}.undef\"")
+ systemr("objdump -T \"#{base_b}/#{f}\" | grep '*UND*' | cut -c 34- > \"#{base_b}/#{f}.undef\"")
s = `diff -u #{base_b}/#{f}.undef #{base_b}/#{f}.undef`.chomp
if s.length != 0
puts "E: #{d}: #{f} undefined symbols differ:"
puts s
end
- systemr("objdump -T #{base_a}/#{f} | grep '.text' | cut -c 34- > #{base_a}/#{f}.def")
- systemr("objdump -T #{base_b}/#{f} | grep '.text' | cut -c 34- > #{base_b}/#{f}.def")
+ systemr("objdump -T \"#{base_a}/#{f}\" | grep '.text' | cut -c 34- > \"#{base_a}/#{f}.def\"")
+ systemr("objdump -T \"#{base_b}/#{f}\" | grep '.text' | cut -c 34- > \"#{base_b}/#{f}.def\"")
s = `diff -u #{base_b}/#{f}.def #{base_b}/#{f}.def`.chomp
if s.length != 0
puts "E: #{d}: #{f} Defined symbols differ:"
puts s
end
- systemr("rm -f #{base_a}/#{f}.objdumpp #{base_b}/#{f}.objdumpp #{base_a}/#{f}.undef #{base_b}/#{f}.undef #{base_a}/#{f}.def #{base_b}/#{f}.def")
+ systemr("rm -f \"#{base_a}/#{f}.objdumpp\" \"#{base_b}/#{f}.objdumpp\" \"#{base_a}/#{f}.undef\" \"#{base_b}/#{f}.undef\" \"#{base_a}/#{f}.def\" \"#{base_b}/#{f}.def\"")
elsif t =~ /^application\/x-executable.*dynamically linked \(uses shared libs\)/
- system("objdump -p #{base_a}/#{f} |grep NEEDED > #{base_a}/#{f}.objdumpp")
- system("objdump -p #{base_b}/#{f} |grep NEEDED > #{base_b}/#{f}.objdumpp")
- s = `diff -u #{base_a}/#{f}.objdumpp #{base_a}/#{f}.objdumpp`.chomp
+ system("objdump -p \"#{base_a}/#{f}\" |grep NEEDED > \"#{base_a}/#{f}.objdumpp\"")
+ system("objdump -p \"#{base_b}/#{f}\" |grep NEEDED > \"#{base_b}/#{f}.objdumpp\"")
+ s = `diff -u \"#{base_a}/#{f}.objdumpp\" \"#{base_a}/#{f}.objdumpp\"`.chomp
if s.length != 0
puts "E: #{d}: #{f} NEEDED in headers differ:"
puts s
end
- systemr("objdump -T #{base_a}/#{f} | grep '*UND*' | cut -c 34- > #{base_a}/#{f}.undef")
- systemr("objdump -T #{base_b}/#{f} | grep '*UND*' | cut -c 34- > #{base_b}/#{f}.undef")
- s = `diff -u #{base_b}/#{f}.undef #{base_b}/#{f}.undef`.chomp
+ systemr("objdump -T \"#{base_a}/#{f}\" | grep '*UND*' | cut -c 34- > \"#{base_a}/#{f}.undef\"")
+ systemr("objdump -T \"#{base_b}/#{f}\" | grep '*UND*' | cut -c 34- > \"#{base_b}/#{f}.undef\"")
+ s = `diff -u \"#{base_b}/#{f}.undef\" \"#{base_b}/#{f}.undef\"`.chomp
if s.length != 0
puts "E: #{d}: #{f} undefined symbols differ:"
puts s
end
- systemr("rm -f #{base_a}/#{f}.objdumpp #{base_b}/#{f}.objdumpp #{base_a}/#{f}.undef #{base_b}/#{f}.undef")
+ systemr("rm -f \"#{base_a}/#{f}.objdumpp\" \"#{base_b}/#{f}.objdumpp\" \"#{base_a}/#{f}.undef\" \"#{base_b}/#{f}.undef\"")
cmpsize(d, base_a, base_b, f)
elsif t =~ /^text\// or t == 'application/x-perl' or t == 'application/x-empty' or t == '' or t =~ /^image\// or t == 'application/x-shellscript' or t == 'application/pdf'
@@ -306,7 +359,7 @@
cmpsize(d, base_a, base_b, f)
else
if not equalfiles?(d, base_a, base_b, f)
- puts "I: #{d} Filetype unknown, files differ: #{f} / #{t}"
+ puts "I: #{d}: Filetype unknown, files differ: #{f} / #{t}"
cmpsize(d, base_a, base_b, f)
end
end
@@ -316,9 +369,9 @@
debstrip_a.each do |d|
files = {}
IO::read("#{$wd}/a_#{d}.filei_output").each_line do |l|
- f,t = l.split($;,2)
+ f,t = l.split(':',2)
t.chomp!
- f.gsub!(/:$/,'')
+ t.strip!
files[f] = t
end
files.each_pair do |f,t|
@@ -326,8 +379,7 @@
end
end
-system("rm -rf #{$wd}")
-exit(0)
+clean_exit(0)
# Compare file lists
More information about the Collab-qa-commits
mailing list