]> git.tdb.fi Git - builder.git/commitdiff
Make symlink a feature of the Install target rather than a target on its own
authorMikko Rasa <tdb@tdb.fi>
Sat, 31 Mar 2012 10:51:23 +0000 (13:51 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 31 Mar 2012 10:51:23 +0000 (13:51 +0300)
source/component.cpp
source/copy.cpp
source/copy.h
source/install.cpp
source/install.h
source/makesymlink.cpp [deleted file]
source/makesymlink.h [deleted file]
source/symlink.cpp [deleted file]
source/symlink.h [deleted file]

index 4451a69f662f4074260520f4173eb98ec318dac8..c12399f670f944e2a22f953862f3763ba05ff795 100644 (file)
@@ -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<SharedLibrary *>(*i))
-                               if(!shlib->get_soname().empty())
-                                       inst_tgt->add_depend(new Symlink(builder, pkg, *inst, shlib->get_name()));
        }
 }
 
index 2c35ef30e1b1f3467421170df7f0f41525ffa318..8ea7f3537ab32d8e84aa2a3dd2731cf32ed1df1f 100644 (file)
 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;
 }
index c8917c371cbd57a117a95ec9492e0cad3e4dab6d..bc4c173b140be542a47f35ff91282c7a91e3e9cd 100644 (file)
@@ -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
index 6f6bca3432266ef1d4ee70950dea45f835aab946..f0cce2301c587729afff93cb4a3760d1b8b0b34d 100644 (file)
@@ -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<const SharedLibrary *>(&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)
index d20a32273ee49b37e311c764364a8936069fcbd2..0cc0fb8a178bdcc874389ecbb74f072fa7565902 100644 (file)
@@ -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 (file)
index 6286bac..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <unistd.h>
-#include <msp/fs/utils.h>
-#include <msp/io/print.h>
-#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 (file)
index 038dfd5..0000000
+++ /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 (file)
index 915dccb..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <msp/fs/utils.h>
-#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 (file)
index 92ba0d2..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef SYMLINK_H_
-#define SYMLINK_H_
-
-#include "filetarget.h"
-
-/**
-Symbolic link.
-*/
-class Symlink: public FileTarget
-{
-private:
-       FileTarget &target;
-       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