From b3ce9052ba98a4585aec75117265d170b7ccfdb8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Sep 2009 17:34:22 +0000 Subject: [PATCH] Add support for building datafiles --- source/component.cpp | 11 ++++++++++ source/component.h | 1 + source/datacompile.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ source/datacompile.h | 21 ++++++++++++++++++++ source/datafile.cpp | 31 +++++++++++++++++++++++++++++ source/datafile.h | 34 +++++++++++++++++++++++++++++++ source/install.cpp | 3 +++ source/sourcepackage.cpp | 1 + 8 files changed, 145 insertions(+) create mode 100644 source/datacompile.cpp create mode 100644 source/datacompile.h create mode 100644 source/datafile.cpp create mode 100644 source/datafile.h diff --git a/source/component.cpp b/source/component.cpp index de42d92..26ce710 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -13,6 +13,7 @@ Distributed under the LGPL #include #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(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) diff --git a/source/component.h b/source/component.h index 08bce23..1b32bfa 100644 --- a/source/component.h +++ b/source/component.h @@ -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 index 0000000..9e9a287 --- /dev/null +++ b/source/datacompile.cpp @@ -0,0 +1,43 @@ +/* $Id$ + +This file is part of builder +Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include +#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 index 0000000..b46ab96 --- /dev/null +++ b/source/datacompile.h @@ -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 index 0000000..66e610c --- /dev/null +++ b/source/datafile.cpp @@ -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 index 0000000..d76671c --- /dev/null +++ b/source/datafile.h @@ -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 diff --git a/source/install.cpp b/source/install.cpp index a0029ac..b5d70f4 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -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(&tgt)) mid="lib/pkgconfig"; + else if(dynamic_cast(&tgt)) + mid="share/"+tgt.get_package()->get_name(); if(mid.empty()) throw InvalidParameterValue("Don't know where to install "+tgtname); diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 6b52884..f5b9f09 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -222,6 +222,7 @@ SourcePackage::Loader::Loader(Package &p): add("module", &Loader::component); add("headers", &Loader::component); add("install", &Loader::component); + add("datafile", &Loader::component); add("tarball", &Loader::tarball); add("tar_file", &Loader::tar_file); } -- 2.45.2