Rake Bug

Discussion in 'Ruby' started by jim@freeze.org, Aug 27, 2004.

  1. Guest

    I think you can call this a bug.
    When the Rakefile is newer than the file dependencies,
    the dependencies do not rebuild.

    I was hoping they would.
    I think make does this.

    --
    Jim Freeze
    , Aug 27, 2004
    #1
    1. Advertising

  2. GNU make doesn't do this.
    -Charlie

    $ make
    ...
    $ touch Makefile
    $ make
    make: Nothing to be done for `all'.

    On Aug 27, 2004, at 12:53 PM, wrote:

    > I think you can call this a bug.
    > When the Rakefile is newer than the file dependencies,
    > the dependencies do not rebuild.
    >
    > I was hoping they would.
    > I think make does this.
    >
    > --
    > Jim Freeze
    >
    Charles Mills, Aug 27, 2004
    #2
    1. Advertising

  3. Jim Weirich Guest

    said:
    > I think you can call this a bug.
    > When the Rakefile is newer than the file dependencies,
    > the dependencies do not rebuild.
    >
    > I was hoping they would.
    > I think make does this.


    If you want something to be dependent upon the rakefile, then declare the
    Rakefile in the dependencies.

    I sometimes do this with package generation since the metadata for the
    package is often in the Rakefile. If I tweek the metadata, I want the
    package to rebuild.

    --
    -- 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, Aug 27, 2004
    #3
  4. Guest

    * Jim Weirich <> [2004-08-28 05:11:24 +0900]:

    >
    > If you want something to be dependent upon the rakefile, then declare the
    > Rakefile in the dependencies.


    Good idea. So, does the following look like a good way to do this?

    The following:

    file "app" => ["app.o"] do
    # link app
    end

    file "app.o" => ["main.c", "app.c"] do
    # compile app.o
    end

    would become:

    file "app" => ["app.o"] do
    # link app
    end

    file "app.o" => ["main.c", "app.c"] do
    # compile app.o
    end

    file "app.c" => ["Rakefile"] do |t|
    sh "touch #{t.name}"
    end
    file "main.c" => ["Rakefile"] do |t|
    sh "touch #{t.name}"
    end

    --
    Jim Freeze
    , Aug 27, 2004
    #4
  5. Jim Weirich Guest

    said:
    > * Jim Weirich <> [2004-08-28 05:11:24 +0900]:
    >
    >>
    >> If you want something to be dependent upon the rakefile, then declare
    >> the
    >> Rakefile in the dependencies.

    >
    > Good idea. So, does the following look like a good way to do this?
    >
    > The following:
    >
    > file "app" => ["app.o"] do
    > # link app
    > end
    >
    > file "app.o" => ["main.c", "app.c"] do
    > # compile app.o
    > end
    >
    > would become:
    >
    > file "app" => ["app.o"] do
    > # link app
    > end
    >
    > file "app.o" => ["main.c", "app.c"] do
    > # compile app.o
    > end
    >
    > file "app.c" => ["Rakefile"] do |t|
    > sh "touch #{t.name}"
    > end
    > file "main.c" => ["Rakefile"] do |t|
    > sh "touch #{t.name}"
    > end


    Hmmm ... I don't _think_ the touch is needed. The fact that a dependency
    has a later time _should_ be enough to trigger its rebuild. I won't get a
    chance to test this until this evening however.

    --
    -- 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, Aug 27, 2004
    #5
  6. Jim Weirich Guest

    Jim Weirich wrote:

    >>* Jim Weirich <> [2004-08-28 05:11:24 +0900]:
    >>>If you want something to be dependent upon the rakefile, then declare
    >>>the Rakefile in the dependencies.


    > said:
    >>Good idea. So, does the following look like a good way to do this?

    [... example elided ...]

    Here's what I did. I have a small project of two C files (main.c and
    hello.c) and one header file (hello.h). Here is the rakefile I used ...

    -- BEGIN Rakefile ---------------------------------------------------
    # -*- ruby -*-

    require 'rake/clean'

    CC = 'gcc'
    LD = CC

    PROG = 'hi'
    SRC = FileList['*.c']
    HDR = FileList['*.h']
    OBJ = SRC.sub(/\.c$/, '.o')

    CLOBBER.include(PROG, *OBJ)

    task :default => [:compile]
    task :compile => [PROG]

    file PROG => OBJ
    OBJ.each do |obj|
    header = obj.sub(/\.o$/, '.h')
    file obj => [header] if File.exists?(header)
    file obj => ['Rakefile']
    end

    rule '.o' => ['.c'] do |t|
    sh "#{CC} #{t.source} -c -o #{t.name}"
    end

    rule(/^#{PROG}$/ => lambda { |src| OBJ.first } ) do |t|
    sh "#{LD} #{OBJ} -o #{t.name}"
    end
    -- END --------------------------------------------------------------

    And here's an example session...

    $ rake clobber
    (in /home/jim/pgm/ruby/rakemisc/cstuff)
    rm -r hi
    rm -r hello.o
    rm -r main.o
    $
    $ rake compile
    (in /home/jim/pgm/ruby/rakemisc/cstuff)
    gcc hello.c -c -o hello.o
    gcc main.c -c -o main.o
    gcc hello.o main.o -o hi
    $
    $ rake compile
    (in /home/jim/pgm/ruby/rakemisc/cstuff)
    $
    $ touch Rakefile
    $ rake compile
    (in /home/jim/pgm/ruby/rakemisc/cstuff)
    gcc hello.c -c -o hello.o
    gcc main.c -c -o main.o
    gcc hello.o main.o -o hi
    $
    $ rake compile
    (in /home/jim/pgm/ruby/rakemisc/cstuff)
    $

    --
    -- 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, Aug 28, 2004
    #6
    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:
    219
    Thufir
    Apr 12, 2008
Loading...

Share This Page