2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
6 #include "datacollection.h"
9 #include "datatransform.h"
10 #include "externaltask.h"
11 #include "sourcepackage.h"
16 DataTool::DataTool(Builder &b):
19 executable = builder.get_vfs().find_binary("mspdatatool");
21 builder.problem(string(), format("Can't find executable mspdatatool for tool %s", tag));
23 input_suffixes.push_back(".mdt");
26 Target *DataTool::create_source(const Component &comp, const FS::Path &path) const
28 return new DataTransform(builder, comp, path);
31 Target *DataTool::create_target(const list<Target *> &sources, const string &arg) const
36 throw invalid_argument("DataTool::create_target");
37 DataTransform &source = dynamic_cast<DataTransform &>(*sources.front());
38 DataCollection *coll = new DataCollection(builder, *source.get_component(), source);
39 coll->set_tool(*this);
44 list<FileTarget *> files;
45 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
46 files.push_back(&dynamic_cast<FileTarget &>(**i));
47 DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
48 pack->set_tool(*this);
52 throw invalid_argument("DataTool::create_target");
55 Task *DataTool::run(const Target &tgt) const
57 const Component &comp = *tgt.get_component();
58 FS::Path work_dir = comp.get_package().get_source_directory();
61 argv.push_back(executable->get_path().str());
64 argv.push_back(FS::relative(dynamic_cast<const FileTarget &>(tgt).get_path(), work_dir).str());
66 const BuildInfo &binfo = comp.get_build_info();
76 if(const DataCollection *coll = dynamic_cast<const DataCollection *>(&tgt))
79 argv.push_back(FS::relative(coll->get_source().get_path(), work_dir).str());
81 else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
84 const DataPack::FileList &files = pack->get_files();
85 for(DataPack::FileList::const_iterator i=files.begin(); i!=files.end(); ++i)
86 argv.push_back(FS::relative((*i)->get_path(), work_dir).str());
89 return new ExternalTask(argv, work_dir);