X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finstallmap.cpp;h=448f997b2e0822381707238e556be304a7c808d2;hb=3043044d8ef02ef77def454fdede87927f5aa1f8;hp=942b932b98c29babf1fd0d59eb090d53cb1cda30;hpb=c51e8844f19c31b2809ba459a1659d3b94a86f89;p=builder.git diff --git a/source/installmap.cpp b/source/installmap.cpp index 942b932..448f997 100644 --- a/source/installmap.cpp +++ b/source/installmap.cpp @@ -1,7 +1,10 @@ +#include #include #include "component.h" #include "filetarget.h" #include "installmap.h" +#include "sourcepackage.h" +#include "templatefile.h" using namespace std; using namespace Msp; @@ -20,24 +23,43 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const unsigned overlay_depth = 0; if(comp && !comp->get_overlays().empty()) { - const Component::OverlayList &overlays = comp->get_overlays(); + // Check if the target resides in an overlay directory string last_dir = FS::basename(FS::dirname(target.get_path())); - for(Component::OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i) - if(last_dir==*i) - overlay_depth = 1; + if(any_equals(comp->get_overlays(), last_dir)) + overlay_depth = 1; } - const FS::Path &source = target.get_path(); + FS::Path source = target.get_path(); + if(comp) + { + /* Check if the target is a generated source file, residing in the + temporary directory */ + const SourcePackage &pkg = comp->get_package(); + int temp_depth = FS::descendant_depth(source, pkg.get_temp_directory()); + if(temp_depth>0) + { + // If it is, use the generating template's directory instead + for(Target *d: target.get_dependencies()) + if(const TemplateFile *tmpl = dynamic_cast(d)) + { + source = FS::dirname(tmpl->get_path())/FS::basename(source); + break; + } + } + } + + /* Look for a mapping entry matching both the target's original location + and default install location */ FS::Path install = target.get_install_location(); - for(list::const_iterator i=entries.begin(); i!=entries.end(); ++i) + for(const Entry &e: entries) { - int source_depth = FS::descendant_depth(source, i->source); + int source_depth = FS::descendant_depth(source, e.source); if(source_depth>=0) { - FS::Path install_base = FS::common_ancestor(install, i->install); + FS::Path install_base = FS::common_ancestor(install, e.install); if(install_base.size()>1) { - install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth); + install = e.install/source.subpath(e.source.size(), source_depth-1-overlay_depth); break; } }