From: Mikko Rasa Date: Fri, 11 Sep 2009 22:48:06 +0000 (+0000) Subject: Add install component type X-Git-Tag: 1.0~8 X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=1fdef3ec9d6291af8a467ea0e2c90e7f19141ae2 Add install component type Allow specifying a package for File --- diff --git a/Build b/Build index 2754b9e..e057825 100644 --- a/Build +++ b/Build @@ -23,4 +23,9 @@ package "builder" source "Readme.txt"; source "License.txt"; }; + + install "share/builder" + { + source "builderrc"; + }; }; diff --git a/source/builder.cpp b/source/builder.cpp index 0905bb6..21d311a 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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; diff --git a/source/component.cpp b/source/component.cpp index 5f6237e..de42d92 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -89,7 +89,9 @@ void Component::create_targets() const Target *def_tgt=builder.get_target("default"); PathList files=collect_source_files(); + list inst_list; + string inst_loc; if(type==TARBALL) { string tarname=name; @@ -121,20 +123,34 @@ void Component::create_targets() const return; } - - list 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(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(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(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::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 diff --git a/source/component.h b/source/component.h index c7ffce3..08bce23 100644 --- a/source/component.h +++ b/source/component.h @@ -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 index e605f08..0000000 --- a/source/file.cpp +++ /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) -{ } diff --git a/source/file.h b/source/file.h index ba8f9b4..13fa4e2 100644 --- a/source/file.h +++ b/source/file.h @@ -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; } diff --git a/source/header.h b/source/header.h index a2b7c7d..f52c13b 100644 --- a/source/header.h +++ b/source/header.h @@ -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 diff --git a/source/install.cpp b/source/install.cpp index d80f9a7..a0029ac 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -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(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(&tgt)) + if(!loc.empty()) + mid=loc; + else if(const Header *hdr=dynamic_cast(&tgt)) { if(hdr->get_component()->get_type()!=Component::HEADERS) throw Exception("Header install from non-header component?"); diff --git a/source/install.h b/source/install.h index 764d9a1..7cf56bb 100644 --- a/source/install.h +++ b/source/install.h @@ -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 diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index 0fc6d69..7425a0f 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -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; } } diff --git a/source/sourcefile.h b/source/sourcefile.h index cbfd934..c0abe5c 100644 --- a/source/sourcefile.h +++ b/source/sourcefile.h @@ -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; } diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 54de8f6..6b52884 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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); + add("library", &Loader::component); + add("module", &Loader::component); + add("headers", &Loader::component); + add("install", &Loader::component); 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(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(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(pkg); - Component prog(spkg, Component::MODULE, n); - load_sub(prog); - spkg.components.push_back(prog); -} - -void SourcePackage::Loader::headers(const string &n) +template +void SourcePackage::Loader::component(const string &n) { SourcePackage &spkg=static_cast(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() diff --git a/source/sourcepackage.h b/source/sourcepackage.h index a60c9d2..0745a1b 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -41,11 +41,9 @@ public: private: virtual void finish(); void feature(const std::string &, const std::string &); + template + 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 &);