]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Pass the option map through load_build_file and to Loader
[builder.git] / source / builder.cpp
index 8b900a4987af9230c4f8d860a004bcb49379825a..ea96534cdb0afb7b10bd42d9c4f4608df09e8803 100644 (file)
@@ -16,6 +16,7 @@
 #include "binarypackage.h"
 #include "builder.h"
 #include "copy.h"
+#include "datatool.h"
 #include "gnuarchiver.h"
 #include "gnuccompiler.h"
 #include "gnucxxcompiler.h"
@@ -51,7 +52,8 @@ Builder::Builder(int argc, char **argv):
        conf_only(false),
        build_all(false),
        create_makefile(false),
-       tempdir("temp")
+       tempdir("temp"),
+       top_loader(0)
 {
        string analyze_mode;
        string work_dir;
@@ -150,9 +152,6 @@ Builder::Builder(int argc, char **argv):
                        cmdline_targets.push_back(*i);
        }
 
-       if(cmdline_targets.empty())
-               cmdline_targets.push_back("default");
-
        if(!work_dir.empty())
                FS::chdir(work_dir);
 
@@ -206,6 +205,7 @@ Builder::Builder(int argc, char **argv):
        toolchain.add_tool(new PkgConfigGenerator(*this));
        if(current_arch->get_system()=="windows")
                toolchain.add_tool(new MingwDllTool(*this, *current_arch));
+       toolchain.add_tool(new DataTool(*this));
 }
 
 Builder::~Builder()
@@ -230,7 +230,7 @@ int Builder::main()
                }
        }
 
-       load_build_file(main_file);
+       load_build_file(main_file, &cmdline_options, conf_all);
 
        if(help)
        {
@@ -336,14 +336,14 @@ void Builder::usage(const char *reason, const char *argv0, bool brief)
        }
 }
 
-void Builder::load_build_file(const FS::Path &fn)
+void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *opts, bool all)
 {
        IO::BufferedFile in(fn.str());
 
        logger.log("files", format("Reading %s", fn));
 
        DataFile::Parser parser(in, fn.str());
-       Loader loader(*this);
+       Loader loader(*this, opts, all);
        loader.load(parser);
 }
 
@@ -351,8 +351,7 @@ bool Builder::prepare_build()
 {
        package_manager.get_main_package().prepare();
 
-       // Make the cmdline target depend on all targets mentioned on the command line
-       Target *cmdline = new VirtualTarget(*this, "cmdline");
+       // Add targets from command line as goals
        for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
        {
                Target *tgt = build_graph.get_target(*i);
@@ -366,10 +365,10 @@ bool Builder::prepare_build()
                        return false;
                }
 
-               cmdline->add_dependency(*tgt);
+               build_graph.add_goal(*tgt);
        }
 
-       cmdline->prepare();
+       build_graph.prepare();
 
        // Apply what-ifs
        for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
@@ -384,11 +383,7 @@ bool Builder::prepare_build()
        }
 
        if(build_all)
-       {
-               for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
-                       if(i->second->is_buildable() && !i->second->needs_rebuild())
-                               i->second->force_rebuild();
-       }
+               build_graph.force_full_rebuild();
 
        if(!dry_run)
        {
@@ -402,13 +397,7 @@ bool Builder::prepare_build()
 
 int Builder::do_build()
 {
-       Target *cmdline = build_graph.get_target("cmdline");
-
-       unsigned total = 0;
-       const BuildGraph::TargetMap &targets = build_graph.get_targets();
-       for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && i->second->needs_rebuild())
-                       ++total;
+       unsigned total = build_graph.count_rebuild_targets();
 
        if(!total)
        {
@@ -429,7 +418,7 @@ int Builder::do_build()
        {
                if(tasks.size()<jobs && !fail && !starved)
                {
-                       Target *tgt = cmdline->get_buildable_target();
+                       Target *tgt = build_graph.get_buildable_target();
                        if(tgt)
                        {
                                if(tgt->get_tool())
@@ -564,14 +553,27 @@ string Builder::usagemsg;
 string Builder::helpmsg;
 
 
-Builder::Loader::Loader(Builder &b):
-       DataFile::ObjectLoader<Builder>(b)
+Builder::Loader::Loader(Builder &b, const Config::InputOptions *o, bool a):
+       DataFile::ObjectLoader<Builder>(b),
+       options(o),
+       conf_all(a)
 {
        add("architecture", &Loader::architecture);
        add("binary_package", &Loader::binpkg);
        add("build_type", &Loader::build_type);
        add("profile", &Loader::profile);
        add("package", &Loader::package);
+
+       if(!obj.top_loader)
+               obj.top_loader = this;
+       else if(!options && obj.top_loader!=this && obj.top_loader->conf_all)
+               options = obj.top_loader->options;
+}
+
+Builder::Loader::~Loader()
+{
+       if(obj.top_loader==this)
+               obj.top_loader = 0;
 }
 
 void Builder::Loader::architecture(const string &n)
@@ -604,8 +606,8 @@ void Builder::Loader::package(const string &n)
 {
        SourcePackage *pkg = new SourcePackage(obj, n, get_source());
 
-       if(obj.conf_all || pkg==&obj.package_manager.get_main_package())
-               load_sub(*pkg, obj.cmdline_options);
+       if(options)
+               load_sub(*pkg, *options);
        else
                load_sub(*pkg);