you know what you are doing.
_a command string_::
Hash the standard output and standard error output of the specified
- command. The command is passed to +/bin/sh+ for execution. You can use
- ``$compiler'' in the command string to refer to the compiler. Example
- commands:
+ command. The string will be split on whitespace to find out the command and
+ arguments to run. No other interpretation of the command string will be
+ done, except that the special word ``%compiler%'' will be replaced with the
+ path to the compiler. Several commands can be specified with semicolon as
+ separator. Examples:
+
--
-* +$compiler -v+
-* +$compiler -dumpmachine && $compiler -dumpversion+
+* +%compiler% -v+
+* +%compiler% -dumpmachine; %compiler% -dumpversion+
You should make sure that the specified command is as fast as possible since it
will be run once for each ccache invocation.
hash_int(hash, st.st_size);
hash_int(hash, st.st_mtime);
} else { /* command string */
- char buf[8192];
- static char compiler_env[1024];
- size_t n;
- char *command;
- FILE *f;
- int status;
-
- cc_log("Running compiler check command: %s", compilercheck);
- snprintf(compiler_env, sizeof(compiler_env),
- "compiler=%s", orig_args->argv[0]);
- putenv(compiler_env);
- command = format("{ %s ; } </dev/null 2>&1", compilercheck);
- f = popen(command, "r");
- free(command);
- if (!f) {
- stats_update(STATS_COMPCHECK);
- fatal("Compiler check popen failed");
- }
- hash_delimiter(hash, "cc_command");
- while (1) {
- n = fread(buf, 1, sizeof(buf), f);
- hash_buffer(hash, buf, n);
- if (n < sizeof(buf)) {
- if (feof(f)) {
- break;
- } else {
- stats_update(STATS_COMPCHECK);
- fatal("Failed reading from compiler check command");
- }
- }
- }
- status = pclose(f);
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
- stats_update(STATS_COMPCHECK);
- fatal("Compiler check command returned %d", WEXITSTATUS(status));
+ if (!hash_multicommand_output(hash, compilercheck, orig_args->argv[0])) {
+ fatal("Failure running compiler check command: %s", compilercheck);
}
}
testname="compilercheck=command"
$CCACHE -z >/dev/null
backdate compiler.sh
- CCACHE_COMPILERCHECK='echo $compiler' $CCACHE ./compiler.sh -c test1.c
+ CCACHE_COMPILERCHECK='echo %compiler%' $CCACHE ./compiler.sh -c test1.c
checkstat 'cache hit (preprocessed)' 0
checkstat 'cache miss' 1
echo "# Compiler upgrade" >>compiler.sh
CCACHE_COMPILERCHECK="echo ./compiler.sh" $CCACHE ./compiler.sh -c test1.c
checkstat 'cache hit (preprocessed)' 1
checkstat 'cache miss' 1
- CCACHE_COMPILERCHECK='echo bar >&2' $CCACHE ./compiler.sh -c test1.c
+ CCACHE_COMPILERCHECK='echo bar' $CCACHE ./compiler.sh -c test1.c
checkstat 'cache hit (preprocessed)' 1
checkstat 'cache miss' 2
- CCACHE_COMPILERCHECK='read x; echo -n b >&2; echo ar >&2' $CCACHE ./compiler.sh -c test1.c
+ CCACHE_COMPILERCHECK='echo -n b; echo ar' $CCACHE ./compiler.sh -c test1.c
checkstat 'cache hit (preprocessed)' 2
checkstat 'cache miss' 2