[27163] users/pipping/merge.rb

source_changes at macosforge.org source_changes at macosforge.org
Sun Jul 22 08:19:28 PDT 2007


Revision: 27163
          http://trac.macosforge.org/projects/macports/changeset/27163
Author:   pipping at macports.org
Date:     2007-07-22 08:19:27 -0700 (Sun, 22 Jul 2007)

Log Message:
-----------
r52: trivial changes
r53: minor changes
r54: trivial change
r55: use more meaningful variable names, adhere to some basic coding standards (camelCase variables e.g.)
r56: remove stray slash from regex, use true_for_all? to check links for correctness
r57: reorder arguments, rename variables

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

Modified: users/pipping/merge.rb
===================================================================
--- users/pipping/merge.rb	2007-07-22 11:27:25 UTC (rev 27162)
+++ users/pipping/merge.rb	2007-07-22 15:19:27 UTC (rev 27163)
@@ -91,12 +91,15 @@
 # ignore duplicates and trailing slashes
 ARGS = ARGV.collect {|arg| arg.chomp( '/' )}.uniq
 
-def true_for_all? ( path, opts, first_too, &block )
+def true_for_all? ( filePath, includeFirst, opts )
 # checks if a predicate is true for all (but the first) architecture
   result = true
-  iter_over = first_too ? ARGS : ARGS[1..-1]
-  iter_over.each {|arch|
-    result = false unless yield( opts.input + arch + path, arch )
+  iterable = includeFirst ? ARGS : ARGS[1..-1]
+  iterable.each {|arch|
+    unless yield( opts.input + arch + filePath, arch )
+      result = false
+      break
+    end
   }
   return result
 end
@@ -111,40 +114,40 @@
   end
 end
 
-def check_singlearch( my_path, opts, regex )
+def check_consistency( path, regex, opts )
 # checks if a file has the correct type and architecture across all trees
-  type_matches = true_for_all?( my_path, opts, true ) {|filepath, arch|
-    filecall_out = %x{#{ FILE } -b "#{ filepath }"}.chomp
-    filecall_out =~ regex
+  type_matches = true_for_all?( path, true, opts ) {|filePath, arch|
+    fileCallOutput = %x{#{ FILE } -b "#{ filePath }"}.chomp
+    fileCallOutput =~ regex
   }
-  arch_matches = true_for_all?( my_path, opts, true ) {|filepath, arch|
-    lipocall_out = %x{lipo -info "#{ filepath }"}.chomp
-    lipocall_out =~ %r{is architecture: #{ arch }$}
+  arch_matches = true_for_all?( path, true, opts ) {|filePath, arch|
+    lipoCallOutput = %x{lipo -info "#{ filePath }"}.chomp
+    lipoCallOutput =~ %r{is architecture: #{ arch }$}
   }
   raise 'type or architecture mismatch' unless type_matches and arch_matches
 end
 
-def lipo ( filepath, architectures, opts )
+def lipo ( filePath, opts )
 # glues single-architecture files together using lipo(1)
-  lipoargs = Array.new
-  architectures.each {|arch|
-    lipoargs << sprintf( '-arch %s %s', arch, opts.input + arch + filepath )
+  lipoArgs = Array.new
+  ARGS.each {|arch|
+    lipoArgs << sprintf( '-arch %s %s', arch, opts.input + arch + filePath )
   }
-  lipotarget = opts.output + filepath
-  lipocmd = sprintf( 'lipo %s -create -o %s', lipoargs.join( ' ' ), lipotarget )
-  unless lipotarget.exist? and !opts.force
-    puts lipocmd if opts.verbose
-    system lipocmd unless opts.dryrun
+  lipoTarget = opts.output + filePath
+  lipoCommand = sprintf( 'lipo %s -create -o %s', lipoArgs.join( ' ' ), lipoTarget )
+  unless lipoTarget.exist? and !opts.force
+    puts lipoCommand if opts.verbose
+    system lipoCommand unless opts.dryrun
   end
 end
 
-def make_wrapper ( filepath, first, opts )
+def make_wrapper ( filePath, first, opts )
 # creates a wrapper for config scripts that differ across trees
-  wrapper_target = opts.output + filepath
-  unless wrapper_target.exist? and !opts.force
-    wrapper_target.open( 'w' ) {|wrapper|
+  wrapperTarget = opts.output + filePath
+  unless wrapperTarget.exist? and !opts.force
+    wrapperTarget.open( 'w' ) {|wrapper|
       wrapper.puts '#! /bin/sh'
-      wrapper.puts 'DIR="%s"' % filepath.dirname
+      wrapper.puts 'DIR="%s"' % filePath.dirname
       wrapper.puts 'args=$@'
       wrapper.puts 'if [ "${args/-arch/}" != "$args" ]; then'
       wrapper.puts '  arch=`echo "$args" | ' +
@@ -153,14 +156,14 @@
       wrapper.puts '  arch=`uname -p`'
       wrapper.puts 'fi'
       wrapper.puts 'args=`echo $@ | sed "s!-arch  *${arch}!!"`'
-      wrapper.puts 'exec $DIR/${arch}/%s ${args}' % filepath.basename
+      wrapper.puts 'exec $DIR/${arch}/%s ${args}' % filePath.basename
     }
-    wrapper_target.chmod( first.stat.mode )
+    wrapperTarget.chmod( first.stat.mode )
   end
 end
 
 
-ORIGINAL_DIR = Pathname.pwd
+ORIGIN = Pathname.pwd
 processed = Set.new
 
 # make sure we're given a valid root directory
@@ -170,138 +173,141 @@
 
 # make sure the requested architectures have corresponding subdirectories
 # in the the given input directory
-unless true_for_all?( '.', options, true) {|filepath, arch|
-  filepath.directory?
+unless true_for_all?( '.', true, options) {|filePath, arch|
+  filePath.directory?
 }
   raise 'architecture missing from input directory'
 end
 
 ARGS.each {|architecture|
   FileUtils.cd options.input + architecture
-  Pathname.new( '.' ).find {|path|
-    options.exclude.each {|exclude_me|
-      Find.prune if path.basename.fnmatch? exclude_me
+  Pathname.new( '.' ).find {|subPath|
+    options.exclude.each {|excludedPattern|
+      if subPath.basename.fnmatch? excludedPattern
+        Find.prune
+        break
+      end
     }
-    Find.prune if processed.include? path
+    Find.prune if processed.include? subPath
 
-    first_path = options.input + ARGS[0] + path
-    unless true_for_all?( path, options, false ) {|filepath, arch|
+    firstPath = options.input + ARGS[0] + subPath
+    unless true_for_all?( subPath, false, options ) {|filePath, arch|
       begin
-        filepath.ftype == first_path.ftype
+        filePath.ftype == firstPath.ftype
       rescue Errno::ENOENT
         # DEBUG: file does not exist
         false
       end
     }
-      puts 'DEBUG: skipping %s' % path
+      puts 'DEBUG: skipping %s' % subPath
       Find.prune
     end
 
-    case first_path.ftype
+    case firstPath.ftype
     # handle file type: directory
     when 'directory'
-      my_dir = options.output + path
-      my_dir.mkpath unless options.dryrun
+      dirToCreate = options.output + subPath
+      dirToCreate.mkpath unless options.dryrun
     # handle file type: symlinks
     when 'link'
-      link_target = first_path.readlink
-      if true_for_all?( path, options, false ) {|filepath, arch|
-        my_symlink = options.input + arch + path
-        my_symlink.readlink == link_target
+      linkTarget = firstPath.readlink
+      if true_for_all?( subPath, false, options ) {|filePath, arch|
+        pathToSymlink = options.input + arch + subPath
+        pathToSymlink.readlink == linkTarget
       }
-        link_output = options.output + path
-        unless link_output.symlink? or link_output.exist?
+        linkDestination = options.output + subPath
+        unless linkDestination.symlink? or linkDestination.exist?
           FileUtils.copy_entry(
-            first_path,
-            link_output
+            firstPath,
+            linkDestination
           )
         end
       else
         # DEBUG: link targets differ
       end
     when 'file'
-      if true_for_all?( path, options, false ) {|filepath, arch|
-        FileUtils.identical?( filepath, first_path )
+      if true_for_all?( subPath, false, options ) {|filePath, arch|
+        FileUtils.identical?( filePath, firstPath )
       }
-        copy( first_path, options.output + path, options )
+        copy( firstPath, options.output + subPath, options )
         Find.prune
       end
 
-      case path.extname
+      case subPath.extname
       # handle file type: header files
       when '.h', '.hpp'
-        unless ( options.output + path ).exist? and !options.force
-          open( options.output + path, 'w' ) {|my_file|
+        unless ( options.output + subPath ).exist? and !options.force
+          open( options.output + subPath, 'w' ) {|headerTarget|
             ARGS.each {|arch|
-              my_file.puts '#ifdef __%s__' % arch
-              my_file.puts open( options.input + arch + path, 'r' ).read
-              my_file.puts '#endif'
+              headerInput = options.input + arch + subPath
+              headerTarget.puts '#ifdef __%s__' % arch
+              headerTarget.puts headerFile.open( 'r' ).read
+              headerTarget.puts '#endif'
             }
           }
         end
       # handle file type: pkg-config files
       when '.pc'
         ARGS.each {|arch|
-          copy_target = options.output + path.dirname + arch + path.basename
-          copy_target.dirname.mkpath unless options.dryrun
-          copy( options.input + arch + path, copy_target, options )
+          copyTarget = options.output + subPath.dirname + arch + subPath.basename
+          copyTarget.dirname.mkpath unless options.dryrun
+          copy( options.input + arch + subPath, copyTarget, options )
         }
       # handle file type: other files
       else
-        file_output = %x{ #{ FILE } -b "#{ first_path }" }.chomp
-        case file_output
+        fileOutput = %x{ #{ FILE } -b "#{ firstPath }" }.chomp
+        case fileOutput
         # handle file type: ar archives
         when %r{^current ar archive}
-          check_singlearch( path, options, %r{^current ar archive} )
-          lipo( path, ARGS, options )
+          check_consistency( subPath, %r{^current ar archive}, options )
+          lipo( subPath, options )
         # handle file type: mach-o files
         when %r{^Mach-O}
-          check_singlearch( path, options, %r{^Mach-O} )
+          check_consistency( subPath, %r{^Mach-O}, options )
           links = Hash.new
-          ARGS.each {|my_arch|
-            links[my_arch] = %x{
+          ARGS.each {|arch|
+            links[arch] = %x{
               #{
-                my_arch[-2..-1] == '64' ? 'otool64' : 'otool'
-              } -arch #{ my_arch } -LX #{
-                options.input + my_arch + path
+                arch[-2..-1] == '64' ? 'otool64' : 'otool'
+              } -arch #{ arch } -LX #{
+                options.input + arch + subPath
               }
-            }.split( "\n" ).collect {|dep_line|
-              dep_line.lstrip.gsub(
-                / \(compatibility version \d+(\.\d+){2}, current version \d+(\.\d+){2}\)/, ''
+            }.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
           }
-          ARGS.each {|my_arch|
-            unless links[my_arch] == links[ARGS[0]]
-              missing_in  = links[my_arch]-links[ARGS[0]]
-              missing_out = links[ARGS[0]]-links[my_arch]
-              if missing_in.any? or missing_out.any?
-                raise 'difference in linking encountered: file %s' % path
-              end
-            end
+          unless true_for_all?( subPath, false, options ) {|filePath, arch|
+            links[arch] == links[ARGS[0]]
           }
-          lipo( path, ARGS, options )
+            raise 'difference in linking encountered: file %s' % subPath
+          end
+          lipo( subPath, options )
         when 'Bourne shell script text executable'
-          unless path.basename.to_s[-7..-1] == '-config'
+          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
           ARGS.each {|arch|
-            copy_target=options.output + path.dirname + arch + path.basename
-            copy_target.dirname.mkpath unless options.dryrun
-            copy( options.input + arch + path, copy_target, options )
+            copyTarget=options.output + subPath.dirname + arch + subPath.basename
+            copyTarget.dirname.mkpath unless options.dryrun
+            copy( options.input + arch + subPath, copyTarget, options )
           }
-          make_wrapper( path, first_path, options )
+          make_wrapper( subPath, firstPath, options )
         else
           # DEBUG: unable to determine file type
         end
       end
     end
-    processed << path
+    processed << subPath
   }
 }
 
-FileUtils.cd ORIGINAL_DIR
+FileUtils.cd ORIGIN

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


More information about the macports-changes mailing list