using namespace Msp;
Binary::Binary(Builder &b, const FS::Path &p):
- FileTarget(b, 0, p)
+ FileTarget(b, p)
{ }
Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
- FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/p)
+ FileTarget(b, c.get_package(), c.get_package().get_out_dir()/p)
{
component = &c;
for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
using namespace Msp;
CSourceFile::CSourceFile(Builder &b, const FS::Path &p):
- SourceFile(b, 0, p)
+ SourceFile(b, p)
{ }
CSourceFile::CSourceFile(Builder &b, const Component &c, const FS::Path &p):
- SourceFile(b, &c, p)
+ SourceFile(b, c, p)
{
string ext = FS::extpart(FS::basename(path));
if(ext==".h" || ext==".H" || ext==".hpp")
#include "sourcepackage.h"
DataFile::DataFile(Builder &b, const Component &c, File &s):
- FileTarget(b, &c.get_package(), generate_target_path(c)),
+ FileTarget(b, c.get_package(), generate_target_path(c)),
component(c),
source(s)
{
class File: public FileTarget
{
public:
- File(Builder &b, const Msp::FS::Path &t): FileTarget(b, 0, t) { }
- File(Builder &b, SourcePackage &p, const Msp::FS::Path &t): FileTarget(b, &p, t) { }
+ File(Builder &b, const Msp::FS::Path &t): FileTarget(b, t) { }
+ File(Builder &b, SourcePackage &p, const Msp::FS::Path &t): FileTarget(b, p, t) { }
virtual const char *get_type() const { return "File"; }
};
using namespace std;
using namespace Msp;
-FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a):
- Target(b, generate_name(p, a)),
- path(a),
- size(0)
+FileTarget::FileTarget(Builder &b, const FS::Path &a):
+ Target(b, generate_name(b, 0, a)),
+ path(a)
{
+ init(0);
+}
+
+FileTarget::FileTarget(Builder &b, const SourcePackage &p, const FS::Path &a):
+ Target(b, generate_name(b, &p, a)),
+ path(a)
+{
+ init(&p);
+}
+
+void FileTarget::init(const SourcePackage *p)
+{
+ size = 0;
package = p;
builder.get_vfs().register_path(path, this);
}
}
-string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth)
+string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path)
{
- if(pkg)
+ if(pkg && FS::descendant_depth(path, pkg->get_source())>=0)
{
- if(FS::descendant_depth(pth, pkg->get_source())>=0)
- {
- FS::Path relpath = FS::relative(pth, pkg->get_source());
- return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
- }
- else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0)
- {
- FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix());
- return "<prefix>"+relpath.str().substr(1);
- }
+ FS::Path relpath = FS::relative(path, pkg->get_source());
+ return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
+ }
+ else if(FS::descendant_depth(path, builder.get_prefix())>=0)
+ {
+ FS::Path relpath = FS::relative(path, builder.get_prefix());
+ builder.get_logger().log("debug", format("%s %s %s", path, builder.get_prefix(), relpath));
+ return "<prefix>"+relpath.str().substr(1);
}
- return pth.str();
+ return path.str();
}
void FileTarget::touch()
Msp::Time::TimeStamp mtime;
unsigned size;
- FileTarget(Builder &, const SourcePackage *, const Msp::FS::Path &);
+ FileTarget(Builder &, const Msp::FS::Path &);
+ FileTarget(Builder &, const SourcePackage &, const Msp::FS::Path &);
private:
- static std::string generate_name(const SourcePackage *, const Msp::FS::Path &);
+ void init(const SourcePackage *);
+ static std::string generate_name(Builder &, const SourcePackage *, const Msp::FS::Path &);
public:
const Msp::FS::Path &get_path() const { return path; }
using namespace Msp;
InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const string &loc):
- FileTarget(b, &p, generate_target_path(b.get_prefix(), s, loc)),
+ FileTarget(b, p, generate_target_path(b.get_prefix(), s, loc)),
source(s)
{
add_depend(&source);
using namespace Msp;
ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
- FileTarget(b, &c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source()).str())),
+ FileTarget(b, c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source()).str())),
source(s)
{
component = &c;
#include "pkgconfigfile.h"
PkgConfigFile::PkgConfigFile(Builder &b, const SourcePackage &p):
- FileTarget(b, &p, p.get_source()/(p.get_name()+".pc"))
+ FileTarget(b, p, p.get_source()/(p.get_name()+".pc"))
{
tool = &builder.get_toolchain().get_tool("PCG");
#include "sourcefile.h"
#include "sourcepackage.h"
-SourceFile::SourceFile(Builder &b, const Component *c, const Msp::FS::Path &p):
- FileTarget(b, (c ? &c->get_package() : 0), p)
+SourceFile::SourceFile(Builder &b, const Msp::FS::Path &p):
+ FileTarget(b, p)
+{ }
+
+SourceFile::SourceFile(Builder &b, const Component &c, const Msp::FS::Path &p):
+ FileTarget(b, c.get_package(), p)
{
- component = c;
+ component = &c;
}
class SourceFile: public FileTarget
{
protected:
- SourceFile(Builder &, const Component *, const Msp::FS::Path &);
+ SourceFile(Builder &, const Msp::FS::Path &);
+ SourceFile(Builder &, const Component &, const Msp::FS::Path &);
};
#endif
using namespace Msp;
StaticLibrary::StaticLibrary(Builder &b, const FS::Path &p):
- FileTarget(b, 0, p)
+ FileTarget(b, p)
{ }
StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
- FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/generate_filename(c))
+ FileTarget(b, c.get_package(), c.get_package().get_out_dir()/generate_filename(c))
{
component = &c;
for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
using namespace std;
TarBall::TarBall(Builder &b, const SourcePackage &p, const string &n):
- FileTarget(b, &p, p.get_source()/(n+".tar"))
+ FileTarget(b, p, p.get_source()/(n+".tar"))
{ }
const SourcePackage *TarBall::get_package() const