]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert stats_update(x) + failed() to failed(x) in hash_*command*()
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 12:14:21 +0000 (13:14 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 20:53:27 +0000 (21:53 +0100)
src/ccache.cpp
src/hashutil.cpp
src/hashutil.hpp
unittest/test_hashutil.cpp

index f0181032e86790e7cfc75baab78f5680a60dcbd3..44e96c63283d2b6824517107213ace5ce7547175 100644 (file)
@@ -1496,12 +1496,11 @@ hash_compiler(Context& ctx,
     hash_delimiter(hash, "cc_content");
     hash_file(hash, path);
   } else { // command string
-    bool ok = hash_multicommand_output(
-      ctx, hash, ctx.config.compiler_check().c_str(), ctx.orig_args->argv[0]);
-    if (!ok) {
+    if (!hash_multicommand_output(
+          hash, ctx.config.compiler_check().c_str(), ctx.orig_args->argv[0])) {
       cc_log("Failure running compiler check command: %s",
              ctx.config.compiler_check().c_str());
-      failed();
+      failed(STATS_COMPCHECK);
     }
   }
 }
index 3e680dfa4185b00aff19dc54315768e99b7bf582..58ebcb9c54726160c93b028cd69a4511003c022b 100644 (file)
@@ -285,8 +285,7 @@ hash_source_code_file(const Config& config, struct hash* hash, const char* path)
 }
 
 bool
-hash_command_output(Context& ctx,
-                    struct hash* hash,
+hash_command_output(struct hash* hash,
                     const char* command,
                     const char* compiler)
 {
@@ -361,14 +360,12 @@ hash_command_output(Context& ctx,
     free((char*)command); // Original argument was replaced above.
   }
   if (ret == 0) {
-    stats_update(ctx, STATS_COMPCHECK);
     return false;
   }
   int fd = _open_osfhandle((intptr_t)pipe_out[0], O_BINARY);
   bool ok = hash_fd(hash, fd);
   if (!ok) {
     cc_log("Error hashing compiler check command output: %s", strerror(errno));
-    stats_update(ctx, STATS_COMPCHECK);
   }
   WaitForSingleObject(pi.hProcess, INFINITE);
   DWORD exitcode;
@@ -378,7 +375,6 @@ hash_command_output(Context& ctx,
   CloseHandle(pi.hThread);
   if (exitcode != 0) {
     cc_log("Compiler check command returned %d", (int)exitcode);
-    stats_update(ctx, STATS_COMPCHECK);
     return false;
   }
   return ok;
@@ -409,7 +405,6 @@ hash_command_output(Context& ctx,
     if (!ok) {
       cc_log("Error hashing compiler check command output: %s",
              strerror(errno));
-      stats_update(ctx, STATS_COMPCHECK);
     }
     close(pipefd[0]);
 
@@ -420,7 +415,6 @@ hash_command_output(Context& ctx,
     }
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
       cc_log("Compiler check command returned %d", WEXITSTATUS(status));
-      stats_update(ctx, STATS_COMPCHECK);
       return false;
     }
     return ok;
@@ -429,8 +423,7 @@ hash_command_output(Context& ctx,
 }
 
 bool
-hash_multicommand_output(Context& ctx,
-                         struct hash* hash,
+hash_multicommand_output(struct hash* hash,
                          const char* commands,
                          const char* compiler)
 {
@@ -440,7 +433,7 @@ hash_multicommand_output(Context& ctx,
   char* saveptr = NULL;
   bool ok = true;
   while ((command = strtok_r(p, ";", &saveptr))) {
-    if (!hash_command_output(ctx, hash, command, compiler)) {
+    if (!hash_command_output(hash, command, compiler)) {
       ok = false;
     }
     p = NULL;
index 560fae20681113e2b9a2918c5a560f6ebfc0af39..a6299186b8d3b46a98443f319879459123346dd0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2019 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2020 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -44,11 +44,9 @@ int hash_source_code_string(const Config& config,
 int hash_source_code_file(const Config& config,
                           struct hash* hash,
                           const char* path);
-bool hash_command_output(Context& ctx,
-                         struct hash* hash,
+bool hash_command_output(struct hash* hash,
                          const char* command,
                          const char* compiler);
-bool hash_multicommand_output(Context& ctx,
-                              struct hash* hash,
+bool hash_multicommand_output(struct hash* hash,
                               const char* command,
                               const char* compiler);
index 2abac0ab2ef09dd4de584234b4b85f07df4fe57f..dca60a7b56c55db311239d0ae00c890939a57ee8 100644 (file)
@@ -27,16 +27,14 @@ TEST_SUITE(hashutil)
 
 TEST(hash_command_output_simple)
 {
-  Context ctx;
-
   char d1[DIGEST_STRING_BUFFER_SIZE];
   char d2[DIGEST_STRING_BUFFER_SIZE];
 
   struct hash* h1 = hash_init();
   struct hash* h2 = hash_init();
 
-  CHECK(hash_command_output(ctx, h1, "echo", "not used"));
-  CHECK(hash_command_output(ctx, h2, "echo", "not used"));
+  CHECK(hash_command_output(h1, "echo", "not used"));
+  CHECK(hash_command_output(h2, "echo", "not used"));
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
   CHECK_STR_EQ(d1, d2);
@@ -55,8 +53,8 @@ TEST(hash_command_output_space_removal)
   struct hash* h1 = hash_init();
   struct hash* h2 = hash_init();
 
-  CHECK(hash_command_output(ctx, h1, "echo", "not used"));
-  CHECK(hash_command_output(ctx, h2, " echo ", "not used"));
+  CHECK(hash_command_output(h1, "echo", "not used"));
+  CHECK(hash_command_output(h2, " echo ", "not used"));
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
   CHECK_STR_EQ(d1, d2);
@@ -75,8 +73,8 @@ TEST(hash_command_output_hash_inequality)
   struct hash* h1 = hash_init();
   struct hash* h2 = hash_init();
 
-  CHECK(hash_command_output(ctx, h1, "echo foo", "not used"));
-  CHECK(hash_command_output(ctx, h2, "echo bar", "not used"));
+  CHECK(hash_command_output(h1, "echo foo", "not used"));
+  CHECK(hash_command_output(h2, "echo bar", "not used"));
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
   CHECK(!str_eq(d1, d2));
@@ -95,8 +93,8 @@ TEST(hash_command_output_compiler_substitution)
   struct hash* h1 = hash_init();
   struct hash* h2 = hash_init();
 
-  CHECK(hash_command_output(ctx, h1, "echo foo", "not used"));
-  CHECK(hash_command_output(ctx, h2, "%compiler% foo", "echo"));
+  CHECK(hash_command_output(h1, "echo foo", "not used"));
+  CHECK(hash_command_output(h2, "%compiler% foo", "echo"));
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
   CHECK_STR_EQ(d1, d2);
@@ -118,12 +116,12 @@ TEST(hash_command_output_stdout_versus_stderr)
 #ifndef _WIN32
   create_file("stderr.sh", "#!/bin/sh\necho foo >&2\n");
   chmod("stderr.sh", 0555);
-  CHECK(hash_command_output(ctx, h1, "echo foo", "not used"));
-  CHECK(hash_command_output(ctx, h2, "./stderr.sh", "not used"));
+  CHECK(hash_command_output(h1, "echo foo", "not used"));
+  CHECK(hash_command_output(h2, "./stderr.sh", "not used"));
 #else
   create_file("stderr.bat", "@echo off\r\necho foo>&2\r\n");
-  CHECK(hash_command_output(ctx, h1, "echo foo", "not used"));
-  CHECK(hash_command_output(ctx, h2, "stderr.bat", "not used"));
+  CHECK(hash_command_output(h1, "echo foo", "not used"));
+  CHECK(hash_command_output(h2, "stderr.bat", "not used"));
 #endif
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
@@ -146,12 +144,12 @@ TEST(hash_multicommand_output)
 #ifndef _WIN32
   create_file("foo.sh", "#!/bin/sh\necho foo\necho bar\n");
   chmod("foo.sh", 0555);
-  CHECK(hash_multicommand_output(ctx, h2, "echo foo; echo bar", "not used"));
-  CHECK(hash_multicommand_output(ctx, h1, "./foo.sh", "not used"));
+  CHECK(hash_multicommand_output(h2, "echo foo; echo bar", "not used"));
+  CHECK(hash_multicommand_output(h1, "./foo.sh", "not used"));
 #else
   create_file("foo.bat", "@echo off\r\necho foo\r\necho bar\r\n");
-  CHECK(hash_multicommand_output(ctx, h2, "echo foo; echo bar", "not used"));
-  CHECK(hash_multicommand_output(ctx, h1, "foo.bat", "not used"));
+  CHECK(hash_multicommand_output(h2, "echo foo; echo bar", "not used"));
+  CHECK(hash_multicommand_output(h1, "foo.bat", "not used"));
 #endif
   hash_result_as_string(h1, d1);
   hash_result_as_string(h2, d2);
@@ -168,7 +166,7 @@ TEST(hash_multicommand_output_error_handling)
   struct hash* h1 = hash_init();
   struct hash* h2 = hash_init();
 
-  CHECK(!hash_multicommand_output(ctx, h2, "false; true", "not used"));
+  CHECK(!hash_multicommand_output(h2, "false; true", "not used"));
 
   hash_free(h2);
   hash_free(h1);