From 40863a594372ede117533d5c0970a96d60e34371 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Apr 2021 10:10:34 +0200 Subject: Incorporate project environment checksum into cc::compiler_info cache key --- libbuild2/cc/guess.cxx | 17 +++++++++++++++++ libbuild2/cc/guess.hxx | 4 ++++ libbuild2/cc/module.cxx | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'libbuild2/cc') diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx index 839bf20..ff96466 100644 --- a/libbuild2/cc/guess.cxx +++ b/libbuild2/cc/guess.cxx @@ -1577,6 +1577,9 @@ namespace build2 // but we include them in case linking is done via the compiler without // loading bin.ld. BTW, the same applies to rc.exe INCLUDE. // + // See also the note on environment and caching below if adding any new + // variables. + // static const char* msvc_env[] = {"INCLUDE", "IFCPATH", "CL", "_CL_", "LIB", "LINK", "_LINK_", nullptr}; @@ -1822,6 +1825,9 @@ namespace build2 // would need to detect which linker is being used at which point we might // as well load bin.ld). // + // See also the note on environment and caching below if adding any new + // variables. + // static const char* gcc_c_env[] = { "CPATH", "C_INCLUDE_PATH", "LIBRARY_PATH", "LD_RUN_PATH", @@ -2275,6 +2281,8 @@ namespace build2 // These are derived from gcc_* plus the sparse documentation (clang(1)) // and source code. // + // See also the note on environment and caching below if adding any new + // variables. // static const char* clang_c_env[] = { "CPATH", "C_INCLUDE_PATH", @@ -3064,6 +3072,7 @@ namespace build2 const compiler_info& guess (const char* xm, lang xl, + const string& ec, const path& xc, const string* xis, const string* xv, @@ -3075,6 +3084,13 @@ namespace build2 { // First check the cache. // + // Note that in case of MSVC (and Clang targeting MSVC) sys_*_dirs can + // be affected by the environment (INCLUDE, LIB, and IFCPATH) which is + // project-specific. So we have to include those into the key. But we + // don't know yet know whether it's those compilers/targets. So it seems + // we have no better choice than to include the project environment if + // overridden. + // // @@ We currently include config.{cc,x}.[pc]options into the key which // means any project-specific tweaks to these result in a different // key. Perhaps we should assume that any options that can affect the @@ -3087,6 +3103,7 @@ namespace build2 sha256 cs; cs.append (static_cast (xl)); cs.append (xc.string ()); + if (!ec.empty ()) cs.append (ec); if (xis != nullptr) cs.append (*xis); append_options (cs, x_mo); if (c_po != nullptr) append_options (cs, *c_po); diff --git a/libbuild2/cc/guess.hxx b/libbuild2/cc/guess.hxx index 6bab649..0180c97 100644 --- a/libbuild2/cc/guess.hxx +++ b/libbuild2/cc/guess.hxx @@ -173,6 +173,9 @@ namespace build2 // search paths (similar to the PATH environment variable), in which case // it will end with a directory separator but will not contain '*'. // + // Watch out for the environment variables affecting any of the extracted + // information (like sys_*_dirs) since we cache it. + // struct compiler_info { process_path path; @@ -252,6 +255,7 @@ namespace build2 const compiler_info& guess (const char* xm, // Module (for var names in diagnostics). lang xl, // Language. + const string& ec, // Environment checksum. const path& xc, // Compiler path. const string* xi, // Compiler id (optional). const string* xv, // Compiler version (optional). diff --git a/libbuild2/cc/module.cxx b/libbuild2/cc/module.cxx index 98e0451..44f1943 100644 --- a/libbuild2/cc/module.cxx +++ b/libbuild2/cc/module.cxx @@ -154,7 +154,9 @@ namespace build2 // we are now folding *.std options into mode options. // x_info = &build2::cc::guess ( - x, x_lang, move (xc), + x, x_lang, + rs.root_extra->environment_checksum, + move (xc), cast_null (lookup_config (rs, config_x_id)), cast_null (lookup_config (rs, config_x_version)), cast_null (lookup_config (rs, config_x_target)), -- cgit v1.1