Thursday 4 December 2008

Running IRake

This post will show you how to setup and run irake and feel incredible power of great tool written in great language that runs in great framework.

NOTE: in this post I assume all paths are correct and you can write 'rake' instead of 'd:/ruby/bin/rake'.

First, download IronRuby alpha 2. Unpack and have a look what we have. In /bin folder we have some executables, including iirb and irake. We're actually interested in second one. Let's create a simple task to try it!

task :default do
print 'rake is up and running!'
end

Let's try how it works with simple rake:

>rake

rake is up and running!

Cool. Let's try irake:

>irake

unknown: Could not find RubyGem rake (>= 0)
(Gem::LoadError)

Ok. Let's install it. As we are using irake we should use igem.

>igem install --remote rake


ERROR: While executing gem ... (System::IO::DirectoryNotFoundException)
Could not find a part of the path 'D:\External\languages\ruby\ruby-1.8.6\lib\ironruby\gems\1.8\gems\rake-0.8.3\bin\rake'.

That's the trickiest part of all. This path is not configurable (at least I could not find it), so we'll have to place ruby just where program expects it to find. What is interesting, this folder is already created. We'll install ruby 1.8.6 and copy it to this tricky folder ("D:\External\languages\ruby\ruby-1.8.6").

After that, let's try to install rake once again.

>igem install --remote rake


ERROR: While executing gem ... (System::IO::DirectoryNotFoundException)
Could not find a part of the path 'D:\External\languages\ruby\ruby-1.8.6\lib\ironruby\gems\1.8\gems\rake-0.8.3\bin\rake'.

Argh! What's wrong now? Let's check the path once again. Oops, 'rake-0.8.3' folder contains no 'bin' folder but only the following files:

CHANGES
install.rb
MIT-LICENSE
Rakefile
README
TODO

So this means rake is actually not installed even in native ruby. Let's do it.

>gem install --remote rake


Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rake-0.8.3
Installing ri documentation for rake-0.8.3...
Installing RDoc documentation for rake-0.8.3...

Ok, fine. Copy installed rake folder to ':\External\languages\ruby\ruby-1.8.6\lib\ironruby\gems\1.8\gems\rake-0.8.3\'. Going back to igem...

>igem install --remote rake


Successfully installed rake-0.8.3
1 gem installed
Installing ri documentation for rake-0.8.3...
Installing RDoc documentation for rake-0.8.3...
Error in template: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index
Original line: <td>%dtm_modified%</td>

Even some error can't upset us seeing line 'Successfully installed rake-0.8.3' =) So let's try irake in action:

>irake


(in D:/information/projects/ironruby)
rake is up and running!

Wonderful :) Irake is up and running. The last thing to do is to is to show that irake is not rake and can work with standard .NET library. Let's modify our rake task to use some .NET code:

task :default do
require 'mscorlib'

require 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
print System::Guid.NewGuid().ToString()
end

Making sure this task doesn't work in standard rake:

>rake


rake aborted!
no such file to load -- mscorlib

And, finally:

>irake


df2869e8-6b24-49d4-8915-424028b9871e

Conclusion:
We've installed irake, configured it to work and wrote a small task that works in it but not in standard rake. Later on I'll try to port some compilation tasks to irake and switch to it from nant in my projects.

Note:
For now, irake call is MUCH slower, than rake call. Hope later on IronRuby guys will speed it up.



kick it on DotNetKicks.com

1 comment:

Maxild said...

Hi,

I managed to use irake by setting the GEM_PATH environment variable to the folder 'MRI\lib\ruby\gems\1.8', where MRI is where I installed the C-based Matz Ruby Interpreter (c:\Ruby in my case).

I also managed to play a bit with some simple ruby in a Rakefile, and .NET interop. But when I tried to run the Rakefile I use for automated builds it choked. I also tried building/running from trunk, but at HEAD (=r179) ir.exe couldn't load rake.rb at all, so I returned to r175; that revisison equals the ironruby_10_alpha_2 release. Also I found IronRuby way slower than running 'rake.rb' on the c-based interpreter of Ruby.

All in all IronRuby is too 'alpha' right now to use for anything real, but I love that MS is working on bringing Ruby to the .NET community, and how they are doing it:-)