From f0c501af5d99233efd3a45076ffbe69a71294863 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 9 Jul 2012 01:58:36 +0300 Subject: [PATCH] Put constructor helper functions next to the constructors --- source/datafile.h | 6 +++--- source/executable.h | 5 +++-- source/filetarget.cpp | 38 +++++++++++++++++++------------------- source/filetarget.h | 5 +++-- source/installedfile.cpp | 28 ++++++++++++++-------------- source/installedfile.h | 6 ++++-- source/objectfile.cpp | 25 ++++++++++++------------- source/objectfile.h | 6 ++++-- source/sharedlibrary.h | 6 +++--- source/staticlibrary.h | 5 +++-- 10 files changed, 68 insertions(+), 62 deletions(-) diff --git a/source/datafile.h b/source/datafile.h index 071a82b..0ba501c 100644 --- a/source/datafile.h +++ b/source/datafile.h @@ -14,13 +14,13 @@ private: public: DataFile(Builder &, const Component &, File &); +private: + static Msp::FS::Path generate_target_path(const Component &); +public: virtual const char *get_type() const { return "DataFile"; } const Component &get_component() const { return component; } File &get_source() const { return source; } - -private: - static Msp::FS::Path generate_target_path(const Component &); }; #endif diff --git a/source/executable.h b/source/executable.h index d235e29..967aaf9 100644 --- a/source/executable.h +++ b/source/executable.h @@ -8,10 +8,11 @@ class Executable: public Binary public: Executable(Builder &, const Msp::FS::Path &); Executable(Builder &, const Component &, const std::list &); - - virtual const char *get_type() const { return "Executable"; } private: static std::string generate_filename(const Component &); + +public: + virtual const char *get_type() const { return "Executable"; } }; #endif diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 1c61810..634b297 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -25,6 +25,25 @@ FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): } } +string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) +{ + if(pkg) + { + if(FS::descendant_depth(pth, pkg->get_source())>=0) + { + 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) + { + FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix()); + return ""+relpath.str().substr(1); + } + } + + return pth.str(); +} + void FileTarget::touch() { mtime = Time::now(); @@ -53,22 +72,3 @@ void FileTarget::check_rebuild() if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime) mark_rebuild("Package options changed"); } - -string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) -{ - if(pkg) - { - if(FS::descendant_depth(pth, pkg->get_source())>=0) - { - 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) - { - FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix()); - return ""+relpath.str().substr(1); - } - } - - return pth.str(); -} diff --git a/source/filetarget.h b/source/filetarget.h index 7d42c91..22df520 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -16,6 +16,9 @@ protected: unsigned size; FileTarget(Builder &, const SourcePackage *, const Msp::FS::Path &); +private: + static std::string generate_name(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; } @@ -28,8 +31,6 @@ public: protected: virtual void check_rebuild(); -private: - static std::string generate_name(const SourcePackage *, const Msp::FS::Path &); }; #endif diff --git a/source/installedfile.cpp b/source/installedfile.cpp index 4ee821f..3ca4906 100644 --- a/source/installedfile.cpp +++ b/source/installedfile.cpp @@ -20,6 +20,20 @@ InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, builder.get_vfs().register_path(link, this); } +FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc) +{ + if(!tgt.is_installable() && loc.empty()) + throw invalid_argument(tgt.get_name()+" is not installable"); + + string mid; + if(!loc.empty()) + mid = loc; + else + mid = tgt.get_install_location(); + + return prefix/mid/FS::basename(tgt.get_path()); +} + Target *InstalledFile::get_real_target() { return source.get_real_target(); @@ -34,17 +48,3 @@ void InstalledFile::check_rebuild() else if(source.needs_rebuild()) mark_rebuild(source.get_name()+" needs rebuilding"); } - -FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc) -{ - if(!tgt.is_installable() && loc.empty()) - throw invalid_argument(tgt.get_name()+" is not installable"); - - string mid; - if(!loc.empty()) - mid = loc; - else - mid = tgt.get_install_location(); - - return prefix/mid/FS::basename(tgt.get_path()); -} diff --git a/source/installedfile.h b/source/installedfile.h index ef76ae7..0b9a455 100644 --- a/source/installedfile.h +++ b/source/installedfile.h @@ -15,14 +15,16 @@ private: public: InstalledFile(Builder &, const SourcePackage &, FileTarget &, const std::string & =std::string()); +private: + static Msp::FS::Path generate_target_path(const Msp::FS::Path &, const FileTarget &i, const std::string &); + +public: virtual const char *get_type() const { return "InstalledFile"; } FileTarget &get_source() const { return source; } const Msp::FS::Path &get_symlink() const { return link; } virtual Target *get_real_target(); private: virtual void check_rebuild(); - - static Msp::FS::Path generate_target_path(const Msp::FS::Path &, const FileTarget &i, const std::string &); }; #endif diff --git a/source/objectfile.cpp b/source/objectfile.cpp index a27c067..7db1b2d 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -17,6 +17,18 @@ ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): add_depend(&source); } +FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src) +{ + const SourcePackage &pkg = comp.get_package(); + string fn = FS::basepart(src)+".o"; + if(!fn.compare(0, 2, "./")) + fn.erase(0, 2); + for(string::iterator i=fn.begin(); i!=fn.end(); ++i) + if(*i=='/') + *i = '_'; + return pkg.get_temp_dir()/comp.get_name()/fn; +} + void ObjectFile::find_depends() { for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) @@ -26,7 +38,6 @@ void ObjectFile::find_depends() } } - void ObjectFile::find_depends(FileTarget *tgt) { FileTarget *rtgt = dynamic_cast(tgt->get_real_target()); @@ -61,15 +72,3 @@ void ObjectFile::find_depends(FileTarget *tgt) if(find(depends.begin(), depends.end(), *i)==depends.end()) add_depend(*i); } - -FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src) -{ - const SourcePackage &pkg = comp.get_package(); - string fn = FS::basepart(src)+".o"; - if(!fn.compare(0, 2, "./")) - fn.erase(0, 2); - for(string::iterator i=fn.begin(); i!=fn.end(); ++i) - if(*i=='/') - *i = '_'; - return pkg.get_temp_dir()/comp.get_name()/fn; -} diff --git a/source/objectfile.h b/source/objectfile.h index af47c66..9754095 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -17,6 +17,10 @@ private: public: ObjectFile(Builder &, const Component &, SourceFile &); +private: + static Msp::FS::Path generate_target_path(const Component &, const std::string &); + +public: virtual const char *get_type() const { return "ObjectFile"; } const Component &get_component() const { return comp; } SourceFile &get_source() const { return source; } @@ -29,8 +33,6 @@ public: private: /** Recursively looks for header targets and adds them as dependencies. */ void find_depends(FileTarget *); - - static Msp::FS::Path generate_target_path(const Component &, const std::string &); }; #endif diff --git a/source/sharedlibrary.h b/source/sharedlibrary.h index 076cfdb..5331ef5 100644 --- a/source/sharedlibrary.h +++ b/source/sharedlibrary.h @@ -18,13 +18,13 @@ private: public: SharedLibrary(Builder &, const Msp::FS::Path &); SharedLibrary(Builder &, const Component &, const std::list &); +private: + static std::string generate_filename(const Component &); +public: 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: - static std::string generate_filename(const Component &); }; #endif diff --git a/source/staticlibrary.h b/source/staticlibrary.h index 451e9f8..033e98a 100644 --- a/source/staticlibrary.h +++ b/source/staticlibrary.h @@ -14,10 +14,11 @@ 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"; } private: static std::string generate_filename(const Component &); + +public: + virtual const char *get_type() const { return "StaticLibrary"; } }; #endif -- 2.45.2