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 input_suffixes.push_back(".mdt");
21 Target *DataTool::create_source(const Component &comp, const FS::Path &path) const
23 return new DataTransform(builder, comp, path);
26 Target *DataTool::create_target(const list<Target *> &sources, const string &arg)
31 throw invalid_argument("DataTool::create_target");
32 DataTransform &source = dynamic_cast<DataTransform &>(*sources.front());
33 DataCollection *coll = new DataCollection(builder, *source.get_component(), source);
34 coll->set_tool(*this);
39 list<FileTarget *> files;
40 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
41 files.push_back(&dynamic_cast<FileTarget &>(**i));
42 DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
43 pack->set_tool(*this);
47 throw invalid_argument("DataTool::create_target");
50 void DataTool::do_prepare()
52 set_executable("mspdatatool");
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);