From: Mikko Rasa Date: Sun, 8 Jul 2012 22:50:23 +0000 (+0300) Subject: Binary packages can't have files, so avoid some dynamic casts X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ad88e1ba08cf798e5f87796021c947cf500a02e1;p=builder.git Binary packages can't have files, so avoid some dynamic casts --- diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 58c2b90..b040496 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -3,8 +3,8 @@ #include "analyzer.h" #include "builder.h" #include "objectfile.h" -#include "package.h" #include "sourcefile.h" +#include "sourcepackage.h" #include "target.h" #include "tool.h" diff --git a/source/copy.cpp b/source/copy.cpp index 5b524a4..0073320 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -19,8 +19,7 @@ Copy::Copy(Builder &b): Target *Copy::create_target(const list &sources, const string &arg) const { FileTarget &file_tgt = dynamic_cast(*sources.front()); - const SourcePackage &pkg = dynamic_cast(*file_tgt.get_package()); - InstalledFile *inst = new InstalledFile(builder, pkg, file_tgt, arg); + InstalledFile *inst = new InstalledFile(builder, *file_tgt.get_package(), file_tgt, arg); inst->set_tool(*this); return inst; } diff --git a/source/file.h b/source/file.h index 4f5618f..0e92b72 100644 --- a/source/file.h +++ b/source/file.h @@ -10,7 +10,7 @@ class File: public FileTarget { public: File(Builder &b, const Msp::FS::Path &t): FileTarget(b, 0, t) { } - File(Builder &b, Package &p, const Msp::FS::Path &t): FileTarget(b, &p, t) { } + File(Builder &b, SourcePackage &p, const Msp::FS::Path &t): FileTarget(b, &p, t) { } virtual const char *get_type() const { return "File"; } }; diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 6626db8..1c61810 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -9,7 +9,7 @@ using namespace std; using namespace Msp; -FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a): +FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): Target(b, generate_name(p, a)), path(a), size(0) @@ -50,18 +50,17 @@ void FileTarget::check_rebuild() } } - const SourcePackage *spkg = dynamic_cast(package); - if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime) + if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime) mark_rebuild("Package options changed"); } -string FileTarget::generate_name(const Package *pkg, const FS::Path &pth) +string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) { - if(const SourcePackage *spkg = dynamic_cast(pkg)) + if(pkg) { - if(FS::descendant_depth(pth, spkg->get_source())>=0) + if(FS::descendant_depth(pth, pkg->get_source())>=0) { - FS::Path relpath = FS::relative(pth, spkg->get_source()); + FS::Path relpath = FS::relative(pth, pkg->get_source()); return format("<%s>%s", pkg->get_name(), relpath.str().substr(1)); } else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0) diff --git a/source/filetarget.h b/source/filetarget.h index 32092d0..7d42c91 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -15,7 +15,7 @@ protected: Msp::Time::TimeStamp mtime; unsigned size; - FileTarget(Builder &, const Package *, const Msp::FS::Path &); + FileTarget(Builder &, const SourcePackage *, const Msp::FS::Path &); public: const Msp::FS::Path &get_path() const { return path; } const Msp::Time::TimeStamp &get_mtime() const { return mtime; } @@ -29,7 +29,7 @@ public: protected: virtual void check_rebuild(); private: - static std::string generate_name(const Package *, const Msp::FS::Path &); + static std::string generate_name(const SourcePackage *, const Msp::FS::Path &); }; #endif diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 39372a4..a27c067 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -42,7 +42,7 @@ void ObjectFile::find_depends(FileTarget *tgt) { /* The target has been displaced by installing it. Displace any dependencies that come from the same package as well. */ - const SourcePackage *tpkg = dynamic_cast(rtgt->get_package()); + const SourcePackage *tpkg = rtgt->get_package(); for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i) { FileTarget *file = dynamic_cast(*i); diff --git a/source/pkgconfiggenerator.cpp b/source/pkgconfiggenerator.cpp index f29ae4a..141b363 100644 --- a/source/pkgconfiggenerator.cpp +++ b/source/pkgconfiggenerator.cpp @@ -33,7 +33,7 @@ PkgConfigGenerator::Worker::Worker(const PkgConfigFile &t): void PkgConfigGenerator::Worker::main() { Builder &builder = target.get_package()->get_builder(); - const SourcePackage &spkg = dynamic_cast(*target.get_package()); + const SourcePackage &spkg = *target.get_package(); IO::BufferedFile out(target.get_path().str(), IO::M_WRITE); IO::print(out, "prefix=%s\n", builder.get_prefix().str()); diff --git a/source/tar.cpp b/source/tar.cpp index 49b4c08..3bcf3cb 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -19,9 +19,8 @@ Target *Tar::create_target(const list &sources, const string &arg) con { if(!sources.front()->get_package()) throw invalid_argument("Tar::create_target"); - const SourcePackage &src_pkg = dynamic_cast(*sources.front()->get_package()); - TarBall *tarball = new TarBall(builder, src_pkg, arg); + TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg); for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) tarball->add_depend(*i); diff --git a/source/target.cpp b/source/target.cpp index 095228b..43ecb7b 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -3,7 +3,7 @@ #include #include "builder.h" #include "filetarget.h" -#include "package.h" +#include "sourcepackage.h" #include "target.h" #include "task.h" #include "tool.h" diff --git a/source/target.h b/source/target.h index 88642dc..790a7e3 100644 --- a/source/target.h +++ b/source/target.h @@ -10,7 +10,7 @@ class Builder; class Component; -class Package; +class SourcePackage; class Task; class Tool; @@ -40,7 +40,7 @@ public: protected: Builder &builder; - const Package *package; + const SourcePackage *package; const Component *component; std::string name; @@ -57,7 +57,7 @@ public: virtual const char *get_type() const = 0; const std::string &get_name() const { return name; } - const Package *get_package() const { return package; } + const SourcePackage *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