From: Mikko Rasa Date: Fri, 5 Feb 2010 10:35:21 +0000 (+0000) Subject: Make the name of a FileTarget be its basename instead of full path X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=75bdcf13fbd285e2006337ec606ca28fa4ddae9e;p=builder.git Make the name of a FileTarget be its basename instead of full path --- diff --git a/source/analyzer.cpp b/source/analyzer.cpp index f8af44f..563143f 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -58,12 +58,13 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) TableRow row; - string fn; - if(full_paths) - fn = tgt.get_name(); + string name; + FileTarget *ft = dynamic_cast(&tgt); + if(full_paths && ft) + name = ft->get_path().str(); else - fn = FS::basename(tgt.get_name()); - row.push_back(string(depth*2, ' ')+fn); + name = tgt.get_name(); + row.push_back(string(depth*2, ' ')+name); const Package *pkg = tgt.get_package(); if(pkg) diff --git a/source/binary.cpp b/source/binary.cpp index e82b65a..590471f 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -59,7 +59,7 @@ void Binary::find_depends() queue.push_back(&stlib->get_component()); } else - builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, FS::basename(name))); + builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, name)); } } diff --git a/source/builder.cpp b/source/builder.cpp index 77579ea..208e7d5 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -487,7 +487,13 @@ void Builder::problem(const string &p, const string &d) problems.push_back(Problem(p, d)); } -void Builder::add_target(Target *t) +void Builder::add_target(FileTarget *t) +{ + targets.insert(TargetMap::value_type(t->get_path().str(), t)); + new_tgts.push_back(t); +} + +void Builder::add_target(VirtualTarget *t) { targets.insert(TargetMap::value_type(t->get_name(), t)); new_tgts.push_back(t); diff --git a/source/builder.h b/source/builder.h index 653a81a..9dca6f0 100644 --- a/source/builder.h +++ b/source/builder.h @@ -22,8 +22,10 @@ Distributed under the LGPL class Analyzer; class Config; +class FileTarget; class Package; class SourcePackage; +class VirtualTarget; /** The main application class. Controls and owns everything. Rules the world. @@ -146,7 +148,8 @@ public: /** Adds a target to both the target map and the new target queue. Called from Target constructor. */ - void add_target(Target *); + void add_target(FileTarget *); + void add_target(VirtualTarget *); void problem(const std::string &, const std::string &); diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 37cc65c..8f35cfc 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -7,17 +7,19 @@ Distributed under the LGPL #include #include -#include "file.h" +#include "builder.h" +#include "filetarget.h" using namespace std; using namespace Msp; FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a): - // XXX Builder depends on target name being its path for locating file targets - Target(b, p, /*FS::basename*/(a.str())), + Target(b, p, FS::basename(a.str())), path(a), size(0) { + builder.add_target(this); + struct stat st; if(!FS::stat(path, st)) { diff --git a/source/install.cpp b/source/install.cpp index 893f021..e59e0d9 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -33,9 +33,9 @@ void Install::check_rebuild() if(!mtime) mark_rebuild("Does not exist"); else if(source.get_mtime()>mtime || source.get_size()!=size) - mark_rebuild(FS::basename(source.get_name())+" has changed"); + mark_rebuild(source.get_name()+" has changed"); else if(source.get_rebuild()) - mark_rebuild(FS::basename(source.get_name())+" needs rebuilding"); + mark_rebuild(source.get_name()+" needs rebuilding"); } Action *Install::create_action() diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index 3a1941a..d95ea5e 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -36,7 +36,7 @@ void SourceFile::find_depends() } const SourcePackage &spkg = comp->get_package(); - string relname = FS::relative(name, spkg.get_source()).str(); + string relname = FS::relative(path, spkg.get_source()).str(); DependencyCache &deps_cache = spkg.get_deps_cache(); bool deps_found = false; if(mtime=4) - IO::print("Reading includes from %s\n", name); + IO::print("Reading includes from %s\n", path.str()); Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]"); @@ -70,7 +70,9 @@ void SourceFile::find_depends() } catch(const IO::FileNotFound &) { - // XXX WTF? + if(builder.get_verbose()>=4) + IO::print("Failed to read includes from %s\n", path.str()); + deps_ready = true; return; } } diff --git a/source/target.cpp b/source/target.cpp index 3ee6bc5..5329011 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -28,9 +28,7 @@ Target::Target(Builder &b, const Package *p, const string &n): deps_ready(false), preparing(false), prepared(false) -{ - builder.add_target(this); -} +{ } Target *Target::get_buildable_target() { @@ -128,9 +126,9 @@ void Target::check_rebuild() for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i) { if((*i)->get_mtime()>mtime) - mark_rebuild(FS::basename((*i)->get_name())+" has changed"); + mark_rebuild((*i)->get_name()+" has changed"); else if((*i)->get_rebuild()) - mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding"); + mark_rebuild((*i)->get_name()+" needs rebuilding"); } } diff --git a/source/virtualtarget.cpp b/source/virtualtarget.cpp index 72d369b..85bdbc0 100644 --- a/source/virtualtarget.cpp +++ b/source/virtualtarget.cpp @@ -7,15 +7,22 @@ Distributed under the LGPL #include #include +#include "builder.h" #include "virtualtarget.h" using namespace std; using namespace Msp; +VirtualTarget::VirtualTarget(Builder &b, const string &n): + Target(b, 0, n) +{ + builder.add_target(this); +} + void VirtualTarget::check_rebuild() { // Virtual targets are only rebuilt if their dependencies need rebuilding. for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i) if((*i)->get_rebuild()) - mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding"); + mark_rebuild((*i)->get_name()+" needs rebuilding"); } diff --git a/source/virtualtarget.h b/source/virtualtarget.h index 252c68f..d68dba4 100644 --- a/source/virtualtarget.h +++ b/source/virtualtarget.h @@ -16,7 +16,7 @@ A target that is not associated with any file. class VirtualTarget: public Target { public: - VirtualTarget(Builder &b, const std::string &n): Target(b, 0, n) { } + VirtualTarget(Builder &, const std::string &); virtual const char *get_type() const { return "VirtualTarget"; } private: virtual void check_rebuild();