]> git.tdb.fi Git - builder.git/blobdiff - source/config.cpp
Save caches before starting the build
[builder.git] / source / config.cpp
index f3110039e79e9c84b8e664e7f560d944a473c921..36e7870683b3bfed9e1474306ee8adde2ce13a84 100644 (file)
@@ -16,36 +16,14 @@ Config::Config(SourcePackage &p):
        changed(false)
 { }
 
-void Config::add_option(const string &n, const string &v, const string &d)
+const Config::Option &Config::add_option(const Feature &f)
 {
-       Option opt(n, v, d);
-       if(pending_options.count(n))
-               opt.value = pending_options[n];
-       options.insert(OptionMap::value_type(n, opt));
-}
-
-const Config::Option &Config::get_option(const string &name) const
-{
-       return get_item(options, name);
-}
-
-bool Config::is_option(const string &name) const
-{
-       return options.count(name);
-}
-
-void Config::save() const
-{
-       if(!changed)
-               return;
+       Option opt(f);
+       InputOptions::const_iterator i = pending_options.find(opt.name);
+       if(i!=pending_options.end())
+               opt.value = i->second;
 
-       FS::Path fn = package.get_source_directory()/".config";
-
-       package.get_builder().get_logger().log("files", format("Writing %s", fn));
-       IO::BufferedFile out(fn.str(), IO::M_WRITE);
-
-       for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
-               IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value);
+       return options.insert(OptionMap::value_type(opt.name, opt)).first->second;
 }
 
 bool Config::set_option(const string &opt, const string &val)
@@ -59,6 +37,7 @@ bool Config::set_option(const string &opt, const string &val)
                {
                        result = true;
                        changed = true;
+                       mtime = Time::now();
                }
                i->second.value = val;
        }
@@ -66,6 +45,16 @@ bool Config::set_option(const string &opt, const string &val)
        return result;
 }
 
+bool Config::is_option(const string &name) const
+{
+       return options.count(name);
+}
+
+const Config::Option &Config::get_option(const string &name) const
+{
+       return get_item(options, name);
+}
+
 void Config::load()
 {
        FS::Path fn = package.get_source_directory()/".config";
@@ -83,13 +72,29 @@ void Config::load()
        }
 }
 
+void Config::save() const
+{
+       if(!changed)
+               return;
 
-Config::Option::Option(const string &n, const string &v, const string &d):
-       name(n),
-       default_value(v),
-       description(d),
-       value(v)
-{ }
+       FS::Path fn = package.get_source_directory()/".config";
+
+       package.get_builder().get_logger().log("files", format("Writing %s", fn));
+       IO::BufferedFile out(fn.str(), IO::M_WRITE);
+
+       for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
+               IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value);
+
+       changed = false;
+}
+
+
+Config::Option::Option(const Feature &f):
+       Feature(f),
+       value(default_value)
+{
+       name = "with_"+name;
+}
 
 
 Config::Loader::Loader(Config &c):