]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Add a separate set of functions for registering and looking up targets by path
[builder.git] / source / builder.cpp
index 63ae0613a737fc2939dec7e36e86113458777841..7704a9634a0e7b086276086ddac50a236a3fc9d8 100644 (file)
@@ -370,13 +370,20 @@ Package *Builder::get_package(const string &name)
 
 Target *Builder::get_target(const string &n) const
 {
-       // XXX Used for getting targets by path.  get_target(const FS::Path &)?
        TargetMap::const_iterator i = targets.find(n);
        if(i!=targets.end())
                return i->second;
        return 0;
 }
 
+FileTarget *Builder::get_target_by_path(const FS::Path &p) const
+{
+       TargetMap::const_iterator i = targets_by_path.find(p.str());
+       if(i!=targets_by_path.end())
+               return static_cast<FileTarget *>(i->second);
+       return 0;
+}
+
 Target *Builder::get_header(const string &include, const FS::Path &from, const list<string> &path)
 {
        string hash(8, 0);
@@ -495,16 +502,15 @@ void Builder::problem(const string &p, const string &d)
        problems.push_back(Problem(p, d));
 }
 
-void Builder::add_target(FileTarget *t)
+void Builder::add_target(Target *t)
 {
-       targets.insert(TargetMap::value_type(t->get_path().str(), t));
+       targets.insert(TargetMap::value_type(t->get_name(), t));
        new_tgts.push_back(t);
 }
 
-void Builder::add_target(VirtualTarget *t)
+void Builder::register_path(const FS::Path &path, FileTarget *t)
 {
-       targets.insert(TargetMap::value_type(t->get_name(), t));
-       new_tgts.push_back(t);
+       targets_by_path.insert(TargetMap::value_type(path.str(), t));
 }
 
 void Builder::usage(const char *reason, const char *argv0, bool brief)
@@ -636,7 +642,7 @@ int Builder::create_targets()
        // Apply what-ifs
        for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
        {
-               FileTarget *tgt = dynamic_cast<FileTarget *>(get_target((cwd/ *i).str()));
+               FileTarget *tgt = get_target_by_path(cwd/ *i);
                if(!tgt)
                {
                        IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
@@ -651,7 +657,9 @@ int Builder::create_targets()
        {
                Target *tgt = get_target(*i);
                if(!tgt)
-                       tgt = get_target((cwd/ *i).str());
+                       tgt = get_target_by_path(*i);
+               if(!tgt)
+                       tgt = get_target_by_path(cwd/ *i);
                if(!tgt)
                {
                        IO::print("I don't know anything about %s\n", *i);
@@ -672,7 +680,7 @@ int Builder::create_targets()
 
 Target *Builder::get_header(const FS::Path &fn)
 {
-       Target *tgt = get_target(fn.str());
+       Target *tgt = get_target_by_path(fn);
        if(tgt) return tgt;
 
        if(FS::is_reg(fn))
@@ -708,8 +716,8 @@ Target *Builder::get_library(const string &lib, const FS::Path &path, LibMode mo
 
        for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i)
        {
-               string full = (path/ *i).str();
-               Target *tgt = get_target(full);
+               FS::Path full = path/ *i;
+               Target *tgt = get_target_by_path(full);
 
                if(tgt)
                {
@@ -724,7 +732,7 @@ Target *Builder::get_library(const string &lib, const FS::Path &path, LibMode mo
                }
                else if(FS::is_reg(full))
                {
-                       tgt = new SystemLibrary(*this, full);
+                       tgt = new SystemLibrary(*this, full.str());
                        return tgt;
                }
        }