From: Mikko Rasa Date: Sun, 6 May 2012 11:00:07 +0000 (+0300) Subject: Move the Component reference to Target and make it a pointer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=632361796a7ddadf8a726526c937fab22281fb7b;p=builder.git Move the Component reference to Target and make it a pointer Remove Package pointer from Target constructor --- diff --git a/source/binary.cpp b/source/binary.cpp index b3f0184..ff98644 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -13,22 +13,26 @@ using namespace std; using namespace Msp; Binary::Binary(Builder &b, const Component &c, const list &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::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(this)) libmode = DYNAMIC; list queue; list 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(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)); } } diff --git a/source/binary.h b/source/binary.h index 5239dc3..9f694d8 100644 --- a/source/binary.h +++ b/source/binary.h @@ -13,11 +13,8 @@ library. class Binary: public virtual FileTarget { protected: - const Component ∁ - Binary(Builder &, const Component &, const std::list &); 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 diff --git a/source/filetarget.cpp b/source/filetarget.cpp index decb4bf..2a60c29 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -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)) diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 3f56a2e..d75c627 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -42,7 +42,7 @@ Target *GnuArchiver::create_target(const list &sources, const string & Task *GnuArchiver::run(const Target &target) const { const StaticLibrary &lib = dynamic_cast(target); - const Component &comp = lib.get_component(); + const Component &comp = *lib.get_component(); vector argv; argv.push_back("ar"); diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index a8b07f8..43fb373 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -66,7 +66,7 @@ Task *GnuLinker::run(const Target &target) const vector argv; argv.push_back(command); - const Component &comp = bin.get_component(); + const Component &comp = *bin.get_component(); if(shlib) { diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index fac651a..c4f42e5 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -14,7 +14,7 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const listget_type()==Component::MODULE) { install_location += '/'; install_location += package->get_name(); diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index 13c4e67..45ec3df 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -7,9 +7,9 @@ using namespace std; StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list &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::const_iterator i=objs.begin(); i!=objs.end(); ++i) add_depend(*i); diff --git a/source/staticlibrary.h b/source/staticlibrary.h index 9d0bbad..a4dbf59 100644 --- a/source/staticlibrary.h +++ b/source/staticlibrary.h @@ -11,14 +11,10 @@ A static library target. */ class StaticLibrary: public Library { -private: - const Component ∁ - public: StaticLibrary(Builder &, const Component &, const std::list &); 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 &); }; diff --git a/source/target.cpp b/source/target.cpp index 7c6141d..c43ad99 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -10,9 +10,10 @@ 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), diff --git a/source/target.h b/source/target.h index 04c3c09..d0e68f5 100644 --- a/source/target.h +++ b/source/target.h @@ -8,6 +8,7 @@ #include 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 diff --git a/source/virtualtarget.cpp b/source/virtualtarget.cpp index 82abc90..3a3b254 100644 --- a/source/virtualtarget.cpp +++ b/source/virtualtarget.cpp @@ -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()