2 #include <msp/fs/utils.h>
5 #include "datacollection.h"
8 #include "datatransform.h"
9 #include "externaltask.h"
10 #include "sourcepackage.h"
15 DataTool::DataTool(Builder &b):
18 set_command("mspdatatool");
19 input_suffixes.push_back(".mdt");
22 Target *DataTool::create_source(const Component &comp, const FS::Path &path) const
24 return new DataTransform(builder, comp, path);
27 Target *DataTool::create_target(const list<Target *> &sources, const string &arg)
32 throw invalid_argument("DataTool::create_target");
33 DataTransform &source = dynamic_cast<DataTransform &>(*sources.front());
34 DataCollection *coll = new DataCollection(builder, *source.get_component(), source);
35 coll->set_tool(*this);
40 list<FileTarget *> files;
41 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
42 files.push_back(&dynamic_cast<FileTarget &>(**i));
43 DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
44 pack->set_tool(*this);
48 throw invalid_argument("DataTool::create_target");
51 string DataTool::create_build_signature(const BuildInfo &binfo) const
65 Task *DataTool::run(const Target &tgt) const
67 const Component &comp = *tgt.get_component();
68 FS::Path work_dir = comp.get_package().get_source_directory();
71 argv.push_back(executable->get_path().str());
74 argv.push_back(FS::relative(dynamic_cast<const FileTarget &>(tgt).get_path(), work_dir).str());
76 const BuildInfo &binfo = comp.get_build_info();
86 if(const DataCollection *coll = dynamic_cast<const DataCollection *>(&tgt))
89 argv.push_back(FS::relative(coll->get_source().get_path(), work_dir).str());
91 else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
94 const DataPack::FileList &files = pack->get_files();
95 for(DataPack::FileList::const_iterator i=files.begin(); i!=files.end(); ++i)
96 argv.push_back(FS::relative((*i)->get_path(), work_dir).str());
99 return new ExternalTask(argv, work_dir);