From 921fc49488a68442fb8794e1a0284a3bf1e7b91b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 10 Aug 2007 19:50:21 +0000 Subject: [PATCH] Add an option to component to specify whether or not it should be built by default Handle building world properly --- source/builder.cpp | 17 ++++++++++++++--- source/component.cpp | 4 +++- source/component.h | 4 +++- source/target.cpp | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index ccfb407..38a7139 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -579,7 +579,7 @@ int Builder::create_targets() exe=new Executable(*this, *j, objs); add_target(exe); - if(i->second==default_pkg) + if(i->second==default_pkg && j->get_default()) { def_tgt->add_depend(exe); if(slib) def_tgt->add_depend(slib); @@ -649,7 +649,7 @@ int Builder::create_targets() // Make the cmdline target depend on all targets mentioned on the command line Target *cmdline=new VirtualTarget(*this, "cmdline"); add_target(cmdline); - world->add_depend(cmdline); + bool build_world=false; for(list::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i) { Target *tgt=get_target(*i); @@ -660,10 +660,21 @@ int Builder::create_targets() cerr<<"I don't know anything about "<<*i<<'\n'; return -1; } + if(tgt==world) + build_world=true; cmdline->add_depend(tgt); } - world->prepare(); + /* If world is to be built, prepare cmdline. If not, add cmdline to world + and prepare world. I don't really like this, but it keeps the graph + acyclic. */ + if(build_world) + cmdline->prepare(); + else + { + world->add_depend(cmdline); + world->prepare(); + } return 0; } diff --git a/source/component.cpp b/source/component.cpp index fdc0a6d..4bdff21 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -10,7 +10,8 @@ Component::Component(Package &p, Type t, const string &n): name(n), install(false), module_host(0), - modular(false) + modular(false), + deflt(true) { } /** @@ -62,6 +63,7 @@ Component::Loader::Loader(Component &c): add("require", &Loader::require); add("modular", &Loader::modular); add("host", &Loader::host); + add("default", &Component::deflt); } void Component::Loader::source(const string &s) diff --git a/source/component.h b/source/component.h index e1df73a..e505735 100644 --- a/source/component.h +++ b/source/component.h @@ -34,7 +34,7 @@ public: void host(const std::string &); void build_info(); }; - + enum Type { PROGRAM, @@ -53,6 +53,7 @@ public: const std::string &get_install_headers() const { return install_headers; } bool get_modular() const { return modular; } const PkgRefList &get_requires() const { return requires; } + bool get_default() const { return deflt; } void resolve_refs(); void create_build_info(); protected: @@ -66,6 +67,7 @@ protected: bool modular; BuildInfo build_info; PkgRefList requires; + bool deflt; }; typedef std::list ComponentList; diff --git a/source/target.cpp b/source/target.cpp index e8ed647..3b16853 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -36,6 +36,8 @@ Target *Target::get_buildable_target() void Target::add_depend(Target *dep) { + if(dep==this) + throw InvalidParameterValue("A target can't depend on itself"); depends.push_back(dep); dep->rdepends.push_back(this); } -- 2.43.0