From: Mikko Rasa Date: Mon, 9 Jul 2012 13:08:41 +0000 (+0300) Subject: Refactor FileTarget and SourceFile constructors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=968db78efd29b1f4890068693728299b2c7c92c7;p=builder.git Refactor FileTarget and SourceFile constructors --- diff --git a/source/binary.cpp b/source/binary.cpp index a06bd20..7e32c86 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -12,11 +12,11 @@ using namespace std; 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 &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::const_iterator i=objs.begin(); i!=objs.end(); ++i) diff --git a/source/csourcefile.cpp b/source/csourcefile.cpp index 7a26bb5..8240278 100644 --- a/source/csourcefile.cpp +++ b/source/csourcefile.cpp @@ -11,11 +11,11 @@ using namespace std; 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") diff --git a/source/datafile.cpp b/source/datafile.cpp index 5566bf4..9a47703 100644 --- a/source/datafile.cpp +++ b/source/datafile.cpp @@ -4,7 +4,7 @@ #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) { diff --git a/source/file.h b/source/file.h index 0e92b72..a36259d 100644 --- a/source/file.h +++ b/source/file.h @@ -9,8 +9,8 @@ Just an arbitary file. No special meaning attached. 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"; } }; diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 634b297..adbb058 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -9,11 +9,23 @@ 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); @@ -25,23 +37,21 @@ FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): } } -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 ""+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 ""+relpath.str().substr(1); } - return pth.str(); + return path.str(); } void FileTarget::touch() diff --git a/source/filetarget.h b/source/filetarget.h index 22df520..6d2480f 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -15,9 +15,11 @@ protected: 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; } diff --git a/source/installedfile.cpp b/source/installedfile.cpp index 3ca4906..0928386 100644 --- a/source/installedfile.cpp +++ b/source/installedfile.cpp @@ -7,7 +7,7 @@ using namespace std; 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); diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 22f11fa..70bef6c 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -10,7 +10,7 @@ using namespace std; 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; diff --git a/source/pkgconfigfile.cpp b/source/pkgconfigfile.cpp index 45951cc..ec61496 100644 --- a/source/pkgconfigfile.cpp +++ b/source/pkgconfigfile.cpp @@ -3,7 +3,7 @@ #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"); diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index 220facd..1dcfd2e 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -2,8 +2,12 @@ #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; } diff --git a/source/sourcefile.h b/source/sourcefile.h index 30a5080..bdb657f 100644 --- a/source/sourcefile.h +++ b/source/sourcefile.h @@ -6,7 +6,8 @@ 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 diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index db04f0a..f63eb16 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -8,11 +8,11 @@ using namespace std; 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 &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::const_iterator i=objs.begin(); i!=objs.end(); ++i) diff --git a/source/tarball.cpp b/source/tarball.cpp index 825c0ba..fe5a10a 100644 --- a/source/tarball.cpp +++ b/source/tarball.cpp @@ -5,7 +5,7 @@ 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