]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix empty <obj>.ccache-log in debug mode without log_file set
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 25 Feb 2020 21:02:50 +0000 (22:02 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 25 Feb 2020 21:03:02 +0000 (22:03 +0100)
Regression in dcf6ab3f349a33974b31ce2e7c06a2085149ab4a.

src/logging.cpp
src/logging.hpp
test/suites/base.bash

index 3ef5c785b5019cc5beb7e090cb71307df2de4438..e1c7fcdd46a8447e9166cdab7c1c42cf18521fdf 100644 (file)
@@ -63,39 +63,30 @@ static size_t debug_log_size;
 #define DEBUG_LOG_BUFFER_MARGIN 1024
 
 // Initialize logging. Call only once.
-bool
+void
 init_log(const Config& config)
 {
-  logfile_path = config.log_file();
-
-  if (logfile_path.empty()) {
-    return false;
-  }
-
   if (config.debug()) {
     debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN;
     debug_log_buffer = static_cast<char*>(x_malloc(debug_log_buffer_capacity));
     debug_log_size = 0;
   }
-  if (config.log_file().empty()) {
-    return config.debug();
-  }
+
 #ifdef HAVE_SYSLOG
   if (config.log_file() == "syslog") {
     use_syslog = true;
     openlog("ccache", LOG_PID, LOG_USER);
-    return true;
+    return; // Don't open logfile
   }
 #endif
+
+  logfile_path = config.log_file();
   logfile = fopen(logfile_path.c_str(), "a");
-  if (logfile) {
 #ifndef _WIN32
+  if (logfile) {
     set_cloexec_flag(fileno(logfile));
-#endif
-    return true;
-  } else {
-    return false;
   }
+#endif
 }
 
 static void
index a07c539200057ff49290124712be7f7268301cef..80bddf64bfed1237001002d37c4d9cb6e9b551cd 100644 (file)
@@ -24,7 +24,7 @@
 
 class Config;
 
-bool init_log(const Config& config);
+void init_log(const Config& config);
 void cc_log(const char* format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_bulklog(const char* format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_log_argv(const char* prefix, char** argv);
index e625b34dfe0d292fc22988f8f090fa9e09cd5002..1c0b132dceed80ef0626010c52dd03dc20625164 100644 (file)
@@ -296,6 +296,24 @@ base_tests() {
     expect_stat 'cache miss' 2
     expect_stat 'files in cache' 1
 
+    # -------------------------------------------------------------------------
+    TEST "CCACHE_DEBUG"
+
+    unset CCACHE_LOGFILE
+    unset CCACHE_NODIRECT
+    CCACHE_DEBUG=1 $CCACHE_COMPILE -c test1.c
+    if ! grep -q Result: test1.o.ccache-log; then
+        test_failed "Unexpected data in <obj>.ccache-log"
+    fi
+    if ! grep -q "PREPROCESSOR MODE" test1.o.ccache-input-text; then
+        test_failed "Unexpected data in <obj>.ccache-input-text"
+    fi
+    for ext in c p d; do
+        if ! [ -f test1.o.ccache-input-$ext ]; then
+            test_failed "<obj>.ccache-input-$ext missing"
+        fi
+    done
+
     # -------------------------------------------------------------------------
     TEST "CCACHE_DISABLE"