From c7df14c38a87ceca13df47fa700d3f9fa250be91 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Nov 2021 20:06:23 +0200 Subject: [PATCH] Save caches before starting the build This causes the config cache file's timestamp to be earlier than any built file, preventing a spurious second rebuild after changing options. --- source/builder.cpp | 14 +++++++------- source/builder.h | 3 +++ source/buildercli.cpp | 7 +++++++ source/cache.cpp | 2 ++ source/cache.h | 2 +- source/config.cpp | 2 ++ source/config.h | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 65d7da4..e26c115 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -169,6 +169,13 @@ void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *op loader.load(parser); } +void Builder::save_caches() +{ + const PackageManager::PackageMap &packages = package_manager.get_packages(); + for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) + i->second->save_caches(); +} + int Builder::build(unsigned jobs, bool dry_run, bool show_progress) { unsigned total = build_graph.count_rebuild_targets(); @@ -256,13 +263,6 @@ int Builder::build(unsigned jobs, bool dry_run, bool show_progress) else if(show_progress) get_logger().log("summary", "Build complete"); - if(!dry_run) - { - const PackageManager::PackageMap &packages = package_manager.get_packages(); - for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) - i->second->save_caches(); - } - return fail; } diff --git a/source/builder.h b/source/builder.h index 9ea6677..70ca861 100644 --- a/source/builder.h +++ b/source/builder.h @@ -95,6 +95,9 @@ public: configured. */ void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false); + /** Saves package configuration and dependency caches. */ + void save_caches(); + /** Builds the goal targets. The build graph must be prepared first. */ int build(unsigned jobs = 1, bool dry_run = false, bool show_progress = false); diff --git a/source/buildercli.cpp b/source/buildercli.cpp index a37336f..0a84364 100644 --- a/source/buildercli.cpp +++ b/source/buildercli.cpp @@ -191,7 +191,11 @@ int BuilderCLI::main() { FS::Path main_file = cwd/build_file; if(FS::exists(main_file)) + { builder.load_build_file(main_file, &cmdline_options, conf_all); + if(!dry_run && !cmdline_options.empty()) + builder.save_caches(); + } else if(!help) { IO::print(IO::cerr, "The file %s does not exist.\n", main_file); @@ -286,6 +290,9 @@ int BuilderCLI::main() if(build) exit_code = builder.build(jobs, dry_run, show_progress); + if(!dry_run) + builder.save_caches(); + return exit_code; } diff --git a/source/cache.cpp b/source/cache.cpp index a2d6824..de4643c 100644 --- a/source/cache.cpp +++ b/source/cache.cpp @@ -149,4 +149,6 @@ void Cache::save() const for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) write_string(out, *j); } + + changed = false; } diff --git a/source/cache.h b/source/cache.h index 95ae4fb..69025fd 100644 --- a/source/cache.h +++ b/source/cache.h @@ -29,7 +29,7 @@ private: Msp::FS::Path filename; DataMap data; Msp::Time::TimeStamp mtime; - bool changed; + mutable bool changed; public: Cache(SourcePackage &p); diff --git a/source/config.cpp b/source/config.cpp index 69abe9d..36e7870 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -84,6 +84,8 @@ void Config::save() const 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; } diff --git a/source/config.h b/source/config.h index 1f7fa71..3257794 100644 --- a/source/config.h +++ b/source/config.h @@ -41,7 +41,7 @@ private: OptionMap options; InputOptions pending_options; Msp::Time::TimeStamp mtime; - bool changed; + mutable bool changed; public: Config(SourcePackage &); -- 2.45.2