]> git.tdb.fi Git - builder.git/commitdiff
Add support for building datafiles
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Sep 2009 17:34:22 +0000 (17:34 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 20 Sep 2009 17:34:22 +0000 (17:34 +0000)
source/component.cpp
source/component.h
source/datacompile.cpp [new file with mode: 0644]
source/datacompile.h [new file with mode: 0644]
source/datafile.cpp [new file with mode: 0644]
source/datafile.h [new file with mode: 0644]
source/install.cpp
source/sourcepackage.cpp

index de42d922404f995a186e80a6e62c5819faa59746..26ce71058dfd79edf38b5006e2d5620cd82261b3 100644 (file)
@@ -13,6 +13,7 @@ Distributed under the LGPL
 #include <msp/strings/lexicalcast.h>
 #include "builder.h"
 #include "component.h"
+#include "datafile.h"
 #include "executable.h"
 #include "file.h"
 #include "header.h"
@@ -136,6 +137,16 @@ void Component::create_targets() const
                        inst_list.push_back(ft);
                }
        }
+       else if(type==DATAFILE)
+       {
+               File *source;
+               if(Target *tgt=builder.get_target(files.front().str()))
+                       source=dynamic_cast<File *>(tgt);
+               else
+                       source=new File(builder, pkg, files.front());
+               ::DataFile *result=new ::DataFile(builder, *this, *source);
+               inst_list.push_back(result);
+       }
        else
        {
                for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
index 08bce237e5253c1c0c41d37b25c559bdde30e51b..1b32bfa10cf4dde67dd50ce33b6007f24d5f46d3 100644 (file)
@@ -51,6 +51,7 @@ public:
                LIBRARY,
                PROGRAM,
                MODULE,
+               DATAFILE,
                TARBALL,
                INSTALL
        };
diff --git a/source/datacompile.cpp b/source/datacompile.cpp
new file mode 100644 (file)
index 0000000..9e9a287
--- /dev/null
@@ -0,0 +1,43 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <msp/fs/dir.h>
+#include <msp/fs/utils.h>
+#include "builder.h"
+#include "component.h"
+#include "datacompile.h"
+#include "datafile.h"
+#include "file.h"
+#include "sourcepackage.h"
+
+using namespace Msp;
+
+DataCompile::DataCompile(Builder &b, ::DataFile &dfile):
+       ExternalAction(b)
+{
+       const Component &comp=dfile.get_component();
+
+       work_dir=comp.get_package().get_source();
+
+       argv.push_back("mspdatatool");
+       argv.push_back("-c");
+       argv.push_back("-b");
+
+       FS::Path opath=dfile.get_path();
+       argv.push_back("-o");
+       argv.push_back(relative(opath, work_dir).str());
+
+       FS::Path spath=dfile.get_source().get_path();
+       argv.push_back(relative(spath, work_dir).str());
+
+       if(!builder.get_dry_run())
+               FS::mkpath(FS::dirname(opath), 0755);
+
+       announce(comp.get_package().get_name(), "DATA", relative(opath, work_dir).str());
+
+       launch();
+}
diff --git a/source/datacompile.h b/source/datacompile.h
new file mode 100644 (file)
index 0000000..b46ab96
--- /dev/null
@@ -0,0 +1,21 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef DATACOMPILE_H_
+#define DATACOMPILE_H_
+
+#include "externalaction.h"
+
+class DataFile;
+
+class DataCompile: public ExternalAction
+{
+public:
+       DataCompile(Builder &, DataFile &);
+};
+
+#endif
diff --git a/source/datafile.cpp b/source/datafile.cpp
new file mode 100644 (file)
index 0000000..66e610c
--- /dev/null
@@ -0,0 +1,31 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "component.h"
+#include "datacompile.h"
+#include "datafile.h"
+#include "file.h"
+#include "sourcepackage.h"
+
+DataFile::DataFile(Builder &b, const Component &c, File &s):
+       FileTarget(b, &c.get_package(), generate_target_path(c)),
+       component(c),
+       source(s)
+{
+       buildable=true;
+       add_depend(&source);
+}
+
+Action *DataFile::create_action()
+{
+       return new DataCompile(builder, *this);
+}
+
+Msp::FS::Path DataFile::generate_target_path(const Component &comp)
+{
+       return comp.get_package().get_out_dir()/(comp.get_name()+".dat");
+}
diff --git a/source/datafile.h b/source/datafile.h
new file mode 100644 (file)
index 0000000..d76671c
--- /dev/null
@@ -0,0 +1,34 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef DATAFILE_H_
+#define DATAFILE_H_
+
+#include "filetarget.h"
+
+class Component;
+class File;
+
+class DataFile: public FileTarget
+{
+private:
+       const Component &component;
+       File &source;
+
+public:
+       DataFile(Builder &, const Component &, File &);
+
+       virtual const char *get_type() const { return "DataFile"; }
+       const Component &get_component() const { return component; }
+       File &get_source() const { return source; }
+
+private:
+       virtual Action *create_action();
+       static Msp::FS::Path generate_target_path(const Component &);
+};
+
+#endif
index a0029ac1eed33244fea945686d43347d3a8b6628..b5d70f45557fda665241fb67509b9929a509a59c 100644 (file)
@@ -9,6 +9,7 @@ Distributed under the LGPL
 #include "builder.h"
 #include "copy.h"
 #include "executable.h"
+#include "datafile.h"
 #include "header.h"
 #include "install.h"
 #include "package.h"
@@ -73,6 +74,8 @@ FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string
                mid="lib";
        else if(dynamic_cast<const PkgConfig *>(&tgt))
                mid="lib/pkgconfig";
+       else if(dynamic_cast<const ::DataFile *>(&tgt))
+               mid="share/"+tgt.get_package()->get_name();
 
        if(mid.empty())
                throw InvalidParameterValue("Don't know where to install "+tgtname);
index 6b52884d0af03d0adbf0049f3ca5316a3e3579f2..f5b9f09b533d7f4abbfc9336b4bddf91d6ea6bce 100644 (file)
@@ -222,6 +222,7 @@ SourcePackage::Loader::Loader(Package &p):
        add("module",      &Loader::component<Component::MODULE>);
        add("headers",     &Loader::component<Component::HEADERS>);
        add("install",     &Loader::component<Component::INSTALL>);
+       add("datafile",    &Loader::component<Component::DATAFILE>);
        add("tarball",     &Loader::tarball);
        add("tar_file",    &Loader::tar_file);
 }