From 01d848149c22a69a62eada5fedc2406c54d95ba8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 5 Apr 2019 09:41:18 +0200 Subject: Support for --dry-run|-n mode, perform update part --- build2/cc/windows-manifest.cxx | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'build2/cc/windows-manifest.cxx') diff --git a/build2/cc/windows-manifest.cxx b/build2/cc/windows-manifest.cxx index 268e8c7..f890ad5 100644 --- a/build2/cc/windows-manifest.cxx +++ b/build2/cc/windows-manifest.cxx @@ -37,9 +37,9 @@ namespace build2 // Generate a Windows manifest and if necessary create/update the manifest // file corresponding to the exe{} target. Return the manifest file path - // as well as whether it was changed. + // and its timestamp if unchanged or timestamp_nonexistent otherwise. // - pair link_rule:: + pair link_rule:: windows_manifest (const file& t, bool rpath_assembly) const { tracer trace (x, "link_rule::windows_manifest"); @@ -100,13 +100,15 @@ namespace build2 // path mf (t.path () + ".manifest"); - if (exists (mf)) + timestamp mt (mtime (mf)); + + if (mt != timestamp_nonexistent) { try { - ifdstream ifs (mf); - if (ifs.read_text () == m) - return make_pair (move (mf), false); + ifdstream is (mf); + if (is.read_text () == m) + return make_pair (move (mf), mt); } catch (const io_error&) { @@ -117,18 +119,25 @@ namespace build2 if (verb >= 3) text << "cat >" << mf; - try - { - ofdstream ofs (mf); - ofs << m; - ofs.close (); - } - catch (const io_error& e) + if (!dry_run) { - fail << "unable to write to " << mf << ": " << e; + auto_rmfile rm (mf); + + try + { + ofdstream os (mf); + os << m; + os.close (); + rm.cancel (); + + } + catch (const io_error& e) + { + fail << "unable to write to " << mf << ": " << e; + } } - return make_pair (move (mf), true); + return make_pair (move (mf), timestamp_nonexistent); } } } -- cgit v1.1