]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Only dup2 stderr into $UNCACHED_ERR_FD for preprocessor/compiler
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Feb 2021 12:32:26 +0000 (13:32 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Feb 2021 12:56:29 +0000 (13:56 +0100)
Ccache dup2s the stderr FD and publishes the resulting FD number in
$UNCACHED_ERR_FD for usage by e.g. distcc. This is done any executed
child process.

As noted by Sam Varshavchik on the ccache mailing list, this leads to an
unfortunate and complex problem in combination with GNU Make, LTO
linking and the Linux PTY driver:

    https://www.mail-archive.com/ccache@lists.samba.org/msg01516.html

Since UNCACHED_ERR_FD is only relevant when running the preprocessor or
compiler, let’s only dup2 stderr when executing those, i.e. not when
falling back to just running the wrapped command such as the linker.

src/ccache.cpp
test/suites/base.bash

index 10724c95df026669783a9f6270385cc13da04bf8..1183ef9d8e8aa5474692bd7bbecb142647076d31 100644 (file)
@@ -2369,10 +2369,6 @@ do_cache_compilation(Context& ctx, const char* const* argv)
     throw Failure(Statistic::cache_miss);
   }
 
-  MTR_BEGIN("main", "set_up_uncached_err");
-  set_up_uncached_err();
-  MTR_END("main", "set_up_uncached_err");
-
   LOG("Command line: {}", Util::format_argv_for_logging(argv));
   LOG("Hostname: {}", Util::get_hostname());
   LOG("Working directory: {}", ctx.actual_cwd);
@@ -2390,6 +2386,8 @@ do_cache_compilation(Context& ctx, const char* const* argv)
     throw Failure(*processed.error);
   }
 
+  set_up_uncached_err();
+
   if (ctx.config.depend_mode()
       && (!ctx.args_info.generating_dependencies
           || ctx.args_info.output_dep == "/dev/null"
index e16741ce1d32cadc8b4feea90f1c37d5007827ef..2ed268642faff3321a025ef32e4d282195501fc4 100644 (file)
@@ -1357,7 +1357,7 @@ fi
 
     # -------------------------------------------------------------------------
 if ! $HOST_OS_WINDOWS; then
-    TEST "UNCACHED_ERR_FD"
+    TEST "UNCACHED_ERR_FD set when executing preprocessor and compiler"
 
     cat >compiler.sh <<'EOF'
 #!/bin/sh
@@ -1389,6 +1389,14 @@ EOF
     fi
 fi
 
+if ! $HOST_OS_WINDOWS; then
+    TEST "UNCACHED_ERR_FD not set when falling back to the original command"
+    # -------------------------------------------------------------------------
+
+    $CCACHE bash -c 'echo $UNCACHED_ERR_FD' >uncached_err_fd.txt
+    expect_content uncached_err_fd.txt ""
+fi
+
     # -------------------------------------------------------------------------
     TEST "Invalid boolean environment configuration options"