From: Mikko Rasa Date: Sat, 14 Jul 2012 10:31:18 +0000 (+0300) Subject: Externalize dry run handling from Config and DependencyCache X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d701ca81b781cd061fd60244312b0316cf5bf4d9;p=builder.git Externalize dry run handling from Config and DependencyCache --- diff --git a/source/builder.cpp b/source/builder.cpp index 0b1cd2c..d93bd0a 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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(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; } diff --git a/source/config.cpp b/source/config.cpp index d96140f..1ab70c8 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -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) diff --git a/source/config.h b/source/config.h index 6babde9..5c87eed 100644 --- a/source/config.h +++ b/source/config.h @@ -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 diff --git a/source/dependencycache.cpp b/source/dependencycache.cpp index 11b200d..15abf08 100644 --- a/source/dependencycache.cpp +++ b/source/dependencycache.cpp @@ -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); diff --git a/source/package.h b/source/package.h index 546a892..14b343d 100644 --- a/source/package.h +++ b/source/package.h @@ -62,6 +62,8 @@ protected: public: virtual void create_targets() { } + + virtual void save_caches() { } }; #endif diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 2371d2c..456acfd 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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(p) diff --git a/source/sourcepackage.h b/source/sourcepackage.h index 11f4794..ecd2bc1 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -97,6 +97,8 @@ private: virtual void create_build_info(); virtual void create_targets(); + + virtual void save_caches(); }; #endif