From b211b655adb5940f1d8f78d4d86439d36c607704 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 17 Jul 2012 01:26:34 +0300 Subject: [PATCH] Rewrite ObjectFile::generate_target_path to make it more robust --- source/objectfile.cpp | 21 ++++++++++++--------- source/objectfile.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/objectfile.cpp b/source/objectfile.cpp index ea44216..fff1309 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -10,23 +10,26 @@ using namespace std; using namespace Msp; ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): - FileTarget(b, c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source_directory()).str())), + FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())), source(s) { component = &c; add_dependency(source); } -FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src) +FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &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; + FS::Path rel_src = FS::relative(src, pkg.get_source_directory()).str(); + string fn; + for(FS::Path::Iterator i=rel_src.begin(); i!=rel_src.end(); ++i) + { + if(!fn.empty()) + fn += '_'; + if(*i!=".") + fn += *i; + } + return pkg.get_temp_dir()/comp.get_name()/(FS::basepart(fn)+".o"); } void ObjectFile::find_dependencies() diff --git a/source/objectfile.h b/source/objectfile.h index b04e630..990b16c 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -16,7 +16,7 @@ private: public: ObjectFile(Builder &, const Component &, SourceFile &); private: - static Msp::FS::Path generate_target_path(const Component &, const std::string &); + static Msp::FS::Path generate_target_path(const Component &, const Msp::FS::Path &); public: virtual const char *get_type() const { return "ObjectFile"; } -- 2.43.0