From 0353b231d51ab7ea5ead98ac838e7c2ba1b0df89 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 20 Apr 2021 11:19:28 +0200 Subject: Track changes to environment in cc rules --- libbuild2/utility.ixx | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'libbuild2/utility.ixx') diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx index 9a77fae..3f9d34b 100644 --- a/libbuild2/utility.ixx +++ b/libbuild2/utility.ixx @@ -241,6 +241,73 @@ namespace build2 return find_option_prefixes (ps, s[var], ic); } + // hash_environment() + // + inline void + hash_environment (sha256& cs, const char* n) + { + cs.append (n); + + if (optional v = getenv (n)) + cs.append (*v); + } + + inline void + hash_environment (sha256& cs, const string& n) + { + hash_environment (cs, n.c_str ()); + } + + inline void + hash_environment (sha256& cs, initializer_list ns) + { + for (const char* n: ns) + hash_environment (cs, n); + } + + inline string + hash_environment (initializer_list ns) + { + sha256 cs; + hash_environment (cs, ns); + return cs.string (); + } + + inline void + hash_environment (sha256& cs, const strings& ns) + { + for (const string& n: ns) + hash_environment (cs, n); + } + + inline string + hash_environment (const strings& ns) + { + sha256 cs; + hash_environment (cs, ns); + return cs.string (); + } + + inline void + hash_environment (sha256& cs, const char* const* ns) + { + if (ns != nullptr) + { + for (; *ns != nullptr; ++ns) + hash_environment (cs, *ns); + } + } + + inline string + hash_environment (const char* const* ns) + { + sha256 cs; + hash_environment (cs, ns); + return cs.string (); + } + + // find_stem() + // inline size_t find_stem (const string& s, size_t s_p, size_t s_n, const char* stem, const char* seps) -- cgit v1.1