]> git.tdb.fi Git - builder.git/commitdiff
Move the Component reference to Target and make it a pointer
authorMikko Rasa <tdb@tdb.fi>
Sun, 6 May 2012 11:00:07 +0000 (14:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:50 +0000 (00:08 +0300)
Remove Package pointer from Target constructor

source/binary.cpp
source/binary.h
source/filetarget.cpp
source/gnuarchiver.cpp
source/gnulinker.cpp
source/sharedlibrary.cpp
source/staticlibrary.cpp
source/staticlibrary.h
source/target.cpp
source/target.h
source/virtualtarget.cpp

index b3f018488347fc090d57839a0a0cc7344eaf40e2..ff98644ec53a6711ed3e63910a0876bd6447dc40 100644 (file)
@@ -13,22 +13,26 @@ using namespace std;
 using namespace Msp;
 
 Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
-       FileTarget(b, &c.get_package(), generate_target_path(c)),
-       comp(c)
+       FileTarget(b, &c.get_package(), generate_target_path(c))
 {
+       component = &c;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
                add_depend(*i);
 }
 
 void Binary::find_depends()
 {
-       LibMode libmode = comp.get_package().get_library_mode();
+       if(!component)
+               return;
+
+       const SourcePackage &spkg = component->get_package();
+       LibMode libmode = spkg.get_library_mode();
        if(dynamic_cast<SharedLibrary *>(this))
                libmode = DYNAMIC;
 
        list<const Component *> queue;
        list<Target *> dep_libs;
-       queue.push_back(&comp);
+       queue.push_back(component);
        while(!queue.empty())
        {
                const Component *c = queue.front();
@@ -46,10 +50,10 @@ void Binary::find_depends()
 
                                lib = lib->get_real_target();
                                if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
-                                       queue.push_back(&stlib->get_component());
+                                       queue.push_back(stlib->get_component());
                        }
                        else
-                               builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, name));
+                               builder.problem(spkg.get_name(), format("Couldn't find library %s for %s", *i, name));
                }
        }
 
index 5239dc3fc0e06411df34d1f033b5c9b30abe82c8..9f694d877dbc5e9218ce1cf0f5e60be18e977e3a 100644 (file)
@@ -13,11 +13,8 @@ library.
 class Binary: public virtual FileTarget
 {
 protected:
-       const Component &comp;
-
        Binary(Builder &, const Component &, const std::list<ObjectFile *> &);
 public:
-       const Component &get_component() const { return comp; }
        virtual void find_depends();
 protected:
        /** Returns the path for the binary.  We can't do this in the constructor
index decb4bf793d68015066e1dede84f044e340ae836..2a60c2986bac2ec89f1454995f89283fe5d973da 100644 (file)
@@ -10,10 +10,12 @@ using namespace std;
 using namespace Msp;
 
 FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
-       Target(b, p, make_name(p, a)),
+       Target(b, make_name(p, a)),
        path(a),
        size(0)
 {
+       package = p;
+
        builder.get_vfs().register_path(path, this);
 
        if(FS::Stat st = FS::lstat(path))
index 3f56a2ea4e246e701bd4b18ade03104c4d797f3b..d75c627519694b03207847d3b0c671324c042546 100644 (file)
@@ -42,7 +42,7 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
 Task *GnuArchiver::run(const Target &target) const
 {
        const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
-       const Component &comp = lib.get_component();
+       const Component &comp = *lib.get_component();
 
        vector<string> argv;
        argv.push_back("ar");
index a8b07f8499bdc8307a8378a93c46147dbb70ad5e..43fb373bf6f90236089d1bf4dd5997f79b5d218a 100644 (file)
@@ -66,7 +66,7 @@ Task *GnuLinker::run(const Target &target) const
        vector<string> argv;
        argv.push_back(command);
 
-       const Component &comp = bin.get_component();
+       const Component &comp = *bin.get_component();
 
        if(shlib)
        {
index fac651a8e3518737187f817c0d4d14ee2575e036..c4f42e574ed7a484150966c063d9513d6bb72437 100644 (file)
@@ -14,7 +14,7 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFi
        soname(create_soname(c))
 {
        install_location = "lib";
-       if(comp.get_type()==Component::MODULE)
+       if(component->get_type()==Component::MODULE)
        {
                install_location += '/';
                install_location += package->get_name();
index 13c4e6798bbc519f100f7bde175f1dceecabdf8c..45ec3df5b64a0251ae00506706f7b4ae81314de6 100644 (file)
@@ -7,9 +7,9 @@ using namespace std;
 
 StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
        FileTarget(b, &c.get_package(), generate_target_path(c)),
-       Library(b, package, path, c.get_name()),
-       comp(c)
+       Library(b, package, path, c.get_name())
 {
+       component = &c;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
                add_depend(*i);
 
index 9d0bbadb08dcd268f56b3e143b5b6f00b46884f0..a4dbf59d5c7f80c82e438a0a62b8005d604bd573 100644 (file)
@@ -11,14 +11,10 @@ A static library target.
 */
 class StaticLibrary: public Library
 {
-private:
-       const Component &comp;
-
 public:
        StaticLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
 
        virtual const char *get_type() const { return "StaticLibrary"; }
-       const Component &get_component() const { return comp; }
 private:
        static Msp::FS::Path generate_target_path(const Component &);
 };
index 7c6141df7403b1978ccd32f8fdfa6ce911c10f74..c43ad99ea8361cb71934f3fb57a5f4dce27e23ff 100644 (file)
 using namespace std;
 using namespace Msp;
 
-Target::Target(Builder &b, const Package *p, const string &n):
+Target::Target(Builder &b, const string &n):
        builder(b),
-       package(p),
+       package(0),
+       component(0),
        name(n),
        tool(0),
        state(INIT),
index 04c3c09a3648876578e8b7e7794e64bb3e9b6bd5..d0e68f50588da69decb51b556dd633be63529c05 100644 (file)
@@ -8,6 +8,7 @@
 #include <msp/time/timestamp.h>
 
 class Builder;
+class Component;
 class Package;
 class Task;
 class Tool;
@@ -35,6 +36,7 @@ protected:
 
        Builder &builder;
        const Package *package;
+       const Component *component;
        std::string name;
 
        const Tool *tool;
@@ -45,13 +47,14 @@ protected:
        Dependencies depends;
        bool deps_ready;
 
-       Target(Builder &, const Package *, const std::string &);
+       Target(Builder &, const std::string &);
 public:
        virtual ~Target() { }
 
        virtual const char *get_type() const = 0;
        const std::string &get_name() const { return name; }
        const Package *get_package() const { return package; }
+       const Component *get_component() const { return component; }
 
        /**
        Tries to locate a target that will help getting this target built.  If all
index 82abc90734056778c73cce68e2a39d6645d1cb1d..3a3b254e99945e52245e3d1d06bb6e8047493e01 100644 (file)
@@ -7,7 +7,7 @@ using namespace std;
 using namespace Msp;
 
 VirtualTarget::VirtualTarget(Builder &b, const string &n):
-       Target(b, 0, n)
+       Target(b, n)
 { }
 
 void VirtualTarget::check_rebuild()