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);
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)
// 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);
{
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);
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))
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)
{
}
else if(FS::is_reg(full))
{
- tgt = new SystemLibrary(*this, full);
+ tgt = new SystemLibrary(*this, full.str());
return tgt;
}
}
bool no_externals;
TargetMap targets;
+ TargetMap targets_by_path;
TargetList new_tgts;
TargetMap includes;
TargetMap libraries;
/** Looks up a target by name. Returns 0 if no such target exists. */
Target *get_target(const std::string &) const;
+ FileTarget *get_target_by_path(const Msp::FS::Path &) const;
+
const TargetMap &get_targets() const { return targets; }
/** Tries to locate a header based on location of including file and include
/** Adds a target to both the target map and the new target queue. Called
from Target constructor. */
- void add_target(FileTarget *);
- void add_target(VirtualTarget *);
+ void add_target(Target *);
+ void register_path(const Msp::FS::Path &, FileTarget *);
void problem(const std::string &, const std::string &);
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
FileTarget *ft;
- if(Target *tgt = builder.get_target(i->str()))
+ if(Target *tgt = builder.get_target_by_path(*i))
ft = dynamic_cast<FileTarget *>(tgt);
else
ft = new File(builder, *i);
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
FileTarget *ft;
- if(Target *tgt = builder.get_target(i->str()))
+ if(Target *tgt = builder.get_target_by_path(*i))
ft = dynamic_cast<FileTarget *>(tgt);
else
ft = new File(builder, pkg, *i);
else if(type==DATAFILE)
{
File *source;
- if(Target *tgt = builder.get_target(files.front().str()))
+ if(Target *tgt = builder.get_target_by_path(files.front()))
source = dynamic_cast<File *>(tgt);
else
source = new File(builder, pkg, files.front());
string ext = FS::extpart(FS::basename(*i));
if(ext==".h")
{
- FileTarget *hdr = dynamic_cast<FileTarget *>(builder.get_target(i->str()));
+ FileTarget *hdr = builder.get_target_by_path(*i);
if(!hdr)
hdr = new Header(builder, *this, i->str());
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
+#include <msp/strings/format.h>
#include <msp/time/utils.h>
#include "builder.h"
#include "filetarget.h"
using namespace Msp;
FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
- Target(b, p, FS::basename(a.str())),
+ Target(b, p, make_name(p, a)),
path(a),
size(0)
{
- builder.add_target(this);
+ builder.register_path(path, this);
if(FS::Stat st = FS::lstat(path))
{
if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
mark_rebuild("Package options changed");
}
+
+string FileTarget::make_name(const Package *pkg, const FS::Path &pth)
+{
+ if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(pkg))
+ {
+ FS::Path relpath = FS::relative(pth, spkg->get_source());
+ return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
+ }
+ else
+ return pth.str();
+}
protected:
virtual void check_rebuild();
+private:
+ std::string make_name(const Package *, const Msp::FS::Path &);
};
#endif
deps_ready(false),
preparing(false),
prepared(false)
-{ }
+{
+ builder.add_target(this);
+}
Target *Target::get_buildable_target()
{
VirtualTarget::VirtualTarget(Builder &b, const string &n):
Target(b, 0, n)
-{
- builder.add_target(this);
-}
+{ }
void VirtualTarget::check_rebuild()
{