New Ruby developer Rake questions

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.

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?

Thanks in advance,
Joe

···

--
Posted via http://www.ruby-forum.com/.

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

···

On Feb 13, 2008 6:52 AM, Joe Wirtley <joew@wirtley.com> 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.

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?

Thanks in advance,
Joe
--
Posted via http://www.ruby-forum.com/\.

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.

···

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

Thanks in advance,
Joe
--
Posted via http://www.ruby-forum.com/\.

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.

···

--
Posted via http://www.ruby-forum.com/.

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

Attachments:
http://www.ruby-forum.com/attachment/1430/Raketest.zip

--
Posted via http://www.ruby-forum.com/\.