<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[26522] users/pipping/merge.rb</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/macports/changeset/26522">26522</a></dd>
<dt>Author</dt> <dd>pipping@macports.org</dd>
<dt>Date</dt> <dd>2007-06-27 11:28:46 -0700 (Wed, 27 Jun 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre>== 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)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#userspippingmergerb">users/pipping/merge.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="userspippingmergerb"></a>
<div class="modfile"><h4>Modified: users/pipping/merge.rb (26521 => 26522)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -89,7 +89,8 @@
</span><span class="cx">
</span><span class="cx"> arguments = MergeArguments.new(ARGV)
</span><span class="cx">
</span><del>-ARGS=ARGV.uniq
</del><ins>+# prevent duplicates and trailing backslashes
+ARGS=ARGV.collect {|arg| arg.chomp('/')}.uniq
</ins><span class="cx">
</span><span class="cx"> def true_for_all? (filepath, args, &block)
</span><span class="cx"> result=true
</span><span class="lines">@@ -173,31 +174,62 @@
</span><span class="cx"> )
</span><span class="cx"> end
</span><span class="cx"> else
</span><del>- # TODO: make this non-blindly lipo but check filetypes / archs
- # TODO: beware of symlinks!
</del><span class="cx"> case File.basename path
</span><del>- 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
</del><ins>+ # TODO: more cases
+ when /\.h$/, /\.hpp$/
+ # TODO: deal with header file
</ins><span class="cx"> else
</span><del>- case %x{#{FILE} -b "#{File.join(arguments[:root],ARGS[0],path)}"}
- when sprintf("Mach-O executable %s\n", ARGS[0])
</del><ins>+ file_output = %x{#{FILE} -b "#{File.join(arguments[:root],ARGS[0],path)}"}.chomp
+ case file_output
+ when /^current ar archive/
</ins><span class="cx"> if true_for_all?(path, arguments) {|dir,filename,arch|
</span><del>- %x{#{FILE} -b "#{File.join(dir,path)}"} == sprintf("Mach-O executable %s\n", arch)
</del><ins>+ %x{#{FILE} -b "#{File.join(dir,path)}"}.chomp =~ /^current ar archive/
</ins><span class="cx"> }
</span><del>- lipo(path,ARGS,arguments)
</del><ins>+ 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
</ins><span class="cx"> else
</span><del>- # one of the files is a mach-o file that matches its
- # desired architecture but one of the others doesn't
</del><ins>+ # ERROR: mixed filetypes
</ins><span class="cx"> end
</span><ins>+ 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
</ins><span class="cx"> else
</span><del>- printf "file not handled: %s\n", path
- # TODO: deal with whatever else can differ
</del><ins>+ puts "dunno type: #{path}"
</ins><span class="cx"> end
</span><span class="cx"> end
</span><span class="cx"> end
</span></span></pre>
</div>
</div>
</body>
</html>