X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcefile.cpp;h=cadd1330e0bc94b2816e6b26268b5d0a195e5efb;hb=66d1078c04849ec17a7343d0494d6ed087e04318;hp=af1c04a5cf4205be339b86a1e9cead91f8a02f90;hpb=0f5283a54fd188072eca23fbd980a43c6c869913;p=builder.git diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index af1c04a..cadd133 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -1,12 +1,13 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include #include +#include +#include #include #include "builder.h" #include "component.h" @@ -16,44 +17,58 @@ Distributed under the LGPL using namespace std; using namespace Msp; -SourceFile::SourceFile(Builder &b, const Component *c, const string &n): - Target(b, c?&c->get_package():0, n), +SourceFile::SourceFile(Builder &b, const Component *c, const FS::Path &p): + FileTarget(b, (c ? &c->get_package() : 0), p), comp(c) { } -/** -Parses include directives from the file and looks up the appropriate targets -from Builder. -*/ void SourceFile::find_depends() { if(!comp) return; - DependencyCache &deps_cache=comp->get_package().get_deps_cache(); - if(mtime>deps_cache.get_mtime()) + const SourcePackage &spkg=comp->get_package(); + string relname=FS::relative(name, spkg.get_source()).str(); + DependencyCache &deps_cache=spkg.get_deps_cache(); + bool deps_found=false; + if(mtime=4) - cout<<"Reading includes from "<=4) + cout<<"Reading includes from "<]"); + Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]"); - string line; - while(getline(in, line)) - if(RegMatch match=r_include.match(line)) - includes.push_back(match[1].str); + string line; + while(in.getline(line)) + if(RegMatch match=r_include.match(line)) + includes.push_back(match[1].str); - deps_cache.set_deps(name, includes); + deps_cache.set_deps(relname, includes); + } + catch(const IO::FileNotFound &) + { + return; + } } - else - includes=deps_cache.get_deps(name); const StringList &incpath=comp->get_build_info().incpath; - string path=name.substr(0, name.rfind('/')); + FS::Path dir=FS::dirname(path); for(list::iterator i=includes.begin(); i!=includes.end(); ++i) { Target *hdr=builder.get_header(*i, path, incpath);