// modes and calculate the result name. Returns the result name on success,
// otherwise NULL. Caller frees.
static struct digest*
-calculate_result_name(struct args* args, struct hash* hash, int direct_mode)
+calculate_result_name(struct args* args,
+ struct args* preprocessor_args,
+ struct hash* hash,
+ bool direct_mode)
{
bool found_ccbin = false;
cc_log("Did not find result name in manifest");
}
} else {
+ assert(preprocessor_args);
if (arch_args_size == 0) {
- result_name = get_result_name_from_cpp(args, hash);
+ result_name = get_result_name_from_cpp(preprocessor_args, hash);
cc_log("Got result name from preprocessor");
} else {
- args_add(args, "-arch");
+ args_add(preprocessor_args, "-arch");
for (size_t i = 0; i < arch_args_size; ++i) {
- args_add(args, arch_args[i]);
- result_name = get_result_name_from_cpp(args, hash);
+ args_add(preprocessor_args, arch_args[i]);
+ result_name = get_result_name_from_cpp(preprocessor_args, hash);
cc_log("Got result name from preprocessor with -arch %s", arch_args[i]);
if (i != arch_args_size - 1) {
free(result_name);
result_name = NULL;
}
- args_pop(args, 1);
+ args_pop(preprocessor_args, 1);
}
- args_pop(args, 1);
+ args_pop(preprocessor_args, 1);
}
if (generating_dependencies) {
// Nothing is actually created with -MF /dev/null
if (g_config.direct_mode()) {
cc_log("Trying direct lookup");
MTR_BEGIN("hash", "direct_hash");
- result_name = calculate_result_name(args_to_hash, direct_hash, 1);
+ result_name =
+ calculate_result_name(args_to_hash, nullptr, direct_hash, true);
MTR_END("hash", "direct_hash");
if (result_name) {
update_cached_result_globals(result_name);
cpp_hash, output_obj, 'p', "PREPROCESSOR MODE", debug_text_file);
MTR_BEGIN("hash", "cpp_hash");
- result_name = calculate_result_name(args_to_hash, cpp_hash, 0);
+ result_name =
+ calculate_result_name(args_to_hash, preprocessor_args, cpp_hash, false);
MTR_END("hash", "cpp_hash");
if (!result_name) {
fatal("internal error: calculate_result_name returned NULL for cpp");
# -------------------------------------------------------------------------
TEST "Handling of compiler-only arguments"
- $CCACHE_COMPILE -c test1.c
+ cat >compiler.sh <<EOF
+#!/bin/sh
+printf "[%s]" "\$*" >>compiler.args
+[ \$1 = -E ] && echo test || echo test >test1.o
+EOF
+ chmod +x compiler.sh
+ backdate compiler.sh
+
+ $CCACHE ./compiler.sh -c test1.c
expect_stat 'cache hit (preprocessed)' 0
expect_stat 'cache miss' 1
expect_stat 'files in cache' 1
+ if [ -z "$CCACHE_NOCPP2" ]; then
+ expect_file_content compiler.args "[-E test1.c][-c -o test1.o test1.c]"
+ fi
+ rm compiler.args
- $CCACHE_COMPILE -c test1.c
+ $CCACHE ./compiler.sh -c test1.c
expect_stat 'cache hit (preprocessed)' 1
expect_stat 'cache miss' 1
expect_stat 'files in cache' 1
+ expect_file_content compiler.args "[-E test1.c]"
+ rm compiler.args
# Even though -Werror is not passed to the preprocessor, it should be part
# of the hash, so we expect a cache miss:
- $CCACHE_COMPILE -c -Werror test1.c
+ $CCACHE ./compiler.sh -c -Werror -rdynamic test1.c
expect_stat 'cache hit (preprocessed)' 1
expect_stat 'cache miss' 2
expect_stat 'files in cache' 2
+ if [ -z "$CCACHE_NOCPP2" ]; then
+ expect_file_content compiler.args "[-E test1.c][-Werror -rdynamic -c -o test1.o test1.c]"
+ fi
+ rm compiler.args
# -------------------------------------------------------------------------
TEST "Dependency file content"