]> git.tdb.fi Git - builder.git/commitdiff
Add a tarball component type
authorMikko Rasa <tdb@tdb.fi>
Mon, 11 May 2009 09:51:01 +0000 (09:51 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 11 May 2009 09:51:01 +0000 (09:51 +0000)
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

Build
source/builder.cpp
source/component.cpp
source/component.h
source/file.cpp
source/file.h
source/sourcepackage.cpp
source/sourcepackage.h
source/tarball.cpp
source/tarball.h

diff --git a/Build b/Build
index 6f8e83825f02ed506f973a7df71a7ed2e69f6c79..2754b9ef5aa7ba257a45ecb848a3a3503c5f09bd 100644 (file)
--- 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";
+       };
 };
index de8375919e17678de591cdff9452cc36bf25057e..b06b8ffb2fd0b1de4c7b288989cd8704ce295919 100644 (file)
@@ -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
index 6bef63651d9ec88f42fbe639010bc9a7935cc73b..cb81f8420429b78bd79b4d3f70c6021db04e4e81 100644 (file)
@@ -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<ObjectFile *> objs;
-       list<FileTarget *> 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<FileTarget *>(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<FileTarget *> 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<FileTarget *>(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<ObjectFile *> 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<FileTarget *> 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<FileTarget *>::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<FileTarget *>::const_iterator i=inst_tgts.begin(); i!=inst_tgts.end(); ++i)
+       for(list<FileTarget *>::const_iterator i=inst_list.begin(); i!=inst_list.end(); ++i)
                inst_tgt->add_depend(new Install(builder, pkg, **i));
 }
 
index 899abc37c81b21e7f41237ffb69b07145dd94fa4..b1b6aea994d3142ceb89f33dc3afb2c770c0790f 100644 (file)
@@ -47,10 +47,11 @@ public:
 
        enum Type
        {
+               HEADERS,
                PROGRAM,
                LIBRARY,
                MODULE,
-               HEADERS
+               TARBALL
        };
 
 protected:
index 4a870e718069cfd2a0cc4c45a819d8b1bc5dc8c3..e605f0804cc8b5173ff664e7aca7c2b8c9da4577 100644 (file)
@@ -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)
 { }
index 19d14af92749a425e2f8268fcb483cc62d9fb0f5..ba8f9b42bfcea925fe967eacaf62d9d976d186da 100644 (file)
@@ -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; }
index 3f38acf39c1eba37024d751ef840543195d2ee1d..6f3db4d8e07e392451dbfe527397cbf3786394f6 100644 (file)
@@ -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()<c2.get_type(); }
+
+}
+
+
 SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &s):
        Package(b, n),
        source(s),
        config(*this),
        deps_cache(*this)
 {
-       tar_files.push_back(source/"Build");
+       components.push_back(Component(*this, Component::TARBALL, "@src"));
 }
 
 Msp::FS::Path SourcePackage::get_temp_dir() const
@@ -216,9 +224,16 @@ SourcePackage::Loader::Loader(Package &p):
        add("library",     &Loader::library);
        add("module",      &Loader::module);
        add("headers",     &Loader::headers);
+       add("tarball",     &Loader::tarball);
        add("tar_file",    &Loader::tar_file);
 }
 
+void SourcePackage::Loader::finish()
+{
+       SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+       spkg.components.sort(component_sort);
+}
+
 void SourcePackage::Loader::feature(const string &n, const string &d)
 {
        static_cast<SourcePackage &>(pkg).features.push_back(Feature(n, d));
@@ -269,8 +284,27 @@ void SourcePackage::Loader::build_info()
        load_sub(static_cast<SourcePackage &>(pkg).build_info);
 }
 
+void SourcePackage::Loader::tarball(const string &n)
+{
+       SourcePackage &spkg=static_cast<SourcePackage &>(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<SourcePackage &>(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<PathList &>(i->get_sources()).push_back(spkg.source/f);
 }
index b8750ee393f3d0946818297c58301840edd5f54e..a60c9d2bee94509287f510b5849ed973f4a10b40 100644 (file)
@@ -39,6 +39,7 @@ public:
                Loader(Package &);
                SourcePackage &get_object() { return static_cast<SourcePackage &>(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);
index d727590808777b58125b294666c3e5990fe7aa9f..2ed9e6b5d5a6a1cb920f976f1675c9d2b14dedb2 100644 (file)
@@ -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<const SourcePackage *>(package);
 }
 
-void TarBall::find_depends()
-{
-       const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(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();
-}
index 6b89ffc0269d02b082f02d6bc17fec52bc4dccab..32b18b0e4dd3dc8b4907fbbc43bd5d1adba26458 100644 (file)
@@ -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