MacRuby Deployment + Load Order
Categories: Uncategorized
After reading the official MacRuby docs on deployment, I read over this guide. Although the deployment build seemed to be working fine on my local machine when I dropped it on my laptop with a standard Lion install it crashed, claiming that there was an defined constant – but that constant was a class. How could it be undefined if it ran fine locally?
Looking into it a bit more the class that was undefined was being used as a superclass for another ruby class. Taking a look at rb_main.rb revealed that there is no specific load order. Since the load order was undefined, the class requiring the other ruby class as a superclass was being loaded before the superclass was loaded. I ended up tweaking the rb_main.rb file to allow for a manual load order, followed by the standard automatic load.
[code lang=”ruby”]
# Loading the Cocoa framework. If you need to load more frameworks, you can
# do that here too.
framework ‘Cocoa’
# Loading all the Ruby project files.
# manual load allows up to specify the load order for some of the classes
manualLoad = [“VTiTunesHeader”]
for file in manualLoad
require file
end
manualLoad < < File.basename(__FILE__, File.extname(__FILE__))
# Auto load the direct of the files in the dir
dir_path = NSBundle.mainBundle.resourcePath
Dir.glob(File.join(dir_path, ‘*.{rb,rbo}’)).map { |x| File.basename(x, File.extname(x)) }.uniq.each do |path|
if not manualLoad.include? path
require(path)
end
end
# Starting the Cocoa main loop.
NSApplicationMain(0, nil)
[/code]
You can grab the gist here.
Cocoa Resources
Some Cocoa libraries / snippet repos that I found during my latest dev session.
- jrc’s Cocoa Snippets
- JSON Kit – awesome objc JSON library
- Cocoa Objects – useful index of pluggable Cocoa code
- AQToolkit – great collection of useful pluggable categories / classes. Contains useful NSFileManager category for managing temporary files.
- NSString category for generating a query string from a NSDictionary
- ASIHTTPRequest – comprehensive HTTP request library
Random Tidbits
- Although old news to most, you can grab the the last n bytes of a file using tail -c. Very useful for cutting down on the size of large text log files.
- I pulled the build versioning code out from a project I was working on. Take a look at this build numbering gist, provides source to pull version number from git or svn and write it in your Info.plist
- The Ruby logging class is more robust than the Log4r class and the built in logger class.
- attr_accessor :variable makes a instance variable Key Value Coding compliant. Just set @variable in your initializer.
- Awesome side-by-side reference sheet for PHP, Ruby, Perl, and Python. Handy reference to python to ruby conversion.
- Obj-c blocks in MacRuby
- Although you can `macgem install json`, macruby comes with a json library built in that seems to have tweaks for deployment. Don’t install the json gem
- The Open3 Ruby library does not return subprocess status correctly when using MacRuby
- Online version of “MacRuby: The Definitive Guide”
- PyObjc on Lion is dead. Although you might get an application to run, there are so many bugs it really isn’t usable for production
- Although macrubyd exists, it doesn’t seem to work with full-fledged Cocoa + MacRuby apps. There isn’t any Xcode integration. Ruby-Debug also doesn’t seem to be compatible with MacRuby. Bottom line: no strong debugging tools for MacRuby… yet.
- The “throw your dotfiles on github” trend has been an interested learning experience for me