[ccache] [PATCH] support caching of translation unit dumps

Dan Aloni da-x at monatomic.org
Wed Sep 28 14:02:55 GMT 2005


Hello,

With the -fdump-translation-unit-all flag, gcc generates trnaslation
unit dumps (see docs) in the current directory. However, currently ccache
doesn't handle it, let alone cache it. I've attached a fix.

-- 
Dan Aloni
da-x at monatomic.org, da-x at colinux.org, da-x at gmx.net
-------------- next part --------------
diff --git a/ccache.c b/ccache.c
--- a/ccache.c
+++ b/ccache.c
@@ -65,6 +65,9 @@ char *stats_file = NULL;
 /* can we safely use the unification hashing backend? */
 static int enable_unify;
 
+/* compilation will generate a .tu file */
+static int has_tu_file;
+
 /* a list of supported file extensions, and the equivalent
    extension for code that has been through the pre-processor
 */
@@ -153,8 +156,9 @@ static const char *tmp_string(void)
 /* run the real compiler and put the result in cache */
 static void to_cache(ARGS *args)
 {
-	char *path_stderr;
-	char *tmp_stdout, *tmp_stderr, *tmp_hashname;
+	char *path_stderr, *path_tu;
+	char *tmp_stdout, *tmp_stderr, *tmp_hashname, *tmp_tu;
+	char *input_file_final;
 	struct stat st1, st2;
 	int status;
 
@@ -175,10 +179,24 @@ static void to_cache(ARGS *args)
 	
 	if (getenv("CCACHE_CPP2")) {
 		args_add(args, input_file);
+		input_file_final = input_file;
 	} else {
 		args_add(args, i_tmpfile);
+		input_file_final = i_tmpfile;
 	}
+
+	if (has_tu_file) {
+		char *temp_basename;
+		char temp_curdir[0x100];
+
+		x_asprintf(&temp_basename, "%s.tu", input_file_final);
+		getcwd(temp_curdir, sizeof(temp_curdir));
+		x_asprintf(&tmp_tu, "%s/%s", temp_curdir, basename(temp_basename));
+		free(temp_basename);
+	}
+
 	status = execute(args->argv, tmp_stdout, tmp_stderr);
+
 	args_pop(args, 3);
 
 	if (stat(tmp_stdout, &st1) != 0 || st1.st_size != 0) {
@@ -239,6 +257,14 @@ static void to_cache(ARGS *args)
 		failed();
 	}
 
+	if (has_tu_file) {
+		int ret;
+		x_asprintf(&path_tu, "%s.tu", hashname);
+		ret = rename(tmp_tu, path_tu);
+		free(tmp_tu);
+		free(path_tu);
+	}
+
 	cc_log("Placed %s into cache\n", output_file);
 	stats_tocache(file_size(&st1) + file_size(&st2));
 
@@ -518,6 +544,32 @@ static void from_cache(int first)
 		utime(output_file, NULL);
 	}
 
+	if (has_tu_file) {
+		char *temp_basename;
+		char *tu_destname, *path_tu;
+		char temp_curdir[0x100];
+
+		x_asprintf(&path_tu, "%s.tu", hashname);
+		x_asprintf(&temp_basename, "%s.tu", input_file);
+		getcwd(temp_curdir, sizeof(temp_curdir));
+		x_asprintf(&tu_destname, "%s/%s", temp_curdir, basename(temp_basename));
+		free(temp_basename);
+
+		if (getenv("CCACHE_HARDLINK")) {
+			ret = link(path_tu, tu_destname);
+		} else {
+			ret = copy_file(path_tu, tu_destname);
+		}
+
+		if (ret == 0) {
+			/* update the mtime on the file so that make doesn't get confused */
+			utime(tu_destname, NULL);
+		}
+
+		free(path_tu);
+		free(tu_destname);
+	}
+
 	/* get rid of the intermediate preprocessor file */
 	if (i_tmpfile) {
 		if (!direct_i_file) {
@@ -638,6 +690,10 @@ static void process_args(int argc, char 
 			failed();
 		}
 
+		if (strcmp(argv[i], "-fdump-translation-unit-all") == 0) {
+			has_tu_file = 1;
+		}
+
 		/* these are too hard */
 		if (strcmp(argv[i], "-fbranch-probabilities")==0 ||
 		    strcmp(argv[i], "-M") == 0 ||


More information about the ccache mailing list