Rakefile rule output generation problem
i have a Rakefile with a rule like this :
rule '.so' => '.cc' do |t|
puts "@ Compiling #{t.source}"
output = t.source.ext("so")
output['stdlib'] = 'build'
sh "mkdir -p #{File.dirname(output)}"
sh "#{CXX} #{t.source} -o#{output} #{STDLIB_CFLAGS} #{STDLIB_LFLAGS}"
end
As you can see, it generates many .so libraries from the 'stdlib' directory (which contains the sources) to the 'build' directory where the binaries are stored.
Now the problem is, due to this "directory exchange", rake seems to not recognize the .so files as file开发者_运维知识库s it has generated, causing the recompilation of each .so module each time o run the rake command, even if nothing is changed.
Is there any way to solve this?
Thanks
You can either use the pathmap syntax or an explicit proc to change the output filename/path into the input filename/path.
The pathmap syntax will look something like this (untested):
rule '.so' => '%{build,stdlib}X.cc' do |t|
puts "@ Compiling #{t.source}"
sh "mkdir -p #{File.dirname(t.name)}"
sh "#{CXX} #{t.source} -o#{t.name} #{STDLIB_CFLAGS} #{STDLIB_LFLAGS}"
end
The proc method will look something like this (also untested):
rule '.so' => [proc { |f| f.sub(/build/, 'stdlib').ext('.cc') }] do |t|
puts "@ Compiling #{t.source}"
sh "mkdir -p #{File.dirname(t.name)}"
sh "#{CXX} #{t.source} -o#{t.name} #{STDLIB_CFLAGS} #{STDLIB_LFLAGS}"
end
Note that you can get rid of the explicit 'mkdir' in your action and use a 'directory' task instead (if you know in advance the possible destination directories)
possible_dest_dirs.each { |d|
directory d
}
rule '.so' => [proc { |f| f.sub(/build/, 'stdlib').ext('.cc') },
proc { |f| File.dirname(f) }] do |t|
puts "@ Compiling #{t.source}"
sh "#{CXX} #{t.source} -o#{t.name} #{STDLIB_CFLAGS} #{STDLIB_LFLAGS}"
end
精彩评论