X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finstallmap.cpp;h=8f1995bc905c3a4a6d38dfea113958570191712e;hb=bc85cc286c8a3f1055f1979a7ff8697cf1b61912;hp=22d92b1586751d96943dfe73b675a6d75c112318;hpb=e0c863681c8a5fad5918bb7730ecbc65fbdfbc64;p=builder.git diff --git a/source/installmap.cpp b/source/installmap.cpp index 22d92b1..8f1995b 100644 --- a/source/installmap.cpp +++ b/source/installmap.cpp @@ -1,6 +1,9 @@ #include +#include "component.h" #include "filetarget.h" #include "installmap.h" +#include "sourcepackage.h" +#include "templatefile.h" using namespace std; using namespace Msp; @@ -15,7 +18,40 @@ void InstallMap::add_mapping(const FS::Path &src, const FS::Path &inst) FS::Path InstallMap::get_install_location(const FileTarget &target) const { - const FS::Path &source = target.get_path(); + const Component *comp = target.get_component(); + unsigned overlay_depth = 0; + if(comp && !comp->get_overlays().empty()) + { + // Check if the target resides in an overlay directory + const Component::OverlayList &overlays = comp->get_overlays(); + 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; + } + + 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 + const Target::Dependencies &deps = target.get_dependencies(); + for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) + if(const TemplateFile *tmpl = dynamic_cast(*i)) + { + 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) { @@ -25,7 +61,7 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const FS::Path install_base = FS::common_ancestor(install, i->install); if(install_base.size()>1) { - install = i->install/FS::dirname(source).subpath(i->source.size()); + install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth); break; } }