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/cc/common.hxx | 4 ++++ libbuild2/cc/compile-rule.cxx | 7 ++++++- libbuild2/cc/link-rule.cxx | 11 +++++++---- libbuild2/cc/module.cxx | 14 ++++++++++++++ libbuild2/cc/module.hxx | 2 ++ 5 files changed, 33 insertions(+), 5 deletions(-) (limited to 'libbuild2/cc') diff --git a/libbuild2/cc/common.hxx b/libbuild2/cc/common.hxx index 612d081..758c675 100644 --- a/libbuild2/cc/common.hxx +++ b/libbuild2/cc/common.hxx @@ -170,6 +170,8 @@ namespace build2 const string& tsys; // x.target.system const string& tclass; // x.target.class + const string& env_checksum; // config_module::env_checksum + bool modules; // x.features.modules bool symexport; // x.features.symexport @@ -230,6 +232,7 @@ namespace build2 const process_path& path, const strings& mode, const target_triplet& tgt, + const string& env_cs, bool fm, bool fs, const dir_paths& sld, @@ -250,6 +253,7 @@ namespace build2 cmaj (mj), cmin (mi), cpath (path), cmode (mode), ctgt (tgt), tsys (ctgt.system), tclass (ctgt.class_), + env_checksum (env_cs), modules (fm), symexport (fs), importable_headers (nullptr), diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index b5016bc..ce586bb 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -197,7 +197,7 @@ namespace build2 compile_rule:: compile_rule (data&& d) : common (move (d)), - rule_id (string (x) += ".compile 4") + rule_id (string (x) += ".compile 5") { static_assert (sizeof (match_data) <= target::data_size, "insufficient space"); @@ -929,6 +929,11 @@ namespace build2 if (dd.expect (cast (rs[x_checksum])) != nullptr) l4 ([&]{trace << "compiler mismatch forcing update of " << t;}); + // Then the compiler environment checksum. + // + if (dd.expect (env_checksum) != nullptr) + l4 ([&]{trace << "environment mismatch forcing update of " << t;}); + // Then the options checksum. // // The idea is to keep them exactly as they are passed to the compiler diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx index 9c72969..0ab61b1 100644 --- a/libbuild2/cc/link-rule.cxx +++ b/libbuild2/cc/link-rule.cxx @@ -37,7 +37,7 @@ namespace build2 link_rule:: link_rule (data&& d) : common (move (d)), - rule_id (string (x) += ".link 2") + rule_id (string (x) += ".link 3") { static_assert (sizeof (match_data) <= target::data_size, "insufficient space"); @@ -2427,10 +2427,13 @@ namespace build2 l4 ([&]{trace << "linker mismatch forcing update of " << t;}); } - // Hash and compare any changes to the environment. + // Then the linker environment checksum (original and our modifications). // - if (dd.expect (env_cs.string ()) != nullptr) - l4 ([&]{trace << "environment mismatch forcing update of " << t;}); + { + bool e (dd.expect (env_checksum) != nullptr); + if (dd.expect (env_cs.string ()) != nullptr || e) + l4 ([&]{trace << "environment mismatch forcing update of " << t;}); + } // Next check the target. While it might be incorporated into the linker // checksum, it also might not (e.g., VC link.exe). diff --git a/libbuild2/cc/module.cxx b/libbuild2/cc/module.cxx index 5bb3f60..7ef8cd5 100644 --- a/libbuild2/cc/module.cxx +++ b/libbuild2/cc/module.cxx @@ -202,8 +202,22 @@ namespace build2 } } + // Hash the environment (used for change detection). + // + // Note that for simplicity we use the combined checksum for both + // compilation and linking (which may compile, think LTO). + // + { + sha256 cs; + hash_environment (cs, xi.compiler_environment); + hash_environment (cs, xi.platform_environment); + env_checksum = cs.string (); + } + // Assign values to variables that describe the compiler. // + // @@ TODO: env_checksum. + // rs.assign (x_path) = process_path_ex (xi.path, x_name, xi.checksum); const strings& xm (cast (rs.assign (x_mode) = move (mode))); diff --git a/libbuild2/cc/module.hxx b/libbuild2/cc/module.hxx index f9d435d..ed6ec41 100644 --- a/libbuild2/cc/module.hxx +++ b/libbuild2/cc/module.hxx @@ -59,6 +59,8 @@ namespace build2 const compiler_info* x_info; + string env_checksum; // Environment checksum (also in x.path). + // Temporary storage for data::sys_*_dirs_*. // size_t sys_lib_dirs_mode; -- cgit v1.1