diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-01-20 16:25:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-01-20 16:25:34 +0200 |
commit | 214f1f05dfb3f2ae2090e491f3dd78836076c2e0 (patch) | |
tree | 3c9ce42b2cd783dc120ee727fa3dff6a8da3c25a /libbuild2 | |
parent | 70e095024ab33404ba0cf20c184a7a9560bca5f0 (diff) |
Add in::rule::perform_update_{pre,post}() hooks
Also fix bug in depdb line parsing.
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/in/rule.cxx | 40 | ||||
-rw-r--r-- | libbuild2/in/rule.hxx | 10 |
2 files changed, 41 insertions, 9 deletions
diff --git a/libbuild2/in/rule.cxx b/libbuild2/in/rule.cxx index faf1ec1..2117b0e 100644 --- a/libbuild2/in/rule.cxx +++ b/libbuild2/in/rule.cxx @@ -255,6 +255,9 @@ namespace build2 assert (v); // Rule semantics change without version increment? + if (p3 != string::npos) + p3 -= p2; // Hash length. + if (s->compare (p2, p3, sha256 (*v).string ()) == 0) { dd_skip++; @@ -336,7 +339,7 @@ namespace build2 #endif auto_rmfile arm (tp); - // Note: this default will only be used if the file if empty (i.e., + // Note: this default will only be used if the file is empty (i.e., // does not contain even a newline). // const char* nl ( @@ -347,8 +350,8 @@ namespace build2 #endif ); - string s; // Reuse the buffer. - for (uint64_t ln (1);; ++ln) + uint64_t ln (1); + for (string s;; ++ln) { what = "read"; whom = &ip; if (!getline (ifs, s)) @@ -361,22 +364,31 @@ namespace build2 if (crlf) s.pop_back(); + what = "write"; whom = &tp; + if (ln != 1) + ofs << nl; + + nl = crlf ? "\r\n" : "\n"; // Preserve the original line ending. + + if (ln == 1) + perform_update_pre (a, t, ofs, nl); + // Not tracking column for now (see also depdb above). // process (location (ip, ln), a, t, dd, dd_skip, s, 0, - (crlf ? "\r\n" : "\n"), sym, strict, null); + nl, sym, strict, null); - what = "write"; whom = &tp; - if (ln != 1) - ofs << nl; // See below. ofs << s; - - nl = crlf ? "\r\n" : "\n"; // Preserve the original line ending. } + what = "write"; whom = &tp; + if (ln == 1) + perform_update_pre (a, t, ofs, nl); + perform_update_post (a, t, ofs, nl); + // Close depdb before closing the output file so its mtime is not // newer than of the output. // @@ -416,6 +428,16 @@ namespace build2 } void rule:: + perform_update_pre (action, const target&, ofdstream&, const char*) const + { + } + + void rule:: + perform_update_post (action, const target&, ofdstream&, const char*) const + { + } + + void rule:: process (const location& l, action a, const target& t, depdb& dd, size_t& dd_skip, diff --git a/libbuild2/in/rule.hxx b/libbuild2/in/rule.hxx index 1294586..33caea4 100644 --- a/libbuild2/in/rule.hxx +++ b/libbuild2/in/rule.hxx @@ -66,6 +66,16 @@ namespace build2 virtual void perform_update_depdb (action, const target&, depdb&) const; + // Pre/post update. + // + virtual void + perform_update_pre (action, const target&, + ofdstream&, const char* newline) const; + + virtual void + perform_update_post (action, const target&, + ofdstream&, const char* newline) const; + // Perform variable lookup. // // Flags can be used by a custom implementation to alter the lookup |