X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcegenerator.cpp;h=5123f09d0d0aad9b3e6603fd320b4b7ed92b3bf9;hb=f622661da16d5724a778f87c5be46fe9be8a6412;hp=9acd69658173657db5cc02d0f86094d247be1e63;hpb=445572ee2ea29141d5fb72153b6ce76fe9014d0d;p=builder.git diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp index 9acd696..5123f09 100644 --- a/source/sourcegenerator.cpp +++ b/source/sourcegenerator.cpp @@ -22,13 +22,21 @@ Target *SourceGenerator::create_source(const Component &comp, const FS::Path &pa Target *SourceGenerator::create_target(const list &sources, const string &) { - if(sources.size()!=1) + if(sources.empty()) throw invalid_argument("SourceGenerator::create_target"); + if(out_suffixes.empty()) + throw logic_error("No output suffixes"); TemplateFile &tmpl = dynamic_cast(*sources.front()); const Component *comp = tmpl.get_component(); const SourcePackage *pkg = tmpl.get_package(); - string base = FS::basepart(FS::basename(tmpl.get_path())); + 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 + base = comp->get_name(); Target *primary = 0; for(list::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i) @@ -39,12 +47,15 @@ Target *SourceGenerator::create_target(const list &sources, const stri FS::Path fn = pkg->get_temp_directory()/comp->get_name()/(base+*i); Target *target = tool->create_source(*comp, fn); target->set_tool(*this); - target->add_dependency(tmpl); + for(list::const_iterator j=sources.begin(); j!=sources.end(); ++j) + target->add_dependency(**j); if(primary) primary->add_side_effect(*target); else primary = target; } + else + throw runtime_error("No tool found for suffix "+*i); } return primary; @@ -64,6 +75,8 @@ Task *SourceGenerator::run(const Target &target) const if(const TemplateFile *tmpl = dynamic_cast(*i)) args.push_back(FS::relative(tmpl->get_path(), work_dir).str()); + if(!out_argument.empty()) + args.push_back(out_argument); args.push_back(FS::relative(out_src.get_path(), work_dir).str()); return new ExternalTask(args, work_dir); @@ -75,9 +88,12 @@ SourceGenerator::Loader::Loader(SourceGenerator &sg): ConditionalLoader(sg.package, format("%s/%s", sg.package.get_name(), sg.tag)) { add("argument", &Loader::argument); + add("arguments", &Loader::arguments); add("command", &Loader::command); add("in_suffix", &Loader::in_suffix); + add("out_argument", &SourceGenerator::out_argument); add("out_suffix", &Loader::out_suffix); + add("processing_unit", static_cast(&SourceGenerator::processing_unit)); } void SourceGenerator::Loader::argument(const string &a) @@ -85,9 +101,17 @@ void SourceGenerator::Loader::argument(const string &a) obj.arguments.push_back(a); } +void SourceGenerator::Loader::arguments(const vector &a) +{ + obj.arguments.insert(obj.arguments.end(), a.begin(), a.end()); +} + void SourceGenerator::Loader::command(const string &c) { - obj.set_command((obj.package.get_source_directory()/c).str()); + if(c.find('/')!=string::npos) + obj.set_command((obj.package.get_source_directory()/c).str()); + else + obj.set_command(c); } void SourceGenerator::Loader::in_suffix(const string &s)