]> git.tdb.fi Git - builder.git/commitdiff
Better use of OOP in determining file install locations
authorMikko Rasa <tdb@tdb.fi>
Mon, 30 Apr 2012 08:25:50 +0000 (11:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:49 +0000 (00:08 +0300)
source/binary.cpp
source/datafile.cpp
source/header.h
source/installedfile.cpp
source/pkgconfig.cpp
source/staticlibrary.cpp
source/target.h

index d73c59450f97501bcab4d32554fc33f9ef8724ce..709dbd16a52cfbd068d9c3733ca2f7671a2ebac6 100644 (file)
@@ -19,6 +19,13 @@ Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
        buildable = true;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
                add_depend(*i);
+
+       if(c.get_type()==Component::LIBRARY)
+               install_location = "lib";
+       else if(c.get_type()==Component::MODULE)
+               install_location = "lib/"+package->get_name();
+       else if(c.get_type()==Component::PROGRAM)
+               install_location = "bin";
 }
 
 void Binary::find_depends()
index 3164d8e38caeec5a532df9d8e402defe3e01fbf5..5457a2b98f883cde0174aa85cd54ffc0477f3e0b 100644 (file)
@@ -10,6 +10,8 @@ DataFile::DataFile(Builder &b, const Component &c, File &s):
 {
        buildable = true;
        add_depend(&source);
+
+       install_location = "share/"+package->get_name();
 }
 
 Msp::FS::Path DataFile::generate_target_path(const Component &comp)
index 466375f485635c2e463d87995f0214378cacd36e..445fc9c163b32e67caf2318fedf0afdcb34f8c15 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef HEADER_H_
 #define HEADER_H_
 
+#include "component.h"
 #include "sourcefile.h"
 
 /**
@@ -11,7 +12,7 @@ class Header: public SourceFile
 protected:
        Header(Builder &b, const std::string &f): SourceFile(b, f) { }
 public:
-       Header(Builder &b, const Component &c, const std::string &f): SourceFile(b, c, f) { }
+       Header(Builder &b, const Component &c, const std::string &f): SourceFile(b, c, f) { install_location = "include/"+c.get_name(); }
        virtual const char *get_type() const { return "Header"; }
 };
 
index 2a96066c9202e6deadcc5addfa842fe7b0783308..1750a15df6e97bcfc02a94da004666144d990644 100644 (file)
@@ -54,32 +54,8 @@ FS::Path InstalledFile::generate_target_path(const FileTarget &tgt, const std::s
        string mid;
        if(!loc.empty())
                mid = loc;
-       else if(const Header *hdr = dynamic_cast<const Header *>(&tgt))
-       {
-               if(hdr->get_component()->get_type()!=Component::HEADERS)
-                       throw logic_error("Header install from non-header component?");
-               mid = "include/"+hdr->get_component()->get_name();
-       }
-       else if(dynamic_cast<const Executable *>(&tgt))
-               mid = "bin";
-       else if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
-       {
-               const Component &comp = shlib->get_component();
-               if(comp.get_type()==Component::LIBRARY)
-               {
-                       mid = "lib";
-                       if(!shlib->get_soname().empty())
-                               tgtname = shlib->get_soname();
-               }
-               else if(comp.get_type()==Component::MODULE)
-                       mid = "lib/"+tgt.get_package()->get_name();
-       }
-       else if(dynamic_cast<const StaticLibrary *>(&tgt))
-               mid = "lib";
-       else if(dynamic_cast<const PkgConfig *>(&tgt))
-               mid = "lib/pkgconfig";
-       else if(dynamic_cast<const ::DataFile *>(&tgt))
-               mid = "share/"+tgt.get_package()->get_name();
+       else
+               mid = tgt.get_install_location();
 
        if(mid.empty())
                throw invalid_argument("Don't know where to install "+tgtname);
index eb4fad0c3ac9c24e412e2a89e561d9b18b341ebe..cfac2cded1e1712e304d94bdf6944a69cbeed560 100644 (file)
@@ -7,4 +7,6 @@ PkgConfig::PkgConfig(Builder &b, const SourcePackage &p):
 {
        buildable = true;
        tool = &builder.get_toolchain().get_tool("PCG");
+
+       install_location = "lib/pkgconfig";
 }
index f69f98f85fd141e7e0a386d7be01c6c3bf44780e..c7fd78157b5ead882954dd1274464949fa9fdedf 100644 (file)
@@ -13,6 +13,8 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list<ObjectFi
        buildable = true;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
                add_depend(*i);
+
+       install_location = "lib";
 }
 
 Msp::FS::Path StaticLibrary::generate_target_path(const Component &c)
index a47eb756f868cc0663939f7d255c6b31f3f15d8d..891d75752396471978048d65cb7ffefc2f49cecf 100644 (file)
@@ -33,6 +33,7 @@ protected:
        bool building;
        bool rebuild;
        std::string rebuild_reason;
+       std::string install_location;
 
        Dependencies depends;
        bool deps_ready;
@@ -69,6 +70,8 @@ public:
        bool is_buildable() const { return buildable; }
        bool get_rebuild() const { return rebuild; }
        const std::string &get_rebuild_reason() const { return rebuild_reason; }
+       bool is_installable() const { return !install_location.empty(); }
+       const std::string &get_install_location() const { return install_location; }
        void add_depend(Target *);
        const Dependencies &get_depends() const { return depends; }
        bool get_depends_ready() const { return deps_ready; }