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);
41 throw invalid_argument("DataTool::create_target");
42 list<FileTarget *> files;
43 for(Target *t: sources)
44 files.push_back(&dynamic_cast<FileTarget &>(*t));
45 DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
46 pack->set_tool(*this);
50 throw invalid_argument("DataTool::create_target");
53 string DataTool::create_build_signature(const BuildInfo &binfo) const
67 Task *DataTool::run(const Target &tgt) const
69 const Component &comp = *tgt.get_component();
70 FS::Path work_dir = comp.get_package().get_source_directory();
73 argv.push_back(executable->get_path().str());
76 argv.push_back(FS::relative(dynamic_cast<const FileTarget &>(tgt).get_path(), work_dir).str());
79 tgt.collect_build_info(binfo);
89 if(const DataCollection *coll = dynamic_cast<const DataCollection *>(&tgt))
92 argv.push_back(FS::relative(coll->get_source().get_path(), work_dir).str());
94 else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
97 for(const FileTarget *f: pack->get_files())
98 argv.push_back(FS::relative(f->get_path(), work_dir).str());
101 return new ExternalTask(argv, work_dir);