From 172db6b81ecc2aa418729a6815b9134a685545fc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 30 Apr 2012 11:25:50 +0300 Subject: [PATCH] Better use of OOP in determining file install locations --- source/binary.cpp | 7 +++++++ source/datafile.cpp | 2 ++ source/header.h | 3 ++- source/installedfile.cpp | 28 ++-------------------------- source/pkgconfig.cpp | 2 ++ source/staticlibrary.cpp | 2 ++ source/target.h | 3 +++ 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index d73c594..709dbd1 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -19,6 +19,13 @@ Binary::Binary(Builder &b, const Component &c, const list &objs): buildable = true; for(list::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() diff --git a/source/datafile.cpp b/source/datafile.cpp index 3164d8e..5457a2b 100644 --- a/source/datafile.cpp +++ b/source/datafile.cpp @@ -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) diff --git a/source/header.h b/source/header.h index 466375f..445fc9c 100644 --- a/source/header.h +++ b/source/header.h @@ -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"; } }; diff --git a/source/installedfile.cpp b/source/installedfile.cpp index 2a96066..1750a15 100644 --- a/source/installedfile.cpp +++ b/source/installedfile.cpp @@ -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(&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(&tgt)) - mid = "bin"; - else if(const SharedLibrary *shlib = dynamic_cast(&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(&tgt)) - mid = "lib"; - else if(dynamic_cast(&tgt)) - mid = "lib/pkgconfig"; - else if(dynamic_cast(&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); diff --git a/source/pkgconfig.cpp b/source/pkgconfig.cpp index eb4fad0..cfac2cd 100644 --- a/source/pkgconfig.cpp +++ b/source/pkgconfig.cpp @@ -7,4 +7,6 @@ PkgConfig::PkgConfig(Builder &b, const SourcePackage &p): { buildable = true; tool = &builder.get_toolchain().get_tool("PCG"); + + install_location = "lib/pkgconfig"; } diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index f69f98f..c7fd781 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -13,6 +13,8 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list::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) diff --git a/source/target.h b/source/target.h index a47eb75..891d757 100644 --- a/source/target.h +++ b/source/target.h @@ -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; } -- 2.43.0