From: Joel Rosdahl Date: Thu, 5 Jan 2012 14:49:03 +0000 (+0100) Subject: Refactor code into a hash_compiler function X-Git-Tag: v3.1.7~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c68eb939afe9526bd7d5aa7cb74f48e619ac805e;p=thirdparty%2Fccache.git Refactor code into a hash_compiler function --- diff --git a/ccache.c b/ccache.c index e35916885..8b9b5f390 100644 --- a/ccache.c +++ b/ccache.c @@ -2,7 +2,7 @@ * ccache -- a fast C/C++ compiler cache * * Copyright (C) 2002-2007 Andrew Tridgell - * Copyright (C) 2009-2011 Joel Rosdahl + * Copyright (C) 2009-2012 Joel Rosdahl * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -792,6 +792,36 @@ update_cached_result_globals(struct file_hash *hash) free(object_name); } +/* + * Hash mtime or content of a file, or the output of a command, according to + * the CCACHE_COMPILERCHECK setting. + */ +static void +hash_compiler(struct mdfour *hash, struct stat *st, const char *path, + bool allow_command) +{ + const char *compilercheck; + + compilercheck = getenv("CCACHE_COMPILERCHECK"); + if (!compilercheck) { + compilercheck = "mtime"; + } + if (str_eq(compilercheck, "none")) { + /* Do nothing. */ + } else if (str_eq(compilercheck, "mtime")) { + hash_delimiter(hash, "cc_mtime"); + hash_int(hash, st->st_size); + hash_int(hash, st->st_mtime); + } else if (str_eq(compilercheck, "content") || !allow_command) { + hash_delimiter(hash, "cc_content"); + hash_file(hash, path); + } else { /* command string */ + if (!hash_multicommand_output(hash, compilercheck, orig_args->argv[0])) { + fatal("Failure running compiler check command: %s", compilercheck); + } + } +} + /* * Update a hash sum with information common for the direct and preprocessor * modes. @@ -800,7 +830,6 @@ static void calculate_common_hash(struct args *args, struct mdfour *hash) { struct stat st; - const char *compilercheck; char *p; hash_string(hash, HASH_PREFIX); @@ -821,24 +850,7 @@ calculate_common_hash(struct args *args, struct mdfour *hash) /* * Hash information about the compiler. */ - compilercheck = getenv("CCACHE_COMPILERCHECK"); - if (!compilercheck) { - compilercheck = "mtime"; - } - if (str_eq(compilercheck, "none")) { - /* Do nothing. */ - } else if (str_eq(compilercheck, "content")) { - hash_delimiter(hash, "cc_content"); - hash_file(hash, args->argv[0]); - } else if (str_eq(compilercheck, "mtime")) { - hash_delimiter(hash, "cc_mtime"); - hash_int(hash, st.st_size); - hash_int(hash, st.st_mtime); - } else { /* command string */ - if (!hash_multicommand_output(hash, compilercheck, orig_args->argv[0])) { - fatal("Failure running compiler check command: %s", compilercheck); - } - } + hash_compiler(hash, &st, args->argv[0], true); /* * Also hash the compiler name as some compilers use hard links and