]> git.tdb.fi Git - builder.git/commitdiff
Rewrite ObjectFile::generate_target_path to make it more robust
authorMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 22:26:34 +0000 (01:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 23:30:04 +0000 (02:30 +0300)
source/objectfile.cpp
source/objectfile.h

index ea4421674b0632372e5bddfb8ae5f18782ec9c56..fff1309057916baefffe63bf4ce8192469796647 100644 (file)
@@ -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()
index b04e630823c046506a16be4bae913b882f840f67..990b16c029c16330ee09f1145c018499f2a0d490 100644 (file)
@@ -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"; }