[26522] users/pipping/merge.rb

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 27 11:28:46 PDT 2007


Revision: 26522
          http://trac.macosforge.org/projects/macports/changeset/26522
Author:   pipping at macports.org
Date:     2007-06-27 11:28:46 -0700 (Wed, 27 Jun 2007)

Log Message:
-----------
== new filetype recognition ==
don't check for .dylib/.so/.a extension (easy to detect via file/lipo)
do check for .h/.hpp (hard to detect via file)
== check linking ==
use otool(64) -LX to find differences that matter (whitelist for exceptions)

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

Modified: users/pipping/merge.rb
===================================================================
--- users/pipping/merge.rb	2007-06-27 16:35:33 UTC (rev 26521)
+++ users/pipping/merge.rb	2007-06-27 18:28:46 UTC (rev 26522)
@@ -89,7 +89,8 @@
 
 arguments = MergeArguments.new(ARGV)
 
-ARGS=ARGV.uniq
+# prevent duplicates and trailing backslashes
+ARGS=ARGV.collect {|arg| arg.chomp('/')}.uniq
 
 def true_for_all? (filepath, args, &block)
   result=true
@@ -173,31 +174,62 @@
                     )
                   end
                 else
-                  # TODO: make this non-blindly lipo but check filetypes / archs
-                  # TODO: beware of symlinks!
                   case File.basename path
-                  when /\.dylib(\.\d*)*/, /\.so(\.\d*)*/, /\.a$/
-                    lipo(path,ARGS,arguments)
-                # when /\.h$/, /\.hpp$/
-                #   # TODO: handle header files
-                # when /\.pc$/
-                #   # TODO: handle pkgconfig files
-                # when /\.sh$/
-                #   # TODO: handle shell scripts
+                  # TODO: more cases
+                  when /\.h$/, /\.hpp$/
+                    # TODO: deal with header file
                   else
-                    case %x{#{FILE} -b "#{File.join(arguments[:root],ARGS[0],path)}"}
-                    when sprintf("Mach-O executable %s\n", ARGS[0])
+                    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)}"} == sprintf("Mach-O executable %s\n", arch)
+                        %x{#{FILE} -b "#{File.join(dir,path)}"}.chomp =~ /^current ar archive/
                       }
-                        lipo(path,ARGS,arguments)
+                        if true_for_all?(path, arguments) {|dir,filename,arch|
+                          %x{lipo -info "#{File.join(dir,path)}"}.chomp =~ /is architecture: #{arch}$/
+                        }
+                          lipo(path,ARGS,arguments)
+                        else
+                          # ERROR: processing universal binary or wrong arch
+                        end
                       else
-                        # one of the files is a mach-o file that matches its
-                        # desired architecture but one of the others doesn't
+                        # 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) {|dir,filename,arch|
+                          %x{lipo -info "#{File.join(dir,path)}"}.chomp =~ /is architecture: #{arch}$/
+                        }
+                          links=Hash.new
+                          ARGS.each {|my_arch|
+                            links[my_arch]=%x{#{'otool'} -arch #{my_arch} -LX #{File.join(arguments[:root],my_arch,path)}}.split("\n").collect {|x| x.lstrip}.to_set
+                          }
+                          # TODO: dummy whitelist only! (64bit needs to be tested here)
+                          whitelist=%w{/usr/lib/libSystem.B.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)
+                              # TODO: come up with a better error message
+                              if missing_in.any? or missing_out.any?
+                                raise sprintf(
+                                  'difference in linking, file %s', path
+                                )
+                              end
+                            end
+                          }
+                          lipo(path,ARGS,arguments)
+                        else
+                          # ERROR: processing universal binary or wrong arch
+                        end
+                      else
+                        # ERROR: mixed filetypes
+                      end
+                    # TODO: handle more filetypes
                     else
-                      printf "file not handled: %s\n", path
-                      # TODO: deal with whatever else can differ
+                      puts "dunno type: #{path}"
                     end
                   end
                 end

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


More information about the macports-changes mailing list