[27308] users/pipping/merge.rb

source_changes at macosforge.org source_changes at macosforge.org
Sat Jul 28 09:15:57 PDT 2007


Revision: 27308
          http://trac.macosforge.org/projects/macports/changeset/27308
Author:   pipping at macports.org
Date:     2007-07-28 09:15:57 -0700 (Sat, 28 Jul 2007)

Log Message:
-----------
r58: previously, if a file only existed in a dir other than ARGS[0], no message was given. fixed now.
r59: fix name of variable
r60: handle gzip-compressed man pages
r61: remove --force as it is not really needed and error-prone
r62: use correct Zlib::GzipReader syntax, minor formatting change

Modified Paths:
--------------
    users/pipping/merge.rb

Modified: users/pipping/merge.rb
===================================================================
--- users/pipping/merge.rb	2007-07-28 11:35:48 UTC (rev 27307)
+++ users/pipping/merge.rb	2007-07-28 16:15:57 UTC (rev 27308)
@@ -26,6 +26,8 @@
 require 'ostruct'
 require 'pathname'
 require 'set'
+require 'tempfile'
+require 'zlib'
 
 ###
 # we need GNU File with Apple's patches applied, otherwise we will not be
@@ -38,7 +40,6 @@
     # set up defaults
     options = OpenStruct.new
     options.dryrun  = false
-    options.force   = false
     options.verbose = false
 
     options.exclude = %w{.svn CVS}
@@ -68,10 +69,6 @@
         options.dryrun = d
       }
 
-      opts.on( '-f', '--[no-]force', 'Ignore collisions' ) {|f|
-        options.force = f
-      }
-
       opts.on( '-v', '--[no-]verbose', 'Run verbosely' ) {|v|
         options.verbose = v
       }
@@ -106,7 +103,7 @@
 
 def copy ( origin, target, opts )
 # copies files
-  unless target.exist? and !opts.force
+  unless target.exist?
     FileUtils.cp( origin, target,
       :noop => opts.dryrun,
       :verbose => opts.verbose
@@ -135,7 +132,7 @@
   }
   lipoTarget = opts.output + filePath
   lipoCommand = sprintf( 'lipo %s -create -o %s', lipoArgs.join( ' ' ), lipoTarget )
-  unless lipoTarget.exist? and !opts.force
+  unless lipoTarget.exist?
     puts lipoCommand if opts.verbose
     system lipoCommand unless opts.dryrun
   end
@@ -144,7 +141,7 @@
 def make_wrapper ( filePath, first, opts )
 # creates a wrapper for config scripts that differ across trees
   wrapperTarget = opts.output + filePath
-  unless wrapperTarget.exist? and !opts.force
+  unless wrapperTarget.exist?
     wrapperTarget.open( 'w' ) {|wrapper|
       wrapper.puts '#! /bin/sh'
       wrapper.puts 'DIR="%s"' % filePath.dirname
@@ -188,125 +185,138 @@
         break
       end
     }
-    Find.prune if processed.include? subPath
-
-    firstPath = options.input + ARGS[0] + subPath
-    unless true_for_all?( subPath, false, options ) {|filePath, arch|
-      begin
-        filePath.ftype == firstPath.ftype
-      rescue Errno::ENOENT
-        # DEBUG: file does not exist
-        false
-      end
-    }
-      puts 'DEBUG: skipping %s' % subPath
-      Find.prune
-    end
-
-    case firstPath.ftype
-    # handle file type: directory
-    when 'directory'
-      dirToCreate = options.output + subPath
-      dirToCreate.mkpath unless options.dryrun
-    # handle file type: symlinks
-    when 'link'
-      linkTarget = firstPath.readlink
-      if true_for_all?( subPath, false, options ) {|filePath, arch|
-        pathToSymlink = options.input + arch + subPath
-        pathToSymlink.readlink == linkTarget
-      }
-        linkDestination = options.output + subPath
-        unless linkDestination.symlink? or linkDestination.exist?
-          FileUtils.copy_entry(
-            firstPath,
-            linkDestination
-          )
+    unless processed.include? subPath
+      firstPath = options.input + ARGS[0] + subPath
+      unless true_for_all?( subPath, false, options ) {|filePath, arch|
+        begin
+          filePath.ftype == firstPath.ftype
+        rescue Errno::ENOENT
+          # DEBUG: file does not exist
+          false
         end
-      else
-        # DEBUG: link targets differ
-      end
-    when 'file'
-      if true_for_all?( subPath, false, options ) {|filePath, arch|
-        FileUtils.identical?( filePath, firstPath )
       }
-        copy( firstPath, options.output + subPath, options )
+        puts 'DEBUG: skipping %s' % subPath
         Find.prune
       end
 
-      case subPath.extname
-      # handle file type: header files
-      when '.h', '.hpp'
-        unless ( options.output + subPath ).exist? and !options.force
-          open( options.output + subPath, 'w' ) {|headerTarget|
-            ARGS.each {|arch|
-              headerInput = options.input + arch + subPath
-              headerTarget.puts '#ifdef __%s__' % arch
-              headerTarget.puts headerFile.open( 'r' ).read
-              headerTarget.puts '#endif'
-            }
-          }
+      case firstPath.ftype
+      # handle file type: directory
+      when 'directory'
+        dirToCreate = options.output + subPath
+        dirToCreate.mkpath unless options.dryrun
+      # handle file type: symlinks
+      when 'link'
+        linkTarget = firstPath.readlink
+        if true_for_all?( subPath, false, options ) {|filePath, arch|
+          pathToSymlink = options.input + arch + subPath
+          pathToSymlink.readlink == linkTarget
+        }
+          linkDestination = options.output + subPath
+          unless linkDestination.symlink? or linkDestination.exist?
+            FileUtils.copy_entry(
+              firstPath,
+              linkDestination
+            )
+          end
+        else
+          # DEBUG: link targets differ
         end
-      # handle file type: pkg-config files
-      when '.pc'
-        ARGS.each {|arch|
-          copyTarget = options.output + subPath.dirname + arch + subPath.basename
-          copyTarget.dirname.mkpath unless options.dryrun
-          copy( options.input + arch + subPath, copyTarget, options )
+      when 'file'
+        if true_for_all?( subPath, false, options ) {|filePath, arch|
+          FileUtils.identical?( filePath, firstPath )
         }
-      # handle file type: other files
-      else
-        fileOutput = %x{ #{ FILE } -b "#{ firstPath }" }.chomp
-        case fileOutput
-        # handle file type: ar archives
-        when %r{^current ar archive}
-          check_consistency( subPath, %r{^current ar archive}, options )
-          lipo( subPath, options )
-        # handle file type: mach-o files
-        when %r{^Mach-O}
-          check_consistency( subPath, %r{^Mach-O}, options )
-          links = Hash.new
-          ARGS.each {|arch|
-            links[arch] = %x{
-              #{
-                arch[-2..-1] == '64' ? 'otool64' : 'otool'
-              } -arch #{ arch } -LX #{
-                options.input + arch + subPath
+          copy( firstPath, options.output + subPath, options )
+          Find.prune
+        end
+
+        case subPath.extname
+        # handle file type: header files
+        when '.h', '.hpp'
+          unless ( options.output + subPath ).exist?
+            open( options.output + subPath, 'w' ) {|headerTarget|
+              ARGS.each {|arch|
+                headerInput = options.input + arch + subPath
+                headerTarget.puts '#ifdef __%s__' % arch
+                headerTarget.puts headerInput.open( 'r' ).read
+                headerTarget.puts '#endif'
               }
-            }.entries.collect {|dependencyLine|
-              dependencyLine.strip.gsub(
-                Regexp.new(
-                  ' \(compatibility version \d+(\.\d+){2}, ' +
-                  'current version \d+(\.\d+){2}\)'
-                ), ''
-              )
-            }.reject {|dep|
-              dep[0..7] == '/usr/lib'
-            }.to_set
-          }
-          unless true_for_all?( subPath, false, options ) {|filePath, arch|
-            links[arch] == links[ARGS[0]]
-          }
-            raise 'difference in linking encountered: file %s' % subPath
+            }
           end
-          lipo( subPath, options )
-        when 'Bourne shell script text executable'
-          unless subPath.basename.to_s[-7..-1] == '-config'
-            Find.prune
-            # DEBUG: no way to handle a shell script in general
-          end
-          # handle file type: config script
+        # handle file type: pkg-config files
+        when '.pc'
           ARGS.each {|arch|
-            copyTarget=options.output + subPath.dirname + arch + subPath.basename
+            copyTarget = options.output + subPath.dirname + arch + subPath.basename
             copyTarget.dirname.mkpath unless options.dryrun
             copy( options.input + arch + subPath, copyTarget, options )
           }
-          make_wrapper( subPath, firstPath, options )
+        # handle file type: gzip-compressed man pages
+        when '.gz'
+          temporaryFiles = Hash.new
+          ARGS.each {|arch|
+            compressed = options.input + arch + subPath
+            uncompressed = Tempfile.new( compressed.basename )
+            uncompressed.write( Zlib::GzipReader.open( compressed ).read )
+            uncompressed.close
+            temporaryFiles[arch] = uncompressed.path
+          }
+        if true_for_all?( subPath, false, options ) {|filePath, arch|
+          FileUtils.identical?( temporaryFiles[arch], temporaryFiles[ARGS[0]] )
+        }
+          copy( firstPath, options.output + subPath, options )
+        end
+        # handle file type: other files
         else
-          # DEBUG: unable to determine file type
+          fileOutput = %x{ #{ FILE } -b "#{ firstPath }" }.chomp
+          case fileOutput
+          # handle file type: ar archives
+          when %r{^current ar archive}
+            check_consistency( subPath, %r{^current ar archive}, options )
+            lipo( subPath, options )
+          # handle file type: mach-o files
+          when %r{^Mach-O}
+            check_consistency( subPath, %r{^Mach-O}, options )
+            links = Hash.new
+            ARGS.each {|arch|
+              links[arch] = %x{
+                #{
+                  arch[-2..-1] == '64' ? 'otool64' : 'otool'
+                } -arch #{ arch } -LX #{
+                  options.input + arch + subPath
+                }
+              }.entries.collect {|dependencyLine|
+                dependencyLine.strip.gsub(
+                  Regexp.new(
+                    ' \(compatibility version \d+(\.\d+){2}, ' +
+                    'current version \d+(\.\d+){2}\)'
+                  ), ''
+                )
+              }.reject {|dep|
+                dep[0..7] == '/usr/lib'
+              }.to_set
+            }
+            unless true_for_all?( subPath, false, options ) {|filePath, arch|
+              links[arch] == links[ARGS[0]]
+            }
+              raise 'difference in linking encountered: file %s' % subPath
+            end
+            lipo( subPath, options )
+          when 'Bourne shell script text executable'
+            # DEBUG: no way to handle a shell script in general
+            Find.prune unless subPath.basename.to_s[-7..-1] == '-config'
+            # handle file type: config script
+            ARGS.each {|arch|
+              copyTarget=options.output + subPath.dirname + arch + subPath.basename
+              copyTarget.dirname.mkpath unless options.dryrun
+              copy( options.input + arch + subPath, copyTarget, options )
+            }
+            make_wrapper( subPath, firstPath, options )
+          else
+            # DEBUG: unable to determine file type
+          end
         end
       end
+      processed << subPath
     end
-    processed << subPath
   }
 }
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070728/b3aec45e/attachment.html


More information about the macports-changes mailing list