[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: incremental rebuild with Rake

Simon Strandgaard

3/17/2006 5:53:00 PM

On 3/17/06, Simon Strandgaard <neoneye@gmail.com> wrote:
> I am using Rake for testing c++ code.
>
> Incremental rebuild does not work for .h files,
> Any ideas?

I have made some changes to my .h files
and nothing happens when I type 'rake'!

I wonder how to describe, that the application also
depends on the .h files.

--
Simon Strandgaard


4 Answers

Simon Strandgaard

3/17/2006 7:53:00 PM

0

On 3/17/06, Simon Strandgaard <neoneye@gmail.com> wrote:
> On 3/17/06, Simon Strandgaard <neoneye@gmail.com> wrote:
> > I am using Rake for testing c++ code.
> >
> > Incremental rebuild does not work for .h files,
> > Any ideas?
>
> I have made some changes to my .h files
> and nothing happens when I type 'rake'!
>
> I wonder how to describe, that the application also
> depends on the .h files.


Anything smarter than converting makedepend to ruby, like this?

--
Simon Strandgaard



task :depend do
sh "makedepend -f- -- #{CFLAGS} -- #{CPP_SOURCES} > .depend"
end



=begin
input:
code.o: code.h morecode.h

output:
{'code.o' => ['code.h', 'morecode.h']}
=end
def convert_makedepend_to_hash(filename)
lines1 = IO.readlines(filename)
# get rid of comments and empty lines
lines2 = lines1.reject{|line| line =~ /^#|^\s*$/ }

deps = {}
lines2.each do |line|
o_file, h_files_str = line.strip.split(': ')
h_files = h_files_str.split(' ')
deps[o_file] = h_files
end

deps
end


task :rakedepend do
deps = convert_makedepend_to_hash('.depend')
#p deps

ary = []
deps.each do |o_file, deps|
s = 'file "' + o_file + '" => ' + deps.inspect
ary << s
end
result = ary.join("\n")
result += "\n\n"
File.open('.rakedepends', 'w+') {|f| f.write(result)}
end

load '.rakedepends'


Jim Weirich

3/17/2006 9:21:00 PM

0

Simon Strandgaard wrote:
> On 3/17/06, Simon Strandgaard <neoneye@gmail.com> wrote:
>> depends on the .h files.
> Anything smarter than converting makedepend to ruby, like this?

Actually, its a bit easier than that ... but its a poorly documented
area of Rake.

Rake supports dependency files by importing them, like this:

require 'rake/loaders/makefile' # Load the makefile dependency
loader
import '.depend.mf' # Import the dependencies.

(notice the .mf extension, that tells Rake that the dependencies are in
makefile format).

So just create a task that builds the dependency files, similar to the
above.

file '.depend.mf' do
sh "makedepend -f- -- #{CFLAGS} -- #{CPP_SOURCES} > .depend.mf"
end

After the Rakefile has been read, but before the user requested targets
are built, Rake will check to see if any imported dependencies have been
requested. If they have, rake will run any build targets for the
dependencies (i.e. if the dependency file is out of date, it will
rebuild it). It will then load the dependencies (no need to convert
makefile style dependencies, rake will parse the file if the makefile
loader has been required as shown above).

The only gotcha in the scenario is that the dependency file rebuild
cannot be triggered by any of the dependencies defined in the file
(since the that file has not been loaded yet).

--
-- Jim Weirich

--
Posted via http://www.ruby-....


Simon Strandgaard

3/18/2006 11:19:00 AM

0

On 3/17/06, Jim Weirich <jim@weirichhouse.org> wrote:
[snip]
> Rake supports dependency files by importing them, like this:
[snip]


Touching 'a.cpp' does not result in a compile, what am I doing wrong?
(Touching 'a.h' works fine.)

prompt> ls
Rakefile a.cpp a.h main.cpp
prompt> rake
(in /Users/simonstrandgaard/rake)
makedepend -f- -- -- a.cpp main.cpp > .depend.mf
makedepend: warning: a.cpp (reading a.h, line 4): cannot find include
file "string"
not in /usr/local/lib/gcc-include/string
not in /usr/include/string
g++ -c -o a.o a.cpp
g++ -c -o main.o main.cpp
g++ a.o main.o -o test.exe
prompt> ./test.exe
test a
prompt> touch a.h
prompt> rake
(in /Users/simonstrandgaard/rake)
g++ -c -o a.o a.cpp
g++ -c -o main.o main.cpp
g++ a.o main.o -o test.exe
prompt> touch a.cpp
prompt> rake
(in /Users/simonstrandgaard/rake)
prompt>



Below are my files



prompt> cat .depend.mf
# DO NOT DELETE

a.o: a.h
main.o: a.h






prompt> cat a.h
#ifndef __A_H__
#define __A_H__

#include <string>

std::string test_a();

#endif // __A_H__






prompt> cat a.cpp
#include "a.h"

std::string test_a()
{
return std::string("a");
}






prompt> cat main.cpp
#include "a.h"

int main(int argc, char **argv)
{
std::string s = test_a();
printf("test %s\n", s.c_str());
return 0;
}






prompt> cat Rakefile
require 'rake/clean'
require 'rake/loaders/makefile'

APPLICATION = 'test.exe'
CPP_FILES = FileList['*.cpp']
O_FILES = CPP_FILES.sub(/\.cpp$/, '.o')

file '.depend.mf' do
sh "makedepend -f- -- -- #{CPP_FILES} > .depend.mf"
end

import ".depend.mf"

file APPLICATION => O_FILES do |t|
sh "g++ #{O_FILES} -o #{t.name}"
end

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

CLEAN.include("**/*.o")
CLEAN.include(APPLICATION)
CLEAN.include(".depend.mf")

task :default => APPLICATION


Jim Weirich

3/18/2006 12:36:00 PM

0

Simon Strandgaard wrote:
> On 3/17/06, Jim Weirich <jim@weirichhouse.org> wrote:
> [snip]
>> Rake supports dependency files by importing them, like this:
> [snip]
>
>
> Touching 'a.cpp' does not result in a compile, what am I doing wrong?
> (Touching 'a.h' works fine.)

Ahh, evidently, makedepend does not create an explicit dependency
between a.o and a.cpp. Make probably deduces this implicitly. however,
rake does not. So just make the relationship explicit. Add the
following to your Rakefile:

CPP_FILES.each do |src|
file src.ext(".o") => src
end

--
-- Jim Weirich

--
Posted via http://www.ruby-....