Inbae Jeong
Inbae Jeong

Reputation: 4103

rake invokes a task twice with -m

I'm building a Rakefile which has a diamond dependency,

  A
 / \
B   C
 \ /
  D

and the Rakefile is as follows.

task :default => :a

task :a => [:b, :c] do |t|
  puts "#{t.name}"
end

task :b => :d do |t|
  puts "#{t.name}"
end

task :c => :d do |t|
  puts "#{t.name}"
end

task :d do |t|
  puts "#{t.name}"
end

The problem is that task :d is invoked twice with the multitask option.

$ rake -m
d
d
c
b
a

task :d is a task which should be called every time I run rake but exactly once in every build.

I considered using filetask but since it actually is a task which sends a signal to a remote server, there's no file generated by this task.

I also tried the following timestamp method but it doesn't make any change.

def (task(:d)).timestamp
  if @timestamp
    @timestamp
  else
    @timestamp = Time.now
  end
end

What should I do to make it work?

Upvotes: 2

Views: 123

Answers (2)

Gizmomogwai
Gizmomogwai

Reputation: 2536

Since rake is regular ruby you could use every normal ruby-technique to ensure that the stuff behind d is only done once.

Actually I tried your example with a quite recent rake version and could not reproduce your problem:

> rake --version
rake, version 10.1.0
> rake
d
b
c
a
> rake -m
d
b
c
a

Upvotes: 1

aarti
aarti

Reputation: 2865

Since the prerequisite tasks are run sequentially, does it make sense to just have one dependent task to D from C and not have one from B. This way, you can ensure that both B and C have run before D runs.

Upvotes: 0

Related Questions