X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcegenerator.cpp;h=192ae289584b186461bd1442cbe1ce800391c7af;hb=69cd5cc73f466181420711fb907979de58687a4c;hp=76d6c892a20942647316b8c2eb8ac83629c215f0;hpb=9053d11310842cb9b8a0f13fe1d86b60cae5231c;p=builder.git diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp index 76d6c89..192ae28 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; @@ -57,6 +68,7 @@ Task *SourceGenerator::run(const Target &target) const vector args; 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) @@ -73,9 +85,16 @@ SourceGenerator::Loader::Loader(SourceGenerator &sg): DataFile::ObjectLoader(sg), ConditionalLoader(sg.package, format("%s/%s", sg.package.get_name(), sg.tag)) { + add("argument", &Loader::argument); add("command", &Loader::command); add("in_suffix", &Loader::in_suffix); add("out_suffix", &Loader::out_suffix); + add("processing_unit", static_cast(&SourceGenerator::processing_unit)); +} + +void SourceGenerator::Loader::argument(const string &a) +{ + obj.arguments.push_back(a); } void SourceGenerator::Loader::command(const string &c)