From: Mikko Rasa Date: Mon, 11 May 2009 09:51:01 +0000 (+0000) Subject: Add a tarball component type X-Git-Tag: 1.0~14 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2edc25f87590bd81808792c3c38cab5ae8b94eb3;p=builder.git Add a tarball component type Turn the default tarball target into a component Deprecate tar_file statement from package config Make File take an Msp::FS::Path instead of an std::string Sort components so that targets will be created in the correct order --- diff --git a/Build b/Build index 6f8e838..2754b9e 100644 --- a/Build +++ b/Build @@ -5,10 +5,6 @@ package "builder" version "0.9"; description "Mikkosoft Productions software builder"; - tar_file "bootstrap.sh"; - tar_file "Readme.txt"; - tar_file "License.txt"; - require "mspcore"; require "mspstrings"; require "mspdatafile"; @@ -20,4 +16,11 @@ package "builder" source "source"; install true; }; + + tarball "@src" + { + source "bootstrap.sh"; + source "Readme.txt"; + source "License.txt"; + }; }; diff --git a/source/builder.cpp b/source/builder.cpp index de83759..b06b8ff 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -34,7 +34,6 @@ Distributed under the LGPL #include "sharedlibrary.h" #include "sourcepackage.h" #include "systemlibrary.h" -#include "tarball.h" #include "unlink.h" #include "virtualtarget.h" @@ -551,8 +550,6 @@ int Builder::create_targets() PkgConfig *pc=new PkgConfig(*this, *spkg); install->add_depend(new Install(*this, *spkg, *pc)); } - - tarballs->add_depend(new TarBall(*this, *spkg)); } // Find dependencies until no new targets are created diff --git a/source/component.cpp b/source/component.cpp index 6bef636..cb81f84 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -14,12 +14,14 @@ Distributed under the LGPL #include "builder.h" #include "component.h" #include "executable.h" +#include "file.h" #include "header.h" #include "install.h" #include "objectfile.h" #include "sharedlibrary.h" #include "sourcepackage.h" #include "staticlibrary.h" +#include "tarball.h" #include "target.h" using namespace std; @@ -88,22 +90,43 @@ void Component::create_targets() const PathList files=collect_source_files(); - bool build_exe=(type!=HEADERS); - - list objs; - list inst_tgts; - for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i) + if(type==TARBALL) { - string ext=FS::extpart(FS::basename(*i)); - if((ext==".cpp" || ext==".c") && build_exe) + string tarname=name; + if(name=="@src") + tarname=pkg.get_name()+"-"+pkg.get_version(); + TarBall *result=new TarBall(builder, pkg, tarname); + + if(name=="@src") { - SourceFile *src=new SourceFile(builder, this, i->str()); + const TargetMap &targets=builder.get_targets(); + for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) + if(i->second->get_package()==&pkg && !i->second->get_buildable()) + result->add_depend(i->second); + files.push_back(pkg.get_source()/"Build"); + } - // Compile sources - ObjectFile *obj=new ObjectFile(builder, *this, *src); - objs.push_back(obj); + for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i) + { + FileTarget *ft; + if(Target *tgt=builder.get_target(i->str())) + ft=dynamic_cast(tgt); + else + ft=new File(builder, *i); + result->add_depend(ft); } - else if(ext==".h") + + Target *tarbls_tgt=builder.get_target("tarballs"); + tarbls_tgt->add_depend(result); + + return; + } + + list inst_list; + for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i) + { + string ext=FS::extpart(FS::basename(*i)); + if(ext==".h") { FileTarget *hdr=dynamic_cast(builder.get_target(i->str())); if(!hdr) @@ -111,43 +134,46 @@ void Component::create_targets() const // Install headers if requested if(type==HEADERS && install) - inst_tgts.push_back(hdr); + inst_list.push_back(hdr); } } - if(build_exe) + if(type==PROGRAM || type==LIBRARY || type==MODULE) { - Binary *bin=0; - StaticLibrary *slib=0; - if(type==LIBRARY) + list objs; + for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i) { - bin=new SharedLibrary(builder, *this, objs); - slib=new StaticLibrary(builder, *this, objs); + string ext=FS::extpart(FS::basename(*i)); + if((ext==".cpp" || ext==".cc" || ext==".c")) + { + SourceFile *src=new SourceFile(builder, this, i->str()); + ObjectFile *obj=new ObjectFile(builder, *this, *src); + objs.push_back(obj); + } } - else - bin=new Executable(builder, *this, objs); - if(&pkg==builder.get_main_package() && deflt) + list results; + if(type==LIBRARY) { - def_tgt->add_depend(bin); - if(slib) def_tgt->add_depend(slib); + results.push_back(new SharedLibrary(builder, *this, objs)); + results.push_back(new StaticLibrary(builder, *this, objs)); } else - { - world->add_depend(bin); - if(slib) world->add_depend(slib); - } + results.push_back(new Executable(builder, *this, objs)); - if(install) + for(list::const_iterator i=results.begin(); i!=results.end(); ++i) { - inst_tgts.push_back(bin); - if(slib) - inst_tgts.push_back(slib); + if(&pkg==builder.get_main_package() && deflt) + def_tgt->add_depend(*i); + else + world->add_depend(*i); + if(install) + inst_list.push_back(*i); } } Target *inst_tgt=builder.get_target("install"); - for(list::const_iterator i=inst_tgts.begin(); i!=inst_tgts.end(); ++i) + for(list::const_iterator i=inst_list.begin(); i!=inst_list.end(); ++i) inst_tgt->add_depend(new Install(builder, pkg, **i)); } diff --git a/source/component.h b/source/component.h index 899abc3..b1b6aea 100644 --- a/source/component.h +++ b/source/component.h @@ -47,10 +47,11 @@ public: enum Type { + HEADERS, PROGRAM, LIBRARY, MODULE, - HEADERS + TARBALL }; protected: diff --git a/source/file.cpp b/source/file.cpp index 4a870e7..e605f08 100644 --- a/source/file.cpp +++ b/source/file.cpp @@ -7,8 +7,6 @@ Distributed under the LGPL #include "file.h" -using namespace std; - -File::File(Builder &b, const string &n): - FileTarget(b, 0, n) +File::File(Builder &b, const Msp::FS::Path &p): + FileTarget(b, 0, p) { } diff --git a/source/file.h b/source/file.h index 19d14af..ba8f9b4 100644 --- a/source/file.h +++ b/source/file.h @@ -16,7 +16,7 @@ Just a file. Any file, not attached to a package. class File: public FileTarget { public: - File(Builder &, const std::string &); + File(Builder &, const Msp::FS::Path &); virtual const char *get_type() const { return "File"; } private: virtual Action *create_action() { return 0; } diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 3f38acf..6f3db4d 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -16,13 +16,21 @@ Distributed under the LGPL using namespace std; using namespace Msp; +namespace { + +bool component_sort(const Component &c1, const Component &c2) +{ return c1.get_type()(pkg); + spkg.components.sort(component_sort); +} + void SourcePackage::Loader::feature(const string &n, const string &d) { static_cast(pkg).features.push_back(Feature(n, d)); @@ -269,8 +284,27 @@ void SourcePackage::Loader::build_info() load_sub(static_cast(pkg).build_info); } +void SourcePackage::Loader::tarball(const string &n) +{ + SourcePackage &spkg=static_cast(pkg); + if(n=="@src") + { + for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i) + if(i->get_type()==Component::TARBALL && i->get_name()==n) + load_sub(*i); + } + else + { + Component trbl(spkg, Component::TARBALL, n); + load_sub(trbl); + } +} + void SourcePackage::Loader::tar_file(const string &f) { + IO::print("%s: Note: tar_file is deprecated\n", get_source()); SourcePackage &spkg=static_cast(pkg); - spkg.tar_files.push_back(spkg.source/f); + for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i) + if(i->get_type()==Component::TARBALL && i->get_name()=="@src") + const_cast(i->get_sources()).push_back(spkg.source/f); } diff --git a/source/sourcepackage.h b/source/sourcepackage.h index b8750ee..a60c9d2 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -39,6 +39,7 @@ public: Loader(Package &); SourcePackage &get_object() { return static_cast(pkg); } private: + virtual void finish(); void feature(const std::string &, const std::string &); void condition(const std::string &); void program(const std::string &); @@ -46,6 +47,7 @@ public: void module(const std::string &); void headers(const std::string &); void build_info(); + void tarball(const std::string &); void tar_file(const std::string &); }; @@ -62,7 +64,6 @@ private: Config config; bool conf_done; mutable DependencyCache deps_cache; - PathList tar_files; public: SourcePackage(Builder &, const std::string &, const Msp::FS::Path &); @@ -83,7 +84,6 @@ public: unsigned get_install_flags(); LibMode get_library_mode() const; - const PathList &get_tar_files() const { return tar_files; } DependencyCache &get_deps_cache() const { return deps_cache; } private: virtual void do_configure(const StringMap &, unsigned); diff --git a/source/tarball.cpp b/source/tarball.cpp index d727590..2ed9e6b 100644 --- a/source/tarball.cpp +++ b/source/tarball.cpp @@ -5,16 +5,14 @@ Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include "builder.h" -#include "file.h" #include "sourcepackage.h" #include "tar.h" #include "tarball.h" using namespace std; -TarBall::TarBall(Builder &b, const SourcePackage &p, const string &ev): - FileTarget(b, &p, create_target_name(p, ev)) +TarBall::TarBall(Builder &b, const SourcePackage &p, const string &n): + FileTarget(b, &p, p.get_source()/(n+".tar")) { buildable=true; } @@ -24,38 +22,7 @@ const SourcePackage *TarBall::get_package() const return static_cast(package); } -void TarBall::find_depends() -{ - const SourcePackage *spkg=dynamic_cast(package); - - const TargetMap &targets=builder.get_targets(); - for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->get_package()==package && i->second!=this && !i->second->get_buildable()) - add_depend(i->second); - - const PathList &tar_files=spkg->get_tar_files(); - for(PathList::const_iterator i=tar_files.begin(); i!=tar_files.end(); ++i) - { - Target *tgt=builder.get_target(i->str()); - if(!tgt) - tgt=new File(builder, i->str()); - add_depend(tgt); - } - - deps_ready=true; -} - Action *TarBall::create_action() { return new Tar(builder, *this); } - -string TarBall::create_target_name(const SourcePackage &pkg, const string &extra_ver) -{ - string basename=pkg.get_name()+"-"+pkg.get_version(); - if(!extra_ver.empty()) - basename+="-"+extra_ver; - basename+=".tar"; - - return (pkg.get_source()/basename).str(); -} diff --git a/source/tarball.h b/source/tarball.h index 6b89ffc..32b18b0 100644 --- a/source/tarball.h +++ b/source/tarball.h @@ -13,14 +13,11 @@ Distributed under the LGPL class TarBall: public FileTarget { public: - TarBall(Builder &, const SourcePackage &, const std::string & =std::string()); + TarBall(Builder &, const SourcePackage &, const std::string &); virtual const char *get_type() const { return "TarBall"; } const SourcePackage *get_package() const; - virtual void find_depends(); private: virtual Action *create_action(); - - static std::string create_target_name(const SourcePackage &, const std::string &); }; #endif