]> git.tdb.fi Git - builder.git/commitdiff
Save caches before starting the build
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 18:06:23 +0000 (20:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 18:06:23 +0000 (20:06 +0200)
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
source/builder.h
source/buildercli.cpp
source/cache.cpp
source/cache.h
source/config.cpp
source/config.h

index 65d7da48c3cd8be5e9e568df17148f12bdc7ceac..e26c1157ec88ff5b06a3f08710d41a16cfcbf442 100644 (file)
@@ -169,6 +169,13 @@ void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *op
        loader.load(parser);
 }
 
        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();
 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");
 
        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;
 }
 
        return fail;
 }
 
index 9ea6677ecfebe8caf06625cbfff0ad4a9a9b43ce..70ca861bc64cefb22c13c7d91c98eacfbef61a15 100644 (file)
@@ -95,6 +95,9 @@ public:
        configured. */
        void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false);
 
        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);
 
        /** Builds the goal targets.  The build graph must be prepared first. */
        int build(unsigned jobs = 1, bool dry_run = false, bool show_progress = false);
 
index a37336f20e886686a7873d08947d1b6855c33f4b..0a84364c988e69bee2925f405573fcff63e66d74 100644 (file)
@@ -191,7 +191,11 @@ int BuilderCLI::main()
 {
        FS::Path main_file = cwd/build_file;
        if(FS::exists(main_file))
 {
        FS::Path main_file = cwd/build_file;
        if(FS::exists(main_file))
+       {
                builder.load_build_file(main_file, &cmdline_options, conf_all);
                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);
        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(build)
                exit_code = builder.build(jobs, dry_run, show_progress);
 
+       if(!dry_run)
+               builder.save_caches();
+
        return exit_code;
 }
 
        return exit_code;
 }
 
index a2d68248d14a91fcb641b9c76c59df5e0772f896..de4643c4bf23abe1f9eb640a90756503d2e3313e 100644 (file)
@@ -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);
        }
                for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
                        write_string(out, *j);
        }
+
+       changed = false;
 }
 }
index 95ae4fbfda4f1b3137d5d6ada72ede398a294591..69025fd97911613d6f3dfbda2a14a9fb408d1cf9 100644 (file)
@@ -29,7 +29,7 @@ private:
        Msp::FS::Path filename;
        DataMap data;
        Msp::Time::TimeStamp mtime;
        Msp::FS::Path filename;
        DataMap data;
        Msp::Time::TimeStamp mtime;
-       bool changed;
+       mutable bool changed;
 
 public:
        Cache(SourcePackage &p);
 
 public:
        Cache(SourcePackage &p);
index 69abe9d0b51b929d84a50ee08f3e9d7ef2bbb673..36e7870683b3bfed9e1474306ee8adde2ce13a84 100644 (file)
@@ -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);
 
        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;
 }
 
 
 }
 
 
index 1f7fa712839f5b5bdc346681e3a346c117aafba4..3257794671530e119edcc9de67a9f78633d2d0c6 100644 (file)
@@ -41,7 +41,7 @@ private:
        OptionMap options;
        InputOptions pending_options;
        Msp::Time::TimeStamp mtime;
        OptionMap options;
        InputOptions pending_options;
        Msp::Time::TimeStamp mtime;
-       bool changed;
+       mutable bool changed;
 
 public:
        Config(SourcePackage &);
 
 public:
        Config(SourcePackage &);