]> git.tdb.fi Git - builder.git/commitdiff
Get rid of the Library and SystemLibrary classes as unnecessary abstractions
authorMikko Rasa <tdb@tdb.fi>
Sun, 6 May 2012 11:25:11 +0000 (14:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:50 +0000 (00:08 +0300)
14 files changed:
source/binary.cpp
source/binary.h
source/builder.cpp
source/executable.cpp
source/gnulinker.cpp
source/library.cpp [deleted file]
source/library.h [deleted file]
source/sharedlibrary.cpp
source/sharedlibrary.h
source/staticlibrary.cpp
source/staticlibrary.h
source/systemlibrary.cpp [deleted file]
source/systemlibrary.h [deleted file]
source/virtualfilesystem.cpp

index ff98644ec53a6711ed3e63910a0876bd6447dc40..a809e64b0745341d21c4734cb60513cf8f0b6d2a 100644 (file)
 using namespace std;
 using namespace Msp;
 
+Binary::Binary(Builder &b, const FS::Path &p):
+       FileTarget(b, 0, p)
+{ }
+
 Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
        FileTarget(b, &c.get_package(), generate_target_path(c))
 {
@@ -23,7 +27,10 @@ Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
 void Binary::find_depends()
 {
        if(!component)
+       {
+               deps_ready = true;
                return;
+       }
 
        const SourcePackage &spkg = component->get_package();
        LibMode libmode = spkg.get_library_mode();
index 9f694d877dbc5e9218ce1cf0f5e60be18e977e3a..ef71a0691b6101df2661d59bf626a42e75978691 100644 (file)
@@ -10,9 +10,10 @@ class ObjectFile;
 Produces a binary file, which may be either a standalone executable or a shared
 library.
 */
-class Binary: public virtual FileTarget
+class Binary: public FileTarget
 {
 protected:
+       Binary(Builder &, const Msp::FS::Path &);
        Binary(Builder &, const Component &, const std::list<ObjectFile *> &);
 public:
        virtual void find_depends();
index 1bff8761dd49d2a4a1da3b1f2b2d90bc42a19970..0c39f6d48befd871ff7883ac7d53d72755723c47 100644 (file)
@@ -28,7 +28,6 @@
 #include "pkgconfiggenerator.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
-#include "systemlibrary.h"
 #include "tar.h"
 #include "task.h"
 #include "virtualtarget.h"
index 039267a0b86d9a3b5b7544e7c14d651ddbe09318..923ff8891ae53f8d65f00ca918b0f3279a89baff 100644 (file)
@@ -3,7 +3,6 @@
 #include "sourcepackage.h"
 
 Executable::Executable(Builder &b, const Component &c, const std::list<ObjectFile *> &objs):
-       FileTarget(b, &c.get_package(), generate_target_path(c)),
        Binary(b, c, objs)
 {
        install_location = "bin";
index 43fb373bf6f90236089d1bf4dd5997f79b5d218a..ad9de775f3acecf3534cf61b37b6b630fc2574ab 100644 (file)
@@ -50,7 +50,6 @@ Target *GnuLinker::create_target(const list<Target *> &sources, const std::strin
 Task *GnuLinker::run(const Target &target) const
 {
        const Binary &bin = dynamic_cast<const Binary &>(target);
-       const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin);
 
        string command = "gcc";
 
@@ -68,7 +67,7 @@ Task *GnuLinker::run(const Target &target) const
 
        const Component &comp = *bin.get_component();
 
-       if(shlib)
+       if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin))
        {
                argv.push_back("-shared");
                argv.push_back("-fPIC");
@@ -103,8 +102,8 @@ Task *GnuLinker::run(const Target &target) const
                        argv.push_back(relative(obj->get_path(), work_dir).str());
                else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
                        argv.push_back(stlib->get_path().str());
-               else if(Library *lib = dynamic_cast<Library *>(tgt))
-                       argv.push_back("-l"+lib->get_libname());
+               else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(tgt))
+                       argv.push_back("-l"+shlib->get_libname());
        }
 
        if(!builder.get_dry_run())
diff --git a/source/library.cpp b/source/library.cpp
deleted file mode 100644 (file)
index 9a19d51..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "library.h"
-
-Library::Library(Builder &b, const Package *p, const Msp::FS::Path &a, const std::string &l):
-       FileTarget(b, p, a),
-       libname(l)
-{ }
diff --git a/source/library.h b/source/library.h
deleted file mode 100644 (file)
index 040affe..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef LIBRARY_H_
-#define LIBRARY_H_
-
-#include "filetarget.h"
-
-class Library: public virtual FileTarget
-{
-protected:
-       std::string libname;
-
-       Library(Builder &, const Package *, const Msp::FS::Path &, const std::string &);
-public:
-       const std::string &get_libname() const { return libname; }
-};
-
-#endif
index c4f42e574ed7a484150966c063d9513d6bb72437..d3a8ceb25568e8f4077cc077f3deeb3dea69062a 100644 (file)
@@ -7,10 +7,17 @@
 using namespace std;
 using namespace Msp;
 
+SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
+       Binary(b, p)
+{
+       libname = FS::basepart(FS::basename(path));
+       if(!libname.compare(0, 3, "lib"))
+               libname = libname.substr(3);
+}
+
 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
-       FileTarget(b, &c.get_package(), generate_target_path(c)),
        Binary(b, c, objs),
-       Library(b, &c.get_package(), path, c.get_name()),
+       libname(c.get_name()),
        soname(create_soname(c))
 {
        install_location = "lib";
index 81c617e963a8862a8eecc770069ff82d46b80b57..3feb9aad19176affae9f72a993e09695dd0f3199 100644 (file)
@@ -2,20 +2,25 @@
 #define SHAREDLIB_H_
 
 #include "binary.h"
-#include "library.h"
 
 /**
-Represents a shared library.  Mainly exists to give extra information to the
-user.
+Represents a shared library.  It has two special properties: libname and
+soname.  Libname is the name used by the linker.  Soname is the canonical
+filename of the library, including version number.  If the owning package has
+no version, soname will be empty.
 */
-class SharedLibrary: public Binary, public Library
+class SharedLibrary: public Binary
 {
 private:
+       std::string libname;
        std::string soname;
 
 public:
+       SharedLibrary(Builder &, const Msp::FS::Path &);
        SharedLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
+
        virtual const char *get_type() const { return "SharedLibrary"; }
+       const std::string &get_libname() const { return libname; }
        const std::string &get_soname() const { return soname; }
 
 private:
index 45ec3df5b64a0251ae00506706f7b4ae81314de6..556ee54295963e8c55b7483947f6289160207da1 100644 (file)
@@ -4,10 +4,14 @@
 #include "staticlibrary.h"
 
 using namespace std;
+using namespace Msp;
+
+StaticLibrary::StaticLibrary(Builder &b, const FS::Path &p):
+       FileTarget(b, 0, p)
+{ }
 
 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())
+       FileTarget(b, &c.get_package(), generate_target_path(c))
 {
        component = &c;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
index a4dbf59d5c7f80c82e438a0a62b8005d604bd573..60b900587ecc22393070b8de7979967dfb20bdb7 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef STATICLIBRARY_H_
 #define STATICLIBRARY_H_
 
-#include "library.h"
+#include "filetarget.h"
 
 class Component;
 class ObjectFile;
@@ -9,9 +9,10 @@ class ObjectFile;
 /**
 A static library target.
 */
-class StaticLibrary: public Library
+class StaticLibrary: public FileTarget
 {
 public:
+       StaticLibrary(Builder &, const Msp::FS::Path &);
        StaticLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
 
        virtual const char *get_type() const { return "StaticLibrary"; }
diff --git a/source/systemlibrary.cpp b/source/systemlibrary.cpp
deleted file mode 100644 (file)
index 61bd810..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <msp/fs/path.h>
-#include <msp/fs/utils.h>
-#include "systemlibrary.h"
-
-using namespace std;
-using namespace Msp;
-
-SystemLibrary::SystemLibrary(Builder &b, const FS::Path &p):
-       FileTarget(b, 0, p),
-       Library(b, 0, p, extract_libname(p))
-{ }
-
-string SystemLibrary::extract_libname(const FS::Path &p)
-{
-       string result = FS::basepart(FS::basename(p));
-       if(!result.compare(0, 3, "lib"))
-               result.erase(0, 3);
-       return result;
-}
diff --git a/source/systemlibrary.h b/source/systemlibrary.h
deleted file mode 100644 (file)
index ee647ff..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef SYSTEMLIBRARY_H_
-#define SYSTEMLIBRARY_H_
-
-#include "library.h"
-
-/**
-A library that doesn't belong to any known package.
-*/
-class SystemLibrary: public Library
-{
-public:
-       SystemLibrary(Builder &, const Msp::FS::Path &);
-
-       virtual const char *get_type() const { return "SystemLibrary"; }
-private:
-       static std::string extract_libname(const Msp::FS::Path &);
-};
-
-#endif
index 7febdb62b78c58d3e3ca0813ea526d12284e6798..fe0159e857d61892ee7cc055bacedcc40d00b303 100644 (file)
@@ -5,7 +5,7 @@
 #include "csourcefile.h"
 #include "misc.h"
 #include "sharedlibrary.h"
-#include "systemlibrary.h"
+#include "staticlibrary.h"
 #include "virtualfilesystem.h"
 
 using namespace std;
@@ -168,7 +168,7 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa
                {
                        FileTarget *tgt = get_target(fn);
                        if(!tgt)
-                               return new SystemLibrary(builder, fn.str());
+                               return new SharedLibrary(builder, fn);
                        else if(mode==DYNAMIC || !tgt->get_package())
                                return tgt;
                }
@@ -182,7 +182,7 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa
                if(FileTarget *tgt = get_target(fn))
                        return tgt;
                else
-                       return new SystemLibrary(builder, fn.str());
+                       return new StaticLibrary(builder, fn);
        }
 
        return 0;