Launch directory in Rake

J

Jim Freeze

Hi

I have a directory of projects and in the directory above that, I
would like to put a Rakefile that manages tasks on those projects.=20
The problem is that I cannot obtain the directory from with rake is
run.

What I want is the following:

projects/
Rakefile
commandline/
pkg/
commandline.gem
quiz42/
project_xyz.../

cd commandline
rake gem

Inside the gem file is a task:

task :gem do
sh "gem build pkg/*gem"
end

The problem is that the pwd is 'projects/=10', not 'projects/commandline'.
Also, I cannot tell that there is a way to know that the
rake command was run from 'projects/commandline'.

If a way exists, I would be happy to hear about it. If not, can we
add a @launch_dir (or @run_dir) to #load_rakefile?

Thanks

--=20
Jim Freeze
 
J

Jim Freeze

The problem is that I cannot obtain the directory from with rake is
---------------------------------------------------------------------------=
------^^^^
=20
which
Inside the gem file is a task: ------------------^^^^
rakefile
=20
task :gem do
sh "gem build pkg/*gem"
end

--=20
Jim Freeze
 
J

Jim Freeze

Thanks Jim

I'm really surprised this has not already been requested.

=20
Reasonable request. Committed to CVS. Use Rake.original_dir to get the
original directory.
=20
If you are impatient, a beta is available at http://onestepback.org/betag= ems.
=20
--
-- Jim Weirich (e-mail address removed) http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
=20
=20


--=20
Jim Freeze
 
J

Jim Menard

Thanks Jim
=20
I'm really surprised this has not already been requested.

I'm not. If I'm not mistaken, Make and Ant both assume that you are
running the makefile/Ant build file from the directory in which the
file exists. All path names are relative to that file, not to the file
in which you happen to be running the script.

I always write my {rm}akefiles and build.xml files so that everything
happens relative to the top-level directory where the file lives.

Jim
--=20
Jim Menard, (e-mail address removed), (e-mail address removed)
http://www.io.com/~jimm
 
J

Jim Weirich

Jim Menard said:
I'm not. If I'm not mistaken, Make and Ant both assume that you are
running the makefile/Ant build file from the directory in which the
file exists. All path names are relative to that file, not to the file
in which you happen to be running the script.

Make (and I believe Ant) will not change the current directory to the
build file directory when doing a build. Since (by default) both program=
s
look for a build file in the current directory, there is rarely a
difference between the two. However, you can override this default
behavior with a -f flag, in which case make runs in your current director=
y
with a Makefile (possibly) in a different directory.

Rake works differently in this regard. It will search up the directory
tree for a Rakefile if it does not find one locally (inspired by ant's
-find flag). This allows you to fire off rake from anywhere in the
project source tree and have it do the right thing. And since Rake aways
cd's to the location of the Rakefile, you just write your build tasks
assuming that. It makes everything very easy.

However, Jim Freeze *wanted* location specific behavior. (Are there too
many Jims in this conversation?).
I always write my {rm}akefiles and build.xml files so that everything
happens relative to the top-level directory where the file lives.

Yes, the difference is that make/ant require you to cd into that top leve=
l
directory before running. Rake does not.

--=20
-- Jim Weirich (e-mail address removed) http://onestepback.org
 
W

why the lucky stiff

Jim said:
However, Jim Freeze *wanted* location specific behavior. (Are there
too many Jims in this conversation?).


Actually, the Jims currently in this conversation only represent a small
sampling of the worldwide Jim contingency. It behooves all Jims,
wherever they may be, to chime into this conversation immediately, to
run rather than walk, to dash quickly past the street urchin and
alleyway lieutenants and tambourine buccaneers, resisting urges to stop
and play with a plastic lasso or an infant babboon. You have my license
to topple watermelon stands or to block the mirror-carrying. Pop
balloons, if you must. The fate of a certain working directory is at hand!!

_why
 
J

Jim Freeze

=20
I'm not. If I'm not mistaken, Make and Ant both assume that you are
running the makefile/Ant build file from the directory in which the
file exists. All path names are relative to that file, not to the file
in which you happen to be running the script.
=20
I always write my {rm}akefiles and build.xml files so that everything
happens relative to the top-level directory where the file lives.

Maybe I just don't understand. Assume you have the following:

proj/
[RM]akefile
dira/
a.c
dirb/
b.c

How do you write the [RM]akefile such that if in proj/dira/,
that it knows how to compile a.c? Without the orginal_dir,
the only information you have is that the cwd is proj/ and
you want to compile some file.

--=20
Jim Freeze
 
J

Jim Freeze

I guess to put it succinctly, is that I want to use Rakefile
such that I have a single Rakefile for multiple projects
and I am working in one of the project directories. NOT
the case where I have a single Rakefile for a project with
multiple directories and I am working in one of the project
subdirectories.

In the latter, the Rakefile can be more knowledgable, in=20
the former, the Rakefile needs to be told what directory
is being worked in.

=20
(Are there too
many Jims in this conversation?).

:)
You would think that there would not be so much confusion
since, as James Edward Gray II says, "All Jim's program the same".


--=20
Jim Freeze
 
J

Jim Menard

Jim Weirich wrote:
=20
=20
=20
Actually, the Jims currently in this conversation only represent a small
sampling of the worldwide Jim contingency. It behooves all Jims,
wherever they may be, to chime into this conversation immediately, to
run rather than walk, to dash quickly past the street urchin and
alleyway lieutenants and tambourine buccaneers, resisting urges to stop
and play with a plastic lasso or an infant babboon. You have my license
to topple watermelon stands or to block the mirror-carrying. Pop
balloons, if you must. The fate of a certain working directory is at han=
d!!

Once, I played in a band with a drummer named Jim. Our soundman was
named Jim, too. I'll give you one guess as to the name of a guest
guitarist one evening. It's not a trick question.

Jim
--=20
Jim Menard, (e-mail address removed), (e-mail address removed)
http://www.io.com/~jimm
 
J

Joel VanderWerf

Jim said:
I guess to put it succinctly, is that I want to use Rakefile
such that I have a single Rakefile for multiple projects
and I am working in one of the project directories. NOT
the case where I have a single Rakefile for a project with
multiple directories and I am working in one of the project
subdirectories.

In the latter, the Rakefile can be more knowledgable, in
the former, the Rakefile needs to be told what directory
is being worked in.

Can I pop into this thread even if I am not a Jim?

Now I understand why your request makes sense--multiple projects that
use the same rakefile. One way to handle this is to use require. Have a
very simple "stub" rakefile in each project that just requires or loads
a generic rakefile. That way, the current dir is inherited from the
stub, but you have all the tasks defined in the generic rakefile.

This seems less fragile than having to keep track of a launch_dir
separately from the dir of the makefile.

Btw, I really like the fact that you can run rake from any subdir of the
project.
 
J

Jim Weirich

Once, I played in a band with a drummer named Jim. Our soundman was
named Jim, too. I'll give you one guess as to the name of a guest
guitarist one evening. It's not a trick question.

Heh. I play guitar with Jim the drummer and Jim the bass guitarist. We
occasionally have a vocalist named Jim. Sounds like we need to get our
bands together :)
 
W

why the lucky stiff

Jim said:
Heh. I play guitar with Jim the drummer and Jim the bass guitarist. We
occasionally have a vocalist named Jim. Sounds like we need to get our
bands together :)

This is uncanny. I'm freaking out over this! Think about it:

* Ruby was invented by Jim Matsumoto
* AND! The most popular package for Ruby is called RubyJims.
* AND! Jim Heinemeier Hansson and Jim Alan Black were born on the same
day as all the other Jims ever!
* AND! Ruby is cross-platform, meaning it works well on Jimux and
Jimdows and Macjimtosh.
* AND! Proof: RUBY_PLATFORM =~ /j/im
* AND! Ruby starts with the letter Jim!
* AND! Jim is the key ingredient in making computers. (No surprise here.)
* BUT! When a computer breaks and its modem is going crazy, some people
curse, "Looks like I'm the first log on the train to Jimsville!"

_why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top