X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcegenerator.cpp;h=f4b43a82c8c32e7ffa016f9a57f00004174f5875;hb=7c2db9e2b91da953701be233336c5bfa1f3c4af0;hp=5123f09d0d0aad9b3e6603fd320b4b7ed92b3bf9;hpb=f622661da16d5724a778f87c5be46fe9be8a6412;p=builder.git diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp index 5123f09..f4b43a8 100644 --- a/source/sourcegenerator.cpp +++ b/source/sourcegenerator.cpp @@ -30,32 +30,40 @@ Target *SourceGenerator::create_target(const list &sources, const stri TemplateFile &tmpl = dynamic_cast(*sources.front()); const Component *comp = tmpl.get_component(); const SourcePackage *pkg = tmpl.get_package(); + FS::Path subdir; string base; - if(processing_unit==ONE_FILE) - base = FS::basepart(FS::basename(tmpl.get_path())); - else if(processing_unit==DIRECTORY) - base = FS::basename(FS::dirname(tmpl.get_path())); - else + if(processing_unit==COMPONENT) base = comp->get_name(); + else + { + subdir = FS::dirname(FS::relative(tmpl.get_path(), pkg->get_source_directory())); + if(processing_unit==ONE_FILE) + base = FS::basepart(FS::basename(tmpl.get_path())); + else if(processing_unit==DIRECTORY) + { + base = FS::basename(subdir); + subdir = FS::dirname(subdir); + } + } Target *primary = 0; - for(list::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i) + for(const string &s: out_suffixes) { - Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true); + Tool *tool = builder.get_toolchain().get_tool_for_suffix(s, true); if(tool) { - FS::Path fn = pkg->get_temp_directory()/comp->get_name()/(base+*i); + FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+s); Target *target = tool->create_source(*comp, fn); target->set_tool(*this); - for(list::const_iterator j=sources.begin(); j!=sources.end(); ++j) - target->add_dependency(**j); + for(Target *t: sources) + target->add_dependency(*t); if(primary) primary->add_side_effect(*target); else primary = target; } else - throw runtime_error("No tool found for suffix "+*i); + throw runtime_error("No tool found for suffix "+s); } return primary; @@ -70,9 +78,8 @@ Task *SourceGenerator::run(const Target &target) const args.push_back(executable->get_path().str()); args.insert(args.end(), arguments.begin(), arguments.end()); - 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)) + for(const Target *d: target.get_dependencies()) + if(const TemplateFile *tmpl = dynamic_cast(d)) args.push_back(FS::relative(tmpl->get_path(), work_dir).str()); if(!out_argument.empty())