[ccache] [PATCH] CCACHE_BASEDIR and dependency file creation (-MD/-MMD)
Hi, I am creating dependency files with my gcc compile, with something like: gxx -c -MMD -MF _dep_file.d -o _out_file.o and am using CCACHE_BASEDIR to share the cache across different work boxes. Both _dep_file.d and _out_file.o are absolute paths and start with CCACHE_BASEDIR. Looking at the code, my understanding is that if ccache determines that dependencies are being created it does the following: - If -MF is not specified, ccache add -MF _out_file.d to the preprocessor args. - Similarly if -MQ is not specified, it adds -MQ _out_file.o to the preprocessor args. These arguments are also used in the hash calculation. I see that ccache does not seem to strip out CCACHE_BASEDIR from them. This seems to be the reason I am not getting any hits in the subsequent compiles in other work spaces. I have appended a patch against ccache version 3.1.7 that fixes this. I would appreciate if it could be reviewed (and hopefully incorporated into ccache). Thanks, Lalit Chhabra --- ccache-3.1.7/ccache.c 2012-01-08 06:40:55.0 -0800 +++ ccache-3.1.7.mod/ccache.c 2012-07-26 18:40:04.268732000 -0700 @@ -1414,7 +1414,6 @@ char *arg; dependency_filename_specified = true; free(output_dep); - args_add(dep_args, argv[i]); if (strlen(argv[i]) == 3) { /* -MF arg */ if (i = argc - 1) { @@ -1424,13 +1423,14 @@ goto out; } arg = argv[i + 1]; - args_add(dep_args, argv[i + 1]); i++; } else { /* -MFarg */ arg = argv[i][3]; } output_dep = make_relative_path(x_strdup(arg)); + args_add(dep_args, -MF); + args_add(dep_args, output_dep); continue; } if (str_startswith(argv[i], -MQ) || str_startswith(argv[i], -MT)) { @@ -1726,11 +1726,13 @@ * Add flags for dependency generation only to the preprocessor command line. */ if (generating_dependencies) { + char *stripped_output_obj; + stripped_output_obj = make_relative_path(x_strdup(output_obj)); if (!dependency_filename_specified) { char *default_depfile_name; char *base_name; - base_name = remove_extension(output_obj); + base_name = remove_extension(stripped_output_obj); default_depfile_name = format(%s.d, base_name); free(base_name); args_add(dep_args, -MF); @@ -1740,8 +1742,9 @@ if (!dependency_target_specified) { args_add(dep_args, -MQ); - args_add(dep_args, output_obj); + args_add(dep_args, stripped_output_obj); } + free(stripped_output_obj); } if (compile_preprocessed_source_code) { ___ ccache mailing list ccache@lists.samba.org https://lists.samba.org/mailman/listinfo/ccache
Re: [ccache] ccache problem with CCACHE_BASEDIR
Hi, It seems you forgot to make cwd_canonicalized static? Currently, it has no effect. Also, the test suite crashes with your patch. I recommend running the test suite during development even for minor patches (and for bonus points: add new tests for the new functionality :-)). The crash happens because realpath returns NULL for nonexisting paths, and the test suite sets up fake paths for some parameters; this could happen in real usage as well. So, the code needs to handle x_realpath returning NULL. Thinking more about this, it would probably be better to (instead of realpath) use some function that doesn't expand symlinks and doesn't care whether the path exists or not. I'm not aware of such an existing (and portable) function, though, so we likely will have to write it ourselves. -- Joel On 20 July 2012 19:45, Eric Blau eric.b...@tekelec.com wrote: On 2012-07-20 13:09, Joel Rosdahl wrote: Thanks. Two things: 1. The patch canonicalizes the from parameter, but I think that the to parameter should be canonicalized as well, for two reasons: a) realpath() expands symlinks, and comparing (see common_dir_prefix_length) an expanded path with an unexpanded path won't work well when symlinks are present. b) The to parameter (which for instance may be a path given on the command line) could also contain path elements that could benefit from canonicalization (to increase cache hits). 2. The patch canonicalizes the from parameter every time get_relative_path is called, which is unnecessary since it's always the same. Therefore, as mentioned earlier, I think that its' better to do the canonicalization in make_relative_path where current_working_dir can be canonicalized when created. Thanks for the comments. Please discard the previous patch. This attached version of the patch should be better. It canonicalizes the current working directory once and canonicalizes the path each time get_relative_path is called. Thanks, Eric ___ ccache mailing list ccache@lists.samba.org https://lists.samba.org/mailman/listinfo/ccache ___ ccache mailing list ccache@lists.samba.org https://lists.samba.org/mailman/listinfo/ccache
[ccache] [PATCH] add support for '@' parameters
These indicate to the compiler that additional command line options should be read from a text file. If encountered, read the file, tokenize any arguments, and if any are found, do an in-place replacement of the '@' parameter with the arguments within the file. Signed-off-by: Andrew Boie andrew.p.b...@intel.com --- ccache.c | 56 +++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/ccache.c b/ccache.c index 692b222..4b7ff6a 100644 --- a/ccache.c +++ b/ccache.c @@ -1432,9 +1432,63 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, goto out; } + if (str_startswith(argv[i], @)) { + char *argpath = argv[i] + 1; + struct args *file_args; + char *argdata; + int j; + + if (!(argdata = read_text_file(argpath, 0))) { + cc_log(Coudln't read arg file %s, argpath); + stats_update(STATS_ARGS); + result = false; + goto out; + } + + file_args = args_init_from_string(argdata); + free(argdata); + + if (file_args-argc == 0) { + args_free(file_args); + continue; + } + + free(argv[i]); /* Will be replaced */ + if (file_args-argc == 1) { + argv[i] = x_strdup(file_args-argv[0]); + args_free(file_args); + i--; + continue; + } + + /* Expand argv to hold both current and file +* arguments */ + orig_args-argv = (char**)x_realloc(orig_args-argv, + (orig_args-argc + file_args-argc) * + sizeof(char *)); + /* Move all unprocessed arguments to the end of the +* new list */ + for (j = orig_args-argc; j i; j--) { + orig_args-argv[j + file_args-argc - 1] = + orig_args-argv[j]; + } + /* Fill in the space we just made with the +* new arguments. Current '@' argument gets +* replaced */ + for (j = 0; j file_args-argc; j++) { + orig_args-argv[j + i] = + x_strdup(file_args-argv[j]); + } + orig_args-argc += file_args-argc - 1; + args_free(file_args); + argc = orig_args-argc; + argv = orig_args-argv; + i--; + continue; + } + /* These are always too hard. */ if (compopt_too_hard(argv[i]) - || str_startswith(argv[i], @) || str_startswith(argv[i], -fdump-)) { cc_log(Compiler option %s is unsupported, argv[i]); stats_update(STATS_UNSUPPORTED); -- 1.7.9.5 ___ ccache mailing list ccache@lists.samba.org https://lists.samba.org/mailman/listinfo/ccache