Launch directory in Rake

Discussion in 'Ruby' started by Jim Freeze, Sep 13, 2005.

  1. Jim Freeze

    Jim Freeze Guest

    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
    Jim Freeze, Sep 13, 2005
    #1
    1. Advertising

  2. Jim Freeze

    Jim Freeze Guest

    > 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
    Jim Freeze, Sep 13, 2005
    #2
    1. Advertising

  3. Jim Freeze

    Jim Weirich Guest

    On Tuesday 13 September 2005 03:48 pm, Jim Freeze wrote:
    > 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?


    Reasonable request. Committed to CVS. Use Rake.original_dir to get the
    original directory.

    If you are impatient, a beta is available at http://onestepback.org/betagems.

    --
    -- Jim Weirich 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)
    Jim Weirich, Sep 14, 2005
    #3
  4. Jim Freeze

    Jim Freeze Guest

    Thanks Jim

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

    On 9/14/05, Jim Weirich <> wrote:
    > On Tuesday 13 September 2005 03:48 pm, Jim Freeze wrote:
    > > 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?

    >=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 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
    Jim Freeze, Sep 14, 2005
    #4
  5. Jim Freeze

    Jim Menard Guest

    On 9/14/05, Jim Freeze <> wrote:
    > 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, ,
    http://www.io.com/~jimm
    Jim Menard, Sep 14, 2005
    #5
  6. Jim Freeze

    Jim Weirich Guest

    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 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)
    Jim Weirich, Sep 14, 2005
    #6
  7. Jim Weirich wrote:

    > 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
    why the lucky stiff, Sep 14, 2005
    #7
  8. Jim Freeze

    Jim Freeze Guest

    On 9/14/05, Jim Menard <> wrote:
    > On 9/14/05, Jim Freeze <> wrote:
    > > Thanks Jim
    > >
    > > I'm really surprised this has not already been requested.

    >=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
    Jim Freeze, Sep 14, 2005
    #8
  9. Jim Freeze

    Jim Freeze Guest

    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.

    On 9/14/05, Jim Weirich <> wrote:
    >=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
    Jim Freeze, Sep 14, 2005
    #9
  10. Jim Freeze

    Jim Menard Guest

    On 9/14/05, why the lucky stiff <> wrote:
    > Jim Weirich wrote:
    >=20
    > > However, Jim Freeze *wanted* location specific behavior. (Are there
    > > too many Jims in this conversation?).

    >=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, ,
    http://www.io.com/~jimm
    Jim Menard, Sep 15, 2005
    #10
  11. Jim Freeze wrote:
    > 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.

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Sep 15, 2005
    #11
  12. Jim Freeze

    Jim Weirich Guest

    On Wednesday 14 September 2005 07:08 pm, Jim Menard wrote:
    > 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 :)

    --
    -- Jim Weirich 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)
    Jim Weirich, Sep 15, 2005
    #12
  13. Jim Weirich wrote:

    > 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
    why the lucky stiff, Sep 15, 2005
    #13
  14. This thread is dead, Jim!

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Sep 15, 2005
    #14
  15. Jim Weirich <> wrote:
    > On Wednesday 14 September 2005 07:08 pm, Jim Menard wrote:
    > > 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 :)



    Maybe you can form a cricket team :)

    http://www.rediff.com/cricket/2001/jul/19patel.htm

    martin
    Martin DeMello, Sep 15, 2005
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Van Dyk
    Replies:
    2
    Views:
    102
    Damphyr
    Jan 31, 2006
  2. peppermonkey
    Replies:
    1
    Views:
    243
    Gregory Brown
    Feb 10, 2007
  3. Adam Anderson
    Replies:
    1
    Views:
    130
    Adam Anderson
    Sep 19, 2007
  4. James Mead
    Replies:
    0
    Views:
    144
    James Mead
    Jan 15, 2008
  5. thufir
    Replies:
    3
    Views:
    218
    Thufir
    Apr 12, 2008
Loading...

Share This Page