From: Joel Rosdahl Date: Sat, 22 Feb 2020 12:14:21 +0000 (+0100) Subject: Convert stats_update(x) + failed() to failed(x) in hash_*command*() X-Git-Tag: v4.0~604 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fa94aa9428eebfbc096f4dd34be61577ba12562;p=thirdparty%2Fccache.git Convert stats_update(x) + failed() to failed(x) in hash_*command*() --- diff --git a/src/ccache.cpp b/src/ccache.cpp index f0181032e..44e96c632 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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); } } } diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 3e680dfa4..58ebcb9c5 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -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; diff --git a/src/hashutil.hpp b/src/hashutil.hpp index 560fae206..a6299186b 100644 --- a/src/hashutil.hpp +++ b/src/hashutil.hpp @@ -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); diff --git a/unittest/test_hashutil.cpp b/unittest/test_hashutil.cpp index 2abac0ab2..dca60a7b5 100644 --- a/unittest/test_hashutil.cpp +++ b/unittest/test_hashutil.cpp @@ -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);