]> git.tdb.fi Git - builder.git/commitdiff
Add install component type
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Sep 2009 22:48:06 +0000 (22:48 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Sep 2009 22:48:06 +0000 (22:48 +0000)
Allow specifying a package for File

13 files changed:
Build
source/builder.cpp
source/component.cpp
source/component.h
source/file.cpp [deleted file]
source/file.h
source/header.h
source/install.cpp
source/install.h
source/sourcefile.cpp
source/sourcefile.h
source/sourcepackage.cpp
source/sourcepackage.h

diff --git a/Build b/Build
index 2754b9ef5aa7ba257a45ecb848a3a3503c5f09bd..e05782564d7427d9348b6edd02216e5b76e6fc45 100644 (file)
--- a/Build
+++ b/Build
@@ -23,4 +23,9 @@ package "builder"
                source "Readme.txt";
                source "License.txt";
        };
+
+       install "share/builder"
+       {
+               source "builderrc";
+       };
 };
index 0905bb6779530af63a6fd2f25151cf4248609715..21d311a4db2f0573abc0d52e29720adfb6018588 100644 (file)
@@ -152,7 +152,7 @@ Builder::Builder(int argc, char **argv):
        native_arch->set_tool("AR",  "ar");
 
        load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
-       load_build_file((FS::get_home_dir()/".builderrc").str());
+       load_build_file((FS::get_user_data_dir("builder")/"rc").str());
 
        if(arch.empty())
                current_arch=native_arch;
index 5f6237e743f88f37d4f8929f59794e65e79e1c41..de42d922404f995a186e80a6e62c5819faa59746 100644 (file)
@@ -89,7 +89,9 @@ void Component::create_targets() const
        Target *def_tgt=builder.get_target("default");
 
        PathList files=collect_source_files();
+       list<FileTarget *> inst_list;
 
+       string inst_loc;
        if(type==TARBALL)
        {
                string tarname=name;
@@ -121,20 +123,34 @@ void Component::create_targets() const
 
                return;
        }
-
-       list<FileTarget *> inst_list;
-       for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
+       else if(type==INSTALL)
        {
-               string ext=FS::extpart(FS::basename(*i));
-               if(ext==".h")
+               inst_loc=name;
+               for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
                {
-                       FileTarget *hdr=dynamic_cast<FileTarget *>(builder.get_target(i->str()));
-                       if(!hdr)
-                               hdr=new Header(builder, this, i->str());
+                       FileTarget *ft;
+                       if(Target *tgt=builder.get_target(i->str()))
+                               ft=dynamic_cast<FileTarget *>(tgt);
+                       else
+                               ft=new File(builder, pkg, *i);
+                       inst_list.push_back(ft);
+               }
+       }
+       else
+       {
+               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)
+                                       hdr=new Header(builder, *this, i->str());
 
-                       // Install headers if requested
-                       if(type==HEADERS && install)
-                               inst_list.push_back(hdr);
+                               // Install headers if requested
+                               if(type==HEADERS && install)
+                                       inst_list.push_back(hdr);
+                       }
                }
        }
 
@@ -146,7 +162,7 @@ void Component::create_targets() const
                        string ext=FS::extpart(FS::basename(*i));
                        if((ext==".cpp" || ext==".cc" || ext==".c"))
                        {
-                               SourceFile *src=new SourceFile(builder, this, i->str());
+                               SourceFile *src=new SourceFile(builder, *this, i->str());
                                ObjectFile *obj=new ObjectFile(builder, *this, *src);
                                objs.push_back(obj);
                        }
@@ -174,7 +190,7 @@ void Component::create_targets() const
 
        Target *inst_tgt=builder.get_target("install");
        for(list<FileTarget *>::const_iterator i=inst_list.begin(); i!=inst_list.end(); ++i)
-               inst_tgt->add_depend(new Install(builder, pkg, **i));
+               inst_tgt->add_depend(new Install(builder, pkg, **i, inst_loc));
 }
 
 PathList Component::collect_source_files() const
index c7ffce3ca88bf583844a1c3dc7546fbad425b73f..08bce237e5253c1c0c41d37b25c559bdde30e51b 100644 (file)
@@ -48,10 +48,11 @@ public:
        enum Type
        {
                HEADERS,
-               PROGRAM,
                LIBRARY,
+               PROGRAM,
                MODULE,
-               TARBALL
+               TARBALL,
+               INSTALL
        };
 
 protected:
diff --git a/source/file.cpp b/source/file.cpp
deleted file mode 100644 (file)
index e605f08..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2007, 2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include "file.h"
-
-File::File(Builder &b, const Msp::FS::Path &p):
-       FileTarget(b, 0, p)
-{ }
index ba8f9b42bfcea925fe967eacaf62d9d976d186da..13fa4e28e9e0b86396d778b69e773b77471d2325 100644 (file)
@@ -11,12 +11,13 @@ Distributed under the LGPL
 #include "filetarget.h"
 
 /**
-Just a file.  Any file, not attached to a package.
+Just an arbitary file.  No special meaning attached.
 */
 class File: public FileTarget
 {
 public:
-       File(Builder &, const Msp::FS::Path &);
+       File(Builder &b, const Msp::FS::Path &t): FileTarget(b, 0, t) { }
+       File(Builder &b, Package &p, const Msp::FS::Path &t): FileTarget(b, &p, t) { }
        virtual const char *get_type() const { return "File"; }
 private:
        virtual Action *create_action() { return 0; }
index a2b7c7da2e912002991ef54a4f41723f46a6ed70..f52c13b53c0baa3add28731fe007f5c3297ac33f 100644 (file)
@@ -15,8 +15,10 @@ Represents a header file.  Mainly exists to give extra information to the user.
 */
 class Header: public SourceFile
 {
+protected:
+       Header(Builder &b, const std::string &f): SourceFile(b, f) { }
 public:
-       Header(Builder &b, const Component *c, const std::string &f): SourceFile(b, c, f) { }
+       Header(Builder &b, const Component &c, const std::string &f): SourceFile(b, c, f) { }
        virtual const char *get_type() const { return "Header"; }
 };
 
@@ -26,9 +28,8 @@ A header file that doesn't belong to any known package.
 class SystemHeader: public Header
 {
 public:
-       SystemHeader(Builder &b, const std::string &f): Header(b, 0, f) { }
+       SystemHeader(Builder &b, const std::string &f): Header(b, f) { }
        virtual const char *get_type() const { return "SystemHeader"; }
-       virtual void find_depends() { deps_ready=true; }
 };
 
 #endif
index d80f9a74d80e15f9c2110f4c9745e6ba0dd7a8d9..a0029ac1eed33244fea945686d43347d3a8b6628 100644 (file)
@@ -19,8 +19,8 @@ Distributed under the LGPL
 using namespace std;
 using namespace Msp;
 
-Install::Install(Builder &b, const SourcePackage &p, FileTarget &s):
-       FileTarget(b, &p, generate_target_path(s)),
+Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
+       FileTarget(b, &p, generate_target_path(s, loc)),
        source(s)
 {
        buildable=true;
@@ -42,15 +42,18 @@ Action *Install::create_action()
        return new Copy(builder, *package, source.get_path(), path);
 }
 
-FS::Path Install::generate_target_path(const FileTarget &tgt)
+FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc)
 {
-       const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(tgt.get_package());
+       if(!tgt.get_package())
+               throw InvalidParameterValue("Can't install package-less targets");
 
-       FS::Path base=spkg->get_builder().get_prefix();
+       FS::Path base=tgt.get_package()->get_builder().get_prefix();
        string tgtname=FS::basename(tgt.get_path());
 
        string mid;
-       if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
+       if(!loc.empty())
+               mid=loc;
+       else if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
        {
                if(hdr->get_component()->get_type()!=Component::HEADERS)
                        throw Exception("Header install from non-header component?");
index 764d9a19bc20f8547ed484e281974eb840c32931..7cf56bb80fec36b7841f339d5909558df484bf05 100644 (file)
@@ -20,14 +20,14 @@ private:
        FileTarget &source;
 
 public:
-       Install(Builder &, const SourcePackage &, FileTarget &);
+       Install(Builder &, const SourcePackage &, FileTarget &, const std::string & =std::string());
        virtual const char *get_type() const { return "Install"; }
        FileTarget &get_source() const { return source; }
 private:
        virtual void check_rebuild();
        virtual Action *create_action();
 
-       static Msp::FS::Path generate_target_path(const FileTarget &);
+       static Msp::FS::Path generate_target_path(const FileTarget &i, const std::string &);
 };
 
 #endif
index 0fc6d696c2394776a10b7692b381f1dabcc9c2ec..7425a0f132c893c0448d0954993c1bde0321262f 100644 (file)
@@ -17,15 +17,23 @@ Distributed under the LGPL
 using namespace std;
 using namespace Msp;
 
-SourceFile::SourceFile(Builder &b, const Component *c, const FS::Path &p):
-       FileTarget(b, (c ? &c->get_package() : 0), p),
-       comp(c)
+SourceFile::SourceFile(Builder &b, const FS::Path &p):
+       FileTarget(b, 0, p),
+       comp(0)
+{ }
+
+SourceFile::SourceFile(Builder &b, const Component &c, const FS::Path &p):
+       FileTarget(b, &c.get_package(), p),
+       comp(&c)
 { }
 
 void SourceFile::find_depends()
 {
        if(!comp)
+       {
+               deps_ready=true;
                return;
+       }
 
        const SourcePackage &spkg=comp->get_package();
        string relname=FS::relative(name, spkg.get_source()).str();
@@ -62,6 +70,7 @@ void SourceFile::find_depends()
                }
                catch(const IO::FileNotFound &)
                {
+                       // XXX WTF?
                        return;
                }
        }
index cbfd93428de9a09631c977b39adf18603e478af0..c0abe5c7615beeb0af7b9cd97458d60dd4fe950e 100644 (file)
@@ -21,8 +21,10 @@ private:
        const Component *comp;
        StringList includes;
 
+protected:
+       SourceFile(Builder &, const Msp::FS::Path &);
 public:
-       SourceFile(Builder &, const Component *, const Msp::FS::Path &);
+       SourceFile(Builder &, const Component &, const Msp::FS::Path &);
        virtual const char *get_type() const { return "SourceFile"; }
        const StringList &get_includes() const { return includes; }
        const Component *get_component() const { return comp; }
index 54de8f6a7cf076c178c95440d70ba4cb614d1c67..6b52884d0af03d0adbf0049f3ca5316a3e3579f2 100644 (file)
@@ -122,9 +122,6 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
        }
 
        deps_cache.load();
-
-       /*for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
-               (*i)->configure(opts, flag&2);*/
 }
 
 void SourcePackage::init_config()
@@ -220,10 +217,11 @@ SourcePackage::Loader::Loader(Package &p):
        add("build_info",  &Loader::build_info);
        add("feature",     &Loader::feature);
        add("if",          &Loader::condition);
-       add("program",     &Loader::program);
-       add("library",     &Loader::library);
-       add("module",      &Loader::module);
-       add("headers",     &Loader::headers);
+       add("program",     &Loader::component<Component::PROGRAM>);
+       add("library",     &Loader::component<Component::LIBRARY>);
+       add("module",      &Loader::component<Component::MODULE>);
+       add("headers",     &Loader::component<Component::HEADERS>);
+       add("install",     &Loader::component<Component::INSTALL>);
        add("tarball",     &Loader::tarball);
        add("tar_file",    &Loader::tar_file);
 }
@@ -247,36 +245,13 @@ void SourcePackage::Loader::condition(const string &c)
        spkg.conditions.push_back(cond);
 }
 
-void SourcePackage::Loader::program(const string &n)
-{
-       SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
-       Component prog(spkg, Component::PROGRAM, n);
-       load_sub(prog);
-       spkg.components.push_back(prog);
-}
-
-void SourcePackage::Loader::library(const string &n)
-{
-       SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
-       Component prog(spkg, Component::LIBRARY, n);
-       load_sub(prog);
-       spkg.components.push_back(prog);
-}
-
-void SourcePackage::Loader::module(const string &n)
-{
-       SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
-       Component prog(spkg, Component::MODULE, n);
-       load_sub(prog);
-       spkg.components.push_back(prog);
-}
-
-void SourcePackage::Loader::headers(const string &n)
+template<Component::Type t>
+void SourcePackage::Loader::component(const string &n)
 {
        SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
-       Component prog(spkg, Component::HEADERS, n);
-       load_sub(prog);
-       spkg.components.push_back(prog);
+       Component comp(spkg, t, n);
+       load_sub(comp);
+       spkg.components.push_back(comp);
 }
 
 void SourcePackage::Loader::build_info()
index a60c9d2bee94509287f510b5849ed973f4a10b40..0745a1b1614389643e5bf6ffc3936283a08bddc1 100644 (file)
@@ -41,11 +41,9 @@ public:
        private:
                virtual void finish();
                void feature(const std::string &, const std::string &);
+               template<Component::Type>
+               void component(const std::string &);
                void condition(const std::string &);
-               void program(const std::string &);
-               void library(const std::string &);
-               void module(const std::string &);
-               void headers(const std::string &);
                void build_info();
                void tarball(const std::string &);
                void tar_file(const std::string &);