]> git.tdb.fi Git - builder.git/commitdiff
Externalize dry run handling from Config and DependencyCache
authorMikko Rasa <tdb@tdb.fi>
Sat, 14 Jul 2012 10:31:18 +0000 (13:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 15 Jul 2012 14:05:47 +0000 (17:05 +0300)
source/builder.cpp
source/config.cpp
source/config.h
source/dependencycache.cpp
source/package.h
source/sourcepackage.cpp
source/sourcepackage.h

index 0b1cd2cf0b02cc061383df31d4201670cb029722..d93bd0aff646a4d2c5b428e5557ad39dc14fc906 100644 (file)
@@ -444,9 +444,11 @@ int Builder::create_targets()
                                i->second->force_rebuild();
        }
 
-       for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
-               if(SourcePackage *spkg = dynamic_cast<SourcePackage *>(i->second))
-                       spkg->get_deps_cache().save();
+       if(!dry_run)
+       {
+               for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+                       i->second->save_caches();
+       }
 
        return 0;
 }
index d96140fdc9feb60b1ac83bc204d89a52acea9f33..1ab70c8a8af3431e983b9f6bdc38f9642ba4af24 100644 (file)
@@ -13,7 +13,8 @@ using namespace Msp;
 
 Config::Config(SourcePackage &p):
        package(p),
-       freeze_mtime(false)
+       freeze_mtime(false),
+       changed(false)
 { }
 
 void Config::add_option(const string &n, const string &v, const string &d)
@@ -53,12 +54,6 @@ void Config::select_profile(const string &profile)
 {
        set_option("profile", profile);
 
-       if(!package.get_builder().get_dry_run())
-       {
-               IO::BufferedFile out((package.get_source()/".profile").str(), IO::M_WRITE);
-               IO::print(out, "%s\n", profile);
-       }
-
        freeze_mtime = true;
        package.get_builder().apply_profile_template(*this, profile);
        freeze_mtime = false;
@@ -68,17 +63,20 @@ void Config::select_profile(const string &profile)
 
 bool Config::update(const StringMap &opts)
 {
-       bool changed = false;
+       bool changed_now = false;
        for(StringMap::const_iterator i=opts.begin(); i!=opts.end(); ++i)
        {
                if(set_option(i->first, i->second) && i->first!="profile")
-                       changed = true;
+                       changed_now = true;
        }
 
-       if(changed && !freeze_mtime)
+       if(changed_now && !freeze_mtime)
+       {
                mtime = Time::now();
+               changed = true;
+       }
 
-       return changed;
+       return changed_now;
 }
 
 void Config::finish()
@@ -89,12 +87,20 @@ void Config::finish()
 
 void Config::save() const
 {
+       if(!changed)
+               return;
+
        FS::Path fn = package.get_source()/".options";
 
        OptionMap::const_iterator i = options.find("profile");
        if(i!=options.end())
+       {
                fn = package.get_source()/(".options."+i->second.value);
 
+               IO::BufferedFile profile_out((package.get_source()/".profile").str(), IO::M_WRITE);
+               IO::print(profile_out, "%s\n", i->second.value);
+       }
+
        IO::BufferedFile out(fn.str(), IO::M_WRITE);
 
        for(i=options.begin(); i!=options.end(); ++i)
index 6babde995d94ad7628d70f385bead9ed211a067a..5c87eedf98d78644d3bf742f4791be7b697b6832 100644 (file)
@@ -43,6 +43,7 @@ private:
        OptionMap options;
        Msp::Time::TimeStamp mtime;
        bool freeze_mtime;
+       bool changed;
 
 public:
        Config(SourcePackage &);
@@ -63,8 +64,7 @@ public:
        present, the default profile is assumed. */
        void select_last_profile();
 
-       /** Selects a profile.  The profile cache file is updated, unless doing a
-       dry run. */
+       /** Selects a profile. */
        void select_profile(const std::string &);
 
        /** Processes options from the given raw option map.  Nonexistent options
index 11b200d9983a1ae20056495e101a5f35fe8e2e25..15abf0858b054f7df80563f887dc63c54a344679 100644 (file)
@@ -33,7 +33,7 @@ const StringList &DependencyCache::get_deps(const string &tgt) const
 
 void DependencyCache::save() const
 {
-       if(deps.empty() || !changed || package.get_builder().get_dry_run())
+       if(deps.empty() || !changed)
                return;
 
        IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE);
index 546a892ab409a58e258378868845eec4b80befa4..14b343d9687227599a865130fa6fbe28dbe596cf 100644 (file)
@@ -62,6 +62,8 @@ protected:
 
 public:
        virtual void create_targets() { }
+
+       virtual void save_caches() { }
 };
 
 #endif
index 2371d2cea44dd61415ebc2d8318b9a1642584fba..456acfd6af1e0f37505a6973c3ce20e8bd0f3764 100644 (file)
@@ -127,11 +127,7 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
                config.select_last_profile();
 
        if(flag && config.update(opts))
-       {
                builder.get_logger().log("configure", format("Configuration of %s changed", name));
-               if(!builder.get_dry_run())
-                       config.save();
-       }
 
        config.finish();
 
@@ -242,6 +238,12 @@ void SourcePackage::create_targets()
        }
 }
 
+void SourcePackage::save_caches()
+{
+       config.save();
+       deps_cache.save();
+}
+
 
 SourcePackage::Loader::Loader(SourcePackage &p):
        DataFile::DerivedObjectLoader<SourcePackage, Package>(p)
index 11f47940dc29f8712a79cd1da203bfe39d52d19d..ecd2bc15e4ac1a78091be79d08311b304ce8de9f 100644 (file)
@@ -97,6 +97,8 @@ private:
        virtual void create_build_info();
 
        virtual void create_targets();
+
+       virtual void save_caches();
 };
 
 #endif