# New Ruby developer Rake questions

**URL:** <https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941>\
**Category:** Ruby\
**Created:** [February 12, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941 "2008-02-12T21:22:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wannabe-coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@wannabe-coder](https://www.ruby-forum.com/u/wannabe-coder)\
**Post date:** [February 12, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941/1 "2008-02-12T21:22:55Z")

</div>

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:

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.

1. 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?

Thanks in advance,  
Joe

---

<div class="post-metadata">

**Author:** ![wannabe-coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@wannabe-coder](https://www.ruby-forum.com/u/wannabe-coder)\
**Post date:** [February 13, 2008, 12:22am UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941/2 "2008-02-13T00:22:05Z")

</div>

I’ve done a similar thing with a current .NET project i’m working on.  
Instead of having child rakefiles, i just have the one at the project  
root.  
If you want to build a child project, you can just specify the childs  
project file.

# if a project file is not specified, it searches the current directory

for  
a proj file and uses that, i.e. from your root directory  
task :build\_all do  
sh #{DOT\_NET\_PATH}msbuild.exe /p:Configuration=Release  
end

# to build a child project just specify its project file in a

subdirectory  
task :build\_child\_proj do  
sh #{DOT\_NET\_PATH}msbuild.exe ChildProj1/Child.csproj  
/p:Configuration=Release  
end

Or are you after something more complex than that?

Ta

---

<div class="post-metadata">

**Author:** ![wannabe-coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@wannabe-coder](https://www.ruby-forum.com/u/wannabe-coder)\
**Post date:** [February 13, 2008, 1:39am UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941/3 "2008-02-13T01:39:01Z")

</div>

Thanks for the suggestion. I had not considered that. I also should  
have been a little more explicit about the .NET stuff. Each child  
project really represents one or more solutions. And in addition to the  
solution build itself, I want to be able to create databases, run unit  
tests, create deployment files, etc, so yes the child rakefiles are more  
than just a call to msbuild.

I’d also like the individual child projects to have a build independent  
of the root build which is why I was attempting something like I’ve  
described. I could likely take the approach you’ve described and put  
everything in one root build file, but I still think I’d prefer to have  
separate independent rakefiles if I can work it out.

---

<div class="post-metadata">

**Author:** ![wannabe-coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@wannabe-coder](https://www.ruby-forum.com/u/wannabe-coder)\
**Post date:** [February 13, 2008, 9:43am UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941/4 "2008-02-13T09:43:38Z")

</div>

On 12 Feb 2008, at 20:22, Joe Wirtley wrote:

> Child Project 1  
> 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’

> 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.

---

<div class="post-metadata">

**Author:** ![wannabe-coder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@wannabe-coder](https://www.ruby-forum.com/u/wannabe-coder)\
**Post date:** [February 14, 2008, 1:44am UTC](https://www.ruby-forum.com/t/new-ruby-developer-rake-questions/128941/5 "2008-02-14T01:44:22Z")

</div>

Thanks for the suggestion. I’m having trouble making this work. I’ve  
created a couple test scripts to illustrate. In the Raketest folder, I  
have the following Rakefile.rb script:

task :default do  
sh “cd Child;rake”  
end

The Child folder under this has the following Rakefile.rb:

task :default do  
puts “Child Rake Default task”  
end

The following shows the result of running rake first in the child  
folder, then in the Raketest folder:

C:\Raketest\Child\>rake  
(in C:/Raketest/Child)  
Child Rake Default task

C:\Raketest\Child\>cd …

C:\Raketest\>rake  
cd Child;rake  
(in C:/Raketest)  
The system cannot find the path specified.  
rake aborted!  
Command failed with status (1): [cd Child;rake…]  
C:/Raketest/rakefile.rb:2  
(See full trace by running task with --trace)

When I run rake in the child folder, it works. When I run rake in the  
Raketest folder, I get the “The system cannot find the path specified.”  
message. So what am I missing?

Just for good measure, I uninstalled all versions of Rake (via gem) then  
installed the latest version, which didn’t change anything.

I’ve attached my zipped contrived sample. I’d appreciate any help.

Dave B. wrote:

> On 12 Feb 2008, at 20:22, Joe Wirtley wrote:
> 
> > Child Project 1  
> > 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’
> 
> > 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.
