From 309cccfffc15657dd8654aa6a14e444bb47417ae Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 21 Feb 2022 22:54:05 +0300 Subject: Increment version iteration for external packages on buildfiles change --- bpkg/manifest-utility.cxx | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'bpkg/manifest-utility.cxx') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index fc54eba..f690a40 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -357,4 +357,64 @@ namespace bpkg fail << "unable to read from " << f << ": " << e << endf; } } + + string + package_buildfiles_checksum (const optional& bb, + const optional& rb, + const dir_path& d) + { + if (bb && rb) + { + sha256 cs (*bb); + cs.append (*rb); + return cs.string (); + } + + auto checksum = [&bb, &rb] (const path& b, const path& r) + { + sha256 cs; + + auto append_file = [&cs] (const path& f) + { + try + { + // Open the buildfile in the text mode and hash the NULL character + // at the end to calculate the checksum over files consistently with + // calculating it over the *-build manifest values. + // + ifdstream ifs (f); + cs.append (ifs); + cs.append ('\0'); + } + catch (const io_error& e) + { + fail << "unable to read from " << f << ": " << e; + } + }; + + if (bb) + cs.append (*bb); + else + append_file (b); + + if (rb) + cs.append (*rb); + else if (exists (r)) + append_file (r); + + return string (cs.string ()); + }; + + // Check the alternative bootstrap file first since it is more + // specific. + // + path bf; + if (exists (bf = d / alt_bootstrap_file)) + return checksum (bf, d / alt_root_file); + else if (exists (bf = d / std_bootstrap_file)) + return checksum (bf, d / std_root_file); + else + fail << "unable to find bootstrap.build file in package directory " + << d << endf; + } } -- cgit v1.1