X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsourcegenerator.cpp;h=5123f09d0d0aad9b3e6603fd320b4b7ed92b3bf9;hb=HEAD;hp=c09e5c7d9527c3b60f17ce2bcef6069fac239144;hpb=6140518acb736f9020005245686bfbc5fca2d329;p=builder.git diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp deleted file mode 100644 index c09e5c7..0000000 --- a/source/sourcegenerator.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#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.size()!=1) - throw invalid_argument("SourceGenerator::create_target"); - - 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())); - - 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); - target->add_dependency(tmpl); - if(primary) - primary->add_side_effect(*target); - else - primary = target; - } - } - - return primary; -} - -void SourceGenerator::do_prepare() -{ - FS::Path exe_fn = package.get_source_directory()/command; - executable = builder.get_vfs().get_target(exe_fn); - if(!executable) - executable = new Executable(builder, exe_fn); -} - -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()); - - 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()); - - 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) -{ - add("command", &Loader::command); - add("in_suffix", &Loader::in_suffix); - add("out_suffix", &Loader::out_suffix); -} - -void SourceGenerator::Loader::command(const string &c) -{ - 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); -}