Rake Bug

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

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, jim@freeze.org 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

jim@freeze.org 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 jim@weirichhouse.org 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 <jim@weirichhouse.org> [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

jim@freeze.org said:

* Jim Weirich <jim@weirichhouse.org> [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 jim@weirichhouse.org 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 wrote:

* Jim Weirich <jim@weirichhouse.org> [2004-08-28 05:11:24 +0900]:

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

jim@freeze.org 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 jim@weirichhouse.org 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)