[Collab-qa-commits] r384 - tools/debcmp

lucas at alioth.debian.org lucas at alioth.debian.org
Tue Aug 21 13:29:27 UTC 2007


Author: lucas
Date: 2007-08-21 13:29:27 +0000 (Tue, 21 Aug 2007)
New Revision: 384

Modified:
   tools/debcmp/debcmp.rb
Log:
debcmp updates

Modified: tools/debcmp/debcmp.rb
===================================================================
--- tools/debcmp/debcmp.rb	2007-08-20 22:22:02 UTC (rev 383)
+++ tools/debcmp/debcmp.rb	2007-08-21 13:29:27 UTC (rev 384)
@@ -6,6 +6,7 @@
 # read ./debcmp.rb --help
 
 require 'optparse'
+require 'find'
 
 package = nil
 version = nil
@@ -17,6 +18,20 @@
 pool = false
 tmpbase = '/scratch/grenoble/lnussbaum/tmp'
 
+# create the first working directories
+$wd = `mktemp -d #{tmpbase}/debcmp.XXXXXX`.chomp
+system("mkdir -p #{$wd}/a #{$wd}/b")
+
+# utility functions
+def clean_exit(n)
+  system("rm -rf #{$wd}") unless $nocleanup
+  exit(n)
+end
+
+def systemr(cmd)
+  raise "Command failed: #{cmd}" if not system(cmd)
+end
+
 progname = File::basename($PROGRAM_NAME)
 opts = OptionParser::new do |opts|
   opts.program_name = progname
@@ -66,6 +81,11 @@
   clean_exit(1)
 end
 
+eversion = version
+if eversion =~ /:/
+  version = eversion.gsub(/^[^:]+:/,'')
+end
+
 # determine upstream version
 if version =~ /-/
   sversion = version.gsub(/-[^-]*$/,'')
@@ -73,10 +93,6 @@
   sversion = version
 end
 
-# create the first working directories
-$wd = `mktemp -d #{tmpbase}/debcmp.XXXXXX`.chomp
-system("mkdir -p #{$wd}/a #{$wd}/b")
-
 puts "# Working dir: #{$wd}" if $verbose
 
 # determine source dirs
@@ -93,21 +109,13 @@
   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")
+if not Dir::glob("#{sdir_b}/*_#{version}.diff.gz").empty?
   native = false
   if version =~ /-/
     sversion = version.gsub(/-[^-]*$/,'')
@@ -118,6 +126,8 @@
   native = true
   sversion = version
 end
+tgz_a = ! Dir::glob("#{sdir_a}/*_#{sversion}*.tar.gz").empty?
+tgz_b = ! Dir::glob("#{sdir_b}/*_#{sversion}*.tar.gz").empty?
 
 if Dir::glob("#{sdir_b}/*_#{version}_*.deb").length == 0
   puts "E: No .deb files found! Build probably failed."
@@ -133,10 +143,12 @@
   l = Dir::glob("#{sdir_b}/*_#{version}_*.deb").reject { |e| e !~ /_(#{$arch}|all).deb/ }
   systemr("cp #{l.join(' ')} #{$wd}/b")
 else
-  systemr("cp #{sdir_a}/*_#{sversion}.orig.tar.gz #{sdir_a}/*_#{version}{.dsc,.diff.gz} #{$wd}/a")
+  systemr("cp #{sdir_a}/*_#{version}{.dsc,.diff.gz} #{$wd}/a")
+  systemr("cp #{sdir_a}/*_#{sversion}.orig.tar.gz #{$wd}/a") if tgz_a
   l = Dir::glob("#{sdir_a}/*_#{version}_*.deb").reject { |e| e !~ /_(#{$arch}|all).deb/ }
   systemr("cp #{l.join(' ')} #{$wd}/a")
-  systemr("cp #{sdir_b}/*_#{sversion}.orig.tar.gz #{sdir_b}/*_#{version}{.dsc,.diff.gz} #{$wd}/b")
+  systemr("cp #{sdir_b}/*_#{version}{.dsc,.diff.gz} #{$wd}/b")
+  systemr("cp #{sdir_b}/*_#{sversion}.orig.tar.gz #{$wd}/b") if tgz_b
   l = Dir::glob("#{sdir_b}/*_#{version}_*.deb").reject { |e| e !~ /_(#{$arch}|all).deb/ }
   systemr("cp #{l.join(' ')} #{$wd}/b")
 end
@@ -147,7 +159,7 @@
   if not system("cmp #{$wd}/a/*.tar.gz #{$wd}/b/*.tar.gz &>/dev/null")
     puts "E: .tar.gz files differ (native package)."
   end
-else
+elsif tgz_a and tgz_b
   if not system("cmp #{$wd}/a/*.orig.tar.gz #{$wd}/b/*.orig.tar.gz")
     puts "E: .orig.tar.gz files differ."
   end
@@ -203,6 +215,36 @@
 # Compare control files
 # We ignore the Installed-Size line
 debstrip_a.each do |d|
+
+  # sort control files' headers
+  order = Hash::new(20)
+  order['Package'] = 0
+  order['Version'] = 1
+  order['Architecture'] = 2
+  order['Maintainer'] = 3
+  order['Depends'] = 4
+  order['Section'] = 5
+  order['Source'] = 6
+  order['Conflicts'] = 7
+  order['Replaces'] = 8
+  order['Provides'] = 9
+  order['Priority'] = 10
+  [ "#{$wd}/c_a/#{d}/control", "#{$wd}/c_b/#{d}/control" ].each do |f|
+    before, after = IO::read(f).split(/^Description:/)
+    lines = before.split(/\n/)
+    lines.sort! do |a,b|
+      if a =~ /^\s/ or b =~ /^\s/
+        0
+      else
+        ha = a.split(/:/,2)[0]
+        hb = b.split(/:/,2)[0]
+        order[ha] <=> order[hb]
+      end
+    end
+    File::open(f, 'w') { |fd| fd.puts lines.join("\n") + "\nDescription:" + after }
+#   puts lines.join("\n") + "\nDescription:" + after
+  end
+
   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
@@ -216,23 +258,39 @@
   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: other control files for #{d} differ:"
-    puts s
+# sort lines of control files that should be sorted
+[ "#{$wd}/c_a", "#{$wd}/c_b" ].each do |dir|
+  Find::find(dir) do |path|
+    if File::file?(path) and [ 'conffiles' ].include?(File::basename(path))
+      str = IO::read(path).split(/\n/).sort.join("\n")
+      File::open(path, 'w') { |fd| fd.puts str }
+    end
   end
 end
+   
+# compare other control files
+s = `bash -c "diff -bur --exclude='control' --exclude='md5sums' #{$wd}/c_a #{$wd}/c_b"`.chomp
+if s.length != 0
+  puts "E: other control files differ:"
+  puts s
+end
 
 # Get files lists
 debstrip_a.each do |d|
   systemr("cd #{$wd}/p_a/#{d} && find . | sort > #{$wd}/a_#{d}.files")
   systemr("cd #{$wd}/p_b/#{d} && find . | sort > #{$wd}/b_#{d}.files")
-  systemr("cd #{$wd}/p_a/#{d} && find . -exec file {} + | sort | sed -e 's/for GNU\\/Linux .\\..\\../for GNU\\/Linux X.X.X/g' > #{$wd}/a_#{d}.file_output")
-  systemr("cd #{$wd}/p_b/#{d} && find . -exec file {} + | sort | sed -e 's/for GNU\\/Linux .\\..\\../for GNU\\/Linux X.X.X/g' > #{$wd}/b_#{d}.file_output")
-  systemr("cd #{$wd}/p_a/#{d} && find . -exec file -i {} + | sort | sed -e 's/for GNU\\/Linux .\\..\\../for GNU\\/Linux X.X.X/g' > #{$wd}/a_#{d}.filei_output")
-  systemr("cd #{$wd}/p_b/#{d} && find . -exec file -i {} + | sort | sed -e 's/for GNU\\/Linux .\\..\\../for GNU\\/Linux X.X.X/g' > #{$wd}/b_#{d}.filei_output")
+  systemr("cd #{$wd}/p_a/#{d} && find . -exec file {} + | sort > #{$wd}/a_#{d}.file_output")
+  systemr("cd #{$wd}/p_b/#{d} && find . -exec file {} + | sort > #{$wd}/b_#{d}.file_output")
+  systemr("cd #{$wd}/p_a/#{d} && find . -exec file -i {} + | sort > #{$wd}/a_#{d}.filei_output")
+  systemr("cd #{$wd}/p_b/#{d} && find . -exec file -i {} + | sort > #{$wd}/b_#{d}.filei_output")
+
+  [ "#{$wd}/a_#{d}.file_output", "#{$wd}/b_#{d}.file_output",
+    "#{$wd}/a_#{d}.filei_output", "#{$wd}/b_#{d}.filei_output"].each do |fn|
+    str = IO::read(fn)
+    str.gsub!(/for GNU\/Linux \d\.\d\.\d+,/, 'for GNU/Linux X.X.X,')
+    str.gsub!(/[ \t]+/, ' ')
+    File::open(fn, 'w') { |f| f.puts str }
+  end
 end
 
 # compare files list
@@ -289,7 +347,14 @@
 # Compare two files
 def filecmp(d, base_a, base_b, f, t)
   if t == 'application/x-not-regular-file'
-    # nothing to do
+    if File::directory?("#{base_a}/#{f}") and File::directory?("#{base_b}/#{f}")
+      # nothing to do
+    elsif File::symlink?("#{base_a}/#{f}") and File::symlink?("#{base_b}/#{f}") and 
+      (File::readlink("#{base_a}/#{f}") == lb = File::readlink("#{base_b}/#{f}"))
+      # nothing to do
+    else
+      puts "E: #{d}: #{f} not regular file of unknown type"
+    end
   elsif t == 'application/octet-stream'
     s = `file -b "#{base_a}/#{f}"`.chomp
     if s =~ /gzip compressed data/
@@ -369,39 +434,15 @@
 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(/:\s/,2)
     t.chomp!
     t.strip!
     files[f] = t
   end
   files.each_pair do |f,t|
+    next if not File::exist?("#{$wd}/p_b/#{d}/#{f}") # skip if file in A but not in B
     filecmp(d, "#{$wd}/p_a/#{d}", "#{$wd}/p_b/#{d}", f, t)
   end 
 end
 
 clean_exit(0)
-
-# Compare file lists
-
-#
-#tar tvzf + output filtering
-#interdiff
-#
-## binaries
-#ar x pathto.deb
-#compare content of data.tar.gz
-#extract control.tar.gz and compare content
-#extract data. for each file, the result of "file" must be the same:
-#find . -exec file {} +
-#same with file -i
-#
-#use file -i output and check some files:
-#- same content
-#- same size: equal, or +/- 1,5,10%
-#
-#By filetype:
-#  /application\/x-executable .* dynamically linked/
-#  nm -D
-#  objdump -x # headers
-#  objdump -T # dynamic relocation records
-#




More information about the Collab-qa-commits mailing list