Using built-in ruby libraries in packaged applications.
I have a bit of code that uses the Ruby base64 library and I would like to package the MacRuby framework into my application. I've added the "Embed MacRuby" target to my build and the MacRuby framework shows up properly in my application's contents directory. The problem is that when the program launches the call for requiring the base64.rb file causes the runtime to bomb out saying it couldn't find 'base64.rb'. After a bit of hacking I ended up adding this stanza in the rb_main.rb file prior to the loop that requires all the local files: $:.unshift(File.join(NSBundle.mainBundle.privateFrameworksPath, "MacRuby.framework", "Versions", "Current", "usr/lib/ruby/1.9.1")) This seems a little hacky to me. Is there a better way of doing this? Thanks, Alex V. ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
Hi Alex, On Apr 19, 2009, at 9:53 PM, Alex Vollmer wrote:
I have a bit of code that uses the Ruby base64 library and I would like to package the MacRuby framework into my application. I've added the "Embed MacRuby" target to my build and the MacRuby framework shows up properly in my application's contents directory. The problem is that when the program launches the call for requiring the base64.rb file causes the runtime to bomb out saying it couldn't find 'base64.rb'. After a bit of hacking I ended up adding this stanza in the rb_main.rb file prior to the loop that requires all the local files:
$:.unshift(File.join(NSBundle.mainBundle.privateFrameworksPath, "MacRuby.framework", "Versions", "Current", "usr/lib/ruby/1.9.1"))
This seems a little hacky to me. Is there a better way of doing this?
This is the right way to do it. The "Embed MacRuby" target configures the linking settings of your app but you still need to hack the load path in rb_main.rb to point it to the MacRuby stdlib. Here is another way: $:.map! { |x| x.sub(/^\/Library\/Frameworks/, NSBundle.mainBundle.privateFrameworksPath) } $:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation I wasn't able to perform this change automatically during the target build. Maybe we could ship a new rb_main.rb in the template that does this change based on a heuristic... if you have any idea let me know. Laurent
On Apr 20, 2009, at Apr 20, 1:32 PM, Laurent Sansonetti wrote:
This is the right way to do it. The "Embed MacRuby" target configures the linking settings of your app but you still need to hack the load path in rb_main.rb to point it to the MacRuby stdlib.
Here is another way:
$:.map! { |x| x.sub(/^\/Library\/Frameworks/, NSBundle.mainBundle.privateFrameworksPath) } $:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation
I wasn't able to perform this change automatically during the target build. Maybe we could ship a new rb_main.rb in the template that does this change based on a heuristic... if you have any idea let me know.
Thanks for the response Laurent. I wonder if there wouldn't be some way to have the "Embed MacRuby" target generate an additional file that would modify the load path in that way. Then it could just be an additional ruby file that gets automatically required by the default rb_main.rb. There would obviously be a problem of ensuring the load- order so we could always do it with a conditional require. Hmmm...maybe that's kind of hacky too. :-P Cheers, Alex ---- Musings & Notes http://blog.livollmers.net
That is actually a pretty good idea, the default rb_main.rb could require an extra file if it exists in the resource directory, and the target would generate it. If anyone wants to contribute a patch I would commit it :-) Laurent Sent from my iPhone On Apr 20, 2009, at 4:37 PM, Alex Vollmer <alex.vollmer@gmail.com> wrote:
On Apr 20, 2009, at Apr 20, 1:32 PM, Laurent Sansonetti wrote:
This is the right way to do it. The "Embed MacRuby" target configures the linking settings of your app but you still need to hack the load path in rb_main.rb to point it to the MacRuby stdlib.
Here is another way:
$:.map! { |x| x.sub(/^\/Library\/Frameworks/, NSBundle.mainBundle.privateFrameworksPath) } $:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation
I wasn't able to perform this change automatically during the target build. Maybe we could ship a new rb_main.rb in the template that does this change based on a heuristic... if you have any idea let me know.
Thanks for the response Laurent. I wonder if there wouldn't be some way to have the "Embed MacRuby" target generate an additional file that would modify the load path in that way. Then it could just be an additional ruby file that gets automatically required by the default rb_main.rb. There would obviously be a problem of ensuring the load-order so we could always do it with a conditional require. Hmmm...maybe that's kind of hacky too. :-P
Cheers,
Alex
---- Musings & Notes http://blog.livollmers.net
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Apr 20, 2009, at Apr 20, 5:51 PM, Laurent Sansonetti wrote:
That is actually a pretty good idea, the default rb_main.rb could require an extra file if it exists in the resource directory, and the target would generate it.
If anyone wants to contribute a patch I would commit it :-)
Cool! I'll clone the git repo and see if I can formulate a fix. Just send the patch to the mailing list? Cheers, Alex ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
participants (2)
-
Alex Vollmer
-
Laurent Sansonetti