]> git.tdb.fi Git - builder.git/blobdiff - source/datatool.cpp
Refactor transitive dependencies to work on all targets
[builder.git] / source / datatool.cpp
diff --git a/source/datatool.cpp b/source/datatool.cpp
deleted file mode 100644 (file)
index 1bc629e..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <stdexcept>
-#include <msp/fs/utils.h>
-#include "builder.h"
-#include "component.h"
-#include "datacollection.h"
-#include "datapack.h"
-#include "datatool.h"
-#include "datatransform.h"
-#include "externaltask.h"
-#include "sourcepackage.h"
-
-using namespace std;
-using namespace Msp;
-
-DataTool::DataTool(Builder &b):
-       Tool(b, "DATA")
-{
-       set_command("mspdatatool");
-       set_run(_run);
-       input_suffixes.push_back(".mdt");
-}
-
-Target *DataTool::create_source(const Component &comp, const FS::Path &path) const
-{
-       return new DataTransform(builder, comp, path);
-}
-
-Target *DataTool::create_target(const vector<Target *> &sources, const string &arg)
-{
-       if(arg=="collection")
-       {
-               if(sources.size()!=1)
-                       throw invalid_argument("DataTool::create_target");
-               DataTransform &source = dynamic_cast<DataTransform &>(*sources.front());
-               DataCollection *coll = new DataCollection(builder, *source.get_component(), source);
-               coll->set_tool(*this);
-               return coll;
-       }
-       else if(arg=="pack")
-       {
-               if(sources.empty())
-                       throw invalid_argument("DataTool::create_target");
-               vector<FileTarget *> files;
-               files.reserve(sources.size());
-               for(Target *t: sources)
-                       files.push_back(&dynamic_cast<FileTarget &>(*t));
-               DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
-               pack->set_tool(*this);
-               return pack;
-       }
-       else
-               throw invalid_argument("DataTool::create_target");
-}
-
-string DataTool::create_build_signature(const BuildInfo &binfo) const
-{
-       string result = Tool::create_build_signature(binfo);
-       if(binfo.debug || binfo.optimize)
-               result += ',';
-       if(binfo.debug)
-               result += 'g';
-       if(binfo.optimize>0)
-       {
-               result += 'b';
-               if(binfo.optimize>1)
-                       result += 'z';
-       }
-       return result;
-}
-
-Task *DataTool::_run(const Target &tgt)
-{
-       const Tool &tool = *tgt.get_tool();
-       const Component &comp = *tgt.get_component();
-       FS::Path work_dir = comp.get_package().get_source_directory();
-
-       vector<string> argv;
-       argv.push_back(tool.get_executable()->get_path().str());
-
-       argv.push_back("-o");
-       argv.push_back(FS::relative(dynamic_cast<const FileTarget &>(tgt).get_path(), work_dir).str());
-
-       BuildInfo binfo;
-       tgt.collect_build_info(binfo);
-       if(binfo.debug)
-               argv.push_back("-g");
-       if(binfo.optimize>0)
-       {
-               argv.push_back("-b");
-               if(binfo.optimize>1)
-                       argv.push_back("-z");
-       }
-
-       if(const DataCollection *coll = dynamic_cast<const DataCollection *>(&tgt))
-       {
-               argv.push_back("-c");
-               argv.push_back(FS::relative(coll->get_source().get_path(), work_dir).str());
-       }
-       else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
-       {
-               argv.push_back("-p");
-               for(const FileTarget *f: pack->get_files())
-                       argv.push_back(FS::relative(f->get_path(), work_dir).str());
-       }
-
-       return new ExternalTask(argv, work_dir);
-}