?

Log in

No account? Create an account
Recent Entries Friends Archive Profile Tags My wildlife photography
 
 
 
 
 
 
I'm only vaguely aware of Perl, sad to say, though I'm finally getting around to picking up bits and pieces. So, this script has me a little puzzled. Any Perl guru feel like offering a smidgen of assistance?


file, as you may know, offers up information about what kind of file a particular file actually is. In this case, the output from file is:

/Users/porsupah/Development/ iPhone/Cocoa is my Girlfriend - First App demo/Basic iPhone App/build/Debug-iphoneos/Basic iPhone App.app/Basic iPhone App: Mach-O executable arm


(Cocoa is my Girlfriend being the name of the site which offered up this handy starter tutorial for iPhone development)

The script, by one Tiku, gained from a thread on Apple's discussion boards:

#!/usr/bin/perl
#
$appDir=$ARGV[$#ARGV];
@tmpAry=split(/\//,$appDir);
$baseAppName=$tmpAry[$#tmpAry];
$baseAppName=~s/\.app$//;
$realAppName="$appDir"."/$baseAppName";

$sign=0;
for($b=0;$b<$#ARGV;$b++) {
if($ARGV[$b] eq "-s") {
$sign=1;
}
}

$mums=`/usr/bin/file $realAppName`;
if($sign==1) {
print "codesign debug: we are attempting to sign a file.\n";
}
if($mums=~/executable arm/) {
print "codesign debug: verified the file is an ARM executable.\n";
}
if(($sign==1) && ($mums=~/executable arm/)) {
print "Signing armv6 new style..\n";
$dev="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/";
$tmp="$appDir"."/tmpbin";
`$dev/lipo -create $realAppName -output $tmp`;
`mv $tmp $realAppName`;
system("/usr/bin/codesign.orig",@ARGV);
`$dev/lipo -thin armv6 $realAppName -output $tmp`;
`mv $tmp $realAppName`;
system("rm $appDir"."/CodeResources");
system("cp $appDir"."/_CodeSignature/CodeResources $appDir"."/CodeResources");
exit 0;
} else {
print "Signing armv6 old style..\n";
exec '/usr/bin/codesign.orig',@ARGV;
}


So, the problem at paw: the hack is carried out if both conditions are true - we're passing the -s option in, and the file we want to sign is an ARM executable. I see the first debug output, noting the -s flag, but not the second. Why? Certainly, the output given should match the condition specified, executable arm, so is $mums not being assigned correctly?
 
 
 
 
 
 
Could it be that you're passing in the wrong argument? It reads as though it's expecting the path to the app bundle folder, not the actual executable. i.e., it wants

sign.pl -s "/Users/porsupah/MyGreatApp.app"

and NOT

sign.pl -s "/Users/porsupah/MyGreatApp.app/MyGreatApp"

All that $realAppName business up at the top is fragile.
That does seem to be what Xcode's passing in, elided for clarity:

/usr/bin/codesign -f -s "iPhone Developer" "--resource-rules=blarg/Debug-iphoneos/Basic iPhone App.app/ResourceRules.plist" --entitlements "blarg/Debug-iphoneos/Basic iPhone App.build/Basic iPhone App.xcent" "blarg/Debug-iphoneos/Basic iPhone App.app"

realAppName winds up becoming the full path to the executable within the bundle.



See comments. Sorry, textarea isn't too pretty. But it preserves whitespace, which makes the code prettier (wtf LJ? No pre tag anymore!?)

Edited at 2008-10-19 09:31 am (UTC)
Nope. ^_^; Is $mums getting set correctly? What would you expect to see from:

$mums=`/usr/bin/file $realAppName`; #runs the file command with the $realAppName argument.
print "debug: sign = $sign\n";
print "debug: mums = $mums\n";

..? To me, it feels like it should be:

debug: sign = 1
debug: mums = /Users/porsupah/Development/ iPhone/Cocoa is my Girlfriend - First App demo/Basic iPhone App/build/Debug-iphoneos/Basic iPhone App.app/Basic iPhone App: Mach-O executable arm

When in fact, I see:

debug: sign = 1
debug: mums = /Users/porsupah/Development/: directory
iPhone/Cocoa: cannot open `iPhone/Cocoa' (No such file or directory)
is: cannot open `is' (No such file or directory)
my: cannot open `my' (No such file or directory)
Girlfriend: cannot open `Girlfriend' (No such file or directory)
/dev/stdin: empty
First: cannot open `First' (No such file or directory)
App: cannot open `App' (No such file or directory)
demo/Basic: cannot open `demo/Basic' (No such file or directory)
iPhone: cannot open `iPhone' (No such file or directory)
App/build/Debug-iphoneos/Basic: cannot open `App/build/Debug-iphoneos/Basic' (No such file or directory)
iPhone: cannot open `iPhone' (No such file or directory)
App: cannot open `App' (No such file or directory)

codesign debug: we are attempting to sign a file.
Signing armv6 old style..
/Users/porsupah/Development/ iPhone/Cocoa is my Girlfriend - First App demo/Basic iPhone App/build/Debug-iphoneos/Basic iPhone App.app: object file format invalid or unsuitable

And LJ got rid of the pre tag? Curious! Wonder why..

Aha! The spaces in the filename aren't being escaped, so file thinks it's getting multiple filename arguments instead of one argument with spaces in it, and $mums is garbage. The solution appears to be $mums=`/usr/bin/file "$realAppName"`; (note double quotes).

; perl

$wolves="Lives of the Wolves";
$foo=`ls -l $wolves`;
print $foo;

^d
ls: Lives: No such file or directory
ls: of: No such file or directory
ls: the: No such file or directory
ls: Wolves: No such file or directory

; perl

$wolves="Lives of the Wolves";
$foo=`ls -l "$wolves"`;
print $foo;

^d
-rw-r--r--  1 jkl users 1239 2008-10-05 23:32 Lives of the Wolves
W00T!

So that's how you do it in Perl? Wonderful! Applying similar escaping elsewhere, so lipo, codesign, and friends were also handed the correctly spaced edition of the pathname and application name, results in:



Thank you very much. ^_^

Woo!

Beginner's luck, perhaps—I don't actually know Perl very well either, but the quoting rule above is exactly how bash does it, and given Perl's principle of familiarity it seemed a reasonable guess that it would work the same way. A little playing verified that indeed it does. Quite welcome, nonetheless.

That's a pretty result, too. ^_^
True, it does lead on from the usual shell ways of doing things - I suppose I really should've just tried and seen what blew up, or failed to. ^_^ All a bit daft that this is even necessary, of course, but so it goes - the decision was made, for whatever reason, to support only Intel Macs for iPhone development, yet all the tools are fat binaries nonetheless. So us lucky PPC folk get to navigate a few hoops along the way. ^_^;

It still seems so damn neat, having that little app appear like any other from the Store, sitting on the front page (now up to the last few slots of my seventh page of apps.. most of them free, given the constant churn in developers trying to gauge the right price points, and gain free publicity with sales and giveaways). It doesn't do much, but this is the starting point for me to finally get properly into Objective C - which looks rather nice, actually - as well as CoreAnimation and the like, much of which knowledge can be hauled over to OS X proper.

Hiragana's such a cute character set. ^_^ (Reminds me, I need to see what, if any, well-regarded OS X courses there are for learning Japanese, or even simply online)

looks like the spaces aren't being escaped when you call /usr/bin/file. Add
$realAppName=~s/ /\ /; before $mums=`/usr/bin/file $realAppName`; ?

Also there appears to be a space before iPhone? "/Users/porsupah/Development/ iPhone/" Expected behavior..?

(Oh, any recommended iPhone dev. resources? SGN (current employer) has expanded into the iPhone domain, and while our palo alto location isn't involved in creating them, it is something I want to look into.. especially because there are plans to create some sort of fluff friends for the iPhone...)

[edit] Ah, yep, question was answered already.

Edited at 2008-10-19 08:19 pm (UTC)
Yep, " iPhone" is the name of the top-level directory in my Development folder, so it sorts to the top. And causes all sorts of problems for utilities that aren't expecting spaces anywhere in a pathname. =:)

Damn, it's good to see code I compiled running on the actual device. ^_^

Anyway - one very good place is Apple's own iPhone Dev Center, which has a good number of helpful videos and tutorials. There's a very professional introductory video over here, in Getting Started with Xcode and Interface Builder, as a teaser for the rest of the paid series ($25). And Apps Amuck is running 31 Days of iPhone Development, with a simple app explained and downloadable each day of October.

I also see O'Reilly's got some stuff up, looking at 3D Transformations on iPhone with Core Animation, and ISTR there's more up on Google Code, including the source for the rather fun Pocket Guitar. It's 99¢ on the App Store, which seems like a perfectly reasonable tip for the work the guy's put in.

Do you have an iPhone yourself? (You may well have mentioned it)

And thanks for the assistance anyhow. ^_^