I've dug a bit deeper, and found that when doing a diff between the output
of the preprocessor the resolved include path is emitted as part of the
output as a comment, in our case it's
# 1 "a/a.h" 1

There's a flag -P to the preprocessor to remove these comments.
When adding a patch to the code:

diff --git a/ccache.c b/ccache.c

index 23103ee..acfa0d8 100644

--- a/ccache.c

+++ b/ccache.c

@@ -1406,6 +1406,7 @@ get_object_name_from_cpp(struct args *args, struct
mdfour *hash)

                add_pending_tmp_file(path_stdout);



                args_add(args, "-E");

+               args_add(args, "-P");

                if (conf->keep_comments_cpp) {

                        args_add(args, "-C");

                }

I get a preprocessed cache hit.

I think this should be default, do you think there's a safety issue with
adding -P?

Thanks again

Yoav

On Thu, 12 May 2016 at 22:24 Yoav Alon <yoava...@gmail.com> wrote:

> Hi ccache,
> I'm trying to use ccache with preprocessor mode (direct_mode=false) and
> I'm unable to get cache hits.
> I have the following hierarchy:
> main.c
> includes1/a.h
> includes2/a.h
>
> main.c conatins:
> #include <stdio.h>
> #include <a.h>
> int main() {
>   printf("%s\n", __A__);
> }
>
> includes1/a.h and includes2/a.h are identical and contain just:
> #define __A__ "ccache"
>
> My compilation command is:
>
> ccache gcc -c main.c -o main.o -Iincludes1
>
> ccache gcc -c main.c -o main.o -Iincludes2
>
> And the result is two cache misses (and two new files in cache). And I
> don't understand why.
>
> this is my configuration:
>
> (default) base_dir =
>
> (default) cache_dir = /Users/yoavalon/.ccache
>
> (default) cache_dir_levels = 2
>
> (default) compiler =
>
> (default) compiler_check = mtime
>
> (default) compression = false
>
> (default) compression_level = 6
>
> (default) cpp_extension =
>
> (/Users/yoavalon/.ccache/ccache.conf) direct_mode = false
>
> (default) disable = false
>
> (default) extra_files_to_hash =
>
> (default) hard_link = false
>
> (default) hash_dir = false
>
> (/Users/yoavalon/.ccache/ccache.conf) log_file = /tmp/ccache_log
>
> (default) max_files = 0
>
> (/Users/yoavalon/.ccache/ccache.conf) max_size = 5.0G
>
> (default) path =
>
> (default) prefix_command =
>
> (default) read_only = false
>
> (default) read_only_direct = false
>
> (default) recache = false
>
> (default) run_second_cpp = false
>
> (default) sloppiness =
>
> (default) stats = true
>
> (default) temporary_dir =
>
> (default) umask =
>
> (default) unify = false
>
>
> The reason I'm seeking a cache hit when the include directory is changed
> is that our CI system always increments the version on each build for each
> dependency, thus changing the include directory for that build. reading the
> documentation I thought preprocessor mode will help me but it doesn't seem
> to work. Am i missing something?
>
> Thanks
>
> Yoav
>
_______________________________________________
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache

Reply via email to