26OctCreating launcher scripts for IronRuby

It’s been a while since I blogged, I’ve been terribly busy going through some changes and prepping the book.

Anyway lately a lot of blog posts have been written on how to ironruby with cucumber to test your .NET code. While I think it’s great people are using ironruby and cucumber, the guide you can find on aslak’s github wiki isn’t the most ideal solution as it will  only work for windows and it requires MRI to be installed on your system.  So I thought I’d write up how I’ve been creating launchers that work both on windows .NET and mono systems.

Another problem the approach of setting the GEM_PATH to the MRI gem location is that if your gem requires a C-extension (which could easily be a C# extension in IronRuby) ruby will get confused about which one it’s going to need.

I’m going to use cucumber as an example but this counts for most ruby libraries. I’ve been using this for a few months already so it really doesn’t matter which version of IronRuby you’ve got installed. I’ve compiled a fresh version from github and deployed that to C:\ironruby on windows and added C:\ironruby\bin to my PATH environment variable. I installed my ironruby version on my *nix boxes in /usr/local/ironruby and added /usr/local/ironruby/bin, /usr/local/ironruby/silverlight/bin and /usr/local/ironruby/silverlight/scripts to my PATH environment variable.

1. install the gem: igem install rspec cucumber –no-rdoc –no-ri

this will install the rspec and cucumber gems with their dependencies. And the gems process will actually install the launcher scripts in C:\ironruby\lib\ironruby\gems\1.8\bin and we’re going to use those scripts to create our launcher script

2. Get the launcher scripts into the bin dir

On windows you can now go:

copy C:\ironruby\lib\ironruby\gems\1.8\bin\cucumber C:\ironruby\bin\icucumber
copy C:\ironruby\lib\ironruby\gems\1.8\bin\cucumber.bat C:\ironruby\bin\icucumber.bat

NTFS supports symlinks so you could also use the junction tool from the sysinternals toolkit to create those instead of copying the files. http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

On *nix based systems there is one more step to go through.

cp /usr/local/ironruby/lib/IronRuby/gems/1.8/bin/cucumber /usr/local/ironruby/bin/
mv /usr/local/ironruby/bin/cucumber /usr/local/ironruby/bin/icucumber
cp /usr/local/ironruby/lib/IronRuby/gems/1.8/bin/cucumber /usr/local/ironruby/bin/icucumber
chmod +x /usr/local/ironruby/bin/icucumber

And this is the easier way to properly use installed gems from the ironruby distribution, it will also make it a lot easier to upgrade your gems in 2 different ruby installations at different times etc.


  1. 1 Ryan Riley26 Oct 2009

    Ivan, on *nix, why don’t you just cp directly to /usr/local/ironruby/bin/icucumber since you mv the initial copy?

  2. 2 ivan26 Oct 2009

    No particular reason really. I will edit it out I just wrote it down without thinking much.
    I did copy cucumber* first but then reconsidered against it because a .bat file won’t work anyway.

  3. 3 Michael Heinrich03 Nov 2009

    Hello Ivan,

    I have a question, if I may. When you copied and changed the name of the cucumber file to icucumber under Windows to c:\ironruby\bin and then copied and changed the cucumber.bat to icucumber.bat, did you edit the line in icucumber.bat to point to icucumber in the c:/ironruby/bin/icucumber or did you leave the defaulted “c/ironruby/lib/ironruby/gems/1.8/bin/cucumber”? If you did not change the .bat file, then you did not need to copy the cucumber file and change it to icucumber.

    On another note, do you know of any library for IronRuby to colorize the cucumber output to the console? I get gibberish unless I append “–no-color” to the end of the ‘icucumber features’ statement.

    Thank you!

  4. 4 Michael Heinrich06 Nov 2009

    Hello Ivan,

    Gotta quick question, if I may. Under #2 above, on Windows, you say to “copy C:\ironruby\lib\ironruby\gems\1.8\bin\cucumber.bat C:\ironruby\bin\icucumber.bat”, but you make no mention of editing the .bat file to point to the newly copied “C:/.ironruby/bin/icucumber”. Doesn’t the .bat file still point to “C:/ironruby/lib/ironruby/gems/1.8/bin/cucumber”?

    Also, do you know of a library for IronRuby that will allow the ansi colors come through for use in Cucumber? I can only read my console if I use the –no-color argument.

    Thank you for your hard work and for the book!

    -M

  5. 5 ivan09 Nov 2009

    Sorry I only saw your comment today.
    There is ironterm-ansi-color as a library. It’s still rough around the edges so it might need some tweaking to get right.
    http://github.com/hotgazpacho/iron-term-ansicolor
    With regards to your bat file question. You have to copy both the bat file and the file without an extension on windows. The file without an extension is actually a ruby file. And what happens is. you start execute the batch file which in turn starts up ironruby with the icucumber ruby file (ir icucumer). In that icucumber there is code to load the rubygems library and basically require cucumber which actually starts the cucumber application. So it doesn’t matter where the shebang line points to on windows that doesn’t work anyway.


Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler