[ccache] [PATCH] add support for '@' parameters

Andrew Boie andrew.p.boie at intel.com
Fri Jul 27 15:45:26 MDT 2012


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.boie at 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



More information about the ccache mailing list