X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcegenerator.cpp;h=5123f09d0d0aad9b3e6603fd320b4b7ed92b3bf9;hb=HEAD;hp=c7a4f92204c214e2b9b5877d1cf258fefa4f9eb0;hpb=ae85358a5f3d408f9886f58c8cdb2c6c92c3a25a;p=builder.git diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp deleted file mode 100644 index c7a4f92..0000000 --- a/source/sourcegenerator.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include -#include "builder.h" -#include "executable.h" -#include "externaltask.h" -#include "sourcegenerator.h" -#include "sourcepackage.h" -#include "templatefile.h" - -using namespace std; -using namespace Msp; - -SourceGenerator::SourceGenerator(Builder &b, const SourcePackage &p, const string &t): - Tool(b, t), - package(p) -{ } - -Target *SourceGenerator::create_source(const Component &comp, const FS::Path &path) const -{ - return new TemplateFile(builder, comp, path); -} - -Target *SourceGenerator::create_target(const list &sources, const string &) -{ - 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; - 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) - { - Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true); - if(tool) - { - FS::Path fn = pkg->get_temp_directory()/comp->get_name()/(base+*i); - 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); - if(primary) - primary->add_side_effect(*target); - else - primary = target; - } - else - throw runtime_error("No tool found for suffix "+*i); - } - - return primary; -} - -Task *SourceGenerator::run(const Target &target) const -{ - const SourceFile &out_src = dynamic_cast(target); - const FS::Path &work_dir = out_src.get_package()->get_source_directory(); - - 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) - 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); -} - - -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_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) -{ - obj.arguments.push_back(a); -} - -void SourceGenerator::Loader::command(const string &c) -{ - 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) -{ - obj.input_suffixes.push_back(s); -} - -void SourceGenerator::Loader::out_suffix(const string &s) -{ - obj.out_suffixes.push_back(s); -}