{"id":41,"date":"2009-03-15T21:57:11","date_gmt":"2009-03-15T19:57:11","guid":{"rendered":"http:\/\/tom.paschenda.org\/blog\/?p=41"},"modified":"2010-03-09T07:24:06","modified_gmt":"2010-03-09T05:24:06","slug":"deploying-ruby-and-qtruby-applications","status":"publish","type":"post","link":"https:\/\/tom.paschenda.org\/blog\/?p=41","title":{"rendered":"Deploying Ruby (and QtRuby) Applications"},"content":{"rendered":"<p><strong>Important Note<\/strong><br \/>\nThis post is outdated and as David Mullet points out here, <a href=\"http:\/\/ocra.rubyforge.org\/\">ocra<\/a> is the recommended way for deploying Ruby applications on windows.<\/p>\n<p><strong>Disclaimer<\/strong><br \/>\nThis post is about deploying Ruby apps like in &#8220;plain-old-ruby-desktop-apps-where-no-rails-is-involved&#8221; and covers only MS Windows.<\/p>\n<p>\u2014\u2014RANT MODE: ON\u2014\u2013<\/p>\n<p>OK, now you have spent the last few days hacking together your Qt-and-Ruby application. You want to show it to your client to get some feedback on it. So you type: &#8220;Dear Mr. Client, attached to this mail you find &#8230; eh, ahem&#8221; Well, what exactly do you attach to the mail? A howto.txt that describes how to install Ruby and then use the gem command line version to install qt-ruby and whatever other dependencies your application might have? As you already know, there might be tons of problems like: Does your client have admin privileges on his computer? Is he scared to death by a command line? Do you really want to bother your client with such stuff?<br \/>\nNo, &#8220;Ruby means less painful programming.&#8221; they told you. Well they didn&#8217;t say anything about deploying, did they?<\/p>\n<p>\u2014\u2014RANT MODE: OFF\u2014\u2013<\/p>\n<p>Luckily there guys like Erik Veenstra who think that &#8220;Ruby also means less painful deployment&#8221;. Erik wrote two tools:<br \/>\n<a href=\"http:\/\/www.erikveen.dds.nl\/tar2rubyscript\/\" title=\"tar2rubyscript\" target=\"_blank\">tar2rubyscript<\/a><br \/>\nand<br \/>\n<a href=\"http:\/\/www.erikveen.dds.nl\/rubyscript2exe\/\" title=\"rubyscript2exe\" target=\"_blank\">rubyscript2exe<\/a><\/p>\n<p><strong>tar2rubyscript <\/strong>takes a folder full of Ruby files (and subfolders full of Ruby files) and creates one single Ruby script that contains your whole application.<\/p>\n<p><strong>rubyscript2exe <\/strong>takes any ruby script, runs it, analyzes the dependencies and packages everything into one .exe file.<\/p>\n<p>So here is how to deploy a Ruby desktop app. I will not go into much detail, since everything is explained very well in the tutorial on Erik&#8217;s page:<br \/>\n<a href=\"http:\/\/www.erikveen.dds.nl\/distributingrubyapplications\" title=\"rubyscript2exe\" target=\"_blank\">distributingrubyapplications<\/a><\/p>\n<ol>\n<li>Install tar2rubyscript and rubyscript2exe:<br \/>\ngem install tar2rubyscript<br \/>\ngem install rubyscript2exe<\/li>\n<li>Create a file named &#8220;init.rb&#8221; that requires you main application start script and put it in your top-level source code directory. tar2rubyscript will use init.rb to start your application. Mine looks like this:<br \/>\n<code>Dir.chdir oldlocation<\/code><br \/>\n<code>require 'main.rb'<\/code><br \/>\nThe first line switches the directory, since when starting an application that was packed with tar2rubyscript, it will be extracted to a temporary directory and started from there, but you probably want the current directory to be the directory where the user double-clicked the .exe. I have stolen that line from<br \/>\n<a href=\"http:\/\/www.erikveen.dds.nl\/tar2rubyscript\/#3.2.0\" title=\"init.rb\" target=\"_blank\">www.erikveen.dds.nl\/tar2rubyscript\/#3.2.0<\/a><\/li>\n<li> Pack your application into a single ruby script (assuming that &#8216;source&#8217; is a directory containing &#8216;init.rb&#8217; and your application&#8217;s source code)<br \/>\n<code>tar2rubyscript source<\/code><\/li>\n<li> Pack your application into an executable<br \/>\n<code>rubyscript2exe killerapp.rb --rubyscript2exe-verbose<\/code>The parameter <code>--rubyscript2exe-verbose<\/code> will make rubyscript2exe give some information about what it is doing.<\/li>\n<li>You will end up with a file named killerapp.exe. Double clicking it should start your application. On any Windows PC.<\/li>\n<\/ol>\n<p>This is it. Very simple, eh? However, there are some minor issues that I&#8217;d like to mention:<\/p>\n<ol>\n<li> As stated above, rubyscript2exe starts your application to investigate its dependencies. If you have an application that does not quit by itself, rubyscript2exe will not continue unless you quit the application manually. To avoid that, you may add the following line to the appropriate place in your application:<br \/>\n<code>exit if RUBYSCRIPT2EXE.is_compiling?<\/code><br \/>\nKeep in mind, that some dlls do not get loaded by your application unless you really use them so if you use above line, make sure that all dlls that you app depends on have been loaded.<\/li>\n<li> When you double-click killerapp.exe, a DOS-window appears, showing the output of your application. In case of a command line application this is fine. In case of a Windows application you probably don&#8217;t want a DOS-box. Use<br \/>\n<code>rubyscript2exe killerapp.rb --rubyscript2exe-rubyw<\/code><br \/>\nto create an executable that starts without a DOS-box.<br \/>\nHowever, if I switch off the DOS box, my Qt-Ruby application refuses to start.<\/li>\n<li> When your executable gets started, it extracts all dlls, the Ruby runtime and your application to<br \/>\n<code>[Current User's Home]\\eee\\eee.killerapp.exe<\/code> and starts from there. Your application&#8217;s dependencies might include some large dlls (e.g. QtGui4.dll which is 8 MB), so the extraction takes some time and your application startup feels somewhat slow.<br \/>\nIn case of my application, the directory from which the application is running is 36 MB large and even after the application has quit, not everything is deleted and the dlls take up 21 MB of disk space. This is a HDD memory leak!<\/li>\n<\/ol>\n<p>That&#8217;s it for now. As soon as I make progress on the latter two issues, I will update the post accordingly. I you have a hint, I would welcome your comment.<\/p>\n<p>Happy deploying!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Important Note This post is outdated and as David Mullet points out here, ocra is the recommended way for deploying Ruby applications on windows. Disclaimer This post is about deploying Ruby apps like in &#8220;plain-old-ruby-desktop-apps-where-no-rails-is-involved&#8221; and covers only MS Windows. \u2014\u2014RANT MODE: ON\u2014\u2013 OK, now you have spent the last few days hacking together your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-ruby","category-software-development"],"_links":{"self":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":0,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}