From: Mikko Rasa Date: Sat, 31 Mar 2012 10:51:23 +0000 (+0300) Subject: Make symlink a feature of the Install target rather than a target on its own X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f56fa0c68e0eddf1f01c9584b8761431d29e8fa1;p=builder.git Make symlink a feature of the Install target rather than a target on its own --- diff --git a/source/component.cpp b/source/component.cpp index 4451a69..c12399f 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -15,7 +15,6 @@ #include "sharedlibrary.h" #include "sourcepackage.h" #include "staticlibrary.h" -#include "symlink.h" #include "tarball.h" #include "target.h" @@ -221,11 +220,6 @@ void Component::create_targets() const { Install *inst = new Install(builder, pkg, **i, inst_loc); inst_tgt->add_depend(inst); - - if(type==LIBRARY) - if(SharedLibrary *shlib = dynamic_cast(*i)) - if(!shlib->get_soname().empty()) - inst_tgt->add_depend(new Symlink(builder, pkg, *inst, shlib->get_name())); } } diff --git a/source/copy.cpp b/source/copy.cpp index 2c35ef3..8ea7f35 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -12,10 +12,11 @@ using namespace std; using namespace Msp; -Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d): +Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d, const FS::Path &l): InternalAction(b), src(s), - dest(d) + dest(d), + link(l) { announce(pkg.get_name(), "COPY", dest.str()); if(builder.get_verbose()>=2) @@ -76,5 +77,11 @@ void Copy::Worker::main() if(stat(copy.src.str().c_str(), &st)==0) chmod(copy.dest.str().c_str(), st.st_mode&0777); + if(!copy.link.empty()) + { + FS::Path relpath = FS::relative(copy.dest, FS::dirname(copy.link)); + symlink(relpath.str().c_str(), copy.link.str().c_str()); + } + done = true; } diff --git a/source/copy.h b/source/copy.h index c8917c3..bc4c173 100644 --- a/source/copy.h +++ b/source/copy.h @@ -28,9 +28,10 @@ private: Msp::FS::Path src; Msp::FS::Path dest; + Msp::FS::Path link; public: - Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &); + Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &, const Msp::FS::Path & =Msp::FS::Path()); }; #endif diff --git a/source/install.cpp b/source/install.cpp index 6f6bca3..f0cce23 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -19,6 +19,13 @@ Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::s { buildable = true; add_depend(&source); + + if(const SharedLibrary *shlib = dynamic_cast(&source)) + if(!shlib->get_soname().empty()) + link = FS::dirname(path)/FS::basename(shlib->get_path()); + + if(!link.empty()) + builder.register_path(link, this); } Target *Install::get_real_target() @@ -38,7 +45,7 @@ void Install::check_rebuild() Action *Install::create_action() { - return new Copy(builder, *package, source.get_path(), path); + return new Copy(builder, *package, source.get_path(), path, link); } FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc) diff --git a/source/install.h b/source/install.h index d20a322..0cc0fb8 100644 --- a/source/install.h +++ b/source/install.h @@ -11,6 +11,7 @@ class Install: public FileTarget { private: FileTarget &source; + Msp::FS::Path link; public: Install(Builder &, const SourcePackage &, FileTarget &, const std::string & =std::string()); diff --git a/source/makesymlink.cpp b/source/makesymlink.cpp deleted file mode 100644 index 6286bac..0000000 --- a/source/makesymlink.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include "builder.h" -#include "package.h" -#include "makesymlink.h" -#include "symlink.h" - -using namespace Msp; - -MakeSymlink::MakeSymlink(Builder &b, const Symlink &sl): - Action(b) -{ - FS::Path relpath = FS::relative(sl.get_target().get_path(), FS::dirname(sl.get_path())); - - announce(sl.get_package()->get_name(), "LN", sl.get_path().str()); - if(builder.get_verbose()>=2) - IO::print("%s -> %s\n", sl.get_name(), relpath.str()); - - if(!builder.get_dry_run()) - symlink(relpath.str().c_str(), sl.get_path().str().c_str()); -} - -int MakeSymlink::check() -{ - signal_done.emit(); - return 0; -} diff --git a/source/makesymlink.h b/source/makesymlink.h deleted file mode 100644 index 038dfd5..0000000 --- a/source/makesymlink.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MAKESYMLINK_H_ -#define MAKESYMLINK_H_ - -#include "action.h" - -class Symlink; - -class MakeSymlink: public Action -{ -public: - MakeSymlink(Builder &, const Symlink &); - virtual int check(); -}; - -#endif diff --git a/source/symlink.cpp b/source/symlink.cpp deleted file mode 100644 index 915dccb..0000000 --- a/source/symlink.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "makesymlink.h" -#include "symlink.h" - -using namespace std; -using namespace Msp; - -Symlink::Symlink(Builder &b, const Package &p, FileTarget &t, const string &n): - FileTarget(b, &p, FS::dirname(t.get_path())/n), - target(t) -{ - buildable = true; - add_depend(&target); -} - -Target *Symlink::get_buildable_target() -{ - return target.get_buildable_target(); -} - -Target *Symlink::get_real_target() -{ - return target.get_real_target(); -} - -void Symlink::check_rebuild() -{ - if(!mtime) - mark_rebuild("Does not exist"); -} - -Action *Symlink::create_action() -{ - return new MakeSymlink(builder, *this); -} diff --git a/source/symlink.h b/source/symlink.h deleted file mode 100644 index 92ba0d2..0000000 --- a/source/symlink.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef SYMLINK_H_ -#define SYMLINK_H_ - -#include "filetarget.h" - -/** -Symbolic link. -*/ -class Symlink: public FileTarget -{ -private: - FileTarget ⌖ - bool relative; - -public: - Symlink(Builder &, const Package &, FileTarget &, const std::string &); - - virtual const char *get_type() const { return "Symlink";} - FileTarget &get_target() const { return target; } - virtual Target *get_buildable_target(); - virtual Target *get_real_target(); -private: - virtual void check_rebuild(); - virtual Action *create_action(); -}; - -#endif