[26572] users/pipping

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 28 12:13:45 PDT 2007


Revision: 26572
          http://trac.macosforge.org/projects/macports/changeset/26572
Author:   pipping at macports.org
Date:     2007-06-28 12:13:45 -0700 (Thu, 28 Jun 2007)

Log Message:
-----------
= merge.rb =
remove whitelist - ignore linked libraries in /usr/lib completely instead
simplify interface of `true_for_all?`, make its invocation use the new syntax
make merging of headers play along nicely with --force or existing files
reformat option parsing
= create_testheaders.sh =
add test script for header files

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

Added Paths:
-----------
    users/pipping/create_testheaders.sh

Added: users/pipping/create_testheaders.sh
===================================================================
--- users/pipping/create_testheaders.sh	                        (rev 0)
+++ users/pipping/create_testheaders.sh	2007-06-28 19:13:45 UTC (rev 26572)
@@ -0,0 +1,17 @@
+TARGET=/tmp
+
+for dir in ppc ppc64 i386 x86_64; do
+    mkdir -p "$TARGET/headers_1/$dir" "$TARGET/headers_2/$dir"
+done
+
+for dir in ppc ppc64 i386 x86_64; do
+  echo "foo_${dir}_bar" > "$TARGET/headers_1/$dir/header.hpp"
+done
+
+for dir in ppc i386; do
+  echo foo > "$TARGET/headers_2/$dir/header.hpp"
+done
+
+for dir in ppc64 x86_64; do
+  echo bar > "$TARGET/headers_2/$dir/header.hpp"
+done


Property changes on: users/pipping/create_testheaders.sh
___________________________________________________________________
Name: svn:executable
   + *

Modified: users/pipping/merge.rb
===================================================================
--- users/pipping/merge.rb	2007-06-28 15:37:10 UTC (rev 26571)
+++ users/pipping/merge.rb	2007-06-28 19:13:45 UTC (rev 26572)
@@ -43,42 +43,62 @@
     self[:output]  = File.join(Dir.pwd,'out')
     self[:root]    = Dir.pwd
 
-    opts = OptionParser.new do |opts|
+    opts = OptionParser.new {|opts|
       opts.banner = "Usage: #$0 [options] <arch> <arch> [<arch> ...]"
 
-      opts.on('-r', '--root DIRECTORY', 'specify root directory') do |root|
+      opts.on(
+        '-r', '--root DIRECTORY',
+        'specify root directory'
+      ) {|root|
         self[:root] = root || Dir.pwd
-      end
+      }
 
-      opts.on('-o', '--output DIRECTORY', 'specify output directory') do |out|
+      opts.on(
+        '-o', '--output DIRECTORY',
+        'specify output directory'
+      ) {|out|
         self[:output] = File.expand_path(out)
-      end
+      }
 
-      opts.on('-e', '--exclude NAMES', 'specify names of files/directories to exclude') do |exclude|
+      opts.on(
+        '-e', '--exclude NAMES',
+        'specify names of files/directories to exclude'
+      ) {|exclude|
         self[:exclude] = Set.new
-        exclude.split(" ").each do |item|
+        exclude.split.each {|item|
           self[:exclude] << item
-        end
-      end
+        }
+      }
 
-      opts.on('-d', '--dry-run', 'perform a dry run') do
+      opts.on(
+        '-d', '--dry-run',
+        'perform a dry run'
+      ) {
         self[:dry_run] = true
-      end
+      }
 
-      opts.on('-f', '--force', 'force writing, ignoring collisions') do
+      opts.on(
+        '-f', '--force',
+        'force writing, ignoring collisions'
+      ) {
         self[:force] = true
-      end
+      }
 
-      opts.on('-v', '--verbose', 'enable verbose output') do
+      opts.on(
+        '-v', '--verbose',
+        'enable verbose output'
+      ) {
         self[:verbose] = true
-      end
+      }
 
-      opts.on_tail('-h', '--help', 'display this help and exit') do
+      opts.on_tail(
+        '-h', '--help',
+        'display this help and exit'
+      ) {
         puts opts
         exit
-      end
-    end
-
+      }
+    }
     opts.parse!(args)
   end
 end
@@ -88,10 +108,10 @@
 # prevent duplicates and trailing slashes
 ARGS=ARGV.collect {|arg| arg.chomp('/')}.uniq
 
-def true_for_all? (filepath, args, &block)
+def true_for_all? (path, args, &block)
   result=true
   ARGS.each {|arch|
-    result=false unless yield(File.join(args[:root], arch), filepath, arch)
+    result=false unless yield(File.join(args[:root], arch, path), arch)
   }
   return result
 end
@@ -99,9 +119,12 @@
 def lipo (filepath,architectures,args)
   lipoargs = Array.new
   architectures.each {|arch|
-    lipoargs << sprintf('-arch %s %s', arch, File.join(
-      args[:root], arch, filepath
-    ))
+    lipoargs << sprintf(
+      '-arch %s %s',
+      arch, File.join(
+        args[:root], arch, filepath
+      )
+    )
   }
   lipotarget=File.join(args[:output], filepath)
   lipocmd = sprintf(
@@ -144,18 +167,18 @@
               :noop => arguments[:dry_run]
             )
           end
-          if true_for_all?(path,arguments) {|dir,filename,arch|
-            !FileTest.symlink?(File.join(dir,filename))
+          if true_for_all?(path,arguments) {|filepath,arch|
+            !FileTest.symlink? filepath
           }
-            if true_for_all?(path, arguments) {|dir,filename,arch|
-              File.exist?(File.join(dir, filename))
+            if true_for_all?(path, arguments) {|filepath,arch|
+              File.exist? filepath
             }
-              if true_for_all?(path, arguments) {|dir,filename,arch|
-                !File.directory?(File.join(dir, filename))
+              if true_for_all?(path, arguments) {|filepath,arch|
+                !File.directory? filepath
               }
-                if true_for_all?(path, arguments) {|dir,filename,arch|
+                if true_for_all?(path, arguments) {|filepath,arch|
                   FileUtils.identical?(
-                    File.join(dir, path),
+                    filepath, 
                     File.join(arguments[:root], ARGS[0], path)
                   )
                 }
@@ -173,22 +196,28 @@
                   case File.basename path
                   # TODO: more cases
                   when /\.h$/, /\.hpp$/
-                    open(File.join(arguments[:output], path), 'w') {|file|
-                      ARGS.each {|arch|
-                        file.printf "#ifdef __%s__\n", arch
-                        file.puts open(File.join(arguments[:root],arch,path), 'r').read
-                        file.puts '#endif'
+                    if !File.exists?(File.join(arguments[:output], path)) or arguments[:force]
+                      open(File.join(arguments[:output], path), 'w') {|file|
+                        ARGS.each {|arch|
+                          file.printf "#ifdef __%s__\n", arch
+                          file.puts open(File.join(arguments[:root],arch,path), 'r').read
+                          file.puts '#endif'
+                        }
                       }
-                    }
+                    end
                   else
-                    file_output = %x{#{FILE} -b "#{File.join(arguments[:root],ARGS[0],path)}"}.chomp
+                    file_output = %x{
+                      #{FILE} -b "#{
+                        File.join(arguments[:root],ARGS[0],path)
+                      }"
+                    }.chomp
                     case file_output
                     when /^current ar archive/
-                      if true_for_all?(path, arguments) {|dir,filename,arch|
-                        %x{#{FILE} -b "#{File.join(dir,path)}"}.chomp =~ /^current ar archive/
+                      if true_for_all?(path, arguments) {|filepath,arch|
+                        %x{#{FILE} -b "#{filepath}"}.chomp =~ /^current ar archive/
                       }
-                        if true_for_all?(path, arguments) {|dir,filename,arch|
-                          %x{lipo -info "#{File.join(dir,path)}"}.chomp =~ /is architecture: #{arch}$/
+                        if true_for_all?(path, arguments) {|filepath,arch|
+                          %x{lipo -info "#{filepath}"}.chomp =~ /is architecture: #{arch}$/
                         }
                           lipo(path,ARGS,arguments)
                         else
@@ -198,11 +227,11 @@
                         # ERROR: mixed filetypes
                       end
                     when /^Mach-O/
-                      if true_for_all?(path, arguments) {|dir,filename,arch|
-                        %x{#{FILE} -b "#{File.join(dir,path)}"}.chomp =~ /^Mach-O/
+                      if true_for_all?(path, arguments) {|filepath,arch|
+                        %x{#{FILE} -b "#{filepath}"}.chomp =~ /^Mach-O/
                       }
-                        if true_for_all?(path, arguments) {|dir,filename,arch|
-                          %x{lipo -info "#{File.join(dir,path)}"}.chomp =~ /is architecture: #{arch}$/
+                        if true_for_all?(path, arguments) {|filepath,arch|
+                          %x{lipo -info "#{filepath}"}.chomp =~ /is architecture: #{arch}$/
                         }
                           links=Hash.new
                           ARGS.each {|my_arch|
@@ -216,28 +245,14 @@
                               depline.lstrip.gsub(
                                 / \(compatibility version \d+(\.\d+)*, current version \d+(\.\d+)*\)/, ''
                               )
+                            }.reject {|dep|
+                              dep =~ /^\/usr\/lib\//
                             }.to_set
                           }
-                          # TODO: should /usr/lib be excluded completely?
-                          # pro: no need for an explicit whitelist(?)
-                          # question: do we care if something was linked
-                          # against /usr/lib/<libncurses,...>?
-                          # if another file was instead linked against
-                          # /opt/local/lib/<...> *that* would show up!
-                          whitelist=%w{
-                            /usr/lib/libgcc_s.1.dylib
-                            /usr/lib/libiconv.2.dylib
-                            /usr/lib/libmx.A.dylib
-                            /usr/lib/libmx.A_debug.dylib
-                            /usr/lib/libmx.A_profile.dylib
-                            /usr/lib/libstdc++.6.dylib
-                            /usr/lib/libSystem.B.dylib
-                            /usr/lib/system/libmathCommon.A.dylib
-                          }
                           ARGS.each {|my_arch|
                             unless links[my_arch] == links[ARGS[0]]
-                              missing_in  = (links[my_arch]-links[ARGS[0]] - whitelist)
-                              missing_out = (links[ARGS[0]]-links[my_arch] - whitelist)
+                              missing_in  = links[my_arch]-links[ARGS[0]]
+                              missing_out = links[ARGS[0]]-links[my_arch]
                               # TODO: come up with a better error message
                               if missing_in.any? or missing_out.any?
                                 raise sprintf(
@@ -259,8 +274,8 @@
                     end
                   end
                 end
-              elsif !true_for_all?(path, arguments) {|dir,filename,arch|
-                File.directory?(File.join(dir, filename))
+              elsif !true_for_all?(path, arguments) {|filepath,arch|
+                File.directory? filepath
               }
                 # TODO: we have a mix of at least one directory and items that
                 # are not directories
@@ -268,12 +283,12 @@
             else
               # TODO: a file is not present in all trees. what's wrong?
             end
-          elsif true_for_all?(path,arguments) {|dir,filename,arch|
-            FileTest.symlink?(File.join(dir,filename))
+          elsif true_for_all?(path,arguments) {|filepath,arch|
+            FileTest.symlink? filepath
           }
             # TODO: dealing with symlinks
           else
-            # TODO: dealing with a mix of at least on symlink and items that
+            # TODO: dealing with a mix of at least one symlink and items that
             # are not symlinks
           end
           processed << path

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


More information about the macports-changes mailing list