X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobjectfile.cpp;h=00fa6792859962e9a1a0b984bdde70b8c86bf3e4;hb=d1f9551e05c9d341149eb490e05b1465d3d6b711;hp=b308c2b34301bc51c81929b25df7e86a5d6fbfa1;hpb=4dc31cca056ea293d320928f61fef0558089d32d;p=builder.git diff --git a/source/objectfile.cpp b/source/objectfile.cpp index b308c2b..00fa679 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -1,21 +1,110 @@ -#include +#include +#include #include "builder.h" #include "component.h" #include "objectfile.h" -#include "package.h" #include "sourcefile.h" +#include "sourcepackage.h" using namespace std; using namespace Msp; -ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src): - Target(b, &c.get_package(), generate_target_name(c, src.get_name())), - comp(c) +ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): + FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())), + source(s) { - add_depend(&src); + component = &c; + add_dependency(source); } -string ObjectFile::generate_target_name(const Component &comp, const string &src) +FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &src) { - return (comp.get_package().get_source()/"temp"/comp.get_name()/(Path::splitext(src.substr(src.rfind('/')+1)).base+".o")).str(); + const SourcePackage &pkg = comp.get_package(); + FS::Path temp_dir = pkg.get_temp_directory(); + FS::Path rel_src; + if(FS::descendant_depth(src, temp_dir)>=0) + rel_src = FS::relative(src, temp_dir); + else + rel_src = FS::relative(src, pkg.get_source_directory()); + string fn; + for(const string &c: rel_src) + { + if(!fn.empty()) + fn += '_'; + if(c!=".") + fn += c; + } + const Architecture &arch = comp.get_package().get_builder().get_current_arch(); + return temp_dir/comp.get_name()/arch.create_filename(FS::basepart(fn)); +} + +void ObjectFile::set_used_in_shared_library(bool u) +{ + used_in_shlib = u; +} + +void ObjectFile::collect_build_info(BuildInfo &binfo) const +{ + Target::collect_build_info(binfo); + binfo.update_from(component->get_build_info_for_path(source.get_path())); +} + +void ObjectFile::find_dependencies() +{ + vector headers; + find_dependencies(source, headers); + for(FileTarget *h: headers) + { + add_dependency(*h); + if(h->get_real_target()->is_buildable()) + h->signal_modified.connect(sigc::mem_fun(this, static_cast(&ObjectFile::find_dependencies))); + } +} + +void ObjectFile::find_dependencies(FileTarget &tgt, vector &headers) +{ + tgt.prepare(); + + FileTarget *rtgt = dynamic_cast(tgt.get_real_target()); + Dependencies deps_to_add = rtgt->get_transitive_dependencies(); + if(rtgt!=&tgt) + { + FS::Path inst_dir = rtgt->get_component()->get_install_map().get_install_location(*rtgt); + /* The target has been displaced by installing it. Displace any + dependencies that come from the same package as well. */ + const SourcePackage *tpkg = rtgt->get_package(); + for(Target *&d: deps_to_add) + { + FileTarget *file = dynamic_cast(d); + if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0) + { + const Component *tcomp = file->get_component(); + FS::Path dep_inst = tcomp->get_install_map().get_install_location(*file); + FS::Path displaced = FS::dirname(tgt.get_path())/FS::relative(dep_inst, inst_dir)/FS::basename(file->get_path()); + d = builder.get_vfs().get_target(displaced); + if(!d) + { + /* If the target was in an overlay directory and the displaced + dependency is not found, try removing the overlay from the path. */ + string last_dir = FS::basename(FS::dirname(displaced)); + if(any_equals(tcomp->get_overlays(), last_dir)) + { + displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path()); + d = builder.get_vfs().get_target(displaced); + } + } + } + } + } + + for(Target *d: deps_to_add) + if(FileTarget *file = dynamic_cast(d)) + { + auto i = lower_bound(headers, file); + if(i==headers.end() || *i!=file) + { + headers.insert(i, file); + find_dependencies(*file, headers); + } + } }