From: Dave Baldwin Date: 2008-02-13T17:42:58+09:00 Subject: Re: New Ruby developer Rake questions On 12 Feb 2008, at 20:22, Joe Wirtley wrote: > I am relatively new to Ruby and I am trying to introduce Rake to build > my .NET system. I have a series of related projects that I'd like to > build either separately or together. Conceptually, I have the > following > structure: > > Root > Rakefile > Supporting ruby files > > Child Project 1 > Rakefile > > Child Project 2 > Rakefile > > I want to be able to build each child project separately, or the > entire > tree with the root rakefile. I have two questions: > > 1. I have supporting ruby files (defining tasks) in the root folder > that > I want to be referenced from the child project rakefiles. I'm not > thrilled about something like: > > require '..\..\Support.rb' > > but it does seem to work. What is the "best" way to handle this? I > would rather that the scripts work on any machine with the same > relative > directory structures. > Not sure why you don't like this. An alternative would be to change your load path variable: $:.unshift '..\..' require 'Support' > 2. What is the best way to handle these "nested" rakefiles? > > I've tried something like this to include the child rakefiles in the > root rakefile: > > namespace "child_project1" do > require 'ChildProject1\rakefile.rb' > end > > task :default => [ "child_project1:default" ] > > The problem I have with this approach is in the child rakefiles. I > specify relative paths to files within the child rakefiles, which > works > great when I run the child rakefile within its own folder. However, > when I require it from a parent rakefile, the relative paths don't > work > out. I've tried to leverage the __FILE__ variable to identify files > relative to the rakefile, but cannot make it work successfully > (mostly I > can't make it work elegantly, which makes me think there some Ruby > magic > I don't know). So what's the best way to approach this? > I often do something along the lines of: sh "cd childDir; rake -f ../../Rakefile build" in the top level Rakefile which will change to the child directory and then run a fresh ruby and rake session. Dave. > Thanks in advance, > Joe > -- > Posted via http://www.ruby-forum.com/. >