From: Mikko Rasa Date: Sun, 6 May 2012 11:25:11 +0000 (+0300) Subject: Get rid of the Library and SystemLibrary classes as unnecessary abstractions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;ds=sidebyside;h=dc4b917034c9d3718f07139e2f0f3631a080c6f3;p=builder.git Get rid of the Library and SystemLibrary classes as unnecessary abstractions --- diff --git a/source/binary.cpp b/source/binary.cpp index ff98644..a809e64 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -12,6 +12,10 @@ 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 &objs): FileTarget(b, &c.get_package(), generate_target_path(c)) { @@ -23,7 +27,10 @@ Binary::Binary(Builder &b, const Component &c, const list &objs): void Binary::find_depends() { if(!component) + { + deps_ready = true; return; + } const SourcePackage &spkg = component->get_package(); LibMode libmode = spkg.get_library_mode(); diff --git a/source/binary.h b/source/binary.h index 9f694d8..ef71a06 100644 --- a/source/binary.h +++ b/source/binary.h @@ -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 &); public: virtual void find_depends(); diff --git a/source/builder.cpp b/source/builder.cpp index 1bff876..0c39f6d 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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" diff --git a/source/executable.cpp b/source/executable.cpp index 039267a..923ff88 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -3,7 +3,6 @@ #include "sourcepackage.h" Executable::Executable(Builder &b, const Component &c, const std::list &objs): - FileTarget(b, &c.get_package(), generate_target_path(c)), Binary(b, c, objs) { install_location = "bin"; diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 43fb373..ad9de77 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -50,7 +50,6 @@ Target *GnuLinker::create_target(const list &sources, const std::strin Task *GnuLinker::run(const Target &target) const { const Binary &bin = dynamic_cast(target); - const SharedLibrary *shlib = dynamic_cast(&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(&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(tgt)) argv.push_back(stlib->get_path().str()); - else if(Library *lib = dynamic_cast(tgt)) - argv.push_back("-l"+lib->get_libname()); + else if(SharedLibrary *shlib = dynamic_cast(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 index 9a19d51..0000000 --- a/source/library.cpp +++ /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 index 040affe..0000000 --- a/source/library.h +++ /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 diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index c4f42e5..d3a8ceb 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -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 &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"; diff --git a/source/sharedlibrary.h b/source/sharedlibrary.h index 81c617e..3feb9aa 100644 --- a/source/sharedlibrary.h +++ b/source/sharedlibrary.h @@ -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 &); + 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: diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index 45ec3df..556ee54 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -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 &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::const_iterator i=objs.begin(); i!=objs.end(); ++i) diff --git a/source/staticlibrary.h b/source/staticlibrary.h index a4dbf59..60b9005 100644 --- a/source/staticlibrary.h +++ b/source/staticlibrary.h @@ -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 &); virtual const char *get_type() const { return "StaticLibrary"; } diff --git a/source/systemlibrary.cpp b/source/systemlibrary.cpp deleted file mode 100644 index 61bd810..0000000 --- a/source/systemlibrary.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#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 index ee647ff..0000000 --- a/source/systemlibrary.h +++ /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 diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 7febdb6..fe0159e 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -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;